Skip to content

fix(openai): conversations fail when hooks override saved-context replay - #199451

Merged
vyctorbrzezowski merged 3 commits into
mainfrom
openclaw/briny-barnacle-4
Nov 15, 2026
Merged

vyctorbrzezowski merged 3 commits into
mainfrom
openclaw/briny-barnacle-4

Conversation

@roboclaw-bot

@roboclaw-bot roboclaw-bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #198357

What Problem This Solves

Fixes OpenAI conversations failing with a saved-context conflict when a later payload hook overrides checkpoint replay settings, and restores the recovery guidance that was lost on the way to chat.

User Impact

Conversations using retained OpenAI checkpoints keep their context without re-storing conflicting checkpoint records. If an item conflict still occurs, the chat shows the existing recovery instructions instead of only the raw provider error. No configuration changes, migrations, transcript rewrites, or automatic replay of completed work are introduced.

Why This Change Was Made

The earlier checkpoint safeguard ran before the final payload hook. The transport now reapplies the same storage invariant to the final hooked input, including removing a stale continuation reference. Ordinary stored continuation and Azure/custom endpoint policies remain unchanged.

The reply-failure path now uses the existing code-aware format renderer rather than rebuilding a generic diagnostic from the raw error.

OpenAI can report this conflict after streaming output, so this fix prevents the conflicting request rather than retrying after output or tool work has started.

Evidence

Maintainer verification and test correction

The published head 96d47170 reproduced the failing continuation assertion without incorporating a newer main. Production behavior was correct; the test still expected stored references for a stateless checkpoint replay and recovery.

The corrected test verifies the complete input in the checkpoint request and in recovery, with no previous_response_id. The next normal turn reuses the last valid stored prefix (resp_1) and includes all intervening messages; it never references the unstored recovery response. The scenario retains its exact four requests for three prompts, including the existing recovery attempt. No new retry path or production change was added.

Fresh validation on Tempbook: 25 existing tests passed (22 continuation cases and 3 real-loopback SSE/WebSocket/cached-WebSocket cases). Focused types, lint, formatting and line limits passed. One redundant checkpoint assertion was then removed; formatting was rechecked without repeating the unchanged behavior tests. No external OpenAI API call was repeated; the earlier live proof below remains the implementation author's evidence.

The published correction has the same Git tree as the reviewed local candidate. Current-head CI is the remaining broad validation.

Verified published head: ed2e15050265b21356c539f183c551b40a68fa3e; Git tree matches the reviewed local correction.

  • Before/after regressions reproduce the exact lost-guidance reply and check both the delivered payload and the saved lifecycle notice.
  • Serialized-request regressions fail before the fix and pass for SSE, WebSocket, and cached WebSocket, preserving the checkpoint/input and sending only one request.
  • The earlier implementation report listed 133 focused passes. The fresh maintainer runs above separately reproduce and correct the continuation test failure on the published head.
  • Live OpenAI API-key proof passed with a real stored checkpoint: ordinary restoration, reload, and a late-hook override all retain a tool-derived marker across subsequent agent prompts, with one physical request per prompt.
  • Scoped TypeScript, lint, formatting, and diff checks passed. No package boundary or dependency changes.
  • Independent local autoreview (Codex engine, P0–P2) reviewed the complete candidate against base c5381ef and reported scoped-clean, with no actionable findings. The local ClawSweeper checkout was outside this session's permitted file scope; the documented autoreview fallback was used. Hosted review remains pending.

The original production request payload was not retained. The late-hook escape is reproduced and fixed, but is not claimed as the confirmed trigger of that particular incident. The affected production conversation has not been reset or resumed as part of this change.

Contributor credit

Reported and requested by @vyctorbrzezowski.

Work sessions

Linked for team reference; these sessions aren’t public.

Worked on by

roboclaw-bot and others added 2 commits November 15, 2026 04:38
Enforce stateless checkpoint replay on the final hooked request and preserve code-specific recovery guidance in terminal replies. Do not replay requests after accepted output.

Co-authored-by: vyctorbrzezowski <[email protected]>
Worked on by:
- @vyctorbrzezowski

Co-authored-by: vyctorbrzezowski <[email protected]>
OpenClaw-Publication: 82463cca-ea02-47f4-b2d3-61750f433b26
@clawsweeper

clawsweeper Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: S labels Nov 15, 2026
@roboclaw-bot
roboclaw-bot marked this pull request as ready for review November 15, 2026 04:40
@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. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. 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 15, 2026
@clawsweeper

clawsweeper Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR enforces stateless OpenAI checkpoint replay after payload hooks and preserves conflict recovery guidance in chat replies.

Example: A payload hook adds checkpoint cmp_stored with store:true and previous_response_id:resp_stale.

  • Before: The conflicting storage settings reach OpenAI and can cause item_conflict.
  • After: The request keeps the checkpoint, sends store:false, and omits previous_response_id.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The focused patch appears correct and resolves the prior finding, but published execution evidence does not yet establish the changed shipped behavior.
Proof confidence 🦪 silver shellfish (2/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: OpenAI conversations can reject retained checkpoint replay after a payload hook changes storage settings, and remaining conflicts lose actionable recovery guidance.
Reason: The maintainer-authored direction repairs a source-verified escape from an existing invariant while preserving ordinary continuation and endpoint-specific policies.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR addresses a verified gap still present on main, and the previous continuation-test finding is resolved; no new correctness or security findings were identified.

Priority: P2
Reviewed head: ed2e15050265b21356c539f183c551b40a68fa3e

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Provide redacted CLI/Gateway output or a recording showing successful late-hook checkpoint replay with retained context and one request per prompt, plus the restored conflict guidance in a real chat reply and its saved notice.
Agent review details

How this fits together

The Responses transport converts conversation history and payload-hook output into provider requests; the reply failure pipeline converts provider error facts into visible replies and lifecycle notices.

flowchart TD
  A[Conversation history] --> B[Responses request builder]
  B --> C[Payload hook]
  C --> D[Shared checkpoint policy]
  D --> E[OpenAI transport]
  E --> F[Failure facts]
  F --> G[Chat reply and lifecycle notice]
Loading

Technical review

Best possible solution:

Retain the shared post-hook storage invariant and existing code-aware recovery renderer, with the corrected continuation regression.

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

Current main permits a late hook to restore conflicting checkpoint storage settings, and its reply-facts path bypasses the existing code-aware conflict renderer; the added regressions exercise both paths, but were not run during this read-only review.

Is this the best way to solve the issue?

This is the smallest complete repair using existing owners: reuse one checkpoint policy at final request preparation and one recovery-copy renderer, without adding retries, state, configuration, or transcript changes.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 281042bc8a92.

Provenance checked

  • Checkpoint replay storage keeps the original intent (58c1549: Prevent persistent item_conflict failures by replaying native OpenAI compaction checkpoints statelessly without rewriting saved history.)
  • Stored HTTP continuation keeps the original intent (4e12d05: Continue eligible stored requests from a valid provider response while preserving full-history recovery and never overriding stateless requests.)
  • Shared payload policy keeps the original intent (cc1881a: Share payload patch policy rather than maintain competing implementations; history includes the former src/agents path and its move into packages/ai.)
  • Reply failure diagnostics keeps the original intent (e67e13c: Preserve curated, actionable failure explanations through terminal replies while retaining existing classification precedence.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 58c1549 adds packages/ai/src/transports/openai-responses-payload-policy.ts:159 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 58c15494eda0; files: packages/ai/src/transports/openai-responses-payload-policy.ts)
  • Markus Hartung: Raw commit 4e12d05 adds packages/ai/src/transports/openai-responses-client.continuation.test.ts:259 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 4e12d0556b10; files: packages/ai/src/transports/openai-responses-client.continuation.test.ts)
  • Vincent Koc: Raw commit cc1881a adds src/agents/openai-responses-payload-policy.ts:137 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: cc1881a83846; files: src/agents/openai-responses-payload-policy.ts)

PR surface

Source +27, Tests +119, Docs +4. Total +150 across 9 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 3 39 12 +27
Tests 5 127 8 +119
Docs 1 5 1 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 9 171 21 +150

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.

Labels

Label changes:

  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit. Replaced prior rating: 🧂 unranked krab.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🦪 silver shellfish, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: The fix addresses failed OpenAI conversations under a specific checkpoint and payload-hook combination, with limited scope.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit. Replaced prior rating: 🧂 unranked krab.
  • 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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-11-15T04:56:08.793Z sha 96d4717 :: needs changes before merge. :: [P2] [P2] Align the continuation regression with stateless replay

Reviewed November 15, 2026, 1:12 AM ET / 06:12 UTC (Revision 2).

@vyctorbrzezowski

Copy link
Copy Markdown
Member

The continuation test now verifies complete checkpoint/recovery input and reuse of the valid stored prefix. Fresh 25-case validation passed; production is unchanged. Details are in the updated body.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 15, 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. labels Nov 15, 2026
@vyctorbrzezowski vyctorbrzezowski self-assigned this Nov 15, 2026

@vyctorbrzezowski vyctorbrzezowski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed the post-hook payload policy, continuation preparation, transport tests and error presentation. The final checkpoint replay is made stateless before continuation selection, preserving complete input without adding retries or per-turn preference/network lookups. Azure/custom endpoint policy remains unchanged. Reproduced the obsolete continuation expectation on the original published head and corrected that existing test: 25 continuation and real-loopback transport cases then passed, with scoped type/lint/format checks. All current-head CI checks are green. This does not establish provenance of the originally reported incident, whose payload was not retained; no new external OpenAI API run is claimed.

@vyctorbrzezowski
vyctorbrzezowski merged commit 14c13a5 into main Nov 15, 2026
133 checks passed
@vyctorbrzezowski
vyctorbrzezowski deleted the openclaw/briny-barnacle-4 branch November 15, 2026 06:20
@vyctorbrzezowski

Copy link
Copy Markdown
Member

Merged. Reviewed the post-hook request policy and continuation handling. Corrected the existing continuation test's stale expectations and verified 25 continuation/loopback transport cases; current-head CI passed. The repair preserves full replay input without adding retries, preference lookups, or network calls. The original incident's provenance remains unconfirmed because its payload was not retained. Thanks for the fix.

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

Enforce stateless checkpoint replay after payload hooks and before continuation preparation. Preserve full replay input and code-specific error guidance without replaying accepted output. Align existing continuation coverage with stateless checkpoint and recovery requests.

Co-authored-by: vyctorbrzezowski <[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 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. docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants