Repository navigation
refactor(sessions): record creation, compaction and spawn signals through workers - #164367
Conversation
Move live-turn, compaction, and bundled harness watched-session preparation to the existing shared-state and exact-entry readers. Capture store identity and current disclosure authority across waits, preserving deterministic prompt bytes. Keep the released synchronous SDK helper as deprecated third-party compatibility and require a live host assertion for its async replacement. Record the approved additive SDK surface and compiled-wrapper dependency.
Resolve adjacent worker-access documentation additions by retaining both. Production changes merged without conflicts; the integrated ambient cutover received a clean independent P2 review.
Model the actual worker context and read-context capture so pruning settlement tests reach the worker. The incomplete fixture reproduced four CI failures in five candidate runs; five base runs passed. All 11 repaired tests and the targeted typecheck pass, with a clean independent P2 review.
Main's SQLite cleanup introduced import-time query-cache factories. Keep those helpers real while retaining the fixture's forbidden SQL calls. The missing-export failure reproduced five times on main and five times on the exact CI merge; all 28 tests in the repaired CI group and the targeted typecheck pass, with a clean P2 review.
…ough workers Await best-effort signal settlement through the existing shared-state worker. Prepare custom watcher and creation-notice stores asynchronously, preserve ambient prune invalidation, and join explicit sweeps before applying their cutoff. Keep adopted/native-binding recording on its existing native path. Schema, retention, durability and configuration are unchanged.
Preserve the reviewed session-signal cutover while integrating the landed ambient dependency and current session caller changes.
|
🦞👀 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 3, 2026, 12:03 PM ET / 16:03 UTC (Revision 4). ClawSweeper reviewWhat this changesMove session creation, compaction, child-spawn signals, and periodic history pruning into existing database workers, with callers awaiting settlement. Merge readiness✅ Ready for maintainer review The PR remains useful: current main still records these signals synchronously. Both prior harness findings are resolved, and this review found no blocking introduced defect. Priority: P2 Review scores
Verification
How this fits togetherSession lifecycle actions produce durable signals and notices consumed by session history and agent prompts. This change moves their SQLite work off the Gateway thread while preserving ordering and store ownership. flowchart TD
A[Session lifecycle actions] --> B[Capture store ownership]
B --> C[Prepare watcher stores]
C --> D[Check current admission]
D --> E[Database worker]
E --> F[Durable signals and cursors]
F --> G[Publish notices]
G --> H[Bounded history pruning]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +151, Tests +387, Docs +10, Other +12. Total +560 across 37 files. View PR surface stats
Review metricsNone. Technical reviewBest possible solution: Keep signal persistence and pruning under the existing worker owner while preserving dedupe, notice ordering, live admission checks, and shutdown settlement. Do we have a high-confidence way to reproduce the issue? Not applicable as a refactor; current-main source establishes the synchronous producer path, and the inspected boundary regressions target the worker cutover. Is this the best way to solve the issue? Yes. Reusing existing worker operations and migrating their callers preserves one persistence owner and avoids new schema or configuration surface. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 01d4351e8f93. 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)
|
Include the prune coordinator's ambient-read dependency in the compiled wrapper inventory and route the native-slash signal test through the existing host-broker fork lane without changing its behavioral assertions. Prove that accepted session creation signals settle across the Gateway close prelude while new requests are refused, before shared-state workers close. Focused boundary tests, changed-file checks, and P2 autoreview passed.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
…ough workers (openclaw#164367) * refactor(agents): prepare watched-session prompts from worker reads Move live-turn, compaction, and bundled harness watched-session preparation to the existing shared-state and exact-entry readers. Capture store identity and current disclosure authority across waits, preserving deterministic prompt bytes. Keep the released synchronous SDK helper as deprecated third-party compatibility and require a live host assertion for its async replacement. Record the approved additive SDK surface and compiled-wrapper dependency. * test(sessions): align worker control fixture with admissions Model the actual worker context and read-context capture so pruning settlement tests reach the worker. The incomplete fixture reproduced four CI failures in five candidate runs; five base runs passed. All 11 repaired tests and the targeted typecheck pass, with a clean independent P2 review. * test(sessions): preserve query factories in worker fixture Main's SQLite cleanup introduced import-time query-cache factories. Keep those helpers real while retaining the fixture's forbidden SQL calls. The missing-export failure reproduced five times on main and five times on the exact CI merge; all 28 tests in the repaired CI group and the targeted typecheck pass, with a clean P2 review. * refactor(sessions): record creation, compaction and spawn signals through workers Await best-effort signal settlement through the existing shared-state worker. Prepare custom watcher and creation-notice stores asynchronously, preserve ambient prune invalidation, and join explicit sweeps before applying their cutoff. Keep adopted/native-binding recording on its existing native path. Schema, retention, durability and configuration are unchanged. * test(sessions): await remaining signal caller fixtures * fix(sessions): complete signal worker wrapper and test coverage Include the prune coordinator's ambient-read dependency in the compiled wrapper inventory and route the native-slash signal test through the existing host-broker fork lane without changing its behavioral assertions. Prove that accepted session creation signals settle across the Gateway close prelude while new requests are refused, before shared-state workers close. Focused boundary tests, changed-file checks, and P2 autoreview passed.
What Problem This Solves
Session creation, compaction, and child-spawn signals still executed SQLite on the Gateway thread. Periodic pruning and cold custom-store discovery also retained synchronous access.
Why This Change Was Made
Await the existing
sessionState.recordandsessionState.pruneworker operations at every native producer. Creation notices and watcher cursors prepare their physical stores through the existing asynchronous store owner, retaining live checks at worker admission. Embedded compaction settles through its existing event chain; max-lines compaction settles signaling before replying.Pruning coordination lives in a small sibling module to respect the line cap. Explicit sweeps join an in-flight periodic prune before enforcing their own cutoff. Ambient-watch invalidation stays active through settlement. The compiled-wrapper inventory includes the extracted module.
The native recorder remains only for the explicitly excluded adopted/native-binding paths in
session-catalog-gateway-copy.tsandsession-catalog-continue.ts. Their periodic pruning uses the same worker. Seed-cursor and pruning kernel sites are reclassified by operation, without marking the mixed event kernel worker-only.User Impact
Creation/compaction dedupe, child seed cursors, notice ordering, and the 30-day/50,000-row limits are unchanged. Signal failures remain best effort; a lost acknowledgement after COMMIT never replays creation or compaction. No schema, configuration, durability, retention, or update change; zero new
OPENCLAW_*names.Production: 18 files, +259 / -108 / net +151 (367 changed lines). The complete diff has 37 files including tests, routing, inventory, and documentation.
Related: #164288 (merged dependency). Caller overlap with #164284 is limited to the signal await; pending-input ownership is preserved. #162433 remains the standing umbrella-draft exception. Adjacent profile/workspace authority work is not restructured.
Evidence
b94391aa2c5a6e248ea60848cee6394759187f94. Seven kernel sites now execute only in workers; the native prune transaction is removed. The initial lane measurement was 1,245 → 1,237, also -8.sessions.createfollowed by public read, chat-send creation, both RPC compaction branches, embedded subscription compaction, native subagent spawn, and ACP spawn. Coverage includes dedupe, exact seed cursors, original-store retention across yields, revocation at transaction/commit, retention bounds, unknown commit acknowledgements, and error-class identity.pnpm test <files> --maxWorkers=1. The final lint-only adjustments passed 24 focused tests in 42.49 s. The remaining 12 heartbeat/hook tests passed in 70.90 s after completing their async callers. After main integration, the 24 creation/chat tests passed in 76.74 s. Times include local setup/compilation; CI seconds are pending.test/scripts/runtime-process-build-graph.test.ts,src/state/openclaw-state.worker.imports.test.ts, andsrc/auto-reply/reply/get-reply.imports.test.ts. Embedded persistence tests use the existing database-worker fork lane because the broker intentionally refuses admission from a Vitest worker thread; no new configuration or worker pin was added.node scripts/check-changed.mjspassed on the final main-relative diff, including all core/core-test types, full core/script lint, dead exports, storage/import/auth guards, and ratchets. Madge reports 0 cycles. SDK exports/surface checks passed. Fresh Codex autoreview through P2 is scoped-clean against the pinned main base; the final test-only completion also passed P2 review.Merge preconditions and remaining risk
36384f81fc20931dc2489c6037c7a1a0fdfdd181. Report SHA-256:50ded0495ed11d54fed16e4711245bb4d710d6180f28dccb3ecb1588627b0858; API-diff digest:0ee1df54. The report includes intervening main changes since the release. The changed signal functions andhandleCompactionEndhave no callable released SDK/runtime export; whole-module declaration snapshots in the report are conservative closure detail, not public function exports. The releasedafterEntryMutationcallback already permits and awaitsPromise<void> | void. No compatibility adapter is required for this cutover. Subsequent landing repairs affect only tests, routing, and the wrapper inventory.prepareWatchedSessionsPromptAsyncreads title rows from the default agent database rather than configuredsession.store(src/agents/watched-sessions-prompt.ts:139). This lane does not modify that reader; its own main-relative review is clean.The earlier local SDK comparison failed in managed process cleanup; the completed Testbox comparison above replaces that missing proof.
Landing validation and CI repair
Initial CI found two PR-caused harness defects. The extracted prune module required
session-state-events.ambient-read.tsin the compiled-wrapper inventory; adding that dependency passes all 17 eager-import tests (101.73 s locally), and the baseline passed the file five times. The native-slash creation test needed the existing database-worker fork lane because worker threads cannot own the SQLite broker. The original PR failed that exact attribution assertion in 5/5 runs; the merge base passed 5/5; the routing repair passes all 10 tests (141.61 s including cold compilation). Assertions and production behavior are unchanged. The PR-context failure was the body heading format and is now green.A real Gateway shutdown regression now holds an accepted creation signal across the close prelude, proves new creation requests are refused, then verifies that the accepted signal is persisted exactly once before the database closes.
pnpm test src/gateway/server-close.session-signals.test.ts --maxWorkers=1passed (199.67 s cold total; 32.46 s test execution). The same test passed in 12.131 s in CI on the repaired head. Its real request-entry, shutdown, and worker composition cannot be proven by the existing mocked worker-control tests. Scoped types, lint, and formatting pass; fresh Codex P2 autoreview of the landing repairs is scoped-clean.The inherited watched-title reader is byte-identical at the merge base and reviewed head (
src/agents/watched-sessions-prompt.ts, bloba1b3261822efb4843b9e1fcf64b46d8dc43eeae9). No production change was needed for shutdown settlement or either CI repair.Landing repairs:
3c9ca36bc727538a4ee98077406514ca962b7cae. The full changed-file check completed successfully for all four repair files, including every core test type graph, full core/script lint, storage/source ratchets, and all three dead-export scans. The production and SDK source bytes are unchanged from the completed SDK report.