Skip to content

perf(gateway): reduce artifact and membership read round trips - #166447

Merged
steipete merged 3 commits into
mainfrom
steipete/perf-micro-artifacts-members-evidence-20260919
Oct 7, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/perf-micro-artifacts-members-evidence-20260919

Conversation

@steipete

@steipete steipete commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Artifact reads repeat session-store discovery for already admitted sessions, and membership evidence queues a second metadata read behind transcript history.

User Impact

Faster artifact lists, small downloads, and membership evidence. Current visibility, foreign SQLite changes, caller revocation, and message-scoped download lookup remain enforced. No schema, configuration, stored-data, or update migration.

Why This Change Was Made

Session management, discovery, reactions, and artifact reads now share physical-store selection. Artifact authorization refreshes the stored entry through one admitted projection-worker read; resident metadata alone never grants access. Incognito, filesystem aliases, excluded sessions, and run-specific selectors retain their existing custody contracts.

Membership evidence and current session metadata come from one SQLite snapshot, carrying the canonical-reader continuation. This removes the separate history-lane request while retaining fresh ownership checks. Artifact extraction remains transcript-backed; authorization is request-scoped, and downloads retain their exact artifact/message binding.

Production LOC: +30 (353 added, 323 removed; excludes tests, test support, and docs). The existing permission contract requires observing foreign writes. The direct fresh-entry read and snapshot/continuation transport account for the growth; duplicated selectors and the second membership metadata read are removed.

Evidence

Sequential baseline/candidate handler benchmark on an isolated Ubuntu rig, Node 26.8.1: 100 calls per method after five warmups, a 912-byte artifact, 64 profiles, 128 session creators, and four members. Both runs used baseline c6168a9597e8, with the candidate patch applied for the second run. Candidate file hashes matched the reviewed source.

Method Before avg / p99 After avg / p99
artifacts.list 6.94 / 9.51 ms 2.95 / 4.89 ms
artifacts.download 6.47 / 7.68 ms 3.05 / 3.39 ms
session.members.listEvidence 12.10 / 18.91 ms 3.66 / 4.66 ms

All candidate p99s meet the 150 ms small-payload target in this fixture. Production latency under mixed load remains unmeasured.

Blacksmith Testbox (blacksmith-testbox, openclaw-check):

  • tbx_01m49yq6j881mftkcv4ed38xew: corrected authorization/worker regressions — 44 tests passed. The original membership handler fails the real-handler regression when transcript work is held busy.
  • tbx_01m4a7gbrzh6b56v070ahk4z6q (run): artifact/RPC/run-scope/profile coverage — 125 passed, one opt-in benchmark skipped; HTTPS download integration — one passed; pnpm build — passed in 3m48.5s.
  • Original artifact code fails the new regression by reacquiring session facts twice. A resident-only implementation fails the foreign-visibility assertion; the corrected implementation passes both contracts.

Changed-file gate, run on the authorized Linux rig after the Testbox admission delay: node scripts/check-changed.mjs --staged — exit 0. All 27 test type graphs passed (2,012.1s combined); lint reported zero warnings/errors across 22 files (37.1s); storage, schema, import, media, and authorization guards passed. Source hashes matched after the gate.

Regression cost, on Testbox with one worker:

Command Result Wall time
pnpm test src/gateway/server-methods/artifacts.prepared.test.ts --maxWorkers=1 1 passed; 2.90s test time 25.27s
pnpm test src/config/sessions/session-sharing-store.worker.test.ts --maxWorkers=1 15 passed 25.33s

Independent Codex review of the integrated candidate: scoped-clean through P2. The candidate includes main 1f576e4a4a210394aac7f82774d0afc6cabe7a2e; the sharing test retains main's prepared request context and the typed session-replacement refusal.

The final repair also retains the existing live-manager check after the combined membership read. A real-handler regression uses a synthetic foreign SQLite write and the normal selection projection to publish a different creator while preserving the session identity and lifecycle. The unfixed candidate returns member evidence as the former owner; the repaired candidate refuses it. This synchronous authority check adds no database read.

On blacksmith-testbox tbx_01m4atwp4zpk2ne9rb7kze950n, all eight changed test files passed (75 tests). Export-name collision checking passed, followed by both source-closure guards and the test-plan guard (134 tests). Every command verified the complete materialized candidate tree ac5b79ece58fdbb3c43376178176c13b803b5b45.

On blacksmith-testbox tbx_01m4aw2k7grs6bfgyfc3day3s9, the pinned scoped gate passed all 34 checks in 2,007.9 seconds, including production types, 27 core test type graphs, lint, dead exports, cycles, and storage guards. Command: node scripts/check-changed.mjs --base 1f576e4a4a210394aac7f82774d0afc6cabe7a2e --staged -- src/gateway/server-methods/sessions-sharing.ts src/gateway/server-methods/sessions-sharing.test.ts src/gateway/server-methods/sessions-sharing.authority.test.ts. An initial invocation used the moving hydrated main ref and included unrelated line-cap paths; the corrected invocation pinned the actual base and did not skip guards.

The new authority regression takes 1.467 seconds in the test body; its four-test file passed in 34.86 seconds of runner time (48.854 seconds including the remote command and source checks). The repair retains a synchronous live-authority check and adds no database read. The original latency measurements above precede this restoration; post-repair production latency remains unmeasured.

The final census covers 1,994 files on candidate tree ac5b79ece58fdbb3c43376178176c13b803b5b45: 1,978 passed, three failed, and 13 wholly gated/skipped, with no missing or unclassified file outcomes. It includes every direct *.test.ts sibling in touched production directories plus the changed state test. The three observed failures are disclosed below. Guarded live collection is not live provider/device proof.

The final synthetic reconnect benchmark passed on blacksmith-testbox tbx_01m4b5k2h4nxvxm346n636gdaw (run): OPENCLAW_STARTUP_RECONNECT_BENCH=1 node scripts/run-vitest.mjs src/gateway/server-startup-reconnect.benchmark.test.ts, 5,000 sessions and 20 loopback clients over a 120-second window; one test passed, 187.68 seconds Vitest time. This is functional completion, not a clean latency result: cron.list p99 was 21.9 seconds in that synthetic workload. All owned census leases were stopped. The repaired head 8223db6292bb1b05365e38bd211525c9a4969ab0 passed CI run 37622804774 and merged as 23dae69850132c4d43e1fcc8885396a7f545cebb. The landed tree matches the reviewed head merged with its actual main parent; no inherited-failure bypass was used.

One sibling failure remains under investigation: server.private-completion.test.ts / “publishes failure and retains retry when the worker commit refuses queued-abort” observed an abort controller still present after execution settlement. A clean-main single-file run passed all 23 tests; the original 12-file batch, in the same order on the same Testbox profile and Node 24.19, passed all 296 tests (528.594 seconds, tbx_01m4b30gnt55awb7137ac52jjt). Nine immediate fixture/producer blobs match main and candidate. Settlement and terminal-persistence cleanup may race, but no safe cause or fix is established. This is an unresolved observed failure, not a green or independently qualified inherited result.

The allocation benchmark's captured-wire assertion also failed. Clean main 1f576e4a4a210394aac7f82774d0afc6cabe7a2e reproduced it on the isolated Linux rig under Node 24.19: all 12 expected and all 12 actual hashes match the candidate failure byte for byte. No hashes were updated. The assertion prevents claiming a completed allocation measurement.

The workspace-plugin E2E case in src/gateway/gateway.test.ts observed two registrations instead of one after a successful /tools/invoke. Its 27 inspected test/runner/plugin-load inputs and the complete plugin/agent trees are unchanged from integrated main 1f576e4; source equality alone does not establish independence. The fresh single-case main reproduction on blacksmith-testbox tbx_01m4b4jbp25r3tr541edm6kbm2 never ran: it was stopped while still queued after exact-head CI passed and the landed tree was verified. No replacement proof run was scheduled. The earlier-main reproduction is not reused because three relevant provider inputs changed in the meantime. This remains an investigated local failure with unresolved attribution; green CI does not prove its cause or a fix.

Share prepared physical session selection while refreshing stored artifact
visibility through an admitted direct reader. Read membership evidence and
current session metadata in one projection-worker snapshot, retaining the
canonical-reader continuation and current disclosure authority.

Preserve message-scoped downloads, foreign-write checks, aliases, incognito
custody, and run-specific session resolution. Remove duplicated selectors.

Validated with focused Testbox regressions, HTTP artifact downloads, a full
production build, the staged change gate, and independent review. Synthetic
912-byte artifact p99 improves from 9.51/7.68ms to 4.89/3.39ms for list/download;
membership evidence p99 improves from 18.91ms to 4.66ms.
@clawsweeper

clawsweeper Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: 8223db6292bb1b05365e38bd211525c9a4969ab0
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/gateway/server-methods/sessions-sharing-authority.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.

Carefully review these changes before merging.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: L labels Oct 7, 2026
@steipete
steipete enabled auto-merge (squash) October 7, 2026 04:21
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 7, 2026
@clawsweeper

clawsweeper Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 7, 2026, 8:48 AM ET / 12:48 UTC (Revision 4).

ClawSweeper review

What this changes

The Gateway shares session-store selection across handlers and reads membership evidence with session metadata in one worker snapshot, reducing repeated database work.

Merge readiness

✅ Ready for maintainer review

This PR still provides distinct performance work absent from current main. The repaired head preserves disclosure authorization, and no remaining introduced correctness or security defect was found.

Priority: P2
Reviewed head: 8223db6292bb1b05365e38bd211525c9a4969ab0

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, useful optimization with meaningful boundary proof and repaired live authorization; remaining measurement limitations are accurately disclosed.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): Recorded isolated handler and HTTPS runs exercise artifact reads, while final-tree production-handler regressions exercise real SQLite ownership reassignment and deny disclosure to the former owner. Original timing figures are not final-repair latency proof. Source confirms no stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): Recorded isolated handler and HTTPS runs exercise artifact reads, while final-tree production-handler regressions exercise real SQLite ownership reassignment and deny disclosure to the former owner. Original timing figures are not final-repair latency proof. Source confirms no stored-data contract changes.
Evidence reviewed 10 items Pinned introduction: Reviewed the introduced base-to-head changes. The exact head records parents 39131b2 and 1f576e4, and tree ac5b79ece58fdbb3c43376178176c13b803b5b45 matches the final Testbox evidence identity. The supplied test merge is stale and was not used to infer removal of main behavior.
Still necessary on main: Fetched main still prepares artifact access through prepareSessionMutationFacts and acquires member evidence separately from the subsequent entry read. The central optimization has not landed through the related receipt-publication work.
Latest-release comparison: The v2026.9.8 artifact resolver uses the earlier synchronous sharing-target lookup and does not contain this prepared worker-read implementation. This is a release comparison, not a claim that the PR has shipped.
Findings None None.
Security None None.

How this fits together

Gateway artifact and sharing handlers receive authenticated session requests and select the owning SQLite store. They read transcript artifacts or membership evidence, then check current disclosure authority before returning results.

flowchart TD
  A[Authenticated request] --> B[Shared session selection]
  B --> C[Owning SQLite store]
  C --> D[Artifact transcript read]
  C --> E[Membership and metadata snapshot]
  D --> F[Current disclosure checks]
  E --> F
  F --> G[Response or refusal]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +30, Tests +203, Docs +3. Total +236 across 25 files.

View PR surface stats
Area Files Added Removed Net
Source 15 353 323 +30
Tests 8 246 43 +203
Docs 2 12 9 +3
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 25 611 375 +236

Review metrics

Metric Value Why it matters
Production versus test growth production +30 net lines; tests +203 net lines Production growth is explained by fresh-entry acquisition and snapshot transport while duplicated selectors are removed.

Technical review

Best possible solution:

Use one physical-session selection owner and one membership snapshot while preserving fresh stored visibility and synchronous authorization at disclosure.

Do we have a high-confidence way to reproduce the issue?

Not applicable to a functional bug report: source confirms repeated read work on main, and the supplied isolated handler measurements exercise the targeted performance paths.

Is this the best way to solve the issue?

Yes. Consolidating existing selection and read owners removes round trips without introducing a competing cache, changing stored state, or weakening final disclosure checks.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against ccadf6ace875.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded Gateway read-performance improvement with meaningful authorization coverage and no demonstrated urgent user regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): Recorded isolated handler and HTTPS runs exercise artifact reads, while final-tree production-handler regressions exercise real SQLite ownership reassignment and deny disclosure to the former owner. Original timing figures are not final-repair latency proof. Source confirms no stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. Recorded isolated handler and HTTPS runs exercise artifact reads, while final-tree production-handler regressions exercise real SQLite ownership reassignment and deny disclosure to the former owner. Original timing figures are not final-repair latency proof. Source confirms no stored-data contract changes.

Evidence

What I checked:

  • Pinned introduction: Reviewed the introduced base-to-head changes. The exact head records parents 39131b2 and 1f576e4, and tree ac5b79ece58fdbb3c43376178176c13b803b5b45 matches the final Testbox evidence identity. The supplied test merge is stale and was not used to infer removal of main behavior. (8223db6292bb)
  • Still necessary on main: Fetched main still prepares artifact access through prepareSessionMutationFacts and acquires member evidence separately from the subsequent entry read. The central optimization has not landed through the related receipt-publication work. (src/gateway/server-methods/artifacts-session-resolution.ts:140, ccadf6ace875)
  • Latest-release comparison: The v2026.9.8 artifact resolver uses the earlier synchronous sharing-target lookup and does not contain this prepared worker-read implementation. This is a release comparison, not a claim that the PR has shipped. (src/gateway/server-methods/artifacts-session-resolution.ts, fc23bc864e45)
  • Membership authority at disclosure: The handler calls access.assertCurrent after the combined worker read, then access.current(entry) before replying. This checks the live manager independently of the returned stored snapshot. The new real-handler regression changes the creator through foreign SQLite I/O, publishes through the normal selection projection, preserves session identity and lifecycle, and verifies refusal of the former owner. (src/gateway/server-methods/sessions-sharing.authority.test.ts:82, 8223db6292bb)
  • Artifact freshness and revocation: The artifact resolver refreshes stored visibility through the admitted projection reader while retaining physical identity and lifecycle checks. The handler regression exercises real SQLite and transcript owners, denies both list and download after foreign visibility changes, and refuses a download when visibility changes during transcript acquisition. (src/gateway/server-methods/artifacts.prepared.test.ts:109, 8223db6292bb)
  • Stored-data compatibility: The new kernel performs existing entry and member queries in a synchronous deferred read transaction. Changes affect internal worker result envelopes and their consumers; there is no DDL, persisted-format rewrite, config default, retention change, or migration. Incognito consumers were updated together. (src/config/sessions/session-sharing-store.kernel.ts:24, 8223db6292bb)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Vincent Koc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (3 earlier review cycles)
  • reviewed 2026-10-07T04:24:18.078Z sha 24a78c4 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-07T05:05:19.919Z sha 39131b2 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-07T05:23:16.322Z sha 39131b2 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Oct 7, 2026
Merge main to preserve the sharing fixture's prepared request context while
keeping the typed session-replacement refusal.

Recheck current management rights after the membership snapshot settles. An
older stored creator must not authorize disclosure after a published ownership
change. The real-handler regression retains the session identity and lifecycle,
then verifies that the former owner cannot receive member evidence.

Keep the artifact and membership read reduction without adding another database
read or changing schemas, configuration, or writer permissions.
@steipete
steipete merged commit 23dae69 into main Oct 7, 2026
137 checks passed
@steipete
steipete deleted the steipete/perf-micro-artifacts-members-evidence-20260919 branch October 7, 2026 12:57
@steipete

steipete commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor Author

Verified merge 23dae69850132c4d43e1fcc8885396a7f545cebb of reviewed head 8223db6292bb1b05365e38bd211525c9a4969ab0. Exact-head CI run 37622804774 passed, and the existing watcher completed the squash. The landed tree exactly matches that head merged with the actual main parent 86b83b74b4c68e147277b022b517c0d8b5322c16. No inherited-failure bypass, CI rerun, refresh-only branch update, or CI workflow dispatch was used for this repaired head.

Review found and fixed a real PR-caused authority race: an older membership snapshot could authorize the former owner after current ownership changed. The repair restores the live-manager check immediately after the awaited snapshot, preserving both current authority and snapshot authorization without adding a database read. A real-handler negative control reproduces disclosure on the unfixed candidate; the repaired regression passes. Independent full-candidate review is scoped-clean through P2.

On blacksmith-testbox tbx_01m4atwp4zpk2ne9rb7kze950n, all eight changed test files passed (75 tests), export-name collision checking passed, and both source-closure guards plus the test-plan guard passed (134 tests). tbx_01m4aw2k7grs6bfgyfc3day3s9 passed all 34 pinned scoped checks in 2,007.9 seconds, including production types and 27 core test type graphs. Complete candidate sibling coverage recorded 1,978 passed, three failed, and 13 fully gated/skipped files out of 1,994; no file outcome is missing.

Those additional failures remain visible: the allocation benchmark's 12 expected/actual wire-hash pairs reproduce exactly on clean main 1f576e4; the private-completion controller-cleanup assertion remains unexplained after both a clean-main single-file run and the original ordered 12-file Testbox batch passed; and the workspace-plugin registration assertion remains unqualified because its fresh baseline lease was stopped while queued after this green-CI landing. Older-main proof was not reused across changed provider inputs. Green CI does not turn these observed failures into fixes. The 13 full skips cover 12 external-live files and one Windows-only file.

The synthetic reconnect benchmark passed on tbx_01m4b5k2h4nxvxm346n636gdaw (run), but measured a 21.9-second cron.list p99; it has no passing latency threshold. Original artifact/membership latency improvements precede the final synchronous authority-check restoration, and production latency after that repair remains unmeasured. The PR body retains the measurements and limitations.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 8, 2026
…law#166447)

* perf(gateway): reduce artifact and membership read round trips

Share prepared physical session selection while refreshing stored artifact
visibility through an admitted direct reader. Read membership evidence and
current session metadata in one projection-worker snapshot, retaining the
canonical-reader continuation and current disclosure authority.

Preserve message-scoped downloads, foreign-write checks, aliases, incognito
custody, and run-specific session resolution. Remove duplicated selectors.

Validated with focused Testbox regressions, HTTP artifact downloads, a full
production build, the staged change gate, and independent review. Synthetic
912-byte artifact p99 improves from 9.51/7.68ms to 4.89/3.39ms for list/download;
membership evidence p99 improves from 18.91ms to 4.66ms.

* test(gateway): expect typed refusal for replaced sharing targets
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. security-sensitive-changed size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant