Repository navigation
fix(context-engine): blocked durable turns repeat in the Gateway log on every run - #167595
Conversation
|
🦞👀 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 excludes terminal blocked turns from pre-run recovery so their warnings do not repeat on later session runs. Example: Session session-a retains blocked turn session-a:unrecoverable and has a later ready turn.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Partial Merge readiness✅ Ready for maintainer review Keep this PR open: current main still repeats warnings for terminal blocked turns, and the introduced patch fixes that specific problem without changing retention or advancement behavior. No actionable patch defect was found. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherBefore an agent run, the context-engine recovery worker reads durable outbox rows for the selected engine, plugin, and session, recovers advanceable work, and returns pending status and warnings to the host. flowchart TD
A[Agent run preparation] --> B[Outbox worker]
B --> C[Session outbox selection]
C --> D[Advanceable turn recovery]
D --> E[Ready turn drain]
E --> F[Context engine commit]
C --> G[Retained blocked audit records]
Technical reviewBest possible solution: Use the existing terminal-state predicate in recovery while preserving first-transition diagnostics, blocked audit records, and separate backlog-recovery work. Do we have a high-confidence way to reproduce the issue? Current main deterministically reselects and warns for a retained blocked row on each matching session recovery; the PR reports the same symptom in a live Gateway journal and a before-failing, after-passing boundary regression. Is this the best way to solve the issue? The patch fixes selection at the existing recovery owner, reuses the established predicate, and preserves retryable work and audit retention without adding another policy or storage mechanism. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against d1618ccd0b27. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource -1, Tests +3. Total +2 across 2 files. Added test files: 0. View PR surface stats
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 (1 earlier review cycle)
Reviewed October 11, 2026, 7:45 AM ET / 11:45 UTC (Revision 2). |
Blocked outbox rows are terminal audit markers: the drain already skips them and their outcome is logged once when the turn is blocked. Pre-run recovery still read every blocked row of the session and warned for it on every turn, so a single blocked turn repeated in the Gateway log hundreds of times. Recovery now selects only rows that can still advance.
9505aa0 to
28be933
Compare
…run (#167595) (cherry picked from commit be39fa3) Backport note: the release branch has not split the outbox into context-engine-turn-outbox.kernel.worker.ts; recoverContextEngineTurnOutbox lives in context-engine-turn-outbox.ts. Applied the same change there, reusing the release branch's existing outboxPayloadRequiresAdvancement() predicate (json_extract on payload_json; main uses the later payload_state column).
…solation, and flake fixes from main (#172693) * fix(context-engine): stop re-logging terminal blocked turns on every run Backport of #167595 (be39fa3) to the 2026.9.33 outbox owner, which still lives in context-engine-turn-outbox.ts on this line. * test(agents): retire session MCP managers left by earlier test files (#172515) (cherry picked from commit d4be691) * test(ci): bound native declaration fixture libraries Use ES5 ambient libraries for the synthetic native preparation programs instead of loading the default ES2023/browser library graph on every preparation. Keep the ES2023 syntax target, real native compiler, seven plugin producers, six preparation calls, both compiler failure controls, all assertions, and every existing timeout unchanged. The oversized fixture configuration originated in b78612a. The original ten-file shard reproduces the 30-second repair-case timeout on two CPUs and two workers. With the fixture scoped to its required built-ins, the same shard passes twice: 163 passed, four platform skips, and repair case times of 23.292s and 23.555s (303.26s and 304.25s shard wall times). Focused remote proof: pnpm test test/scripts/prepare-extension-package-boundary-artifacts.native.test.ts --maxWorkers=1 passes 15 tests with three Windows skips in 77.39s wall time on two CPUs. No production code, assertion, retry, or deadline changes. Changed checks pass formatting, ratchets, and all four test-root type shards. The broader namespace-export scan flags the unchanged model-catalog.runtime barrel on the pinned base; upstream ece9d9c already removes that export. (cherry picked from commit 05179a7) * fix(test): prevent Wear reader leaks between test cases (#172075) * fix(test): prevent resource leaks and cold-build shutdown timeouts * fix(test): include the worker bootstrap in the PR wrapper inventory (cherry picked from commit 03b02ee) * test(gateway): wait past the server handshake deadline in Gateway e2e connects (#169479) (cherry picked from commit e482290) * fix(test): managed-process, Vitest shutdown, and worker-artifact tooling tests time out on loaded hosts while polling ready files (#162613) Test-tooling suites for the managed child-process runner, check-changed cancellation, Vitest fork/worker shutdown, worker artifacts, and run-vitest progress waited for fixture wrappers, workers, and descendants by polling ready files, PID files, and the process table against 1-15 s wall-clock deadlines, which a loaded host outlasts. Readiness now arrives on the owned channel each fixture already has: runManagedCommand's onReady stream and child events, stdout/IPC readiness written after the fact it announces (PID files are renamed into place first), relayed worker readiness for the Vitest fork/worker fixtures, and retained command outcomes that fail fast if the child settles first. Foreign-descendant extinction without an owner join keeps a deadline-free check bound to the test signal. check-changed-cancellation and run-vitest-progress drop out of the timeout-race baseline. The reverse-release wait in run-vitest-progress and the native Windows Job cases stay unchanged (follow-ups; the latter has no native CI execution). No product source, test timeout, product timeout, or assertion meaning changed. Part of the polling audit from #162274. Proof on Blacksmith Testbox: delayed-readiness fault probes fail the original bytes and pass these bytes; forced-abort probes reach cleanup; 20/20 standalone runs per file; 3/3 replays of all seven owning tooling shards on the rebased head; tsgo; Codex autoreview and ClawSweeper clean. (cherry picked from commit b9512e7) * test: stabilize release timing boundaries (#166218) (cherry picked from commit 69ccd1e) --------- Co-authored-by: Peter Steinberger <[email protected]>
Related: #163566
Related: #135628
What Problem This Solves
Fixes: the Gateway log repeats
[context-engine] durable turn advancement is blocked: <turn>: transcript range is session-rebound|stale|too-largeon every run of a session that holds an old blocked turn, hundreds of times per turn, forever.User Impact
User impact: each blocked turn is reported once, when it becomes blocked. Later runs of the same session no longer repeat that warning or re-read the blocked rows. Blocked rows are still kept in the outbox for audit. Retention and settlement do not change.
Why This Change Was Made
Since #126593, blocked outbox rows have been terminal markers. The drain and the pending checks already skip them, and the transition logs its outcome once. In the recovery path the message is
blocked unrecoverable turn advancement; at acceptance it isskipped accepted turn advancement: accepted context-engine transcript range is .... Pre-run recovery still selected every blocked row in the session, parsed it, and warned again. Recovery now uses the same advanceable-row predicate as the drain, so it never reads a blocked row.Deleting or expiring blocked rows would be a retention change. This PR leaves that out. The larger backlog problem on the same host is orphaned
admittedheads that starve 2,257readyturns and make the unscopedlistPendingSessionsslow. Evidence for that is in #135628, which still needs its maintainer decision.Evidence
is blockedlines for 54 distinct turns (2,257 session-rebound, 2,248 stale, 95 too-large). One stale turn was logged 261 times across 25 Gateway processes in 35 days. The live outbox holds 54 blocked rows, so every line was a re-report of an existing terminal marker.drainPendingContextEngineTurnsBeforeRunentry point: the existing terminal-marker test now asserts that a later run of the session emits no warnings. It failed before the fix with the exact production line and passes after.pnpm test src/agents/harness/context-engine-turn-outbox.test.ts(15 passed; this PR adds no new test file).context-engine-turn-attempt,context-engine-turn-maintenance, andselectiontests pass (105 passed).pnpm tsgo:core,pnpm tsgo:core:test,oxlint,oxfmt --check, andpnpm check:database-worker-ratchet --base origin/mainall pass.origin/main): clean, with no actionable findings.