Repository navigation
refactor(sessions): route forks, reads, and cleanup through workers - #169566
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review in progressClawSweeper is reviewing this revision. This supersedes any previous blocked status. |
|
Codex review: needs changes before merge. What this changesThis PR moves session forks, transcript reads, append recovery, and cleanup into existing workers while retaining synchronous SDK compatibility. Example: Fork agent:main:main into agent:main:child while backend preparation changes the child label to concurrent child.
Review scores
ProductKind: Refactor · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 1 item remains Keep this PR open: it contains useful, owner-directed worker migration work that current main does not fully provide; no new actionable code defect was established, but current CI failures remain unclassified. Priority: P2 Before merge
FindingsNone. Agent review detailsHow this fits togetherGateway and plugin session operations enter the session owners, which dispatch database work to existing workers and publish committed transcript, identity, and lifecycle facts back to callers. flowchart LR
A[Gateway and plugins] --> B[Session owners]
B --> C[Session writer worker]
B --> D[History reader worker]
C --> E[Agent SQLite database]
D --> E
C --> F[Committed lifecycle facts]
F --> A
Technical reviewBest possible solution: Land the existing worker cutover after resolving attributable CI failures while preserving the documented SDK compatibility and live effect guards. Do we have a high-confidence way to reproduce the issue? Source inspection confirms the remaining caller-thread paths and worker replacements; this is a refactor review, and no target code or tests were executed. Is this the best way to solve the issue? Reusing the existing writer and history workers is the appropriate boundary, with current-row merging, committed publication, and retained public compatibility. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 8239692596a9. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfacePR surface statistics unavailable: the file list is incomplete. LabelsLabel changes: No label changes. Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (12 earlier review cycles; latest 8 shown)
Reviewed October 12, 2026, 7:34 AM ET / 11:34 UTC (Revision 13). |
Repair the sessions-rewind failure from hourlies 38216343022 (c2fe11f, checks-node-compact-large-4) and 38220958692 (5a1f8c6, checks-node-compact-large-3, agentic-gateway-methods-hosted-5). Culprit: af0c38c (#169579), whose stated intent is: "Raw event appends use the existing event operation, including entry-less events and active-branch parent selection." The fixture's event appends now stay in workers instead of warming the host's shared-state reader. A cold fork therefore executes the existing transaction-admission and candidate-commit upstream SELECTs separately. These are authority reads, not duplicate cuts, history, or session rows. Assert both exact keyed SELECTs and exactly the source and returned fork keys after fork plus rewind. Keep the rewind one-read assertion and all editor/media/provenance/sandbox checks. No production behavior changes. Attribution: the culprit parent passes (92.77s); the culprit fails with the original 2-versus-1 assertion (98.02s). Both parents and merged commits for #169458 and #169513 pass. Baseline full file: 24 pass, 1 fail (90.61s). Reverting only this fix reproduces that same failure (86.66s). Proof: 10 full-file runs, 25/25 each: 100.71s, 82.57s, 110.16s, 72.92s, 55.99s, 58.74s, 93.46s, 55.29s, 58.21s, 57.20s. Owning gateway-methods config shard 98/128: 3 files, 53/53 (189.90s). Targeted gateway-methods tsgo passed (72.48s wrapper, 13.8s graph); type-aware oxlint (33.02s), boundary-guards (1.35s), oxfmt (0.33s), git diff --check and fresh independent P2 review passed. check-changed (422.73s) passed its selected guards/types but failed the production unused-export scan on renderPublicSessionCardSvg. The same scan fails identically on clean origin/main 044f8ea (150.38s); full-tree and script scans pass on both. No baseline or suppression changes. Peer recheck: no landed fix. Open #169566 removes these SQL counters in a broader cutover; this focused main repair preserves their exact contract.
Repair the sessions-rewind failure from hourlies 38216343022 (9000810, checks-node-compact-large-4) and 38220958692 (8da3099, checks-node-compact-large-3, agentic-gateway-methods-hosted-5). Culprit: ae4267e (openclaw#169579), whose stated intent is: "Raw event appends use the existing event operation, including entry-less events and active-branch parent selection." The fixture's event appends now stay in workers instead of warming the host's shared-state reader. A cold fork therefore executes the existing transaction-admission and candidate-commit upstream SELECTs separately. These are authority reads, not duplicate cuts, history, or session rows. Assert both exact keyed SELECTs and exactly the source and returned fork keys after fork plus rewind. Keep the rewind one-read assertion and all editor/media/provenance/sandbox checks. No production behavior changes. Attribution: the culprit parent passes (92.77s); the culprit fails with the original 2-versus-1 assertion (98.02s). Both parents and merged commits for openclaw#169458 and openclaw#169513 pass. Baseline full file: 24 pass, 1 fail (90.61s). Reverting only this fix reproduces that same failure (86.66s). Proof: 10 full-file runs, 25/25 each: 100.71s, 82.57s, 110.16s, 72.92s, 55.99s, 58.74s, 93.46s, 55.29s, 58.21s, 57.20s. Owning gateway-methods config shard 98/128: 3 files, 53/53 (189.90s). Targeted gateway-methods tsgo passed (72.48s wrapper, 13.8s graph); type-aware oxlint (33.02s), boundary-guards (1.35s), oxfmt (0.33s), git diff --check and fresh independent P2 review passed. check-changed (422.73s) passed its selected guards/types but failed the production unused-export scan on renderPublicSessionCardSvg. The same scan fails identically on clean origin/main 85f4c3f (150.38s); full-tree and script scans pass on both. No baseline or suppression changes. Peer recheck: no landed fix. Open openclaw#169566 removes these SQL counters in a broader cutover; this focused main repair preserves their exact contract.
…69566) Use the existing session workers for parent forks, transcript reads, pending-input processing, and cleanup. Remove redundant internal rechecks and retain the final authority guards. Migrate bundled callers to async transcript APIs while preserving deprecated synchronous SDK readers and durable recorder completion until the next SDK major.
First-parent upstream eb82fe6..2cddf96 (67 commits, including openclaw#169566 session owner flows through workers). Stops before openclaw#169063 (fp#718), which is step 67 on its own. Conflicts: - session-accessor.sqlite-owner.ts: upstream dropped the in-transaction session-id read and pins the owner UPDATE to current_session_id (replaceSessionOwnerInTransaction's expectedSessionId), throwing when it matches no row. Took that form and kept our owner-change detection (decoded owner/creator, incognito read) and the recipient-authority advance when the owner actually changes. - session.test.ts: import union (upstream's session-store temp dirs, our continuation custody test state). - SDK budgets and worker inventory regenerated. Owner-assignment suites: 16 of 30 files ran green (240 tests) before a 590 s cap under host load; the rest run in the step sweep. Refs #1475 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Upstream openclaw#169566 (absorbed at step 66, 0cc35be) made prepareAgentRequestPreflight async. The fork's launch-key gateway test facade still read preflight.runId from the unresolved promise, so the continuation-supplied run id came back undefined ("expected undefined to equal continuation:record-7:3"). Green at step 65 (2538e5c), red from step 66 through step 69; green with the await (2 files, 48 tests with the production-boundary suite). Refs #1475 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…re drift Found by typechecking every core test shard on its own (the stock shard runner stopped at upstream's red ui/ partition and hid these): - subagent-run-liveness: keep STALE_UNENDED_SUBAGENT_RUN_MS exported. Gate 2.7 batch 2 (50593f1) un-exported it as upstream has it, but 12 continuation work-dispatch suites age runs past this cutoff by importing it; they ran with NaN timestamps. Visible red: parent-lineage "orphan post-staleness-cutoff -> reap" (green at 4753b39, red at 50593f1 and every later head). Now 15 files / 147 tests green. - agent-request-preflight.test: the reserved continuation run-id cases await the preflight upstream made async in openclaw#169566 (step 66). Green at 2538e5c, 4 failed at 1a6c3a1, 33/33 with the fix. - agent-runner-embedded-candidate.continuation.test: createAssistantError Transcript() takes no argument since upstream openclaw#169237 (step 60); type error only. All 32 core test-shard graphs typecheck at this head. Refs #1475 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Problem and change
Async session APIs still reached synchronous SQLite on the Gateway thread for parent forks, transcript/catalog reads, pending-input processing, and cleanup. This change routes bundled callers through the existing session/history workers, preserves prepared source metadata, and deletes duplicate worker operations and redundant internal rereads. Parent forks merge patches into the current child, owner assignment uses one conditional update, and native-binding deletion participants settle before lifecycle publication.
No schema, retention, permission, update, plugin-loading, or service-lifecycle change. SQL projections that bound large transcript payloads remain in SQL. Automatic maintenance retains command cleanup custody while executing database work in workers.
Public deprecate-and-replace pairs:
loadTranscriptEventsSync→loadTranscriptEvents;readTranscriptStatsSync→readTranscriptStatsAsync; recordercompleteProcessing→completeProcessingAsync. Bundled consumers migrate; released synchronous readers and durable recorder completion remain compatible, warn, and are documented for the next SDK major.T1 scope and retained boundaries
The four assigned removals are parent-session calls. This is not zero static T1: shared kernels remain reachable through deprecated synchronous SDK contracts, excluded incognito paths, native Doctor/CLI maintenance, and final authority guards. The paired run has zero assigned warmed MAIN calls. A later 13-turn smoke records four cold MAIN calls at second-session admission/execution boundaries and zero assigned warmed MAIN calls. Those final durable-row checks remain because raw synchronous SDK lifecycle revocations are not completely published; removing them would risk executing against revoked user data. Excluded incognito paths are not ported.
Removed checks and accepted edges
Final execution, external-initialization/policy-injection, cross-store disclosure, and membership checks remain at their effects.
Live SQL evidence
One isolated shared-harness pair exercised 13 turns, subagent, cron, compaction, and shutdown. Base
0c8464cf802c2f7ca62f2bc0def9303f98d0dde1; candidatea3404699d3e7f458a23953719ccc6b576755740d. These historical measurements precede the last caller fixes and main integrations; no final-head performance claim is made.Assigned warmed statement means: participants 22.5→21.8; session reads 3.5→1.5; projections 42→42; pending inputs 18→18; participant writes 2→2; combined 88→85.3. Assigned whole-workload statements stay 1,446→1,446. Parent forks were not exercised. The largest global warmed reduction comes from background publication/memory cadence, so the full reduction is not attributed to this lane.
First-turn statements move 749→1,976 while connect moves 1,214→111: the same memory schema/admission stacks shift phase, and whole-workload totals decrease. Loaded-host timings do not support a latency claim. The shared harness is unchanged; an external copy applies identical fixture relocation and connection deadlines to both sides.
All matched executions have census request identities. Full row-facts operations use 5.6→5.5 requests and 28.0→27.5 statements/turn. Watermark-associated requests are 13.6→13.5. Snapshot volume follows fewer corpus/list operations (8→3), not cheaper individual reads. Families overlap and are not additive; none increases.
A supplementary frozen
dc7960fcdcd9asmoke completed all session flows above: warmed statements 371 [335–421], requests 101.5 [90–127], MAIN 0 [0–2]. It is unpaired attribution evidence only. Its aggregate exit was nonzero for one retryablementions.dismissUNAVAILABLE response; two warmed MAIN samples are scheduled secret-store reads outside this lane.Review and validation
RELAXED TESTING v6: local changed-file oxfmt/oxlint and diff checks; CI owns broad suites/static checks. No remote leases or slots. Two Codex autoreview rounds completed. The second identified a released synchronous completion regression; synchronous durability and memoized completion were restored. No third round.
Production head
21a3832f6158fpassed all seven type jobs, six lint jobs, source contracts/export collisions, guards, Madge (zero cycles), security, and T1/dialect/worker ratchets in CI 38235312566. Dialect growth is zero. Same-head CI 38236392952 passed Knip (zero unused files/exports) and SDK API diff, with API artifact; unrelated remaining dispatch work was canceled after those completed.The integrated SDK surface check passes: 3,700 exports / 2,160 callable / 186 deprecated; no unauthorized removals. Runtime API guardrails pass 7/7 at
8ec44709245d0(1,134 seconds, dominated by cold worker preparation), with test and runtime-api inputs unchanged subsequently. No published-driver update cell is required.Fixture head
85999df5935bdpassed all seven type checks, all six lint checks, source contracts, Madge, database ratchets, and security in CI 38239636270. Wrapper closure regression passes 17/17. Production/SQL/SDK inputs are unchanged after21a.CI exposed two fixture defects: persistent deletion triggers were rejected by canonical-schema admission before the intended fault, and fake-clock maintenance switched to native scope after capturing a worker execution claim. Deletion now injects its TEMP trigger through the existing worker fault helper; maintenance establishes a coherent synthetic native owner from kickoff through completion. The real worker/Doctor-drain regression remains worker-backed. Final focused result is recorded below.
Remaining CI failures are recorded as inherited or untouched-owner results, not passes: cron data-return revalidation expectations, shared physical-reader admission, artifact/agent drainage, detached credentials/model resolution, X hook allowlist, session projection cleanup, send/follow-up/recap timing, native slot/admission and excluded incognito flows, UI catalog/actions, workspace watcher, Code Mode settlement, ACP shutdown, CLI timeout, and retired transport fixtures. The shared reader rejects validation before its SQL callback; logs lack request kind, so no more specific cause is claimed. Cron's data-return API does not retain authority; live cron execution still checks at admission. Catalog readiness fails in the unchanged five-second Codex index deadline before session adoption; a cold main diagnostic was stopped before assertions and is not called a pass.
Landing uses the authorized head-pinned REST squash path under NATIVE PROVISIONING, RELAXED LANDING v4 and v6. Static gates remain mandatory; unrelated test failures are not relabeled green.
Diff against integrated main
6a3b7067d5e98: 101 files, +1,758/−1,689. Production/support +617/−856; tests +1058/−821; docs/tooling +83/−12. Focused diagnosis:pnpm test src/config/sessions/session-accessor.sqlite-maintenance-kick.test.ts src/config/sessions/session-accessor.sqlite-deletion.test.ts --maxWorkers=1passes 53/53 tests (2 files, Vitest 962.94 seconds; 65% cold transform). The real worker/Doctor-drain regression passes without native fixture mocks. The formerly failing busy-writer case commits once with zero rejections. Wrapper source-stability verification also passed; exit 0, total wall 1,118.27 seconds.Final integration
2b83a50786c3049affa450411d0a90edaa0498b5merges main37064938ac97b. CI at4351a62exposed an inherited missing export on its exact base483b8fdaa602: the restored memory caller still used the retired name. Main's existing fix migrates it totranscriptRewritePreservesAdmission; no compatibility alias was restored. The integration also migrates main's new memory-read test to this lane'sloadSessionTranscriptEventsinternal name and explicitly binds the fixture callback to satisfy type-aware lint. Both edited fixtures pass local type-aware oxlint and formatting; diff check passes. Main's removal of duplicate policy cases is preserved; the 53-case preintegration run covers the retained cases. No lane SQL, SDK signature, runtime-api barrel, or runtime behavior changes in this integration. Final CI static results are recorded below.Conflict-only integration
44671a681dc998d65a43b805ced090b086041313includes main6a3b7067d5e98fa9eb4055eb10e99c85591d352e. The sole manual conflict preserves main's newly added off-thread rollback regression plus this lane's existing rollback-authority/acknowledgment regression, without weakening either assertion. Targeted format, type-aware lint and diff checks pass. No lane runtime or SQL code changed.Final-head static proof: CI 38244904967 at
44671a681dc998d65a43b805ced090b086041313passes all seven type jobs, all six lint jobs, source contracts, Madge, package boundary, T1/dialect/worker ratchets, and security. The separate exact-head Security Review also passes. Final repository T1 is 536→532, deprecated-only 2→2; all dialect categories remain 0→0 across 52 changed production files. Knip and SDK API evidence above is reused for unchanged lane production/SDK inputs. Landing uses RELAXED LANDING v4 with the 53-case focused pass after the fixture corrections; pending full-suite jobs are not represented as passing.