Repository navigation
fix(context-engine): isolate corrupt outbox recovery rows - #180772
xiaopan-xydt wants to merge 3 commits into
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 real behavior proof before merge. What this changesThis PR retains undecodable outbox rows as terminal corrupt records so later healthy turns can advance. Example: Session session-a contains truncated payload {"state":"admitted", before session-a:later-ready.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 2 items remain This PR addresses a current recovery bug and resolves both previous findings; no introduced correctness defect was found. Priority: P2 Before merge
FindingsNone. Tests
Agent review detailsHow this fits togetherThe context-engine outbox stores durable turn advancements in the agent database; pre-run recovery prepares pending work, and the drain submits ready turns to the selected engine before context assembly. flowchart TD
A[Next agent run] --> B[Worker recovery]
B --> C[Agent database outbox]
B --> D[Retained corrupt record]
C --> E[Pending turn drain]
E --> F[Context engine commit]
F --> G[Context assembly]
Technical reviewBest possible solution: Keep malformed-row isolation in the existing recovery worker and shared pending predicate while preserving healthy FIFO work and diagnostic bytes. Do we have a high-confidence way to reproduce the issue? Current main directly exposes the reported path: truncated payload_json throws during recovery, and the pre-run caller catches the failure and degrades the lease; no target code was executed during this read-only review. Is this the best way to solve the issue? The patch repairs the existing recovery and selection owner without adding a competing queue or deleting damaged evidence, and the latest head preserves the established missing/unknown-state contract. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 062bbe5f9474. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +53, Tests +91. Total +144 across 2 files. Added test files: 0. View PR surface stats
LabelsLabel changes: No label changes. Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
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 (2 earlier review cycles)
Reviewed October 22, 2026, 2:03 PM ET / 18:03 UTC (Revision 3). |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Closing as not pursued. The remaining proof requires a running Gateway with a durable context engine plus persisted-state upgrade validation, which is not cost-effective for the current batch. The tests and review history remain available in the PR. |
Fixes #180193
What Problem This Solves
One undecodable context-engine outbox row could block every later turn in the same session. Recovery now terminates only the JSON-corrupt row, excludes it from pending selection, and continues with the next ready turn. Valid JSON with a missing or unknown state deliberately remains pending, preserving the compatibility contract established by #126593.
JSON.parse()on each persisted payload. A truncated row threw before later rows were inspected, and even a caught decode failure would leavepayload_state = 'admitted', so pending selection returned the same unreadable row on every run.payload_state = 'corrupt'with a durable error reason; decoded rows without a recognized state remain pending and inspectable.Why This Change Was Made
The malformed bytes invalidate one queue entry, not the remaining session history. Catching the parse error alone was insufficient because the untouched row still won the next pending-selection query, so the later turn was never committed and pre-run preparation still degraded the lease.
User Impact
A damaged queue payload no longer turns into a permanent same-session outage. The affected turn is terminally reported, later healthy turns can advance, and operators can still inspect the original bytes. Existing rows with incomplete state metadata keep their prior pending behavior.
Evidence
The regression runs the production recovery kernel against the real agent SQLite schema, then exercises pending selection and the pre-run drain.
Included cases:
Base-red against the pre-change kernel with the new regressions:
Formatting and whitespace:
What was not tested: a live multi-session Gateway with a manually corrupted production database. The regression uses the shipped recovery/drain entry points and a real SQLite outbox, but runs inside the repository test harness. Full
tsgotype checking is unavailable on this host because the downloaded Linux binary requires a newer glibc; CI will run the repository type checks.AI Assistance
This PR is AI-assisted. Used
rg,git diff, direct SQLite inspection, and focused/full Vitest runs. The implementer understands the code: only JSON decode failure is terminal, missing/unknown states remain pending, and existing FIFO and lease semantics remain in the shared owner.