Repository navigation
perf(gateway): reduce artifact and membership read round trips - #166447
Conversation
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.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
|
Codex review: needs maintainer review before merge. Reviewed October 7, 2026, 8:48 AM ET / 12:48 UTC (Revision 4). ClawSweeper reviewWhat this changesThe 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 Review scores
Verification
How this fits togetherGateway 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]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +30, Tests +203, Docs +3. Total +236 across 25 files. View PR surface stats
Review metrics
Technical reviewBest 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. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles) |
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.
|
Verified merge 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 Those additional failures remain visible: the allocation benchmark's 12 expected/actual wire-hash pairs reproduce exactly on clean main The synthetic reconnect benchmark passed on |
…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
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.artifacts.listartifacts.downloadsession.members.listEvidenceAll 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.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:
pnpm test src/gateway/server-methods/artifacts.prepared.test.ts --maxWorkers=1pnpm test src/config/sessions/session-sharing-store.worker.test.ts --maxWorkers=1Independent 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 treeac5b79ece58fdbb3c43376178176c13b803b5b45.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.tssibling 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.listp99 was 21.9 seconds in that synthetic workload. All owned census leases were stopped. The repaired head8223db6292bb1b05365e38bd211525c9a4969ab0passed CI run 37622804774 and merged as23dae69850132c4d43e1fcc8885396a7f545cebb. 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
1f576e4a4a210394aac7f82774d0afc6cabe7a2ereproduced 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.tsobserved 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 main1f576e4; source equality alone does not establish independence. The fresh single-case main reproduction on blacksmith-testboxtbx_01m4b4jbp25r3tr541edm6kbm2never 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.