Repository navigation
fix(agents): recover sessions after Responses item conflicts - #199757
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
@clawsweeper review Please review head |
|
🦞👀 Re-review progress:
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0f58c2680c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| replayPlan.itemRecovery?.owner && | ||
| msg.providerReplay === replayPlan.itemRecovery.owner.providerReplay |
There was a problem hiding this comment.
Match recovery receipts across cloned async fragments
When a successfully repaired response emits async tools, agent-stream-response.ts:476–481 structured-clones each committed prefix, including its recovery receipt. The terminal fragment retains another receipt object, and the replay resolver selects that last fragment as the owner. This reference-equality check therefore misses the earlier fragments and reanchors their newly generated tool calls. orderResponsesAsyncToolResults places their results after the terminal fragment, where recovery has been disabled, so calls receive replacement IDs while results retain the original IDs. The next request contains unmatched function outputs and can fail again. Identify the recovery boundary using the durable receipt identity across fragments rather than object identity.
AGENTS.md reference: AGENTS.md:L71-L71
Useful? React with 👍 / 👎.
| for (const msg of replayMessages) { | ||
| // The recovery receipt anchors only the rejected past. New output keeps its IDs. | ||
| if ( | ||
| "role" in msg && | ||
| msg.role === "assistant" && |
There was a problem hiding this comment.
Preserve the recovery cutoff when failed owners are filtered
If the repair retry fails without producing content, its empty error message still owns the persisted recovery receipt. On subsequent library requests, the replay plan finds that owner before transformation, but transformMessages drops it through resolveFailedAssistantReplay (transcript-transform.ts:189–199). Consequently, this loop never reaches the owner and never clears recoveryAnchor, even after later requests succeed. Every later assistant output is then treated as rejected history: fresh reasoning is discarded and fresh tool-call IDs are rewritten, preventing normal continuation and repeatedly rebuilding the full history. Preserve the cutoff independently of whether the receipt-bearing message survives transcript filtering.
AGENTS.md reference: AGENTS.md:L71-L71
Useful? React with 👍 / 👎.
|
Codex review: needs maintainer review before merge. What this changesAutomatically recover Responses item conflicts once and preserve the repaired replay boundary across later turns and session reloads. Example: Cold replay reconstructs stored tool arguments from
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR addresses a current session-wedging failure. All three prior findings are resolved at the reviewed head, and no new actionable defects were found; exact-head CI remains pending. Priority: P1 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe Responses transport converts saved conversation messages into provider requests and streams assistant output back to the agent; transcript sanitization and SQLite persistence retain its recovery receipt. flowchart LR
A[Saved conversation] --> B[Agent history normalization]
B --> C[Responses replay projection]
C --> D[Provider transport]
D --> E[Conflict recovery]
E --> C
E --> F[Persisted recovery receipt]
F --> A
Technical reviewBest possible solution: Extend the existing semantic recovery and replay-state owners with one bounded repair that preserves conversation content and durable call/result pairing. Do we have a high-confidence way to reproduce the issue? The committed loopback regression models immutable provider item identity rejecting reconstructed tool arguments, with reported base failures and head passes; this read-only review executed no target code. Is this the best way to solve the issue? The patch repairs the rejected request projection through existing owners, preserves transcript content, and bounds retries before output, making it a focused solution to the demonstrated missing recovery. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 29b1f65e7970. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +218, Tests +392, Docs +17, Other 0. Total +627 across 21 files. Added test files: 1. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. Review metrics
LabelsLabel 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 (2 earlier review cycles)
Reviewed November 15, 2026, 5:02 PM ET / 22:02 UTC (Revision 3). |
|
Final head:
Earlier review dispositions, still verified at the final head:
Sanitized terminal trace from the exact-base writer and candidate reader (all fixture content is synthetic): Final proof: 206 focused tests / 7 files / 5 shards pass, including all 14 prefix-stability cases and all three embedded SQLite reopen modes. Chromium browser 5 and end-to-end 7 cases pass. Final Codex P0–P2 delta review is scoped-clean. @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d413c371b3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| attempted = true; | ||
| const request = await buildRequest({ itemRecovery: anchor }); | ||
| delete request.previous_response_id; | ||
| suppressOpenAIResponsesCompaction(output, model, options, undefined, anchor); |
There was a problem hiding this comment.
Preserve repair receipts through Gateway history normalization
When a repaired response is a silent NO_REPLY, or the repair retry fails without content, the recovery receipt exists only on that assistant message. In the embedded-agent path, normalizeAssistantReplayMessage in src/agents/embedded-agent-runner/replay-history.ts:264–278 drops those messages before transport conversion, so buildOpenAIResponsesCompactionReplayPlan never sees the receipt. Subsequent turns therefore replay the original conflicting IDs and require another repair instead of retaining the repaired prefix. Unlike the previously reported transport-filtering issue, the fresh evidence here is the Gateway's earlier history-normalization stage, which runs before the newly added synthetic-boundary handling. Preserve the receipt independently of whether its assistant content survives that stage.
AGENTS.md reference: AGENTS.md:L71-L71
Useful? React with 👍 / 👎.
|
🦞👀 Re-review progress:
|
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
…w#199757) * fix(agents): recover saved Responses item conflicts automatically * chore: shrink assertion allowance after moving Responses parser * perf(ai): preserve normal Responses projection keys outside recovery * fix(ai): preserve Responses recovery boundaries across async replay * fix(ai): validate recovery receipts in the replay state owner * fix: preserve Responses recovery after failed retries
…penclaw#199846) openclaw#199757 changed the item-conflict recovery message shown to users but left this suite asserting the previous wording, so the test fails on main and on any PR whose changed lanes include auto-reply.
What Problem This Solves
Fixes OpenAI Responses sessions that repeatedly fail with
item_conflictuntil the user compacts or abandons the session.Team reliability evidence for November 15: 13 request-level failures across five dashboard sessions; four wedged, zero automatic recoveries, up to five hours before abandonment. The earlier count of 30 included duplicate log lines. All affected builds contained #198357. Seven conflicts had no visible precursor, three followed degenerate output, and one each followed a tool error, user interruption, or another conflict; none followed compaction or restart.
User Impact
The Responses transport repairs rejected saved items and retries once automatically. The repair survives subsequent turns and SQLite reloads, including when the retry itself failed. A second rejection surfaces actionable retry, compaction, and model-switch guidance. After visible output, repair is deferred to the next request so tool effects are not repeated.
No configuration, dependency, or database schema changes. Repair removes rejected provider IDs and opaque reasoning/checkpoints from the request projection while preserving conversation text and paired tool results. Healthy sessions retain their existing prefix and continuation.
Why This Change Was Made
Reuse the existing semantic replay recovery and compaction-suppression owner. Re-anchor conflicting tool-call/result IDs together, discard
previous_response_id, and persist a repair receipt through transcript sanitization. Preserve that receipt through async clones and both history-normalization and transport filtering boundaries. Log a session-hasheditem_conflict_recoveryoutcome.The uniqueness mock reproduces an abort exposing an older completed item: losing warm continuation forces cold replay, which reconstructs arguments under the original item ID. Incomplete aborted calls are already filtered; no speculative abort-specific guard was added. This proves the missing general recovery, not the precise server-side mismatch in every production incident.
Production delta is +218 lines (278 added / 60 removed); tests/support net +392. The growth implements bounded recovery, durable outcomes, and demonstrated replay boundaries. Existing storage, retry, projection-cache, and failed-output owners remain authoritative. The parser moved beside its encoder, and its assertion allowance shrank from 7 to 6. No new cache or parallel recovery owner.
Evidence
Final source head:
486e6ca2badaea2d4d8c9572cb3d59e05b68163c. Exact-head CI passed. ClawSweeper final-head review has zero open items and no actionable findings.pr-simplifycompleted.pnpm check:changedwas run. The known dead-export main regression reproduces on exact basebdbf30094ec879e410523f95294ff7ff4a9baa4c, introduced bycec47fd13f23/ feat(openclaw-id): name invited members from their email and ask who they are on first visit #198491 (ui/src/lib/openclaw-id/member-welcome.ts). It remains a lead follow-up, not noise or a claimed green check. Final local run completed: every other check passes, including all core/test type graphs, formatting, lint, import cycles, and source guards.4cb4d78c642bCI had one gateway WebSocket event timeout. The selected test and full 15-case Bun file pass locally; the full file also passes on the exact main parent. This failure remains unreproduced, not proven inherited or fixed. No CI rerun was requested; the final source head gets fresh CI.Synthetic scale proof uses a 54.75 GiB SQLite DB, 5,000 session records, 309,410 events, and 62,000 workspace files / 1.116 GB, with no Team data. The ordinary database owner completed integrity/foreign-key checks. APFS host, not btrfs. Eight actual stored histories exercise request preparation; five interleaved A1/A2/B repetitions per timing/allocation mode compare exact base with the reviewed transport implementation:
All wire hashes match. No speedup claim; measurements are owner stress proof, not end-user latency. Fresh rotating-session allocation confirmation measured 76,504→76,875 B/request (+0.485%, 371 B), with A/A variation −1.078…+0.442%. The final upstream normalization owner measurement (1,000 messages, 2,000 attempts, five A1/A2/B repetitions) measured 47.53→45.79 µs wall, 67.09→66.32 µs CPU, and 52,607→52,491 sampled B/request (−0.22%). Hashes and copy/reuse counts match. Allocation A/A variation was −0.377…+0.279%; host contention made timing controls too noisy for a latency conclusion (wall −83.89…+260.00%, CPU −16.93…+53.29%).