Skip to content

fix(openai): recover item conflicts before output and across runs - #199896

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-micro-item-conflict-inturn-retry-20260919
Nov 16, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-micro-item-conflict-inturn-retry-20260919

Conversation

@steipete

@steipete steipete commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Related: #199757

What Problem This Solves

Fixes failed or repeatedly wedged turns when Responses reports item_conflict before assistant output, or a later internal session-effects run inherits a deferred repair.

User Impact

Pre-output conflicts retry once within the same turn. Conflicts after text, reasoning, or tool activity remain deferred to avoid repeating work; the saved repair applies after reload and when that history is copied into an internal session-effects run. Successful requests applying a saved repair log recovered. No configuration or migration is needed.

Why This Change Was Made

The shared SSE/WebSocket classifier inferred output from every event outside a short prelude list. Compaction progress and compaction item lifecycle events emit no assistant content, so they must not disable recovery. The replacement checks actual output items, deltas, and tool activity.

Deferred receipts already survive SQLite reopen, but their session identity fence prevented a copied history from applying its repair. Item-repair receipts now follow that history while preserving provider, model, endpoint, and credential fences. Encrypted checkpoints and ordinary compaction suppression remain session-bound. The converter reports when it applies a repair, including prepared-input reuse, so completion logging needs no additional history scan. Production delta: +62/−17, net +45 lines; growth carries the applied fact across conversion and request completion. No new cache or persistence format.

Evidence

  • Team build dd2d58be, including fix(agents): recover sessions after Responses item conflicts #199757 (d1307e61), logged Model request failed at 2026-11-16 02:07:13.716Z, item_conflict_recovery outcome=deferred at .717Z, and Embedded agent failed before reply at .760Z (run e8dafb99, request 1; dashboard hash 9e428ae0, recovery hash sha256:e1dc26a2550b). The same recovery hash logged deferred at 02:13:22Z and 02:13:54Z on request 1 of new internal-session-effects runs. These logs establish recurrence; the incident's preceding wire events were not captured, so exact production attribution remains unconfirmed.
  • Loopback integration: four compaction-progress cases fail on exact parent 443e9730695d6fa1549d84d9f45187883e9570f1; two full compaction-lifecycle cases fail before the review correction. All 21 pass with the fix. Real text/function/hosted-tool output still defers over both transports.
  • Real embedded runner with synthetic provider, tools, and SQLite: deferred → close/reopen → new run succeeds without another conflict, including a real internal-session-effects fork. Before the fix, the fork fails again; ordinary cold recovery lacked its completion log. All five cold-prefix scenarios now pass with repaired-prefix stability.
  • Focused transport/WebSocket cases, checkpoint isolation, prepared context usage, provider parity, and all 14 agent-tool prefix-stability cases pass. All 5 Chromium browser and 7 UI end-to-end cases pass locally. No live provider or Team mutation was performed.
  • Synthetic fixture: canonical agent schema, 5,000 sessions, 35.06 GiB logical SQLite data, 62,000 files/1.116 GB on compressed btrfs; no Team data copied. Five interleaved A1/A2/B repetitions, 30 operations/sample, with separate CPU/timing and sampled allocation. Stream owner (1,003 events): median 6.671 → 4.998 ms, CPU 4.095 → 4.078 ms, sampled allocation 5.593 → 5.614 MB. A/A wall noise −58% to +65%, CPU −20% to +1.2%, allocation −1.1% to +1.7%: no speedup claim. Fork repair (203 messages) now does the previously skipped work: 0.163 → 0.238 ms, CPU 0.277 → 0.370 ms, allocation 307.6 → 388.6 KB.
  • Codex autoreview is P0–P2 scoped-clean for the full change and the final lexical-callback correction (964b8c5b0a5f8567b7e163cd77e83874a276b9e0, base 443e9730695d6fa1549d84d9f45187883e9570f1). Its compaction-lifecycle finding was fixed with red/green proof. pnpm check:changed found an unbound-method lint error; the arrow callback fixes it, focused type-aware lint passes, and all 21 integration cases pass again. The full pnpm check:changed --base 443e9730695d6fa1549d84d9f45187883e9570f1 rerun passes every check except the attributed baseline dead export (including corrected lint, core and all 29 test type graphs, formatting, and import-cycle guards). Exact-head CI run 43794223591 and openclaw/ci-gate passed. ClawSweeper’s final-head review has zero findings and zero open items. Native landing merged the reviewed head as e1f84d9cf7709ddb23e1e0ab0a906a298c363ee5 on 2026-11-16 at 03:06:09Z; no admin CI exception was needed. The dead-export gate independently fails on the exact parent for resolveRollbackWorkerInputs; perf(update): replace the candidate canary with a runtime contract check #198268 (e4a30936bb35) removed its external caller while leaving it exported. This is an inherited main regression, not a passing check.

@clawsweeper

clawsweeper Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: M labels Nov 16, 2026
@steipete
steipete marked this pull request as ready for review November 16, 2026 02:39
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-16T02:41:48.610558Z 95324d2 Draft marked ready
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Please review final head 964b8c5b0a5f8567b7e163cd77e83874a276b9e0. The complete change and final lexical-callback correction have clean Codex P0–P2 reviews. The 21 transport cases, five cold-run SQLite scenarios (including deferred repair into an internal session-effects fork), prefix stability, and focused type-aware lint pass. The PR body contains the reproduction, Team evidence, and synthetic measurements. No hosted findings have been posted yet; this request updates the review to the final head.

@clawsweeper

clawsweeper Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P1 High-priority user-facing bug, regression, or broken workflow. 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. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 16, 2026
@clawsweeper

clawsweeper Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR permits item-conflict recovery after compaction-only events, carries deferred repairs into copied histories, and logs successful saved repairs.

Example: A Responses stream emits response.compaction.compacting and then item_conflict before assistant output.

  • Before: The progress event disables automatic recovery and the turn fails.
  • After: OpenClaw retries once with repaired conversation items.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Focused production-boundary regressions support the implementation; validation remains synthetic and the production incident's precise event sequence is unknown.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the contributor proof gate; supplied validation uses real SDK clients over loopback and an embedded SQLite runner, without claiming live-provider verification.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Responses turns can fail before any answer or repeatedly fail when an internal run inherits history needing repair.
Reason: The maintainer-authored direction restores documented automatic recovery while preserving the rule against repeating output or tool work.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR addresses concrete recovery gaps still present on main; no actionable correctness or security findings were identified.

Priority: P1
Reviewed head: 964b8c5b0a5f8567b7e163cd77e83874a276b9e0

Before merge

None.

Findings

None.

Agent review details

How this fits together

The Responses transport converts saved conversation history into provider requests and consumes SSE or WebSocket events, producing assistant output and durable replay receipts.

flowchart TD
  A[Saved transcript] --> B[Replay conversion]
  B --> C[Responses client]
  C --> D[SSE or WebSocket]
  D --> E[Recovery decision]
  E --> F[Assistant output]
  E --> B
  E --> A
Loading

Technical review

Best possible solution:

Keep the shared recovery owner, distinguish compaction from output, and let existing repair receipts follow copied history without relaxing checkpoint or credential fences.

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

Current-main source explains both failures: compaction progress marks output observed, and copied repair receipts fail session matching; the supplied regressions target those paths, although the incident's exact wire sequence remains unconfirmed.

Is this the best way to solve the issue?

The patch repairs existing classification and replay owners with a transient applied flag, preserving bounded retries and avoiding another persistence or recovery mechanism.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 7e48c6be722a.

Provenance checked

  • Bounded item-conflict recovery keeps the original intent (d1307e6: Recover rejected saved items once, persist the repair, and defer after output to avoid repeated effects.)
  • Session matching for item-repair receipts changes intended behavior with a stated reason (ef68101: Centralize exact replay identity matching; this PR explains why history-local repair receipts may cross session copies while encrypted checkpoints remain session-bound.)
  • Prepared admission input keeps the original intent (519dd41: Reuse admission's converted input once when conversion contracts match; the patch carries the repair-applied fact through that same handoff.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit d1307e6 adds packages/ai/src/transports/openai-responses-replay-internal.ts:82 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: d1307e616745; files: packages/ai/src/transports/openai-responses-replay-internal.ts)

PR surface

Source +45, Tests +141, Docs +4. Total +190 across 10 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 7 62 17 +45
Tests 2 208 67 +141
Docs 1 5 1 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 275 85 +190

Preflight source

Source 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

Metric Value Why it matters
Production versus test LOC Production +62/−17; tests +208/−67 Production growth carries the applied-repair fact through existing conversion and completion owners; test growth covers distinct transport and persistence boundaries.

Labels

Label changes:

No label changes.

Label justifications:

  • P1: Reported recurring Responses failures interrupt active agent workflows, and source confirms recovery gaps in current main.
  • 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 execution lanes are retired.

Reviewed November 15, 2026, 9:58 PM ET / November 16, 2026, 02:58 UTC.

@steipete
steipete merged commit e1f84d9 into main Nov 16, 2026
148 of 151 checks passed
@steipete
steipete deleted the steipete/perf-micro-item-conflict-inturn-retry-20260919 branch November 16, 2026 03:06
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 16, 2026
…enclaw#199896)

* fix(openai): recover item conflicts before output and across runs

* fix(openai): bind the applied repair callback lexically
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M 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