Repository navigation
fix(sessions): keep transcript backlog traversal moving when the writer revision is unknown - #169467
Conversation
…er revision is unknown
|
🦞👀 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. What this changesThis PR preserves transcript backlog traversal progress when the sibling writer revision is unknown. Example: An agent database contains 300 sessions, only z-299 needs rebuilding, and the sibling writer revision remains unknown.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readiness✅ Ready for maintainer review Keep open: this collaborator-authored PR repairs a source-confirmed traversal livelock still present on main, with no introduced correctness or security defect found. Priority: P1 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe agent database worker enumerates transcript projection work, and reconciliation rebuilds the returned sessions before waiting runs can resume. flowchart TD
A[Session projection wait] --> B[Reconcile owner]
B --> C[Backlog drain]
C --> D[Agent database worker]
D --> E[TEMP cursor and pending sessions]
E --> F[Projection rebuild]
F --> A
Technical reviewBest possible solution: Preserve bounded traversal progress in the existing maintenance owner while continuing to reject clean receipts for unknown revisions. Do we have a high-confidence way to reproduce the issue? The source establishes livelock when the revision remains unknown across batches, supported by the reported production incident and baseline regression failure; no runtime reproduction was executed during this read-only review. Is this the best way to solve the issue? Removing the entry reset repairs the progress invariant directly, preserves schema invalidation and clean-receipt safeguards, and adds no competing owner or recovery machinery. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against ba42b578d2f6. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +2, Tests +43. Total +45 across 2 files. Added test files: 0. View PR surface stats
LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
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, 8:20 PM ET / October 12, 2026, 00:20 UTC (Revision 2). |
|
Landed in 1eec4da. Bug: while the sibling write revision was unknown, transcript backlog traversal reset to its first 128 sessions on every call, so a compacted session further down never rebuilt and its retry waited forever, holding later messages. Fix: an unknown revision no longer resets traversal progress; it only blocks the clean receipt. Proof: new regression fails on the previous main and passes here; 262 transcript reconcile/index/projection tests pass; CI green on the exact head. |
…er revision is unknown (openclaw#169467) ## What Problem This Solves Fixes: after auto-compaction, a run can wait forever for its session's transcript projection to rebuild. The rebuild never comes, so the run never starts its retry. Every later message for that session queues behind the hung run and is never answered or saved. Nothing is logged. Observed on a long-running Gateway (about 2,480 sessions in one agent database): a Telegram topic compacted mid-turn, then silently dropped the next two messages. 45 minutes later `sessions.describe` still reported `hasActiveRun: true`, and `needs_rebuild = 1` was set on that session only. ## Root Cause `maintainSessionTranscriptIndexStatus` stores the sibling write revision in its TEMP cursor, with `-1` for "unknown". On entry it reset the whole traversal (cursor, pending inventory) whenever the stored value was `-1`. While the revision stays unknown, every call therefore stores `-1` again and the next call resets again. Each call scans the same first 128 sessions, the traversal never reaches its end, and `readTranscriptIndexBacklog` loops without bound. The reconcile stays registered, so `waitForPreparedSessionTranscriptProjection` keeps polling for a session past the first batch. A `diagnostics.cpuProfile` of the affected Gateway showed exactly that: the hung run in `waitForPreparedSessionTranscriptProjection`'s poll, and the reconcile owner repeatedly running `drainTranscriptIndexStatus` → status `preflight` publications. The stuck session sorted at position 605 of 2,482. ## Why This Change Was Made An unknown sibling revision only means the clean receipt cannot be trusted. `isSessionTranscriptIndexStatusClean` already refuses an unknown revision, and the end-of-traversal check already restarts the cursor when the stored revision differs from the current one. The entry reset on `-1` adds nothing except the livelock, so it is removed. A schema change still resets the cursor and pending inventory. With the revision unknown, a traversal now reaches its end; `drainTranscriptIndexStatus` sees `completedTraversals` advance and ends the pass with the late dirty session in `sessionIds`. The deployed build where this happened produced the unknown revision through the writer census that openclaw#168859 removed. Current `main` can still return an unknown revision (closed or suspended database, or a file database with no admission record), so the reset path is still reachable. ## User Impact User impact: a session past the first 128 in its agent database no longer hangs after compaction while the writer revision is unknown, and follow-up messages for it are no longer held behind that run. ## Evidence - New regression in `session-transcript-index-status.test.ts`: 300 sessions, the last one dirty, sibling revision reported as unknown. It fails on `main` ("Backlog traversal never reached the late dirty session") and passes with this change. - `src/config/sessions/session-transcript-{reconcile,index,projection}*.test.ts`: 17 files, 262 tests pass. - `check:changed`: all lanes pass except "typecheck core tests", which fails only in the `ui` shard on `main`'s current MCP App test-type errors (fix in openclaw#169439); the `src` test shard is clean. Not covered: - No end-to-end reproduction through a real Gateway; the test reports the revision as unknown through a module mock, because current `main` has no natural way to hold it unknown in a unit test. - Two related defects are out of scope and tracked separately: the follow-up drain lets one hung `runFollowup` hold every later message with no timeout, and an inbound message's lifecycle marks the session idle in diagnostics while the run is still active, which hides the stall from stuck-session recovery. ## Merge Danger Two-way door. The change touches only connection-local TEMP cursor state; no schema, stored rows or protocol change. Blast radius: transcript backlog enumeration. If wrong, a stale pending entry from an unknown-revision window can survive into the next window and cause one extra projection status check for that session. Co-authored-by: Ayaan Zaidi <[email protected]>
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
Fixes: after auto-compaction, a run can wait forever for its session's transcript projection to rebuild. The rebuild never comes, so the run never starts its retry. Every later message for that session queues behind the hung run and is never answered or saved. Nothing is logged.
Observed on a long-running Gateway (about 2,480 sessions in one agent database): a Telegram topic compacted mid-turn, then silently dropped the next two messages. 45 minutes later
sessions.describestill reportedhasActiveRun: true, andneeds_rebuild = 1was set on that session only.Root Cause
maintainSessionTranscriptIndexStatusstores the sibling write revision in its TEMP cursor, with-1for "unknown". On entry it reset the whole traversal (cursor, pending inventory) whenever the stored value was-1. While the revision stays unknown, every call therefore stores-1again and the next call resets again. Each call scans the same first 128 sessions, the traversal never reaches its end, andreadTranscriptIndexBacklogloops without bound. The reconcile stays registered, sowaitForPreparedSessionTranscriptProjectionkeeps polling for a session past the first batch.A
diagnostics.cpuProfileof the affected Gateway showed exactly that: the hung run inwaitForPreparedSessionTranscriptProjection's poll, and the reconcile owner repeatedly runningdrainTranscriptIndexStatus→ statuspreflightpublications. The stuck session sorted at position 605 of 2,482.Why This Change Was Made
An unknown sibling revision only means the clean receipt cannot be trusted.
isSessionTranscriptIndexStatusCleanalready refuses an unknown revision, and the end-of-traversal check already restarts the cursor when the stored revision differs from the current one. The entry reset on-1adds nothing except the livelock, so it is removed. A schema change still resets the cursor and pending inventory.With the revision unknown, a traversal now reaches its end;
drainTranscriptIndexStatusseescompletedTraversalsadvance and ends the pass with the late dirty session insessionIds.The deployed build where this happened produced the unknown revision through the writer census that #168859 removed. Current
maincan still return an unknown revision (closed or suspended database, or a file database with no admission record), so the reset path is still reachable.User Impact
User impact: a session past the first 128 in its agent database no longer hangs after compaction while the writer revision is unknown, and follow-up messages for it are no longer held behind that run.
Evidence
session-transcript-index-status.test.ts: 300 sessions, the last one dirty, sibling revision reported as unknown. It fails onmain("Backlog traversal never reached the late dirty session") and passes with this change.src/config/sessions/session-transcript-{reconcile,index,projection}*.test.ts: 17 files, 262 tests pass.check:changed: all lanes pass except "typecheck core tests", which fails only in theuishard onmain's current MCP App test-type errors (fix in fix(ui): restore MCP App test typechecks #169439); thesrctest shard is clean.Not covered:
mainhas no natural way to hold it unknown in a unit test.runFollowuphold every later message with no timeout, and an inbound message's lifecycle marks the session idle in diagnostics while the run is still active, which hides the stall from stuck-session recovery.Merge Danger
Two-way door. The change touches only connection-local TEMP cursor state; no schema, stored rows or protocol change.
Blast radius: transcript backlog enumeration. If wrong, a stale pending entry from an unknown-revision window can survive into the next window and cause one extra projection status check for that session.