Repository navigation
refactor: simplify session bookkeeping and transcript workers - #169458
Conversation
Consolidate archive and transcript statistics paths, share typed worker message handling, and remove speculative advisory retries and duplicate capture bookkeeping. Preserve first-write ordering, authorization, transcript durability, and accepted-write settlement.
|
🦞👀 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 changes before merge. What this changesThis PR consolidates transcript statistics and archive workers while simplifying baseline capture, notice reconciliation, and upstream bookkeeping. Example: A session has an edited tracked.txt file, but the combined Git inventory command fails.
Review scores
ProductKind: Refactor · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 1 item remains Keep this PR open: it is a maintainer-directed simplification, the three prior findings are resolved, and no new blocking code defect was found; current-head CI failures still need attribution. Priority: P3 Before merge
FindingsNone. Agent review detailsHow this fits togetherGateway session requests and background maintenance enter session owners, which delegate SQLite and Git work to workers and return transcript statistics, archives, baselines, and queued notices. flowchart TD
A[Gateway requests and maintenance] --> B[Session owners]
B --> C[Transcript workers]
C --> D[Canonical SQLite stores]
B --> E[Git read workers]
E --> F[Session diff baseline]
B --> G[Notice queue and delivery owner]
Technical reviewBest possible solution: Retain the consolidated owners and accepted bookkeeping tradeoffs, then land through the normal workflow after the current CI failures are attributed. Do we have a high-confidence way to reproduce the issue? This is a refactor rather than a bug report; source inspection verifies the changed paths, and no target code or tests were executed during this review. Is this the best way to solve the issue? The consolidation follows the existing owners and the maintainer's explicit tradeoffs; restoring the retired advisory protocols would contradict that recorded direction. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against f92690e1753f. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource -491, Tests -137, Other -1. Total -629 across 33 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel 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 (1 earlier review cycle)
Reviewed October 11, 2026, 9:01 PM ET / October 12, 2026, 01:01 UTC (Revision 2). |
Keep SQL results sparse and reconstruct missing and duplicate inputs by ordinal. Remove only synthetic foreign-DDL and partial-notice-retry test paths retired by the sessions cleanup; retain ordinary cancellation, permissions, snapshot and row-budget coverage.
|
Closing under the campaign's BELOW-500 rule; this PR is not merged. The required sparse-statistics correction reduces the production cut from 501 to 491 lines (+341/-832). The corrected work is pushed as Exact original head
The corrective diff has fresh clean independent P2 review, passing core and affected test types, changed-file lint, zero runtime/Madge cycles, and passing statistics API correctness/Unicode/chunking proof. All 19 cold-read cases (including the unchanged sparse-row budget), all 20 retained notice/permission cases, and all 3 lint-suppression cases pass. The combined isolated command took 924.21s on the loaded host. No hosted jobs were rerun or dispatched to seek green. |
Exact-head CI attribution and inherited-failure landingCandidate: Every failed CI job is accounted for:
Main and candidate comparisons ran on the same machine, in that order, with independent isolated HOME, OPENCLAW_HOME, OPENCLAW_STATE_DIR, OPENCLAW_CONFIG_PATH, TMPDIR and XDG directories. The clean main checkout used its own frozen-lockfile install. Both failed test files are byte-identical between main and candidate. No test, assertion, timeout, retry or skip was changed for this comparison. Commands on each checkout, sequentially: node scripts/run-vitest.mjs src/boards/sqlite-board-store.worker.test.ts -t 'executes Board mutations' --maxWorkers=1
node scripts/run-vitest.mjs src/config/sessions/session-accessor.creation-snapshot.test.ts -t 'preserves native warm listing' --maxWorkers=1Main: Board 1 failed (149.80s wrapper); creation 2 failed (105.99s). Candidate: Board 1 passed (254.93s); creation 2 passed (128.45s). Filtered-out cases were not claimed as coverage. No selected CI test job was cancelled or timed out. Two older metadata-automation jobs ( The earlier PR-caused sparse-statistics and obsolete partial-consumption expectations were corrected in this head. The unchanged sparse-row budget and all retained notice/FIFO/permission cases pass locally and no longer fail in hosted CI. Proceeding with the requested exact-head inherited-failure squash exception, not claiming green CI. |
…aw#169458) * refactor: simplify session bookkeeping and transcript workers Consolidate archive and transcript statistics paths, share typed worker message handling, and remove speculative advisory retries and duplicate capture bookkeeping. Preserve first-write ordering, authorization, transcript durability, and accepted-write settlement. * fix(sessions): preserve sparse transcript statistics Keep SQL results sparse and reconstruct missing and duplicate inputs by ordinal. Remove only synthetic foreign-DDL and partial-notice-retry test paths retired by the sessions cleanup; retain ordinary cancellation, permissions, snapshot and row-budget coverage.
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.
Integrate origin/main f13b3cd (533 commits after d220cac). Four production files conflicted: - attempt-auth-selection.ts: take main's async credential store (ensureAuthProfileStoreAsync, openclaw#169111) and keep this branch's import for the CLI auth-forwarding helper. - attempt-execution.ts: runAgentAttempt becomes async as on main (openclaw#169111, openclaw#169449) and keeps its RunAgentAttemptParams type; main's inline parameter type is otherwise unchanged since the previous merge. - sessions-patch.ts: keep the fallback policy patch step ahead of main's narrower explicit-thinkingLevel validation (openclaw#169435). - model-overrides.ts: keep the session fallback policy block and take main's bookkeeping simplification and comment removal (openclaw#169458). docs/.generated/config-baseline.{counts.json,sha256} were regenerated with pnpm config:docs:gen instead of merged by hand: core 2507 -> 2511, the four added entries are this branch's fallbackPriority paths.
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.
First-parent upstream 84a834e..2b9aa2e (112 commits, including openclaw#169327 actor memory storage for incognito consumers, openclaw#169458 session bookkeeping/transcript workers, openclaw#169449 gateway read paths, openclaw#169364 cron worker queue, openclaw#168401 remote compaction V2, openclaw#169467 transcript backlog). Conflicts: - session-reset-service.ts: upstream moved ensureSessionRuntimeCleanup into session-reset-runtime-cleanup.ts. Took upstream's form and ported our delta into the new module: the `reason` parameter and the awaited clearSessionScopeRuntimeState (continuation cancellation that cannot persist returns UNAVAILABLE). Callers keep passing `reason`. - attempt-execution.ts: upstream made the Claude CLI fallback prelude async; ported the await into our extracted resolveClaudeCliFallbackPrelude. - session-accessor.sqlite-lifecycle.ts: upstream's two actor-storage imports; the eviction kick import stays where the fork moved its caller. - status-message.ts: upstream threads preparedTtsPreferences into the voice line; ported into our status-session-lines.ts helper. - plugin-sdk-surface-report.mts budgets; worker inventory regenerated. Also: session-actor-memory-collaboration-contract.ts (new upstream file) excludes the fork's sharing `authority.capture` op from actor memory commands (it runs only on the sharing writer's owner), as at step 26. Refs #1475 Co-Authored-By: Claude Opus 5.5 <[email protected]>
What Problem This Solves
The requested second sessions cleanup removes speculative bookkeeping and parallel implementations that survived the first pass.
User Impact
No session feature, public API, config key, stored shape, retention rule, or durability policy changes. Ordinary transcript writes, authorization, restart recovery, and accepted-work settlement retain their owners. Advisory bookkeeping accepts the explicitly listed rare races instead of carrying separate protocols for them.
Why This Change Was Made
Baseline capture now has one in-flight operation and one guarded persistence instead of a separate reservation write. Private reconcile requests trust their typed producer instead of mirroring its schema. Notice sweeping retains cursor reconciliation and delivery authority without retaining every watcher's read custody. Archive staging/encoding and transcript-statistics projection each have a shared implementation; statistics retain a cheap indexed point shape for small requests.
Net production reduction: 491 lines (+341/-832), excluding tests, fixtures, support, inventories and generated files. The maintainer explicitly waived the floor for this completed honest pass. The coverage log below records both removals and retained candidates.
Best-effort tradeoffs accepted
linkUpdatedAtcomparison resets counts for a changed link; event insertion and settlement still match the exact expected upstream.Evidence
The corrected head is
1a1c2176d91727847c645126ee1633b8da583180. It restores sparse SQL output after the first hosted run caught a row-transfer budget regression, and removes only the obsolete partial-consumption retry and foreign-DDL-between-chunks test cases. All 19 cold-read cases (including the unchanged sparse row budget), all 20 retained notice/permission cases, and all 3 lint-suppression cases pass. Fresh correction review is clean through P2; core and affected test types, lint and both cycle checks pass. The PR was reopened under the maintainer's explicit floor waiver. Exact-head CI completed with only the inherited creation-snapshot and Board permission failures; sequential clean-main-versus-candidate proof and every failed job are recorded in the evidence comment. The requested pinned inherited-failure exception landed squash8444ad628bdaef99beabc2eb7042d41437431486; fresh origin/main ancestry verification passed. This is a verified merge, not a green-CI claim.Core production types and the core/root test type graphs passed. The isolated runtime build passed. Changed checks passed formatting, SQLite/ownership/line-count/assertion/mock ratchets, dependency and plugin boundaries, and wrapper shadowing. The native production and full-tree unused-export scans passed sequentially after parallel scans timed out. Full-core lint exceeded its existing 900-second tool limit; changed-file lint passed separately. Runtime import cycles and Madge cycles are both zero. Limits were not changed.
The broad scope attempt recorded 653 passing cases. Its two failures were the removed legacy reread expectation (corrected; baseline suite then passed 10/10) and the untouched large-shared-branch fixture exceeding its existing 15-second timeout. The corrected Gateway groups passed all 78 cases, including 46/46 diff tests. Archive and worker-lane focused tests passed. A separate worker group hit the existing 30-second fleet/backoff deadlines, then cascaded through a deleted timed-out fixture. In fresh processes, temporary timing markers showed the fleet case still seeding agent 5 of 8 at its 30.15s deadline, before reaching its queue assertion; the backoff case spent 18.65s seeding, paused at 24.64s, and completed its seven passes at 31.49s after the 30.01s deadline. Those timing markers were removed and the lifecycle test is unchanged. This narrows the failures to insufficient wall-clock headroom on the loaded host, not a passing replay or proof that every assertion ran. No timeout, retry or skip changed.
The native statistics API probe passes cold-only/raw-orphan/missing/duplicate IDs, NUL/USV binding and >400-ID chunking on the final SQL projection. This is correctness evidence, not a production performance claim. The point-query fast path remains. Remaining full-scope tests were not all executed locally; a Testbox allocation never obtained a runner and was stopped at the 20-minute queue limit. No remote execution is claimed. Hosted CI must attach to the exact published head.
Single-worker cost evidence: baseline file 92.61s / wrapper 214.07s; final metadata file 91.60s, final user-turn file 144.75s, combined wrapper 377.33s; Gateway diff file 207.56s. These are loaded-host measurements, not budgets or measured CI seconds. The added metadata batch case took 2.562s on the final projection. Exact hosted CI seconds are pending publication.
Review found a real simplification bug before publication: an already-existing caller could bypass an active first-turn baseline capture. The extended concurrency test failed with an absent baseline, then the owner was corrected to join before the early return. Settlement also preserves an authoritative terminal unavailable marker. The Git-error regression initially left its injected failure installed and broke 28 later cases; its mock now restores in
finally. No product retry, timeout increase, skip, or weaker assertion was used to repair either issue.Fresh independent review of the final substantive candidate is clean through P2. The user-turn suite passes 27/27 on the final media projection.
Final media-specific tests pass 11/11 and
test/scripts/lint-suppressions.test.tspasses. Final core types, changed-file lint, formatting andgit diff --checkalso pass after the message-wait helper cleanup.Coverage log
The lane inspected current
origin/mainrules, fourteen-day additions/net growth, and the previous p16/p17 ledgers. Positive-growth config/session files remained with w01; allsrc/sessionsfiles were eligible.