Skip to content

fix(context-engine): blocked durable turns repeat in the Gateway log on every run - #167595

Merged
jalehman merged 1 commit into
mainfrom
fix/turn-outbox-blocked-rows
Oct 13, 2026
Merged

jalehman merged 1 commit into
mainfrom
fix/turn-outbox-blocked-rows

Conversation

@jalehman

@jalehman jalehman commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

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-large on 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 is skipped 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 admitted heads that starve 2,257 ready turns and make the unscoped listPendingSessions slow. Evidence for that is in #135628, which still needs its maintainer decision.

Evidence

  • Live Gateway journal, 2026-09-03 to 2026-10-08 (2026.9.9): 4,600 repeated is blocked lines 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.
  • Regression through the real drainPendingContextEngineTurnsBeforeRun entry 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, and selection tests pass (105 passed).
  • pnpm tsgo:core, pnpm tsgo:core:test, oxlint, oxfmt --check, and pnpm check:database-worker-ratchet --base origin/main all pass.
  • Autoreview (branch vs origin/main): clean, with no actionable findings.

@clawsweeper

clawsweeper Bot commented Oct 9, 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.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS labels Oct 9, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 9, 2026
@clawsweeper

clawsweeper Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

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

  • Before: Every later run repeats the old session-rebound warning.
  • After: Recovery skips the blocked turn, retains its audit record, and commits the later ready turn without repeating the warning.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused, correct repair with meaningful boundary coverage; supplied runtime evidence does not demonstrate the post-fix Gateway behavior, and the broader linked issues remain outside its scope.
Proof confidence 🦐 gold shrimp (3/6) The supplied host state identifies this as maintainer-authored, outside the ordinary contributor proof gate; the body reports a passing recovery-boundary regression, while its live Gateway journal establishes only the pre-fix symptom.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Partial
User problem: Operators repeatedly see old terminal context-engine failures reported as if they happened again on every session run.
Reason: The logging fix has clear incident-backed value and respects the existing terminal-state contract; Related wording correctly leaves the broader linked reports open.

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
Reviewed head: 28be933d0c5b06ee968cef33e1b10c87a67afd70

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: No after-fix Gateway journal is supplied; the reported regression instead exercises the real pre-run recovery boundary with SQLite workers.
Agent review details

How this fits together

Before 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]
Loading

Technical review

Best 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

  • Blocked-row recovery selection and repeated diagnostics keeps the original intent (e63b5a0: The recent worker refactor moved existing outbox SQL and reused recovery results; it did not establish the original logging intent. The earlier terminal-state repair explicitly made blocked rows retained audit evidence rather than retryable work.)
  • Terminal-marker boundary regression keeps the original intent (7b15dcb: The existing regression protects retention of blocked evidence while allowing later ready turns to commit without degrading the session.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit e63b5a0 adds src/agents/harness/context-engine-turn-outbox.kernel.worker.ts:283 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: e63b5a01cf26; files: src/agents/harness/context-engine-turn-outbox.kernel.worker.ts)
  • astra-openclaw: Raw commit 7b15dcb adds src/agents/harness/context-engine-turn-outbox.test.ts:419 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 7b15dcb3edbc; files: src/agents/harness/context-engine-turn-outbox.test.ts)
  • Vito Cappello: Raw commit 5621979 adds src/agents/harness/context-engine-turn-outbox.test.ts:365 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 5621979a469a; files: src/agents/harness/context-engine-turn-outbox.test.ts)

PR surface

Source -1, Tests +3. Total +2 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 2 3 -1
Tests 1 4 1 +3
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 6 4 +2

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Repeated terminal warnings create sustained diagnostic noise and unnecessary recovery processing, with limited blast radius and no advancement or retention change.
  • 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.

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 need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-09T03:55:05.584Z sha 9505aa0 :: needs maintainer review before merge. :: none

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.
@jalehman
jalehman force-pushed the fix/turn-outbox-blocked-rows branch from 9505aa0 to 28be933 Compare October 11, 2026 11:39
@jalehman
jalehman merged commit be39fa3 into main Oct 13, 2026
98 checks passed
@jalehman
jalehman deleted the fix/turn-outbox-blocked-rows branch October 13, 2026 07:17
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 14, 2026
RomneyDa pushed a commit that referenced this pull request Oct 15, 2026
…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).
RomneyDa pushed a commit that referenced this pull request Oct 15, 2026
…run (#167595)

(cherry picked from commit be39fa3)

Backport adaptation: applied to recoverContextEngineTurnOutbox in context-engine-turn-outbox.ts, which this line has not yet split into a kernel worker module.
RomneyDa added a commit that referenced this pull request Oct 15, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P2 Normal backlog priority with limited blast radius. 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