Skip to content

fix(openai): replay encrypted reasoning without unverifiable item ids - #200163

Merged
obviyus merged 2 commits into
mainfrom
fix/responses-unstored-item-ids
Nov 16, 2026
Merged

obviyus merged 2 commits into
mainfrom
fix/responses-unstored-item-ids

Conversation

@obviyus

@obviyus obviyus commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Long OpenAI Responses chats fail with "The AI service could not recover saved conversation state (item_conflict)". Subagent completions sent to those chats fail with the same error.

On the shared team Gateway, 4 to 15 real conflicts happened each day. Every conflict on November 16 had the outcome deferred, so each one failed a visible turn or a completion delivery. The reported rate jump on November 16 (28, then 82 per hour) was not new conflicts. After a deferred repair, outcome=recovered is logged on every later request in that chat: one run logged it 26 times. That day there were 4 real conflicts.

Root cause

OpenAI item IDs show if their response was stored. When a turn is sent with store:false, its reasoning item IDs name no stored record. For example, every turn that carries a compaction checkpoint is sent with store:false (#198357).

The replay converter sent those reasoning items again with both id and encrypted_content whenever the current request had store:true (openai-responses-replay-messages-internal.ts, reasoning branch of convertMessage). The first stored request records that ciphertext under its ID. The next stored request that sends it again fails with item_conflict ("An input item conflicts with an existing record."). The server returns this error only after the whole output has streamed. In-turn recovery then defers the repair to the next request, so the current turn fails.

Session history from the affected team chats agrees (only structural fields were read, no message content). Each chat that failed had reasoning from unstored responses, followed by stored full-history requests:

  • One chat had 45 unstored reasoning items after a compact-endpoint checkpoint. Its next stored turn failed after 100 seconds of output.
  • In two other chats, stored and unstored responses alternate.

The fix for function-call argument bytes (#200020) does not cover this. The real API accepts a changed function_call under the same ID.

Fix

On the native OpenAI Responses endpoint, reasoning that has encrypted content is replayed without its ID. Ciphertext is self-contained. Message and function-call IDs need their reasoning ID, so they are omitted with it. This is the shape that stateless replay already used. Reasoning without ciphertext keeps its ID, as before. Microsoft Foundry and other routes that opt in to item IDs are unchanged: Foundry checks ciphertext against its original ID (#91033).

Production code: net -1 line. No config, schema or stored-data change. Existing transcripts are fixed when the next request is built.

Evidence

Real OpenAI API probes (gpt-6.1-sol):

Replayed input Stored replay 1 Stored replay 2
reasoning from a store:true response, with ID ok ok
reasoning from a store:false response, with ID ok item_conflict after output
same reasoning, ciphertext only (no ID) ok ok (also a third time)
message or function call from an unstored response, with ID ok ok

cached_tokens is the same with and without the reasoning ID: 5327 of 5362 tokens in both cases.

Real OpenAI route through OpenClaw's Responses transport. One store:false turn is followed by two stored turns, cold replay each time, 3 trials per arm:

  • base fcf29c4: the third turn fails 3 out of 3 times with item_conflict "An input item conflicts with an existing record.", and the log shows item_conflict_recovery outcome=deferred. This is the production failure.
  • this PR: 3 out of 3 trials pass, with no conflict.

Real scratch Gateway with gpt-6.1-sol and gpt-6-astra. The journey: a turn, a compact-endpoint checkpoint, a store:false turn, a model switch with server compaction, then three stored turns. Both arms finish every turn. cacheRead for the last three turns is 22614/23293/23516 on base and 22620/23299/23522 on this PR. I did not find a Gateway-only path on current main that drops a checkpoint and also keeps the reasoning ciphertext. The transport run above is the reproduction of the failure.

Regression test: replays reasoning from an unstored response without a conflicting ID, over SSE and WebSocket. The loopback server follows the real store rule: it records ciphertext under its ID, and it requires a stored message ID to come with its reasoning ID. The test fails on base with item_conflict and passes here. It also fails if message IDs are kept without their reasoning ID. The conflict triggers of the existing item-conflict and cold-reopen recovery tests used function-call IDs, which are no longer sent. They now use the identity that their repair removes, so recovery stays covered. Focused transport, provider and agent replay suites pass, and so do tsgo:core and check:test-types.

Merge danger: two-way door. It only changes the request projection; no stored state is written, and a revert restores the old wire shape. Blast radius: native OpenAI Responses requests only. They no longer send reasoning, message or call IDs next to encrypted reasoning. Azure, Copilot, Foundry and custom routes keep their current wire shape.

A turn sent with store:false (for example one carrying a compaction
checkpoint) returns reasoning item IDs that name no stored record. When a
later request stores again, Responses records that ciphertext under its ID;
the next stored replay then fails with item_conflict after output has
streamed, so recovery defers and the turn fails.

Ciphertext is self-contained, so replay it without the ID and omit the
message and call IDs that require it. ID-only reasoning keeps its ID.

Co-authored-by: obviyus <[email protected]>
@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.

ClawSweeper review complete

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

View the workflow run.

@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. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. 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. labels Nov 16, 2026
@clawsweeper

clawsweeper Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: stale review; fresh review needed.

Summary
The latest durable ClawSweeper review was for head 87fa4e7ac42180c73724fa32a8e76813bd0690e2, but the PR head is now a2bad89ab2e43e4273e878717ce5c296fce13f6d. Its old verdict and PR readiness labels are no longer current.

Next step
Comment @clawsweeper re-review when the current head is ready; pushes after the first review are not reviewed automatically.

Review history (1 earlier review cycle)
  • reviewed 2026-11-16T16:18:44.124Z sha 87fa4e7 :: needs changes before merge. :: [P2] Update the remaining replay consumer expectations

Foundry validates encrypted reasoning against its original item ID, so
the ID-free replay applies only to the native OpenAI endpoint, whose
store records replayed ciphertext.

Co-authored-by: obviyus <[email protected]>
@obviyus

obviyus commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator Author

Real OpenAI route (gpt-6.1-sol) through OpenClaw's Responses transport. One store:false turn, then two stored turns, cold replay each time. Response IDs truncated.

=== base
�[22m�[39mstore=false stop=stop code=- err=undefined thinking=1 response=resp_<redacted>bcbe01
�[22m�[39mstore=true stop=stop code=- err=undefined thinking=0 response=resp_<redacted>bcbe00
�[22m�[39mstore=true stop=error code=item_conflict err=An input item conflicts with an existing record. thinking=1 response=resp_<redacted>bcbe00
�[22m�[39mrecovery logs: ["[responses] item_conflict_recovery sessionHash=<redacted> outcome=deferred"]
�[2m      Tests �[22m �[1m�[31m1 failed�[39m�[22m�[90m (1)�[39m
=== head
�[22m�[39mstore=false stop=stop code=- err=undefined thinking=1 response=resp_<redacted>20ed01
�[22m�[39mstore=true stop=stop code=- err=undefined thinking=0 response=resp_<redacted>cb5600
�[22m�[39mstore=true stop=stop code=- err=undefined thinking=1 response=resp_<redacted>8a5900
�[2m      Tests �[22m �[1m�[32m1 passed�[39m�[22m�[90m (1)�[39m
=== trial 2 base
�[22m�[39mstore=true stop=stop code=- err=undefined thinking=0 response=resp_<redacted>9a7b00
�[22m�[39mstore=true stop=error code=item_conflict err=An input item conflicts with an existing record. thinking=0 response=resp_0019285ee0b
�[2m      Tests �[22m �[1m�[31m1 failed�[39m�[22m�[90m (1)�[39m
=== trial 2 head
�[22m�[39mstore=true stop=stop code=- err=undefined thinking=0 response=resp_<redacted>ff3a00
�[22m�[39mstore=true stop=stop code=- err=undefined thinking=0 response=resp_<redacted>e0b200
�[2m      Tests �[22m �[1m�[32m1 passed�[39m�[22m�[90m (1)�[39m
=== trial 3 base
�[22m�[39mstore=true stop=stop code=- err=undefined thinking=0 response=resp_<redacted>742900
�[22m�[39mstore=true stop=error code=item_conflict err=An input item conflicts with an existing record. thinking=0 response=resp_0ed78c6f7ca
�[2m      Tests �[22m �[1m�[31m1 failed�[39m�[22m�[90m (1)�[39m
=== trial 3 head
�[22m�[39mstore=true stop=stop code=- err=undefined thinking=0 response=resp_<redacted>9b5600
�[22m�[39mstore=true stop=stop code=- err=undefined thinking=0 response=resp_<redacted>c3c800
�[2m      Tests �[22m �[1m�[32m1 passed�[39m�[22m�[90m (1)�[39m

Real scratch Gateway journey (sol turn, compact-endpoint checkpoint, store:false turn, astra turn with server compaction, three stored sol turns): every turn succeeds on base and on head. cacheRead for the last three turns is 22614/23293/23516 on base and 22620/23299/23522 on head. Head a2bad89 additionally keeps item IDs on non-native routes such as Foundry; a rerun of the real-route trial on that head passed.

@clawsweeper clawsweeper Bot removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Nov 16, 2026
@obviyus
obviyus merged commit 1fa849c into main Nov 16, 2026
107 checks passed
@obviyus
obviyus deleted the fix/responses-unstored-item-ids branch November 16, 2026 16:51
@obviyus

obviyus commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator Author

Landed as 1fa849c. The bug: a turn sent with store:false returns reasoning IDs that name no stored record. Replaying them by ID in stored requests made the second stored replay fail with item_conflict after output, and recovery deferred, so the turn failed. The fix: native OpenAI replay sends encrypted reasoning by content only, without its ID. Foundry keeps its IDs. The proof: the real OpenAI route failed 3/3 on base and passed 3/3 on head, a real scratch Gateway journey left prompt caching unchanged, and the loopback regression test fails on base and passes on head.

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

## What Problem This Solves

Long OpenAI Responses chats fail with "The AI service could not recover saved conversation state (item_conflict)". Subagent completions sent to those chats fail with the same error.

On the shared team Gateway, 4 to 15 real conflicts happened each day. Every conflict on November 16 had the outcome `deferred`, so each one failed a visible turn or a completion delivery. The reported rate jump on November 16 (28, then 82 per hour) was not new conflicts. After a deferred repair, `outcome=recovered` is logged on every later request in that chat: one run logged it 26 times. That day there were 4 real conflicts.

## Root cause

OpenAI item IDs show if their response was stored. When a turn is sent with `store:false`, its reasoning item IDs name no stored record. For example, every turn that carries a compaction checkpoint is sent with `store:false` (openclaw#198357).

The replay converter sent those reasoning items again with both `id` and `encrypted_content` whenever the current request had `store:true` (`openai-responses-replay-messages-internal.ts`, reasoning branch of `convertMessage`). The first stored request records that ciphertext under its ID. The next stored request that sends it again fails with `item_conflict` ("An input item conflicts with an existing record."). The server returns this error only after the whole output has streamed. In-turn recovery then defers the repair to the next request, so the current turn fails.

Session history from the affected team chats agrees (only structural fields were read, no message content). Each chat that failed had reasoning from unstored responses, followed by stored full-history requests:
- One chat had 45 unstored reasoning items after a compact-endpoint checkpoint. Its next stored turn failed after 100 seconds of output.
- In two other chats, stored and unstored responses alternate.

The fix for function-call argument bytes (openclaw#200020) does not cover this. The real API accepts a changed `function_call` under the same ID.

## Fix

On the native OpenAI Responses endpoint, reasoning that has encrypted content is replayed without its ID. Ciphertext is self-contained. Message and function-call IDs need their reasoning ID, so they are omitted with it. This is the shape that stateless replay already used. Reasoning without ciphertext keeps its ID, as before. Microsoft Foundry and other routes that opt in to item IDs are unchanged: Foundry checks ciphertext against its original ID (openclaw#91033).

Production code: net -1 line. No config, schema or stored-data change. Existing transcripts are fixed when the next request is built.

## Evidence

Real OpenAI API probes (`gpt-6.1-sol`):

| Replayed input | Stored replay 1 | Stored replay 2 |
| --- | --- | --- |
| reasoning from a `store:true` response, with ID | ok | ok |
| reasoning from a `store:false` response, with ID | ok | `item_conflict` after output |
| same reasoning, ciphertext only (no ID) | ok | ok (also a third time) |
| message or function call from an unstored response, with ID | ok | ok |

`cached_tokens` is the same with and without the reasoning ID: 5327 of 5362 tokens in both cases.

Real OpenAI route through OpenClaw's Responses transport. One `store:false` turn is followed by two stored turns, cold replay each time, 3 trials per arm:
- base `9977d5c`: the third turn fails 3 out of 3 times with `item_conflict` "An input item conflicts with an existing record.", and the log shows `item_conflict_recovery outcome=deferred`. This is the production failure.
- this PR: 3 out of 3 trials pass, with no conflict.

Real scratch Gateway with `gpt-6.1-sol` and `gpt-6-astra`. The journey: a turn, a compact-endpoint checkpoint, a `store:false` turn, a model switch with server compaction, then three stored turns. Both arms finish every turn. `cacheRead` for the last three turns is 22614/23293/23516 on base and 22620/23299/23522 on this PR. I did not find a Gateway-only path on current `main` that drops a checkpoint and also keeps the reasoning ciphertext. The transport run above is the reproduction of the failure.

Regression test: `replays reasoning from an unstored response without a conflicting ID`, over SSE and WebSocket. The loopback server follows the real store rule: it records ciphertext under its ID, and it requires a stored message ID to come with its reasoning ID. The test fails on base with `item_conflict` and passes here. It also fails if message IDs are kept without their reasoning ID. The conflict triggers of the existing item-conflict and cold-reopen recovery tests used function-call IDs, which are no longer sent. They now use the identity that their repair removes, so recovery stays covered. Focused transport, provider and agent replay suites pass, and so do `tsgo:core` and `check:test-types`.

Merge danger: two-way door. It only changes the request projection; no stored state is written, and a revert restores the old wire shape. Blast radius: native OpenAI Responses requests only. They no longer send reasoning, message or call IDs next to encrypted reasoning. Azure, Copilot, Foundry and custom routes keep their current wire shape.

Co-authored-by: Ayaan Zaidi <[email protected]>
RomneyDa added a commit that referenced this pull request Nov 17, 2026
Backport of 1fa849c. Adapt to the stable replay owner and retained message-ID helper, without importing the later item-conflict recovery or prepared replay cache. Native Responses ciphertext omits its ID; dependent signed message and function-call identities follow. Foundry/other opted-in routes retain their shape.

Proof: changed provider/replay tests fail 6/68 on base; fixed owner/replay/compaction tests 86/86, real transport warm-to-cold history consumer 8/8. Format and diff checks pass. Self-review confirms scoped native endpoint gating, no stored-state/schema change. Source preemptive golden absent on stable; source item-conflict integration harness also absent. No live API/native Codex proof claimed; parent owns physical-checkout type/lint and final qualification.

Co-authored-by: RomneyDa <[email protected]>
obviyus added a commit that referenced this pull request Nov 24, 2026
…on (#204437)

## Result

The scheduled live job "Verify live agent prompt prefix reuse" passes again. It has failed on every scheduled run since 2026-11-17, while the real OpenAI cache held: after a reopen, the uncached tokens are the same as before #200163.

## Cause

#200163 (1fa849c) stopped sending reasoning item IDs next to encrypted reasoning on cold replay, to fix `item_conflict`. A warm continuation still inherits the stored output items, IDs included. So across a reopen, history item 2 changes from `{id, type, summary, encrypted_content}` to `{type, summary, encrypted_content}`. The live gate reported exactly this on every run since 11-17:

```
openai release turn 4: prefix changed segment=history[2] path=$.keys[2]   ("id" -> "summary")
```

IDs render no model tokens. #200163 changed the transport unit test to ignore reasoning envelopes, but the release gate (`embedded-agent-runner.cache.test-support.ts`) kept its own copy of the rule that ignored only function-call and assistant-message envelopes. Three tests had three copies of the rule, and they diverged.

## Change

- `omitResponsesReplayEnvelopes` in `scripts/e2e/lib/anthropic-cache/prefix-stability.mts`, the owner of prefix snapshots, is now the one definition of token-free Responses envelopes: `id` and `status` on function calls, reasoning items and assistant messages.
- The release gate, the transport history-prefix test and the cold-prefix test all use it. Their local copies are deleted.
- No production code changes. The wire shape from #200163 stays, so its `item_conflict` fix is untouched.

## Evidence

Real OpenAI API (`gpt-5.6-luna`), the release prompt-prefix scenario: 3 warm turns, then a reopen on turn 4, 3 requests per turn. Per-request usage comes from the scenario's own cache diagnostics:

| Request | Base `89d07fe5` (parent of #200163): cacheRead / prompt, uncached | `main` b4cc3bc, gate ignoring reasoning IDs: cacheRead / prompt, uncached |
|---|---|---|
| turn 3 #7 | 96,709 / 97,116, **407** | 96,587 / 96,994, **407** |
| turn 3 #8 | 96,881 / 104,554, 7,673 | 96,759 / 104,431, 7,672 |
| turn 3 #9 | 104,551 / 111,983, 7,432 | 104,428 / 111,860, 7,432 |
| **turn 4 (reopen) #10** | 111,980 / 112,191, **211** | 111,857 / 112,068, **211** |
| turn 4 #11 | 112,152 / 119,629, 7,477 | 112,029 / 119,506, 7,477 |
| turn 4 #12 | 119,626 / 127,058, 7,432 | 119,503 / 126,935, 7,432 |

The reopen request reuses the whole previous prompt in both arms, so the retry prefix is fully cached. The scenario's own check (each request reuses at least 80% of the preceding prompt) passes in both arms.

- The same scenario with the unchanged gate on `main` fails locally with the CI signature. On this head it passes (OpenAI).
- `anthropic-cache-prefix-stability.test.ts`: a new case checks that a warm continuation and its cold replay give equal snapshots, and that changed ciphertext still fails at `history[1]`. 11 passed. `openai-responses-client.history-prefix.test.ts` 8 passed, `embedded-agent-runner.responses-cold-prefix.test.ts` 10 passed.
- Real-API dispatch of the scheduled live workflow on this branch: https://github.com/openclaw/openclaw/actions/runs/45338721403, `validate_release_live_cache` passed.
- New unit cases: changed function-call arguments, call ids and assistant content still fail at the changed index; the projection strips only `id` and `status`.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 25, 2026
…on (openclaw#204437)

## Result

The scheduled live job "Verify live agent prompt prefix reuse" passes again. It has failed on every scheduled run since 2026-11-17, while the real OpenAI cache held: after a reopen, the uncached tokens are the same as before openclaw#200163.

## Cause

openclaw#200163 (a87bd16) stopped sending reasoning item IDs next to encrypted reasoning on cold replay, to fix `item_conflict`. A warm continuation still inherits the stored output items, IDs included. So across a reopen, history item 2 changes from `{id, type, summary, encrypted_content}` to `{type, summary, encrypted_content}`. The live gate reported exactly this on every run since 11-17:

```
openai release turn 4: prefix changed segment=history[2] path=$.keys[2]   ("id" -> "summary")
```

IDs render no model tokens. openclaw#200163 changed the transport unit test to ignore reasoning envelopes, but the release gate (`embedded-agent-runner.cache.test-support.ts`) kept its own copy of the rule that ignored only function-call and assistant-message envelopes. Three tests had three copies of the rule, and they diverged.

## Change

- `omitResponsesReplayEnvelopes` in `scripts/e2e/lib/anthropic-cache/prefix-stability.mts`, the owner of prefix snapshots, is now the one definition of token-free Responses envelopes: `id` and `status` on function calls, reasoning items and assistant messages.
- The release gate, the transport history-prefix test and the cold-prefix test all use it. Their local copies are deleted.
- No production code changes. The wire shape from openclaw#200163 stays, so its `item_conflict` fix is untouched.

## Evidence

Real OpenAI API (`gpt-5.6-luna`), the release prompt-prefix scenario: 3 warm turns, then a reopen on turn 4, 3 requests per turn. Per-request usage comes from the scenario's own cache diagnostics:

| Request | Base `74b2428e` (parent of openclaw#200163): cacheRead / prompt, uncached | `main` aaf0572, gate ignoring reasoning IDs: cacheRead / prompt, uncached |
|---|---|---|
| turn 3 openclaw#7 | 96,709 / 97,116, **407** | 96,587 / 96,994, **407** |
| turn 3 openclaw#8 | 96,881 / 104,554, 7,673 | 96,759 / 104,431, 7,672 |
| turn 3 openclaw#9 | 104,551 / 111,983, 7,432 | 104,428 / 111,860, 7,432 |
| **turn 4 (reopen) openclaw#10** | 111,980 / 112,191, **211** | 111,857 / 112,068, **211** |
| turn 4 openclaw#11 | 112,152 / 119,629, 7,477 | 112,029 / 119,506, 7,477 |
| turn 4 openclaw#12 | 119,626 / 127,058, 7,432 | 119,503 / 126,935, 7,432 |

The reopen request reuses the whole previous prompt in both arms, so the retry prefix is fully cached. The scenario's own check (each request reuses at least 80% of the preceding prompt) passes in both arms.

- The same scenario with the unchanged gate on `main` fails locally with the CI signature. On this head it passes (OpenAI).
- `anthropic-cache-prefix-stability.test.ts`: a new case checks that a warm continuation and its cold replay give equal snapshots, and that changed ciphertext still fails at `history[1]`. 11 passed. `openai-responses-client.history-prefix.test.ts` 8 passed, `embedded-agent-runner.responses-cold-prefix.test.ts` 10 passed.
- Real-API dispatch of the scheduled live workflow on this branch: https://github.com/openclaw/openclaw/actions/runs/45338721403, `validate_release_live_cache` passed.
- New unit cases: changed function-call arguments, call ids and assistant content still fail at the changed index; the projection strips only `id` and `status`.

Co-authored-by: Ayaan Zaidi <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 29, 2026
…on (#204437)

## Result

The scheduled live job "Verify live agent prompt prefix reuse" passes again. It has failed on every scheduled run since 2026-11-17, while the real OpenAI cache held: after a reopen, the uncached tokens are the same as before #200163.

## Cause

#200163 (1fa849c) stopped sending reasoning item IDs next to encrypted reasoning on cold replay, to fix `item_conflict`. A warm continuation still inherits the stored output items, IDs included. So across a reopen, history item 2 changes from `{id, type, summary, encrypted_content}` to `{type, summary, encrypted_content}`. The live gate reported exactly this on every run since 11-17:

```
openai release turn 4: prefix changed segment=history[2] path=$.keys[2]   ("id" -> "summary")
```

IDs render no model tokens. #200163 changed the transport unit test to ignore reasoning envelopes, but the release gate (`embedded-agent-runner.cache.test-support.ts`) kept its own copy of the rule that ignored only function-call and assistant-message envelopes. Three tests had three copies of the rule, and they diverged.

## Change

- `omitResponsesReplayEnvelopes` in `scripts/e2e/lib/anthropic-cache/prefix-stability.mts`, the owner of prefix snapshots, is now the one definition of token-free Responses envelopes: `id` and `status` on function calls, reasoning items and assistant messages.
- The release gate, the transport history-prefix test and the cold-prefix test all use it. Their local copies are deleted.
- No production code changes. The wire shape from #200163 stays, so its `item_conflict` fix is untouched.

## Evidence

Real OpenAI API (`gpt-5.6-luna`), the release prompt-prefix scenario: 3 warm turns, then a reopen on turn 4, 3 requests per turn. Per-request usage comes from the scenario's own cache diagnostics:

| Request | Base `89d07fe5` (parent of #200163): cacheRead / prompt, uncached | `main` b4cc3bc, gate ignoring reasoning IDs: cacheRead / prompt, uncached |
|---|---|---|
| turn 3 #7 | 96,709 / 97,116, **407** | 96,587 / 96,994, **407** |
| turn 3 #8 | 96,881 / 104,554, 7,673 | 96,759 / 104,431, 7,672 |
| turn 3 #9 | 104,551 / 111,983, 7,432 | 104,428 / 111,860, 7,432 |
| **turn 4 (reopen) #10** | 111,980 / 112,191, **211** | 111,857 / 112,068, **211** |
| turn 4 #11 | 112,152 / 119,629, 7,477 | 112,029 / 119,506, 7,477 |
| turn 4 #12 | 119,626 / 127,058, 7,432 | 119,503 / 126,935, 7,432 |

The reopen request reuses the whole previous prompt in both arms, so the retry prefix is fully cached. The scenario's own check (each request reuses at least 80% of the preceding prompt) passes in both arms.

- The same scenario with the unchanged gate on `main` fails locally with the CI signature. On this head it passes (OpenAI).
- `anthropic-cache-prefix-stability.test.ts`: a new case checks that a warm continuation and its cold replay give equal snapshots, and that changed ciphertext still fails at `history[1]`. 11 passed. `openai-responses-client.history-prefix.test.ts` 8 passed, `embedded-agent-runner.responses-cold-prefix.test.ts` 10 passed.
- Real-API dispatch of the scheduled live workflow on this branch: https://github.com/openclaw/openclaw/actions/runs/45338721403, `validate_release_live_cache` passed.
- New unit cases: changed function-call arguments, call ids and assistant content still fail at the changed index; the projection strips only `id` and `status`.

Co-authored-by: Ayaan Zaidi <[email protected]>
(cherry picked from commit 9ac436d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P1 High-priority user-facing bug, regression, or broken workflow.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant