fix(agents): repair persisted tool result pairing#81397
Conversation
|
Codex review: needs changes before merge. Reviewed July 3, 2026, 11:49 PM ET / 03:49 UTC. Summary PR surface: Source +167, Tests +176, Docs +1. Total +344 across 4 files. Reproducibility: yes. Source inspection shows current Review metrics: 1 noteworthy metric.
Stored data model Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Risk before merge
Maintainer options:
Copy recommended automerge instructionNext step before merge
Security Review findings
Review detailsBest possible solution: Land a narrow current-main port of the durable persisted pairing repair that preserves snapshot/cache lifecycle, delivery-mirror repair, real-over-synthetic selection, transient backup cleanup, and current docs/tests. Do we have a high-confidence way to reproduce the issue? Yes. Source inspection shows current Is this the best way to solve the issue? No, not as submitted. Durable session-file repair is the right layer, but the branch must be ported onto current Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 9d68f877ac3e. Label changesLabel justifications:
Evidence reviewedPR surface: Source +167, Tests +176, Docs +1. Total +344 across 4 files. View PR surface stats
Security concerns:
Acceptance criteria:
What I checked:
Likely related people:
What the crustacean ranks mean
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. How this review workflow works
|
1b1e4f5 to
385bc83
Compare
385bc83 to
0fdf37f
Compare
|
Rebased onto current main and resolved the only conflict in CHANGELOG.md; no intended behavior change. Latest local proof on rebased head 0fdf37f:
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
This pull request has been automatically marked as stale due to inactivity. |
|
This pull request has been automatically marked as stale due to inactivity. |
|
ClawSweeper status: review started. I am starting a fresh review of this pull request: fix(agents): repair persisted tool result pairing This is item 1/1 in the current shard. Shard 6/22. This placeholder means the worker is alive and reading the current context. I will edit this same comment with the actual review when the claws are done clicking. Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted. |
Summary
toolResultentries separated from their assistant tool-call entry, duplicated, or orphaned.abortedtool outputs remains unchanged.Change Type
Scope
Linked Issue/PR
Real behavior proof
toolResult, a duplicatetoolResult, and an orphantoolResult.mainJSONL session-file repair path, real temp session file, and productionrepairSessionFileIfNeeded.node --import tsx --input-type=modulecommand that wrote a corruptedsession.jsonl, invokedrepairSessionFileIfNeeded, then read the durable JSONL back from disk.Root Cause
toolResultentries that were displaced, duplicated, or orphaned in the persisted transcript.Regression Test Plan
src/agents/session-file-repair.test.tssrc/agents/session-transcript-repair.test.ts, but durable session-file repair did not have persisted-entry coverage for this corruption shape.User-visible / Behavior Changes
Sessions with persisted tool-call/tool-result pairing corruption can recover on restart instead of repeatedly failing during later context rebuilds.
Diagram
Security Impact
Repro + Verification
Environment
Steps
toolCallentry.toolResult.toolResultand an unrelated orphantoolResult.repairSessionFileIfNeeded.Expected
toolResultis moved next to the assistant tool call.toolResultentries are removed.Actual
Evidence
Attach at least one:
Human Verification
Review Conversations
Compatibility / Migration
Risks and Mitigations
toolResultentries whose ids match a visible assistant tool call span, duplicate ids, or tool results with no matching assistant tool call. Regression tests assert delivered assistant turns and unrelated non-message entries are preserved.abortedrepair is left as-is.Validation
pnpm docs:listpnpm test src/agents/session-file-repair.test.ts src/agents/session-transcript-repair.test.ts src/agents/pi-embedded-runner.sanitize-session-history.test.tspnpm exec oxfmt --check --threads=1 CHANGELOG.md docs/reference/transcript-hygiene.md src/agents/session-file-repair.ts src/agents/session-file-repair.test.tsgit diff --checkpnpm changed:lanes --base upstream/main --jsonpnpm check:changed --base upstream/main