Repository navigation
fix(agents): wait for deferred transcript projection before reopening the session - #130930
Conversation
… the session After #129182, compaction replace on transcripts past the sync-rebuild gate (4,000 rows / 4 MiB) defers the projection rebuild to the reconcile worker. The overflow-recovery retry reopens the session immediately and the bounded open fails closed with "Session transcript projection is rebuilding", so the turn dies right after a successful compaction. The attempt session open now settles its own session's projection first.
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 27, 2026, 12:28 PM ET / 16:28 UTC. ClawSweeper reviewWhat this changesThe PR waits for a deferred session-transcript projection only before an owned recovery retry, and lets that wait stop when the run is cancelled. Regression provenancePossible regression — probable (reviewed change; known regression link). No predecessor PR is attributed. Merge readinessKeep open for normal maintainer review: the branch addresses the retry-after-compaction failure introduced by deferred projection rebuilding, and the focused cancellation and ordering coverage supports the approach. It is not already on the fetched main revision. Priority: P1 Review scores
Verification
How this fits togetherEmbedded agent runs can compact or truncate a session transcript after context overflow, then retry the prompt. Large transcripts rebuild their search and active-event projection asynchronously, so the retry must wait for that projection before reopening the session. flowchart LR
A[Agent run] --> B[Overflow recovery]
B --> C[Transcript compaction or truncation]
C --> D[Deferred projection worker]
D --> E[Owned retry wait]
E --> F[Reopen session]
F --> G[Retry prompt]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +172, Tests +74. Total +246 across 13 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Copy recommended automerge instructionTechnical reviewBest possible solution: Merge only after exact-head validation confirms the owner-scoped wait remains cancellable and ordinary readers retain their bounded retryable behavior. Do we have a high-confidence way to reproduce the issue? No live reproduction was run in this read-only review, but current source and focused tests provide a high-confidence source reproduction of the deferred-projection retry ordering. Is this the best way to solve the issue? Yes: keeping the wait at the retry owner avoids changing the established fail-fast contract for ordinary session readers while covering transcript-mutating recovery retries. AGENTS.md: found but not applied because it conflicted with ClawSweeper's review contract. Codex review notes: model internal, reasoning high; reviewed against 1c761b712e8c. LabelsLabel justifications:
EvidenceAcceptance criteria:
What I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles)
|
|
Updated head: Scoped projection settlement to retries that own an in-run transcript mutation, removed the unconditional shared-open wait and 5,000-event worker test, and changed the reconcile dependency to a recovery-only dynamic import. Focused validation: 89 tests passed; @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Updated head: Addressed the exact-head ClawSweeper follow-up: @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Updated head: Addressed the latest exact-head ClawSweeper finding: projection ownership is now a one-shot entitlement consumed before settlement. A second dispatch without a new compaction/truncation does not invoke the waiter. Focused recovery tests, core/core-test typing, @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Head |
|
Final exact head |
|
Unrelated CI follow-up recorded from superseded run 33083512648: |
|
Updated head: Addressed the exact-head ClawSweeper P1: owned projection settlement now carries the admitted run abort signal into an abortable poll, so cancellation releases a retry even when the projection worker stalls. The new stalled-worker regression has mutation proof (the non-abortable poll stays blocked past 250 ms); the real SQLite/public-runner recovery scenario still passes. Validation: shared integration 77/77, session prompt 8/8, SQLite handle lifecycle 7/7, |
|
Exact-head validation is complete for
|
|
Live Gateway proof on exact PR head Deployment proof:
Fresh-session real-behavior probe:
The intentionally near-limit retry had only one output token available and emitted |
… the session (openclaw#130930) * fix(agents): wait for deferred transcript projection before reopening the session After openclaw#129182, compaction replace on transcripts past the sync-rebuild gate (4,000 rows / 4 MiB) defers the projection rebuild to the reconcile worker. The overflow-recovery retry reopens the session immediately and the bounded open fails closed with "Session transcript projection is rebuilding", so the turn dies right after a successful compaction. The attempt session open now settles its own session's projection first. * fix(agents): scope projection waits to owned retries * fix(agents): exclude no-op transcript retries * fix(agents): consume projection retry ownership * test(agents): prove owned projection retry ordering * fix(agents): make projection retry wait abortable --------- Co-authored-by: VACInc <[email protected]>
|
Complementary handoff coverage merged in #141718 (merge commit). This PR's owned in-run retry waiter remains intact. The new fix reuses The new SQLite regression covers more than 4,000 retained history entries and immediate bounded reopening, with and without handoff context. Ordinary fresh readers remain bounded/fail-fast; no global wait or replay of completed tools was added. |
What problem this solves
Large-session auto-compaction can commit a transcript replacement, schedule its projection rebuild off-thread, and immediately retry. The retry then opens the durable session while its own projection is dirty and fails with
Session transcript projection is rebuilding: <sessionId>instead of continuing the turn.Live pre-fix evidence from a 5,063-event session showed compaction succeed at
01:35:57.491, followed 68 ms later by the projection-unavailable failure.Root cause and owner
#129182 (
233ac850f03) intentionally moved large projection rebuilds out of the write transaction. Ordinary readers must remain bounded and fail closed while maintenance is active (src/config/sessions/session-accessor.sqlite-active-projection.ts:120).The first version of this PR waited in the shared durable-session open path. That was too broad: a fresh attempt could wait behind another run's rebuild, violating the reader contract.
The active run's prompt/session state is the architectural owner of whether a retry follows an in-run transcript mutation. It now records that fact for successful compaction, mid-turn truncation, in-attempt compaction retries, and successful append-only tool-result truncation.
Immediately before dispatching the next attempt, only that owned retry awaits the existing
waitForSessionTranscriptProjectionseam. The entitlement is consumed before the wait, so later dispatches do not inherit it. Fresh and no-op retries do not load the reconcile module or wait; their existing retryable fail-closed behavior is unchanged.Invariant
A run's transcript-mutating retry must read its own committed transcript once, while fresh, no-op, and later attempts retain bounded projection-unavailable behavior.
The old unconditional session-open helper was removed. The reconcile module is dynamically loaded only on the owned recovery path, avoiding the CLI startup-memory regression caused by the original eager import.
User impact
Large-session recovery continues after compaction or truncation instead of failing in the deferred-projection window. No configuration, protocol, migration, schema, or persistent-store contract changes.
Evidence
SessionTranscriptProjectionUnavailableError; the owned retry waits for the real worker; and the second dispatch reads the rebuilt projection successfully.node scripts/check-changed.mjs: passed, including formatting, lint, dead exports, import cycles, database-first guards, and core/core-test type checks.pnpm tsgo:coreandpnpm tsgo:core:test: passed.plugins list --jsonto the 401 MB ceiling. The eager import is removed; exact-headbuild-artifactsCI is the after-fix measurement.No live Gateway deployment was performed as part of this PR repair. The reported incident remains the pre-fix real-behavior reproduction; the after-fix isolated proof exercises the public runner and real SQLite projection worker without a live provider.
Diff accounting
Relative to current base: production +28/-2 (net +26), tests +166/-3 (net +163). Production growth is the explicit one-shot owner fact, the mutation-producer mappings, and the single pre-dispatch settlement boundary; there is no second session-open path or compatibility fallback. The larger test delta is the isolated public-runner/SQLite regression scenario requested by review.