Skip to content

fix(sessions): keep transcript backlog traversal moving when the writer revision is unknown - #169467

Merged
obviyus merged 1 commit into
mainfrom
fix/dropped-followup-rebuild-hang
Oct 12, 2026
Merged

obviyus merged 1 commit into
mainfrom
fix/dropped-followup-rebuild-hang

Conversation

@obviyus

@obviyus obviyus commented Oct 12, 2026

Copy link
Copy Markdown
Collaborator

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 #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 fix(ui): restore MCP App test typechecks #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.

@clawsweeper

clawsweeper Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 12, 2026
@clawsweeper

clawsweeper Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This 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.

  • Before: Maintenance repeatedly scans the first 128 sessions and never reaches z-299.
  • After: Maintenance reaches z-299 and returns it for rebuilding without certifying an unknown revision as clean.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused repair with meaningful boundary coverage and no actionable finding; complete user-flow confidence remains limited to source inspection and reported harness results.
Proof confidence 🦐 gold shrimp (3/6) This collaborator-authored PR is outside the ordinary contributor proof gate; supplied evidence exercises SQLite maintenance and the production drain with a mocked revision input, without a shipped Gateway capture.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: After compaction, an affected session can wait indefinitely for projection rebuilding and leave later messages unanswered.
Reason: The narrow change restores intended traversal progress without new configuration or persistence; collaborator authorship supplies direction approval.

Regression provenance

Possible 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
Reviewed head: 2a050d09c25e2381c3c4b823954dd8b8e604a3b2

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: No after-fix Gateway capture shows a late dirty session rebuilding and its retry resuming under an unknown revision; the reported baseline regression failure was not independently rerun.
Agent review details

How this fits together

The 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
Loading

Technical review

Best 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

  • Unknown-revision cursor reset changes intended behavior with a stated reason (1d76f57: The committed-revision cutover replaced foreign freshness probes and carried forward the sentinel initialization reset; unknown revisions were intended to prevent clean reuse.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source +2, Tests +43. Total +45 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 3 1 +2
Tests 1 44 1 +43
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 47 2 +45

Labels

Label changes:

  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: The reported compaction stall blocks the affected session's retry and subsequent messages, and source inspection confirms the traversal failure under an unknown revision.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Optionally add redacted Gateway output showing a late dirty session rebuilding and its waiting retry resuming while the revision is unknown.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-12T00:09:46.309Z sha 2a050d0 :: needs changes before merge. :: none

Reviewed October 11, 2026, 8:20 PM ET / October 12, 2026, 00:20 UTC (Revision 2).

@obviyus
obviyus marked this pull request as ready for review October 12, 2026 00:16
@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 12, 2026
@obviyus
obviyus merged commit 1eec4da into main Oct 12, 2026
194 checks passed
@obviyus
obviyus deleted the fix/dropped-followup-rebuild-hang branch October 12, 2026 00:28
@obviyus

obviyus commented Oct 12, 2026

Copy link
Copy Markdown
Collaborator Author

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.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 12, 2026
…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]>
scribe-dandelion-cult added a commit to karmaterminal/openclaw that referenced this pull request Oct 20, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant