Skip to content

fix(context-engine): ignore terminal blocked outbox rows - #126593

Merged
Patrick-Erichsen merged 1 commit into
openclaw:mainfrom
astra-openclaw:fix/context-engine-terminal-outbox
Aug 21, 2026
Merged

Patrick-Erichsen merged 1 commit into
openclaw:mainfrom
astra-openclaw:fix/context-engine-terminal-outbox

Conversation

@astra-openclaw

@astra-openclaw astra-openclaw commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Closes #126591

What Problem This Solves

Fixes an issue where users whose context engine records one unrecoverable turn advancement would have later turns repeatedly degraded because the terminal outbox row was still counted as pending work.

Why This Change Was Made

Blocked outbox payloads are terminal audit evidence, not retryable advancement work. This change excludes only rows whose persisted state is explicitly blocked from all pending/drain selection points while leaving those records stored and inspectable. Retryable failed rows keep their existing ordering behavior, and missing/unknown states remain pending (fail closed).

User Impact

One unrecoverable context-engine advancement no longer forces later turns to degrade or prevents later ready advancement from committing. Operators retain the terminal record for diagnostics.

Evidence

Real setup, after fix

Verified on a running OpenClaw 2026.8.1 main-based installation at 8e0d1bce85d3, with lossless-claw 1.0.0-beta.4 loaded as the active context engine. The installed build contains the same three-selector blocked-row exclusion exercised by this PR. The proof turn used the real Gateway and provider, did not use tools, and was not delivered to a channel.

Two supported openclaw backup sqlite create --agent main snapshots bracketed a turn targeted at a session with a retained blocked row. Identifiers below are one-way SHA-3 prefixes; no transcript or credential content is included.

before snapshot sha256: a4d0239f1835c2143c69ff872d3f42f8a6387d084c2232d9e0aae435128a4865
session_hash | rowid | state   | failure | created_at
A552B1B3A436 | 52    | blocked | stale   | 1787215442326

gateway turn (no channel delivery):
OUTBOX_PROOF_OK
[lcm] commitTurn: tokenBudget not provided; using default 128000
[agents/agent-command] run <redacted> ended with stopReason=stop

after snapshot sha256: 61cfa093a05dfe3b9f4e7529668ef71b2609135af5d0c6b47ea59fd869006c53
session_hash | rowid | state   | failure | created_at
A552B1B3A436 | 52    | blocked | stale   | 1787215442326

after outbox state counts:
admitted | 15
blocked  | 22
ready/failed rows for the proof turn | 0

after snapshot checks:
PRAGMA quick_check       -> ok
PRAGMA integrity_check   -> ok
PRAGMA foreign_key_check -> 0 rows

The retained audit row is unchanged before/after. Lossless commitTurn ran, the proof turn ended normally, and no ready/failed row survived the commit. The bounded Gateway/Lossless trace contained no legacy selection or degradeBeforeStart event.

Kysely/SQLite contract

The repository pins Kysely 0.29.4. In that exact version, sql<T> returns RawBuilder<T>, where accepts an expression of SqlBool, and SqlBool includes boolean/SQLite 0/1.

An isolated Node 24 + node:sqlite execution using OpenClaw's real synchronous Kysely adapter compiled and ran the exact predicate:

{
  "kyselyVersion": "0.29.4",
  "compiledSql": "select \"advancement_key\" from \"context_engine_turn_outbox\" where json_extract(context_engine_turn_outbox.payload_json, '$.state') IS NOT 'blocked' order by \"advancement_key\"",
  "parameters": [],
  "selectedAdvancementKeys": ["later-ready"]
}

The expression is static (no user-controlled interpolation), TypeScript accepted it under NodeNext, and IS NOT is intentional: it excludes only an explicit blocked state, while a missing state remains pending.

Regression and repository checks

  • Focused Vitest lane: 3 files, 13 tests passed.
  • The blocked row remains stored, a later ready row commits, and the current turn is admitted without degradation.
  • A new fail-closed regression proves a persisted payload with no state remains pending.
  • Existing coverage continues to prove that retryable failed rows prevent same-session overtaking.
  • node scripts/check-changed.mjs -- <three changed paths>: passed, including formatting, type checks, lint, dead-code, dependency, plugin-boundary, import-cycle, and schema guards.
  • Kysely contract script: runtime execution passed and standalone TypeScript check passed.
  • git diff --check: passed.

This PR is AI-assisted. The diagnosis, runtime proof, code, and tests were manually reviewed, and the contributor understands the change.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Aug 20, 2026
@clawsweeper

clawsweeper Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 20, 2026
@clawsweeper

clawsweeper Bot commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 20, 2026, 7:15 AM ET / 11:15 UTC.

ClawSweeper review

What this changes

The PR excludes explicitly blocked context-engine outbox rows from pending-work selection while retaining them for diagnostics.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open: current main still counts terminal blocked outbox rows as pending, and this PR applies the narrow owner-boundary repair with strong regression and real-Gateway evidence. No correctness finding was identified; rebase onto current main and rerun exact-head validation before merge.

Priority: P1
Reviewed head: 235fa954c8e36bff56b798bba4b650a0ae3807db

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The branch has a focused owner-boundary repair, meaningful regressions, and convincing real-Gateway after-fix evidence.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR includes redacted after-fix real-Gateway and SQLite snapshot evidence: a blocked row remains retained while the subsequent turn completes normally.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR includes redacted after-fix real-Gateway and SQLite snapshot evidence: a blocked row remains retained while the subsequent turn completes normally.
Evidence reviewed 5 items Current-main defect: Current main's scheduler, per-session selector, and final pending check select all matching outbox rows without a state predicate, so blocked rows can reach the result that degrades the next turn.
Canonical owner repair: The branch defines one closed-union predicate and applies it to all three pending-selection points, while recovery continues retaining and reporting blocked records.
Caller and boundary tests: The pre-turn caller degrades only when drain reports pending; updated tests retain the blocked row, advance a later ready row, avoid degradation, and preserve retryable failure ordering.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs src/agents/harness/context-engine-turn-outbox.test.ts src/agents/harness/context-engine-turn-attempt.test.ts

Result: FAIL (failed) — execution before step 1 run: live-proof package manager pnpm is unavailable after its official installer (curl -fsSL https://get.pnpm.io/install.sh | sh -): command failed without output

live-proof package manager pnpm is unavailable after its official installer (curl -fsSL https://get.pnpm.io/install.sh | sh -): command failed without output

Assertions:

  • FAIL expect_output: passed

How this fits together

The context-engine outbox persists turn-advancement work for an agent session. Before a new turn runs, the harness recovers and drains pending rows; the result decides whether the session starts normally or degrades.

flowchart LR
A[Agent turn admission] --> B[Context-engine outbox]
B --> C[Recovery and pending selection]
C --> D{Persisted row state}
D -->|blocked| E[Retained audit record]
D -->|ready or retryable| F[Commit advancement]
F --> G[Normal or degraded turn start]
Loading

Before merge

  • Resolve merge risk (P1) - The branch is behind current main; rebase and rerun exact-head checks so the persisted-row selection change is validated against the actual merge result.
  • Complete next step (P2) - The PR already contains the narrow source-backed fix; it needs normal rebase and exact-head validation, not an automated repair lane.
Agent review details

Security

None.

PR surface

Source +9, Tests +78. Total +87 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 11 2 +9
Tests 2 87 9 +78
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 98 11 +87

Review metrics

Metric Value Why it matters
Production versus test LOC production +9, tests +78 The small production predicate is paired with boundary coverage for blocked retention, later ready advancement, and missing-state fail-closed behavior.

Stored data model

Persistent data-model change detected: serialized state: src/agents/harness/context-engine-turn-outbox.test.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #126591
Summary: This PR is the linked candidate repair for the current main blocked-outbox behavior.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Rebase and validate durable recovery (recommended)
    Rebase onto current main and run the focused outbox and turn-attempt tests plus changed checks to verify blocked records no longer degrade a session while retryable rows remain ordered.

Technical review

Best possible solution:

Use the single state-based outbox selection rule, preserving blocked records as audit evidence while allowing ready work to progress and retryable failures to retain ordering.

Do we have a high-confidence way to reproduce the issue?

Yes—current main source shows blocked rows reach all pending selectors, and the focused branch regressions cover the resulting pre-turn degradation boundary.

Is this the best way to solve the issue?

Yes—the outbox owns row state and pending selection, so filtering only explicit terminal rows avoids a downstream workaround while preserving retryable ordering.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 755dad74d1fc.

Labels

Label changes:

  • add merge-risk: 🚨 session-state: The patch changes how persisted outbox rows participate in session recovery and turn advancement.

Label justifications:

  • P1: A terminal advancement can repeatedly force later turns in the affected session to degrade.
  • merge-risk: 🚨 session-state: The patch changes how persisted outbox rows participate in session recovery and turn advancement.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR includes redacted after-fix real-Gateway and SQLite snapshot evidence: a blocked row remains retained while the subsequent turn completes normally.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR includes redacted after-fix real-Gateway and SQLite snapshot evidence: a blocked row remains retained while the subsequent turn completes normally.

Evidence

What I checked:

Likely related people:

  • Josh Lehman: Authored the long-session context-engine repair in this outbox path's history. (role: prior context-engine outbox contributor; confidence: medium; commits: 2f4dff742812; files: src/agents/harness/context-engine-turn-outbox.ts)
  • SunnyShu: Authored the durable-state stall repair immediately preceding the current outbox work. (role: prior durable-state contributor; confidence: medium; commits: d758ec48d4d0; files: src/agents/harness/context-engine-turn-outbox.ts, src/agents/harness/context-engine-turn-attempt.ts)

Rank-up moves

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

  • Rebase onto current main and rerun focused exact-head validation before merge.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (3 earlier review cycles)
  • reviewed 2026-08-20T08:08:24.757Z sha 483e5566d814d094906432ab1360536b4dff944d :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-20T08:50:43.510Z sha 483e5566d814d094906432ab1360536b4dff944d :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-20T09:57:27.869Z sha 235fa95 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. and removed P2 Normal backlog priority with limited blast radius. labels Aug 20, 2026
Keep terminal blocked records available as audit evidence while excluding them from pending advancement selection.\n\nRefs openclaw#126591
@astra-openclaw
astra-openclaw force-pushed the fix/context-engine-terminal-outbox branch from 483e556 to 235fa95 Compare August 20, 2026 09:43
@astra-openclaw

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

The draft is rebased onto current main and the PR body now includes redacted real-Gateway evidence from supported before/after SQLite snapshots plus the inspected Kysely 0.29.4 type/runtime contract. The head also uses null-safe IS NOT 'blocked' and adds a fail-closed missing-state regression. Focused tests and check-changed pass on the new head.

@clawsweeper

clawsweeper Bot commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@astra-openclaw
astra-openclaw marked this pull request as ready for review August 20, 2026 09:50
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 20, 2026
@Patrick-Erichsen Patrick-Erichsen self-assigned this Aug 21, 2026

@Patrick-Erichsen Patrick-Erichsen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The terminal-state predicate is at the correct outbox owner boundary and is applied consistently to all three pending selectors. Coverage preserves blocked audit rows, later ready progress, missing-state fail-closed behavior, and retryable same-session ordering.

@Patrick-Erichsen

Copy link
Copy Markdown
Contributor

Maintainer landing note: I reviewed the latest ClawSweeper rank-up move. I am not forcing a manual rebase solely for behind-main drift: the repo-native scripts/pr landing flow reports the PR conflict-free, preserved the reviewed head, and accepted the hosted exact-head/recent-parent gate with OPENCLAW_TESTBOX=1. The current main implementation of the touched selectors is unchanged, and the focused behavior, SQLite/Kysely contract, hosted CI, and autoreview are green.

@Patrick-Erichsen
Patrick-Erichsen merged commit 7b15dcb into openclaw:main Aug 21, 2026
323 checks passed
@Patrick-Erichsen

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 21, 2026
…6593)

Keep terminal blocked records available as audit evidence while excluding them from pending advancement selection.\n\nRefs openclaw#126591

Co-authored-by: astra-openclaw <[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 merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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.

Context engine treats terminal blocked outbox rows as pending work

2 participants