Repository navigation
perf(sessions): serve remaining per-turn session authority reads from workers - #165028
Conversation
… workers Move current chat admission, reply authority, lifecycle preparation, verbosity, and maintenance reads through existing workers. Retain physical source identity and foreign-commit freshness, preserve accepted lifecycle settlement through close, and carry prepared transcript selection facts.
Join accepted event batches and listener settlement in fixtures. Keep restart metadata preparation with the work-admission owner and make callback this contracts explicit.
|
🦞👀 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. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Codex review: needs maintainer review before merge. Reviewed October 5, 2026, 1:50 PM ET / 17:50 UTC (Revision 32). ClawSweeper reviewWhat this changesMoves session reads for reply delivery, restart recovery, lifecycle persistence, progress visibility, and maintenance admission into existing workers while preserving synchronous plugin callbacks. Merge readiness✅ Ready for maintainer review The broader worker migration remains useful on current main. The committed fence repair and recorded qualification address the previous ACP blocker; no actionable correctness or security findings remain. Priority: P2 Review scores
Verification
How this fits togetherThe Gateway uses stored session facts to authorize turns, deliver replies, and persist lifecycle outcomes. Existing database workers prepare those facts while Gateway owners retain current authority and join accepted work before shutdown. flowchart TD
A[Incoming turns and lifecycle events] --> B[Gateway session owners]
B --> C[Retained store discovery]
C --> D[Ordered database worker reads]
D --> E[Current authority checks]
E --> F[Reply delivery and lifecycle writes]
F --> G[Accepted work settles before shutdown]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +452, Tests +1083, Docs +11, Other -10. Total +1536 across 77 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep session reads with existing workers, preserve current authority at consumption and commit, and settle accepted lifecycle work before teardown. Do we have a high-confidence way to reproduce the issue? Not applicable to the performance migration itself; the repaired fence failure has a concrete real-membership regression and recorded failing-before/passing-after qualification. Is this the best way to solve the issue? Yes. The patch extends existing worker and lifecycle owners, retains released callbacks, and couples final reply decisions to one current snapshot. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against d511ab92b63a. 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 (31 earlier review cycles; latest 8 shown)
|
Merge main to resolve session admission and event-test conflicts. Preserve the qualified worker-backed admission owner from #164682 and main's consolidated tests, awaiting asynchronous event handling where required. Reuse internal-effects filtering across both Gateway read paths.\n\nThe complete candidate is clean through P2 autoreview. Focused conflict tests and remaining changed-check and published-driver update gates are tracked on #165028.
Use the existing async-aware event subscription helper in the consolidated verbosity test. The previous merge retained the plain unsubscribe callback while awaiting its drain method, causing a TypeError before the assertions. The corrected event-handler file passes all 82 tests. Together with the four unchanged passing files, the integrated focused group covers 163 cases. The one-line fixture correction is clean through P2 autoreview.
Merge main's transcript-context lane while retaining its prepared-start validation and released callback compatibility. Use the captured session initialization binding instead of a caller-thread session read, and combine context validation with lifecycle facts in the final anchor snapshot. Focused reply, anchor, context, runtime-build and import checks pass. P2 review raised a conditional global-alias concern, rejected after independent source tracing: the final read uses an admission receipt created from the selected stored key, and mismatched admission/session keys are refused beforehand. No actionable review finding remains.
Await asynchronous agent-event consumers and projection disposal. Move lifecycle fault injection to prepared callbacks, and track accepted writes through owner-controlled persistence before fixture cleanup. Initialize runtime config before observing row publications.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
🦞👀 Re-review progress:
|
Incorporate the media facade cleanup from #165631 and the independently reproduced activation-wrapper export fix. Preserve the session-authority cutover alongside main's accepted message-injection settlement and fresh user-turn input custody. All policy assertions stay intact. The full candidate P2 and independent integration reviews are clean. The resulting tree is identical to the reviewed candidate; the published main repair is retained as the second parent. Refreshed qualification follows.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
A row publication before ordered FIFO admission describes state the coming snapshot will include. Starting the outer fence earlier can exhaust its refresh budget and reject current sharing facts before dispatch starts. Validate retained discovery and begin the caller fence after every selected FIFO is admitted, before the first snapshot. Keep physical-store, alias, source, and revocation fencing active during capture and consumption. The new callback is internal and performs no SQL or database admission. A real-membership regression fails on the previous owner and passes after this change. Existing lookup, ordered-read, and pending-input owner suites pass, as do all 12 ACP completion cases locally. The isolated regression takes 11.98s wall time including wrapper setup; no timeout, retry, or assertion was weakened. Scoped lint, types, and P2 review pass.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
Populate gateway method descriptors from the fixture's existing lazy handlers. The dispatcher now consumes descriptors, so the handler-only fixture rejects its synthetic method before reaching lazy preparation. Keep admin scope, timing, exporter, authorization, and cleanup assertions unchanged. Found while qualifying openclaw#165028; the original failure reproduced in all five runs on its head and all five runs on the incorporated main baseline.
… workers (openclaw#165028) * perf(sessions): serve remaining per-turn session authority reads from workers Move current chat admission, reply authority, lifecycle preparation, verbosity, and maintenance reads through existing workers. Retain physical source identity and foreign-commit freshness, preserve accepted lifecycle settlement through close, and carry prepared transcript selection facts. * refactor(sessions): finish async admission cutover Join accepted event batches and listener settlement in fixtures. Keep restart metadata preparation with the work-admission owner and make callback this contracts explicit. * test(sessions): drain the merged event subscription fixture Use the existing async-aware event subscription helper in the consolidated verbosity test. The previous merge retained the plain unsubscribe callback while awaiting its drain method, causing a TypeError before the assertions. The corrected event-handler file passes all 82 tests. Together with the four unchanged passing files, the integrated focused group covers 163 cases. The one-line fixture correction is clean through P2 autoreview. * test(gateway): finish async lifecycle fixture cutover Await asynchronous agent-event consumers and projection disposal. Move lifecycle fault injection to prepared callbacks, and track accepted writes through owner-controlled persistence before fixture cleanup. Initialize runtime config before observing row publications. * test(gateway): preserve lifecycle fixture module exports Use partial mocks for lifecycle preparation, session entry writes, and worker reads. Remove the three obsolete mock-factory baseline entries. The five affected tests, typed core lint, mock-export scanner, and P2 review pass. * test(gateway): serialize malformed-row fixture writes Join the physical-store writer queue before inserting the malformed fixture row. Session replacement starts asynchronous maintenance; an uncoordinated synchronous host write can block the admission callback a worker needs to release its SQLite lock. Preserve the raw bytes, post-admission position, lack of publication, and all assertions. The original lock reproduced in CI and one of five head controls; the targeted repaired case, typed lint, formatting, and P2 review pass. The separate slow handle-cap case remains recorded in local controls. * test(gateway): settle Talk fixture lifecycle work before reseeding Join observed request and root work, accepted lifecycle preparation, and transcript publication before clearing the shared Talk fixture. Writer queue draining alone cannot see preparation still waiting on worker reads. Reuse the existing observer and preparation tracker; preserve every Talk behavior assertion and the real persistence path. A controlled probe showed cleanup could outpace accepted preparation, but did not identify the exact CI conflicting writer. The repaired Node 24 full file passes all eight cases; its exact CI merge/shard composition passes all 297 tests. Typed lint, formatting, and P2 review pass. No timer, retry, production API, or per-test Gateway boot is added. * test(reply): isolate Slack lease cleanup from admission readiness Keep request admission on its real scheduler and control only post-resolver handoff and final settlement with fake time. Replace the one-second resolver poll with an explicit owned gate, preserve delivery assertions, and verify lease release at its configured 25 ms bound. Move the unchanged Slack fixture into the existing harness to satisfy the line cap. All 132 dispatch cases pass; an omitted final release still fails the lease assertion; P2 review is clean. * test(gateway): share private completion recorder assertions Move the unchanged recorder checks into existing private-completion fixture support while preserving the parent callback and current-session binding. This resolves the Testbox line-cap failure without removing assertions or changing deadlines. Full private-completion proof passes 23 cases in 338.21 seconds; typed lint, line cap, formatting, and P2 review pass. * refactor(meetings): keep fixture-only types in test support * test(gateway): reuse session projection fixture seeds * test(gateway): construct complete exporter method descriptors Use the production plugin descriptor constructor so the synthetic RPC fixture supplies the required profileAccess contract. The handler-map conversion helper returns input descriptors intended for later normalization, not the completed descriptors stored by the plugin registry. Keep the same lazy handlers, method names, admin scope, and runtime assertions. The exact failing root-test type graph and all ten method-registry cases pass. * test(gateway): align projection fixture comment with main * fix(sessions): fence sharing snapshots after writer admission A row publication before ordered FIFO admission describes state the coming snapshot will include. Starting the outer fence earlier can exhaust its refresh budget and reject current sharing facts before dispatch starts. Validate retained discovery and begin the caller fence after every selected FIFO is admitted, before the first snapshot. Keep physical-store, alias, source, and revocation fencing active during capture and consumption. The new callback is internal and performs no SQL or database admission. A real-membership regression fails on the previous owner and passes after this change. Existing lookup, ordered-read, and pending-input owner suites pass, as do all 12 ACP completion cases locally. The isolated regression takes 11.98s wall time including wrapper setup; no timeout, retry, or assertion was weakened. Scoped lint, types, and P2 review pass.
Retain the prompt admission through terminal emission and join its accepted terminal writes before finalization seals the saved continuation. Explicit close and replacement still revoke immediately. The asynchronous lookup introduced by #165028 let sealing overtake the cancellation write. The unchanged Gateway regression passes on the parent, fails on that commit, and passes with this fix.
) Retain the prompt admission through terminal emission and join its accepted terminal writes before finalization seals the saved continuation. Explicit close and replacement still revoke immediately. The asynchronous lookup introduced by openclaw#165028 let sealing overtake the cancellation write. The unchanged Gateway regression passes on the parent, fails on that commit, and passes with this fix.
What Problem This Solves
Gateway turns still perform synchronous session-authority reads during reply delivery, lifecycle persistence, restart recovery, and maintenance admission.
User Impact
Part A of the session-authority migration moves these reads to existing workers while preserving fresh authority, FIFO ordering, and teardown settlement. Schemas, retention, durability, permissions, configuration, and released synchronous plugin callbacks remain unchanged. The diff adds zero new
OPENCLAW_*names.The coordinator-approved original workload reduced warmed main-thread SQL from 223.8 to 186.8 statements/turn (−16.53%). Total SQL increased 9.14% on workers; off-main share rose from 82.86% to 85.40%. Worker read amplification remains follow-up work. These are original-head execution counts, not latency claims or a benchmark of the integrated candidate.
Why This Change Was Made
Capture physical store identity before yielding, consume fresh worker-owned rows, and revalidate live run and routing authority immediately before side effects. Initialization supplies the transcript-start binding; the final anchor snapshot includes lifecycle facts. The lifecycle owner joins accepted preparation and persistence before teardown, including when parent scheduling is cancelled.
The final-reply lookup now precedes the final anchor snapshot, preventing a reproduced transcript-branch switch after the anchor decision from returning
delivered. Lifecycle aliases use the worker lookup's canonical identity for the same FIFO. Header and session facts share one deferred snapshot; replay/context checks remain outside its narrow best-effort header catch. Main's qualified admission, session projection, message-injection settlement, current user-turn ownership, transcript-context validation, and commentary-media custody remain intact.Related: #162433. Overlap with #165181, #165193, #165236, #165275, #165470 and the stacked tool-authority and observer/hook parts stays focused. No other PR branch was changed. Children #165205 and #165370 retain this branch as their base until landing.
Evidence
Candidate and qualification
Head:
44f2dc5c239e8bdc5d3c6fd9b9c4347ba5c9c132Tree:
2fc578375d26ceaf461c6c6905c2cf4d95b4e2beIntegrated main:
d5fbbe86a807404123534306615595be89b2f1f3The exact combined tree passed the new sharing-freshness regression, all 12 ACP completion cases, and all 250 cases in the original 26-file CI group on Linux/Node 24.19.0 (run). Wall times were 49s, 132s, and 595s. The source/tree was verified around every gate; the lease is fully released.
Full
check:changedpassed in 2,668s on parent11c4881, including all 27 core-test type graphs, extension production/test types, Knip, lint, ratchets and final guards. Its nine focused tail gates passed 56 selected tests, including ordered reads, pending/withdrawn input authority, worker custody, projection, imports/build guards, transcript mirrors and RPC exporters (run). The lease is fully released. Selectors' nonmatching tests are skips, not additional passes.The five-file successor only repairs the ordered-read publication fence and registers its regression in the existing database-worker test lane. A source-bound applicability audit retains the fullcheck and package/update proof for unchanged contracts; the current delta receives fresh format/lint/types/ratchets, SDK, P2, native review, CI and ClawSweeper qualification. No prior-head receipt is relabeled as current-head CI or a new package. All 13 successor static checks passed: formatting, typed lint, semantic core/Gateway test types, and the affected ratchets/temp-creation check. Fresh P2 review with all three production owners is clean. Native exact-head review and preparation passed. CI run 37349931413 completed successfully with 85 successful jobs and 23 skipped. ClawSweeper revision 32 completed at 2026-10-05 17:50 UTC on this exact head, with no actionable correctness/security findings and nothing required before merge. Native landing follows these exact-head gates.
Sharing-facts fence repair
Parent CI run 37340906733 failed one ACP shard and its aggregate: two scenarios reported
GatewaySessionFactsChangedDuringReadError, and the abort/persistence-failure scenario timed out waiting for runtime start. Main's scheduled run 37333951369 independently showed the same sharing-facts error.Five serial full-file controls on each of parent and main base reproduced that error 5/5 on both. The PR had materially more failing scenarios and three 120s timeouts, so this interaction was repaired before landing rather than classified as unchanged inherited severity. The original Linux group failed 9/250 before the repair. The failed CI job log was fetched once; no CI rerun was used.
44f2dc5cbegins the caller's publication fence after source validation and all ordered FIFO admissions, immediately before the first snapshot. Previously, predecessor writes completed before admission could exhaust the refresh allowance even though the upcoming snapshot included them. Physical-store, cross-owner alias, registry, source and revocation checks remain active throughout snapshot capture and synchronous consumption. The internal synchronous callback adds no SQL, database admission, snapshot subprocess, or retry allowance.A real-membership regression fails on the original main owner and passes after repair; it requires an actual member and exactly one consumption. Local lookup/ordered/pending-authority owners passed 37 cases in 81.13s wall, and the new regression plus full ACP file passed 13 cases in 81.58s wall. The isolated regression cost 1.382s test / 11.98s wall. The exact successor Linux proof above confirms the original failing group passes without weakened assertions, sleeps, timeouts or retries. The identical five-file repair was also published directly to main as
d511ab92b63ae9709ff13eb87da9c4707060dbc4after fresh current-main regression/ACP proof (13 cases, 84.70s wall) and clean P2 review. No unrelated main integration was added to this candidate.Slack readiness repair
afa1a5e51d83b1ee1747930aa9e561c348cf08f5repairs a fixture prerequisite exposed by this branch. The old one-second resolver poll expired before request gathering completed. Admission now keeps its real scheduler; fake time starts only at the resolver for post-resolver settlement. An owned gate replaces polling, while delivery, the 25ms handoff, 30s no-reply deadline, final 25ms cleanup and lease-release assertions remain intact.The full dispatch suite passed 132/132 in 300.98s; the Slack case took 1.178s. A negative control omitting final lease release fails at the active-lease assertion. On integrated
c487eadd, readiness passed again in 1.472s test / 80.52s wall. Its dispatch/admission/scheduler/fixture inputs remain unchanged. The precise asynchronous dependency behind the old readiness delay was not isolated; this is fixture readiness/clock ownership evidence, not a claim of a Slack production bug. No new Gateway boot or production test seam was added.Released SDK and published-driver boundary
Changed functions were traced through
src/plugin-sdkexports, runtime APIs, documented subpaths, and releasedv2026.9.8source. Released synchronous callback shapes are retained; new async readers and the relocated helper are internal. The new ordered admission hook is internal too. The native report conservatively includes its declaration in a wildcard subtree, which requires a refreshed report but does not make it a public export or justify compatibility scaffolding.Parent
11c4881native SDK comparison passed in 195.300s, digest408de91ca583d05fbc6354c9ecf52ec8dfe40fa5cb08cc5a72860da46fd5cc98, with zero PR-scoped compatibility findings. The fresh successor44f2dc5creport passed in 244.758s, digeste5246f6040e7d9360b53eaf51ffd9d173ae006a9dbb02111e2487d111590a46d, with zero introduced compatibility findings. Its sole declaration change from the parent is the internal optionalonReadAdmittedcallback; dependent closure hashes follow that change. Release-wide main-owned removals of the persistent-dedupe migration functions/types from #165288 remain outside this PR's API delta; no function-specific removal record was found, and this report is not blanket approval of upstream release compatibility.Parent
11c4881package/integrity passed in 669s, tarball SHA-2565c588e42f960f3e5ad41869eeac2e6e0cd028d2e5cb063e653d6991fdf64028e. Its published-2026.9.8-driver update cell passed in 456s. Candidate, durable after-record and live service agree on2026.9.8-11c4881282ee-2026-10-05T16-35-24.857Z, distinct from the release. Readiness was 200, the service settled, durable history was unchanged, incognito history was empty (1,073 files/six databases scanned), and PID replacement/orphan-sidecar assertions passed. The lease is released. Update/service/bootstrap/schema/wire/packaging owners and harness inputs are unchanged by the five-file repair; this remains evidence for the named parent artifact, not a newly built successor.Earlier failure disposition and follow-up debt
Main was merged for independently proven failures. The dead policy-wrapper export was reproduced on pristine main and repaired in
d5fbbe86(all three Knip scans, 57 policy/state tests and P2 passed); #165631 supplied the obsolete media-facade export repair. The missing wrapper inventory module was independently fixed by #165572. The RPC exporter fixture failed 5/5 on head and 5/5 on main after main removed descriptor fallback; registration was repaired through the production descriptor owner. A lander-introduced incomplete descriptor type was corrected in248f3812; main independently supplied its equivalent inb9f2ea649750. Current integration retains main's canonical implementation and assertions.The inherited projection fixture exceeded its unchanged deadline in all five head and five baseline controls. Setup now seeds 29 agents once per mode while retaining all six combinations, twelve requests, measured/warm pairs and count/probe assertions; the fix passed Linux and subsequent full checks. No timeout or budget was raised. Real async-caller, prepared-write, fixture-settlement and partial-module-mock defects were also repaired and reviewed. Main's BOOT/cron routing, catalog types, dead exports and obsolete ratchet entries were incorporated without weakening baselines.
Earlier reset-authority, Talk and usage failures were not conclusively attributed after the required controls. The reset group passed 198/198 and five full files on each head/base; no fix is inferred from those passes. Talk's one authorized diagnostic replay repeated its failure. A separate controlled probe proved premature cleanup of accepted preparation; the owner now joins it before restoring shared state, and all eight cases plus the 297-case group pass, without claiming conclusive attribution of the original stale-row error. Usage's five head/base files and one replay passed; its original failure remains unproven. Current-head CI remains independently required.
Original authority/lifecycle proof includes foreign commits, physical-source replacement, post-await revocation, close-prelude draining and maintenance; the final-anchor regression fails before repair. Historical CI run
37231973459used 8,882 summed Node-test runner-seconds including co-sharded tests/setup, not incremental PR cost. Focused wall times include the native wrapper, transforms and real storage/worker setup.Legacy synchronous placement preservation remains debt at
src/gateway/server-worker-placement-startup.ts:384→src/gateway/worker-environments/placement-store.ts:382. Existing short indexed reads of other owners may retain live revocation checks inside a worker grant; no zero-host-SQL assertion is imposed on them. Worker read amplification is a separate follow-up. This PR does not remove every Gateway-thread session read.