Repository navigation
Conversation
…s append-only Dropping a NO_REPLY row left two user turns adjacent. Bedrock Converse and Chat Completions merge them at the stream boundary, which rewrote an already-sent turn and broke the prompt cache. Row-local normalization now keeps the silent reply; the replay sequence drops it only when another assistant turn follows (#99620). The payload-free compaction replay applies the same rule through a silentReply source fact. Ported from 0191111b26aa onto the current replay sequence. Co-authored-by: obviyus <[email protected]>
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
…istory suffix Co-authored-by: obviyus <[email protected]>
|
Codex review: needs maintainer review before merge. What this changesThis PR retains silent assistant replies as separators before later user turns while preserving their removal before another assistant turn. Example: A Bedrock conversation receives user messages “quiet” and “next”, separated by an assistant NO_REPLY.
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 replay defect with a focused shared-owner fix; source review found no definite introduced correctness bug. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe embedded agent runner projects transcript rows into model history; the shared replay normalizer serves both ordinary message arrays and payload-free compaction facts before provider transport preparation. flowchart LR
A[Stored transcript] --> B[Row normalization]
B --> C[Shared sequence normalization]
A --> D[Compaction source facts]
D --> C
C --> E[Transport preparation]
E --> F[Provider request]
Technical reviewBest possible solution: Keep the sequence-dependent decision in the shared replay normalizer and carry only its silence fact into compaction replay. Do we have a high-confidence way to reproduce the issue? Current-main source shows the separator removal followed by user-message merging, and the PR reports the committed boundary regression failing on the pinned base and passing on head; no target code was executed during this review. Is this the best way to solve the issue? The patch repairs the producer of adjacent user turns, reuses the existing classification and sequence owners, and updates both replay representations without adding a competing path. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against f5958f4049ea. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +23, Tests +57. Total +80 across 7 files. Added test files: 0. 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. 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 Reviewed November 19, 2026, 1:33 AM ET / 06:33 UTC. |
|
Closing by maintainer decision. The break reproduces only on Bedrock Converse, the one route that merges adjacent user turns across the runtime-context carrier. Real OpenAI Chat Completions and Anthropic routes never rewrite the sent message on main, so this fix has no measurable effect there and would add tokens to every silent turn. The branch is kept if Bedrock users report it. |
…201843) ## Problem Some routes cannot send a system prompt update as a system message (`inHistorySystemUpdates` is false). Examples: custom OpenAI-compatible Chat Completions providers, and Claude through a non-native Responses proxy. On these routes, the boundary projects the update as a plain `{ role: "user" }` message. The update is the last message of its turn. When that turn ends silent (a `NO_REPLY` turn after an `AGENTS.md` edit, or a silent exec wake that carries a `## Tooling` update), no assistant message follows the update. On the next turn, the stream boundary merges the new user message into the update (`mergeConsecutiveUserMessages`). `canMergeUser` refuses carriers, operator messages and synthetic messages, but not this projected update. The result: a message that the provider already received is rewritten, and the prompt cache misses from that point. ## Fix - When `inHistorySystemUpdates` is false, the projection puts a symbol-keyed marker (`PROJECTED_PROMPT_UPDATE`) on the projected update message. - `canMergeUser` refuses to merge across that marker. - A symbol key is not in `JSON.stringify` or structured clone output, so the marker never reaches a provider request, the worker protocol or the transcript. Only `canMergeUser` reads it. - Why not `synthetic`: at least one route has `inHistorySystemUpdates` false and also reads `synthetic` on user messages. The ChatGPT Codex backend (`provider: "openai"`, `api: "openai-chatgpt-responses"`, `chatgpt.com`) is not a native Responses endpoint (`packages/ai/src/transports/openai-responses-endpoint.ts:21-25` needs `api: "openai-responses"` on `api.openai.com`), so its prompt updates are projected as plain user messages. The same backend is the only one eligible for ChatGPT V2 compaction (`src/agents/embedded-agent-runner/run/chatgpt-v2-compaction.ts:35-55`, `usesNativeOpenAICodexResponsesBackend`). During V2 compaction it sets `retainUserProvenance` (`packages/ai/src/providers/openai-chatgpt-responses.ts:221-223` → `openai-chatgpt-responses-request.ts:118-124`). Then `openai-responses-replay-messages-internal.ts:441-448` tags non-synthetic user input as retained, and `chatgpt-v2-compaction.ts:180-185` checks non-synthetic user input before persistence. A `synthetic` update would drop out of the V2 retained input on that route, which changes behavior. The symbol changes nothing there. - Routes with `inHistorySystemUpdates` (native OpenAI Responses, direct Anthropic) are unchanged: they keep `operatorMessage` and never get the marker. Production diff: 8 added, 2 removed lines in 2 files. ## Scope and limits - Accepted gap: Bedrock Converse. It requires strict role alternation, so the stream boundary calls `mergeConsecutiveUserMessages` with `preserveContextBoundaries: false` for `bedrock-converse-stream` (`attempt-tool-call-replay-sanitization.ts:382`) and never consults `canMergeUser`. A silent turn rewrites the prefix there with or without an update. This PR does not change Bedrock. - One-time cache miss on upgrade: the marker also stops an update from merging backward into a user message directly before it in the same turn. Where history was sent as `[user + update]`, the first request after the upgrade sends `[user, update]`. After that request, history is append-only again. - Longer runs of consecutive user-role messages: after a silent turn a request can now contain, for example, user, carrier, update, user, carrier in a row (main merged the update with the next user). Carriers already produce consecutive user-role messages on every turn on these routes, so this is not a new failure class. - Google Gemini routes do not merge user turns (`validateAnthropicTurns` is false), so this bug does not occur there. - The OpenAI provider plugin's own Chat Completions policy does not merge user turns either. The bug occurs on custom and plugin-owned OpenAI-compatible Chat Completions routes that use the strict OpenAI-compatible replay policy. - This supersedes the closed #201654 (silent replies in replay) for the routes above. ## Evidence ### Tests (`attempt.silent-prompt-update.test.ts`) The test runs the real boundary projection, the real stream sanitization wrapper with the resolved transcript policy, and the real transport for each route (`streamOpenAICompletions` / `streamOpenAIResponses`). It captures the live payload object in `onPayload`, before serialization, so the key check sees symbol keys too. | Test | Merge base `1579eb4` | Head | |---|---|---| | custom Chat Completions, silent `NO_REPLY` after `AGENTS.md` edit | red | green | | custom Chat Completions, silent exec wake with tooling update | red | green | | Claude through custom Responses proxy, silent `NO_REPLY` after `AGENTS.md` edit | red | green | | Claude through custom Responses proxy, silent exec wake with tooling update | red | green | | both routes: update before a visible reply (request unchanged) | green | green | | both routes: unmarked consecutive user text still merges (marker absent = main) | green | green | ### Which route merges The original capture and the gate below use the same config: provider id `oaic` (a custom provider, no owning plugin, plugins disabled), `api: "openai-completions"`, model `gpt-5.6-sol`, base URL pointing to a local logging proxy in front of the OpenAI API. - No plugin owns `oaic`, so `resolveTranscriptPolicy` uses `buildUnownedProviderTransportReplayFallback` (`src/agents/transcript-policy.ts:161`). That fallback sets `validateAnthropicTurns: true` for `openai-completions` (`transcript-policy.ts:79,105`). - With that flag, the stream wrapper merges consecutive user messages (`src/agents/embedded-agent-runner/run/attempt-tool-call-replay-sanitization.ts:378-383`, the same line 381 on `8a23d7c`). `canMergeUser` (`src/agents/embedded-agent-helpers/turns.ts:433`) decides which messages may merge. - The OpenAI plugin's own policy sets `validateAnthropicTurns: false` for every API (`extensions/openai/replay-policy.ts:18`, same on `8a23d7c`), so `provider: "openai"` with Chat Completions never reaches this merge. ### Real Gateway, custom Chat Completions provider `oaic` (`gpt-5.6-sol`) Isolated scratch Gateways (main = merge base, head = this branch), a logging proxy that captures each request body, provider cache numbers from the response `usage`. An unrelated chat ran 6 turns concurrently on each Gateway (6/6 ok). Journey 1: turn 1, then a `NO_REPLY` turn after an `AGENTS.md` edit, then two user turns. | Request | Main | Head | |---|---|---| | silent turn | append-only | append-only | | next user turn | **REWRITE at message 6** (update merged with the new user text); cached 29457, uncached 1205 | append-only; cached 29850, uncached 568 | | following turn | append-only | append-only | Journey 2: background exec, then a silent exec-completion wake that carries a `## Tooling` update, then a user turn. | Request | Main | Head | |---|---|---| | wake turn | append-only | append-only | | next user turn | **REWRITE at message 13**; cached 30860, uncached 5129 | append-only; cached 33013, uncached 2731 | ### No-regression routes (same two journeys, main vs head, concurrent chat active) Native OpenAI Responses (`gpt-6.2-astra`, `inHistorySystemUpdates` on) and Claude (`claude-opus-5-5`) through an Anthropic-compatible proxy (`anthropic-messages`, no stream merge). Request layouts come from the cache trace (`stream:context` fingerprints); cache numbers from `cache:result`. The proxy captured the Claude request bodies; no body contains the marker. | Route / journey | Main | Head | |---|---|---| | Responses, `NO_REPLY` after `AGENTS.md` edit | 4 requests, all append-only, layouts `uu → uuauuu → uuauuuuu → uuauuuuuauu` | same layouts, all append-only | | Responses, silent exec wake | 6 requests, all append-only | same layouts, all append-only | | Claude proxy, `NO_REPLY` after `AGENTS.md` edit | 4 requests, all append-only; last turn cacheRead 72882, cacheWrite 925 | same layouts, all append-only; cacheRead 72771, cacheWrite 925 | | Claude proxy, silent exec wake | 6 requests, all append-only; last turn cacheWrite 8052 | same layouts, all append-only; cacheWrite 8080 | Responses cache numbers differ by at most 3 tokens per request (timestamp text). Concurrent chat: 6/6 turns ok in every run. ### Gates (head `53c326c`) | Gate | Result | |---|---| | `ocx test` on the new test file | 8/8 pass on head; on the merge base the 4 silent-turn cases fail and the 4 controls pass | | `ocx test` sanitization, LLM boundary, cache stability, transcript policy, prefix stability suites | pass | | oxfmt (changed files) | pass | | oxlint (changed files) | pass | | `pnpm tsgo:core` | pass | | `pnpm check:test-types` | 7 errors, all in `test/scripts/release-*` files that this PR does not touch; none in changed files | | Local ClawSweeper (`gpt-6.1-sol`, normal speed) | complete, "patch is correct", 0 findings | ## E2E (exact head `53c326c`, rerun 2026-11-20) Two isolated scratch Gateways from source: merge base `1579eb4` and head `53c326c`. Real custom Chat Completions route `oaic` (`openai-completions`, `gpt-5.6-sol`) through a logging proxy that saves each request body and the provider `usage`. Both Gateways ran the same script. An ordinary chat ran concurrently with the journeys. ### Silent `NO_REPLY` turn after an `AGENTS.md` edit, then user turns, `/compact`, and one more user turn | Request | Base: layout vs previous | Base cached / uncached | Head: layout vs previous | Head cached / uncached | |---|---|---|---|---| | silent turn (update is last) | append-only | 29495 / 646 | append-only | 29222 / 646 | | next user turn | **REWRITE at msg 6** | 29495 / **1207** | append-only | 29865 / **568** | | following user turn | append-only | 30699 / 576 | append-only | 30430 / 576 | | first turn after `/compact` | rewrite (compaction, expected) | 0 / 31085 | rewrite (compaction, expected) | 0 / 30812 | ### Silent exec-completion wake that carries a `## Tooling` update, then a user turn | Request | Base: layout vs previous | Base cached / uncached | Head: layout vs previous | Head cached / uncached | |---|---|---|---|---| | wake turn (update is last) | append-only | 30897 / 2408 | append-only | 30621 / 2409 | | next user turn | **REWRITE at msg 13** | 30897 / **5130** | append-only | 33027 / **2731** | On base the next user message merges into the projected update, so the provider cache stops at that message. On head, history stays append-only and the cache continues to the end of the earlier request. ### Side effects - Ordinary chat, 3 turns: every reply arrives on base and head; every request is append-only (head cached / uncached: 29226 / 583, 29806 / 583). - `/compact`: works the same on base and head ("Compacted (31k → 1.4k)"). The next turn replies normally. The post-compaction request is the one rewrite that compaction is allowed to make, on both sides. - Every turn of every journey returned `status: ok` on both Gateways. ### UI (Control UI of each scratch Gateway, chat history after the journeys) Head and base render the same history. No "System prompt update" bubble or other prompt-update text appears in any session on head (checked in the rendered chat log text as well). The silent `NO_REPLY` turn shows only the user message, as on base. Head, `NO_REPLY` journey with `/compact`:  Base, same journey:  Head, silent exec wake journey:  Base, same journey:  ### Review and CI on this head - Local ClawSweeper on `53c326c`: `review_status: complete`, "patch is correct", 0 findings. - PR CI on `53c326c`: all required checks pass. Co-authored-by: Ayaan Zaidi <[email protected]>
…low and a concurrent chat on five transports (#201723) ## What was wrong The prompt-cache journey is the CI check that each provider request in a chat extends the previous request byte for byte, except where a rebuild is expected. It skipped four triggers that real chats hit: a scheduled job that comes due in the chat, a user message steered into a running tool call, tool results that fill the context window, and an unrelated chat that compacts while this one runs. It also covered only three transports. A break in any of those paths could land without CI noticing. **Example:** a scheduled job sent its reply to the model twice on every route. On Chat Completions and Gemini the copy merged into the next tool-call message, which rewrote history and lost the cache from that point on. Fixed in #201838. This journey would have caught it. ## Fix - Adds the cron, steer, tool-result overflow and concurrent-compaction steps to the stability journey. It now runs on five transports: Anthropic, Responses, Chat Completions, Gemini and Bedrock. - Adds a seeded randomized journey: 15 turn kinds on five transports, plus a variant with Tool Search turned off. - Lists the breaks main still has, each with its owner. Entries expire: when a fix lands, the journey fails until its entry is removed. Each entry checks the whole request, so a known change cannot hide a second one. - Rebuild steps are excused only when the rebuild actually happened. A compaction must put its new summary into the next request, and a model switch must make the next request come from the selected model. - The steer step holds the tool open until the Gateway reports that the run has taken the steer. Before, it slept for a fixed 3 s. ## Numbers | | main (before this PR) | this PR | |---|---|---| | Triggers covered | ordinary turns, tools, compaction | + cron, steer, tool-result overflow, concurrent compaction, cron-first chat, 15-kind randomized journey | | Transports | 3 | 5 | | Stability journey | n/a | 5/5 | | Randomized journey (default seeds, 6 files) + negative controls | n/a | 12/12 + 5/5 | | Anthropic and Tool Search off, seeds 1 and 6 | n/a | 2/2 and 2/2 | <details><summary>Breaks still on main (accepted entries)</summary> | Where | Change | Owner | |---|---|---| | Gemini, tool-result overflow (other chat) | the pre-request pressure check trims tool results that were already sent | #199530 | | Bedrock, randomized | a dropped silent reply merges the user turns around it | accepted gap (#201654 closed) | | Tool Search off, randomized | a provider switch adds `skills_read`/`skills_search` on turns started by a subagent completion or inter-session message | #201710 / documented exception of the opt-out surface | Removed because their owners landed: the cron reply twice (#201838), the Chat Completions silent-turn merge (#201843), the cron-first `message` growth (#201710), and the skills rebuild after `config.patch` (issue #202150, which no longer reproduces on Anthropic seeds 1 and 6). Bedrock refuses `cron.add` for AWS-SDK auth by design, and the journey expects that refusal. </details> <details><summary>Steer signal</summary> - The steer is sent with `queueMode: "steer"`, as the chat composer sends it. The test waits for `sessions.changed` with reason `agent.input.steering`, which the Gateway emits when the active run accepts the steer into its queue. The tool is released only after that event. - On all five transports the event arrives about 200-260 ms after the send is acknowledged, while the tool is still held. - Negative control: releasing right after the acknowledgment lost the race on Gemini (1/5). The steered input became a separate turn. - A default `chat.send` steer exposes nothing before release. Its pending input stays `queued` with no `steerNow`, and `agent.input.steering` only fires when the tool ends. So the step uses the composer's steer path. </details> <details><summary>Rebuild evidence checks</summary> - Compaction: the fake numbers each compaction summary. The step needs a new summary, and the turn after it must contain that summary. - Model switch: the alternate provider has its own model id. Every request after the switch must name exactly the selected model, read from the request body or the URL (Gemini, Bedrock), and at least one request must arrive. - Teeth: with `sessions.compact` turned into a no-op, all 10 randomized seeds failed. With `sessions.patch` pinned to the first model, all 10 failed too. </details> <details><summary>Cron-first red on base</summary> On the parent of #201710 with this PR's test files (no entry), the cron-first step fails on Anthropic and Responses at the owner turn's tool list (`at: 1, change: tools`). On main the step passes. </details> <details><summary>Harness fixes</summary> - Each seed uses its own session keys. A retained subagent from the previous seed made every turn fail with `Retained subagent payload is unavailable`. - After a silent reply, the fake acts only on the newest step marker, because main drops silent replies from replay. - Every request is assigned to its session by its runtime line. A request from an unexpected session fails the journey. - The Advisor fork check is dropped. Forks never arrived in earlier runs. When they did arrive, their requests differed from the parent's on all transports, which needs its own investigation. </details> <details><summary>Gates</summary> - `ocx test` from source with an in-process Gateway and fake provider endpoints: 5 stability files, 6 randomized files and the known-breaks unit, 17/17. Anthropic and Tool Search off at seeds 1 and 6, 2/2 each. A second stability pass, 5/5. - `pnpm tsgo:test:root`, oxfmt and oxlint on the changed files, and the test-lines ratchet all pass. - Local review on this head: patch is correct, no findings. </details> Co-authored-by: Ayaan Zaidi <[email protected]>
…penclaw#201843) ## Problem Some routes cannot send a system prompt update as a system message (`inHistorySystemUpdates` is false). Examples: custom OpenAI-compatible Chat Completions providers, and Claude through a non-native Responses proxy. On these routes, the boundary projects the update as a plain `{ role: "user" }` message. The update is the last message of its turn. When that turn ends silent (a `NO_REPLY` turn after an `AGENTS.md` edit, or a silent exec wake that carries a `## Tooling` update), no assistant message follows the update. On the next turn, the stream boundary merges the new user message into the update (`mergeConsecutiveUserMessages`). `canMergeUser` refuses carriers, operator messages and synthetic messages, but not this projected update. The result: a message that the provider already received is rewritten, and the prompt cache misses from that point. ## Fix - When `inHistorySystemUpdates` is false, the projection puts a symbol-keyed marker (`PROJECTED_PROMPT_UPDATE`) on the projected update message. - `canMergeUser` refuses to merge across that marker. - A symbol key is not in `JSON.stringify` or structured clone output, so the marker never reaches a provider request, the worker protocol or the transcript. Only `canMergeUser` reads it. - Why not `synthetic`: at least one route has `inHistorySystemUpdates` false and also reads `synthetic` on user messages. The ChatGPT Codex backend (`provider: "openai"`, `api: "openai-chatgpt-responses"`, `chatgpt.com`) is not a native Responses endpoint (`packages/ai/src/transports/openai-responses-endpoint.ts:21-25` needs `api: "openai-responses"` on `api.openai.com`), so its prompt updates are projected as plain user messages. The same backend is the only one eligible for ChatGPT V2 compaction (`src/agents/embedded-agent-runner/run/chatgpt-v2-compaction.ts:35-55`, `usesNativeOpenAICodexResponsesBackend`). During V2 compaction it sets `retainUserProvenance` (`packages/ai/src/providers/openai-chatgpt-responses.ts:221-223` → `openai-chatgpt-responses-request.ts:118-124`). Then `openai-responses-replay-messages-internal.ts:441-448` tags non-synthetic user input as retained, and `chatgpt-v2-compaction.ts:180-185` checks non-synthetic user input before persistence. A `synthetic` update would drop out of the V2 retained input on that route, which changes behavior. The symbol changes nothing there. - Routes with `inHistorySystemUpdates` (native OpenAI Responses, direct Anthropic) are unchanged: they keep `operatorMessage` and never get the marker. Production diff: 8 added, 2 removed lines in 2 files. ## Scope and limits - Accepted gap: Bedrock Converse. It requires strict role alternation, so the stream boundary calls `mergeConsecutiveUserMessages` with `preserveContextBoundaries: false` for `bedrock-converse-stream` (`attempt-tool-call-replay-sanitization.ts:382`) and never consults `canMergeUser`. A silent turn rewrites the prefix there with or without an update. This PR does not change Bedrock. - One-time cache miss on upgrade: the marker also stops an update from merging backward into a user message directly before it in the same turn. Where history was sent as `[user + update]`, the first request after the upgrade sends `[user, update]`. After that request, history is append-only again. - Longer runs of consecutive user-role messages: after a silent turn a request can now contain, for example, user, carrier, update, user, carrier in a row (main merged the update with the next user). Carriers already produce consecutive user-role messages on every turn on these routes, so this is not a new failure class. - Google Gemini routes do not merge user turns (`validateAnthropicTurns` is false), so this bug does not occur there. - The OpenAI provider plugin's own Chat Completions policy does not merge user turns either. The bug occurs on custom and plugin-owned OpenAI-compatible Chat Completions routes that use the strict OpenAI-compatible replay policy. - This supersedes the closed openclaw#201654 (silent replies in replay) for the routes above. ## Evidence ### Tests (`attempt.silent-prompt-update.test.ts`) The test runs the real boundary projection, the real stream sanitization wrapper with the resolved transcript policy, and the real transport for each route (`streamOpenAICompletions` / `streamOpenAIResponses`). It captures the live payload object in `onPayload`, before serialization, so the key check sees symbol keys too. | Test | Merge base `0f19e40` | Head | |---|---|---| | custom Chat Completions, silent `NO_REPLY` after `AGENTS.md` edit | red | green | | custom Chat Completions, silent exec wake with tooling update | red | green | | Claude through custom Responses proxy, silent `NO_REPLY` after `AGENTS.md` edit | red | green | | Claude through custom Responses proxy, silent exec wake with tooling update | red | green | | both routes: update before a visible reply (request unchanged) | green | green | | both routes: unmarked consecutive user text still merges (marker absent = main) | green | green | ### Which route merges The original capture and the gate below use the same config: provider id `oaic` (a custom provider, no owning plugin, plugins disabled), `api: "openai-completions"`, model `gpt-5.6-sol`, base URL pointing to a local logging proxy in front of the OpenAI API. - No plugin owns `oaic`, so `resolveTranscriptPolicy` uses `buildUnownedProviderTransportReplayFallback` (`src/agents/transcript-policy.ts:161`). That fallback sets `validateAnthropicTurns: true` for `openai-completions` (`transcript-policy.ts:79,105`). - With that flag, the stream wrapper merges consecutive user messages (`src/agents/embedded-agent-runner/run/attempt-tool-call-replay-sanitization.ts:378-383`, the same line 381 on `db32b2b`). `canMergeUser` (`src/agents/embedded-agent-helpers/turns.ts:433`) decides which messages may merge. - The OpenAI plugin's own policy sets `validateAnthropicTurns: false` for every API (`extensions/openai/replay-policy.ts:18`, same on `db32b2b`), so `provider: "openai"` with Chat Completions never reaches this merge. ### Real Gateway, custom Chat Completions provider `oaic` (`gpt-5.6-sol`) Isolated scratch Gateways (main = merge base, head = this branch), a logging proxy that captures each request body, provider cache numbers from the response `usage`. An unrelated chat ran 6 turns concurrently on each Gateway (6/6 ok). Journey 1: turn 1, then a `NO_REPLY` turn after an `AGENTS.md` edit, then two user turns. | Request | Main | Head | |---|---|---| | silent turn | append-only | append-only | | next user turn | **REWRITE at message 6** (update merged with the new user text); cached 29457, uncached 1205 | append-only; cached 29850, uncached 568 | | following turn | append-only | append-only | Journey 2: background exec, then a silent exec-completion wake that carries a `## Tooling` update, then a user turn. | Request | Main | Head | |---|---|---| | wake turn | append-only | append-only | | next user turn | **REWRITE at message 13**; cached 30860, uncached 5129 | append-only; cached 33013, uncached 2731 | ### No-regression routes (same two journeys, main vs head, concurrent chat active) Native OpenAI Responses (`gpt-6.2-astra`, `inHistorySystemUpdates` on) and Claude (`claude-opus-5-5`) through an Anthropic-compatible proxy (`anthropic-messages`, no stream merge). Request layouts come from the cache trace (`stream:context` fingerprints); cache numbers from `cache:result`. The proxy captured the Claude request bodies; no body contains the marker. | Route / journey | Main | Head | |---|---|---| | Responses, `NO_REPLY` after `AGENTS.md` edit | 4 requests, all append-only, layouts `uu → uuauuu → uuauuuuu → uuauuuuuauu` | same layouts, all append-only | | Responses, silent exec wake | 6 requests, all append-only | same layouts, all append-only | | Claude proxy, `NO_REPLY` after `AGENTS.md` edit | 4 requests, all append-only; last turn cacheRead 72882, cacheWrite 925 | same layouts, all append-only; cacheRead 72771, cacheWrite 925 | | Claude proxy, silent exec wake | 6 requests, all append-only; last turn cacheWrite 8052 | same layouts, all append-only; cacheWrite 8080 | Responses cache numbers differ by at most 3 tokens per request (timestamp text). Concurrent chat: 6/6 turns ok in every run. ### Gates (head `53c326c`) | Gate | Result | |---|---| | `ocx test` on the new test file | 8/8 pass on head; on the merge base the 4 silent-turn cases fail and the 4 controls pass | | `ocx test` sanitization, LLM boundary, cache stability, transcript policy, prefix stability suites | pass | | oxfmt (changed files) | pass | | oxlint (changed files) | pass | | `pnpm tsgo:core` | pass | | `pnpm check:test-types` | 7 errors, all in `test/scripts/release-*` files that this PR does not touch; none in changed files | | Local ClawSweeper (`gpt-6.1-sol`, normal speed) | complete, "patch is correct", 0 findings | ## E2E (exact head `53c326c`, rerun 2026-11-20) Two isolated scratch Gateways from source: merge base `0f19e40` and head `53c326c`. Real custom Chat Completions route `oaic` (`openai-completions`, `gpt-5.6-sol`) through a logging proxy that saves each request body and the provider `usage`. Both Gateways ran the same script. An ordinary chat ran concurrently with the journeys. ### Silent `NO_REPLY` turn after an `AGENTS.md` edit, then user turns, `/compact`, and one more user turn | Request | Base: layout vs previous | Base cached / uncached | Head: layout vs previous | Head cached / uncached | |---|---|---|---|---| | silent turn (update is last) | append-only | 29495 / 646 | append-only | 29222 / 646 | | next user turn | **REWRITE at msg 6** | 29495 / **1207** | append-only | 29865 / **568** | | following user turn | append-only | 30699 / 576 | append-only | 30430 / 576 | | first turn after `/compact` | rewrite (compaction, expected) | 0 / 31085 | rewrite (compaction, expected) | 0 / 30812 | ### Silent exec-completion wake that carries a `## Tooling` update, then a user turn | Request | Base: layout vs previous | Base cached / uncached | Head: layout vs previous | Head cached / uncached | |---|---|---|---|---| | wake turn (update is last) | append-only | 30897 / 2408 | append-only | 30621 / 2409 | | next user turn | **REWRITE at msg 13** | 30897 / **5130** | append-only | 33027 / **2731** | On base the next user message merges into the projected update, so the provider cache stops at that message. On head, history stays append-only and the cache continues to the end of the earlier request. ### Side effects - Ordinary chat, 3 turns: every reply arrives on base and head; every request is append-only (head cached / uncached: 29226 / 583, 29806 / 583). - `/compact`: works the same on base and head ("Compacted (31k → 1.4k)"). The next turn replies normally. The post-compaction request is the one rewrite that compaction is allowed to make, on both sides. - Every turn of every journey returned `status: ok` on both Gateways. ### UI (Control UI of each scratch Gateway, chat history after the journeys) Head and base render the same history. No "System prompt update" bubble or other prompt-update text appears in any session on head (checked in the rendered chat log text as well). The silent `NO_REPLY` turn shows only the user message, as on base. Head, `NO_REPLY` journey with `/compact`:  Base, same journey:  Head, silent exec wake journey:  Base, same journey:  ### Review and CI on this head - Local ClawSweeper on `53c326c`: `review_status: complete`, "patch is correct", 0 findings. - PR CI on `53c326c`: all required checks pass. Co-authored-by: Ayaan Zaidi <[email protected]>
…low and a concurrent chat on five transports (openclaw#201723) ## What was wrong The prompt-cache journey is the CI check that each provider request in a chat extends the previous request byte for byte, except where a rebuild is expected. It skipped four triggers that real chats hit: a scheduled job that comes due in the chat, a user message steered into a running tool call, tool results that fill the context window, and an unrelated chat that compacts while this one runs. It also covered only three transports. A break in any of those paths could land without CI noticing. **Example:** a scheduled job sent its reply to the model twice on every route. On Chat Completions and Gemini the copy merged into the next tool-call message, which rewrote history and lost the cache from that point on. Fixed in openclaw#201838. This journey would have caught it. ## Fix - Adds the cron, steer, tool-result overflow and concurrent-compaction steps to the stability journey. It now runs on five transports: Anthropic, Responses, Chat Completions, Gemini and Bedrock. - Adds a seeded randomized journey: 15 turn kinds on five transports, plus a variant with Tool Search turned off. - Lists the breaks main still has, each with its owner. Entries expire: when a fix lands, the journey fails until its entry is removed. Each entry checks the whole request, so a known change cannot hide a second one. - Rebuild steps are excused only when the rebuild actually happened. A compaction must put its new summary into the next request, and a model switch must make the next request come from the selected model. - The steer step holds the tool open until the Gateway reports that the run has taken the steer. Before, it slept for a fixed 3 s. ## Numbers | | main (before this PR) | this PR | |---|---|---| | Triggers covered | ordinary turns, tools, compaction | + cron, steer, tool-result overflow, concurrent compaction, cron-first chat, 15-kind randomized journey | | Transports | 3 | 5 | | Stability journey | n/a | 5/5 | | Randomized journey (default seeds, 6 files) + negative controls | n/a | 12/12 + 5/5 | | Anthropic and Tool Search off, seeds 1 and 6 | n/a | 2/2 and 2/2 | <details><summary>Breaks still on main (accepted entries)</summary> | Where | Change | Owner | |---|---|---| | Gemini, tool-result overflow (other chat) | the pre-request pressure check trims tool results that were already sent | openclaw#199530 | | Bedrock, randomized | a dropped silent reply merges the user turns around it | accepted gap (openclaw#201654 closed) | | Tool Search off, randomized | a provider switch adds `skills_read`/`skills_search` on turns started by a subagent completion or inter-session message | openclaw#201710 / documented exception of the opt-out surface | Removed because their owners landed: the cron reply twice (openclaw#201838), the Chat Completions silent-turn merge (openclaw#201843), the cron-first `message` growth (openclaw#201710), and the skills rebuild after `config.patch` (issue openclaw#202150, which no longer reproduces on Anthropic seeds 1 and 6). Bedrock refuses `cron.add` for AWS-SDK auth by design, and the journey expects that refusal. </details> <details><summary>Steer signal</summary> - The steer is sent with `queueMode: "steer"`, as the chat composer sends it. The test waits for `sessions.changed` with reason `agent.input.steering`, which the Gateway emits when the active run accepts the steer into its queue. The tool is released only after that event. - On all five transports the event arrives about 200-260 ms after the send is acknowledged, while the tool is still held. - Negative control: releasing right after the acknowledgment lost the race on Gemini (1/5). The steered input became a separate turn. - A default `chat.send` steer exposes nothing before release. Its pending input stays `queued` with no `steerNow`, and `agent.input.steering` only fires when the tool ends. So the step uses the composer's steer path. </details> <details><summary>Rebuild evidence checks</summary> - Compaction: the fake numbers each compaction summary. The step needs a new summary, and the turn after it must contain that summary. - Model switch: the alternate provider has its own model id. Every request after the switch must name exactly the selected model, read from the request body or the URL (Gemini, Bedrock), and at least one request must arrive. - Teeth: with `sessions.compact` turned into a no-op, all 10 randomized seeds failed. With `sessions.patch` pinned to the first model, all 10 failed too. </details> <details><summary>Cron-first red on base</summary> On the parent of openclaw#201710 with this PR's test files (no entry), the cron-first step fails on Anthropic and Responses at the owner turn's tool list (`at: 1, change: tools`). On main the step passes. </details> <details><summary>Harness fixes</summary> - Each seed uses its own session keys. A retained subagent from the previous seed made every turn fail with `Retained subagent payload is unavailable`. - After a silent reply, the fake acts only on the newest step marker, because main drops silent replies from replay. - Every request is assigned to its session by its runtime line. A request from an unexpected session fails the journey. - The Advisor fork check is dropped. Forks never arrived in earlier runs. When they did arrive, their requests differed from the parent's on all transports, which needs its own investigation. </details> <details><summary>Gates</summary> - `ocx test` from source with an in-process Gateway and fake provider endpoints: 5 stability files, 6 randomized files and the known-breaks unit, 17/17. Anthropic and Tool Search off at seeds 1 and 6, 2/2 each. A second stability pass, 5/5. - `pnpm tsgo:test:root`, oxfmt and oxlint on the changed files, and the test-lines ratchet all pass. - Local review on this head: patch is correct, no findings. </details> Co-authored-by: Ayaan Zaidi <[email protected]>
Problem
A silent reply (
NO_REPLY) was dropped from model replay by row-local normalization (normalizeAssistantReplayMessageinreplay-history-sanitization.ts). The next user turn then sat directly after the silent turn's user message. On routes that merge consecutive user turns at the stream boundary (mergeConsecutiveUserMessagesinattempt-tool-call-replay-sanitization.ts), the next request merged the new user turn into the already-sent one. The sent prefix changed, so the prompt cache broke.preserveContextBoundaries: false), so every turn after a silent reply breaks the cache there.Found by the randomized prefix suite: bedrock seed 1 breaks at step 22 (
silentthenuser, after amodelSwitch). Message 38 is the silent turn's user message, and it is rewritten. The model switch is not part of the cause. It only happens to come first in that journey.Fix
This ports 0191111b26aa onto the current replay sequence. The replay code was split into row-local and sequence steps after that commit.
normalizeReplaySequencedrops a visible silent reply only when the next non-custom row is an assistant turn. That turn never merges into it, which keeps Anthropic request builder merges NO_REPLY-yield turn into next tool turn → two thinking blocks in one message → permanent 400 "cannot be modified" loop (deterministic repro; likely root cause of #98760) #99620 intact. A silent reply before a user turn, or as the newest row, stays. Replay is append-only again.silentReplysource fact. The array path and the fact path give the same result, as the existing mixed-history parity test shows.Accepted edge case: a silent reply that is the newest row stays in replay. If the next stored row is an assistant turn with no user turn between them, the silent reply is then dropped. This changes the prefix once. It is rare, visible and recoverable.
This PR supersedes the silent-reply part of draft #198201. That draft also carries a worker-pin fix, which this PR does not touch.
Evidence
Red on base, green on head. The new test
attempt-tool-call-replay-sanitization.test.ts› "keeps the %s request append-only after a silent reply" runsnormalizeMessagesForLlmBoundaryand then the stream wrapper for two consecutive requests.bedrock-converse-streamandopenai-completions: the second request has[quiet, next]merged into message 2.Randomized prefix suite, bedrock seed 1. This is the harness from the prompt-cache branch, run locally and not committed. It uses a real Gateway and a fake Bedrock transport.
{"step":22,"kind":"user","change":"message 38 ..."}.Real route, before/after. This used an isolated scratch Gateway (
env -i, random port) on OpenAI Responses (gpt-6.1-sol, with a switch togpt-6-astraand back). Turn 5 replied a realNO_REPLY. Each value is the provider-reportedcacheReadfor that request:As expected, Responses does not merge user turns, so it shows no break on base and no regression on head. The break needs a route that merges user turns. No Bedrock credentials were available for a real Bedrock run, so the Bedrock proof uses the fake transport above. The Bedrock cacheRead gain is unmeasured on a real route.
Gates
pnpm tsgo:corepassed.pnpm check:test-typespassed.ocx test src/agents/embedded-agent-runner+session-tool-result-guard.transcript-events.test.ts: 1465 passed, 1 failed. The failure wasrun.shared-integration.test.ts› timeout cancellation, on a heavily loaded host. That file passes alone on head.Size: production code +28/-5 (3 files); tests are updated where they asserted the old drop (
replay-history.test.ts,exact-compaction-replay.test.tsGoogle marker case,attempt-prompt-context.test.tsshrink case).Local review: first head flagged a per-silent-row history copy (
slice); fixed in cd54752 with an index walk.