Repository navigation
test(prompt-cache): extend the prefix journey with cron, steer, overflow and a concurrent chat on five transports - #201723
Conversation
|
🦞👀 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. |
|
Codex review: needs changes before merge. What this changesThis PR expands prompt-prefix integration journeys to five transports and adds scheduled, steered, overflow, concurrent-chat, and seeded randomized scenarios. Example: An unrelated chat compacts while the target chat executes a tool.
Review scores
ProductKind: Test only · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 2 items remain Keep open: this maintainer-authored PR adds useful transport coverage, but its Bedrock exception can hide unrelated regressions and its concurrency check can fail solely because compaction takes longer than three seconds. Priority: P2 Before merge
Findings
Agent review detailsHow this fits togetherThe Gateway integration harness drives chat and session operations against local fake provider endpoints, captures outgoing system prompts, tools, and messages, and checks prefix continuity between requests. flowchart LR
A[Journey scenarios] --> B[Gateway RPC]
B --> C[Agent and session runtime]
C --> D[Provider transport]
D --> E[Local fake endpoint]
E --> F[Captured request comparison]
Technical reviewBest possible solution: Keep the shared transport fixtures and journeys, constrain the Bedrock exception to its documented silent-reply transition, and synchronize the concurrent tool with compaction completion. Do we have a high-confidence way to reproduce the issue? Source establishes both harness defects directly: arbitrary Bedrock user-message changes match the exception, and correct compaction lasting over three seconds violates the request-count assertion; no target code was executed. Is this the best way to solve the issue? Extending the existing Gateway journey and sharing transport fixtures is appropriate, but exceptions must preserve detection of unrelated changes and concurrency must depend on explicit completion signals. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against f165544e2ce4. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
PR surfaceTests +1056, Other +3. Total +1059 across 11 files. Added test files: 9. 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, 3:42 AM ET / 08:42 UTC. |
abea265 to
4b53ff1
Compare
…201710) > **Size:** production code vs `main` (base `3da2118`, excluding tests and docs) is +290 / -205 (net +85). Not net negative: the growth is the execution-gate conversion itself (build the session's full list, then gate by turn policy in assembly and the message policy), keeping refused tools out of delegation, capture, guidance and the preparer path, the run-policy mark that keeps the empty-allowlist error identical to `main`, and the opt-out admission path `toolSearch: false` still needs. 27 added lines are a move (`session-prompt-delta.ts`) forced by the line-cap ratchet. > > **Isolated crons keep main's narrowed list.** A session whose key is an isolated cron run (`agent:<id>:cron:<job>:run:<runId>`, one run per session, `isCronRunSessionKey`) has no series to share, so it keeps the listing narrowed to its allowlist, as on `main`. Every other session, including a cron that runs in a shared session, keeps the fixed listing. Call gates apply everywhere. First request of an isolated cron with `toolsAllow: ["read"]` (tools / input tokens; Claude input = uncached + cache read + cache write): > > | | main `3da2118` | `a5d2e08` (fixed listing everywhere) | this head | > |---|---|---|---| > | OpenAI | 4 / 6,128 | 14 / 12,368 | 4 / 6,114 | > | Claude | 4 / 9,206 | 14 / 20,121 | 4 / 9,258 | > > A cron that runs in a named shared session (journey J2) still sends the fixed list (14 tools), which is what keeps that session's later turns on one cached prefix. > > **Scope:** this PR covers core and plugin tools. MCP and LSP keep `main`'s behavior exactly: their runtimes start only when the run's allowlist permits it, and sender/group denies still apply at MCP discovery. Because MCP tools sit in the deferred catalog, an MCP-only-allowlist cron after `/compact` (J12) no longer narrows the pinned tool list on this head; what remains (the deferred directory following the allowlist, sender denies dropping an MCP server, and starting MCP/LSP from the pin) is the follow-up: pin-owned MCP/LSP listing with a lazy runtime start. ## Problem The session prompt owner pins the tool definitions of a prompt series. A turn that built a tool the pin lacked extended the pin, so the provider tool list changed. Tools sit at the front of the request, so the whole cached prefix missed. The list changed with turn authority: - A chat whose series starts on a cron turn has no `message` tool under the `coding` profile. The next user turn in `message_tool_only` delivery builds `message`, the pin grows, and that request reads 0 cached tokens. - A run's `toolsAllow` (cron, queued follow-ups, cross-session events) narrows the list. A subagent child's spawn turn (`disableMessageTool`) lists no `message` while its follow-up turns do. - Group `tools` / `toolsBySender` policy narrows the list per sender, so a guest and an owner in one group chat send different lists. - The deferred MCP directory sat in the `tool_search` definition, so an MCP server that connected later changed a tool definition. Freezing the pin alone made the first turn's omissions permanent (an owner turn after a narrowed turn silently lost tools). This PR makes the list independent of turn authority and gates calls at execution instead. ## Solution 1. **Freeze** (`session-prompt-state.ts`, `prepareSessionToolSurface`): on a fixed listing the series' first request pins the tool set and every definition. A pinned tool a turn did not build stays listed and refuses its call. The tool policy digest's inputs changed (it now includes `config.mcp`), so every session starts one new pin after upgrade. 2. **MCP directory out of `tool_search`**: `buildToolSchemaDirectoryPrompt` appends the bounded, sanitized MCP directory to the system prompt's `### Deferred Tool Schemas` section. An MCP server that connects, disconnects or changes its tools reaches the model as an appended prompt-update note, never as a definition change. 3. **`message` always listed, gated at execution**: on a fixed listing the assembly builds `message` regardless of reply mode; `resolveTurnToolSurface` refuses it on a turn that cannot send ("message cannot send on this turn: ... Do not retry message."). 4. **Every run allowlist and group/sender policy is an execution gate** (core and plugin tools): on a fixed listing, `toolsAllow` on any trigger and the group `tools` / `toolsBySender` policy no longer narrow construction. `resolveTurnToolSurface` refuses the tools the turn's policy omits ("`<tool>` is outside the tools this run allows. Do not retry `<tool>`."), marks them unavailable and as run-policy refusals, and never hands them the source's execution preparer, so direct calls, the agent loop's preparer path and a `dispatch_action` rewrap all refuse. Turn authority, child inheritance, cron-creator capture and the catalog restriction read the same policy, so the callable set is unchanged (table below). An allowlist that leaves nothing callable still fails with "No callable tools remain", as on `main`. 5. **Guidance follows callable tools** (m6): `applyPromptBuildToolsAllow` drops listed-but-refused tools from `callableToolNames`, so a turn that cannot send is not told to "use the message tool". 6. **Docs**: `docs/reference/prompt-caching.md`, `docs/tools/tool-search.md`, `docs/concepts/experimental-features.md`. ### Authority recheck at `390da1c` (fixed in this head) - **A1** (allowlists narrowing the list): for core and plugin tools, the allowlist no longer narrows construction on a fixed listing. The attempt-level filter is skipped (the assembly's turn policy already refuses what the allowlist omits, so the old attempt-level gate was redundant and is deleted). The MCP part (J12) is out of scope; see Scope. - **A2** (refused copies carried the source's execution preparer): `copyAgentToolMetadata` no longer copies the preparer onto a target that refuses execution (the turn-policy refusal in `resolveTurnToolSurface`, including the scoped-reads split). Ring-zero tools: a ring-zero harness run has no Tool Search controls, so it is never a fixed listing and the allowlist still removes them, as on `main` (test). - **m-a**: a tool built after the session pin is logged (`tools built after the session pin wait for the next prompt series`). - **m-b / 1b** (fixed for plugins): on a fixed listing, plugin construction keeps every grant plus the default plugin tools and uses a denylist without sender, group and run denies; those refuse at execution. Children still inherit the full denylist. The MCP part (a sender deny dropping a whole MCP server at discovery) is out of scope. - **1a** (fixed): `progress_card` is built whatever the run allowlist names and refused by the turn policy. `show_widget` keeps its admission rule (a scheduled run gets it only when its allowlist names it); that rule grants a capability rather than narrowing one, and changing it would remove widget authoring from such runs. Documented, not changed. - **1c**: the bundle pass (MCP/LSP) is back to `main`, except that tools the turn refuses are not delegated or captured. - **1d** (fixed): the scoped-reads split is marked before its metadata copy, so it never inherits the source's preparer (test red before the fix). - **1e** (fixed): the built-after-pin log fires once per series and tool set. - **m4a** (accepted): a completion handoff on a fixed listing does not mark run-allowlist refusals, so they can hide an allowlist that matched nothing (`main` removed them). - **m3** (accepted): a grant that only a guest's `allow` names builds that optional plugin tool on the guest's turn only. Plugin tools are catalog entries, so the pin holds; the cost is one prompt-update note per sender flip. Same class as the `show_widget` rule. - **m6** (accepted): a refused call still runs plugin `before_tool_call` hooks; the refusal happens after them and authority is unaffected. - **m5c**: the fixed listing has no unit test of the MCP call lifecycle; the real-route journeys (J5, J12) cover it. A cataloged client tool in the restored empty-allowlist error is also not unit-tested here. - **`fixedToolListing` kept**: Copilot (`tool-bridge.ts`), Codex (`dynamic-tool-build.ts`) and agentsapi pass a run allowlist into OpenClaw tool construction; I did not verify that each of them removes `progress_card` later, so the registration flag stays. - **structured_output** (documented): swarm collectors re-add `structured_output` after policy, so it stays callable under a `toolsAllow` that omits it. `main` removed it. Benign: it only records the collector's own result. - **Restored error** (fixed): "No callable tools remain" now matches `main` exactly except for tools a run allowlist or sender/group policy refuses (these were absent on `main`). Owner-only tools and cataloged client tools count as before (test: an allowlist naming an owner-only tool on a non-owner turn does not error, on `main` and head). - **MCP/LSP startup**: unchanged from `main` (out of scope). Auth prompts: starting the MCP runtime only reads credential status; sign-in starts only when a connect tool is called from an untainted owner direct chat, so a cron start raises no prompt. - **m-c**: the empty-allowlist error counts only callable tools, so a sender `allow` typo or a `toolsAllow` that names only refused tools fails with "No callable tools remain", as on `main` (same test green on both). - **m-d**: guidance drops cataloged tools the turn refuses, not only direct ones. ### Exceptions (behavior unchanged) Items 3-5 apply only when Tool Search lists a fixed set (`listsFixedToolSet`: controls enabled, `mode: "tools"`, no `include`/`exclude`). Otherwise (`tools.toolSearch` off, `disableToolSearch` runs, memory flush, Code Mode, selectors, `mode: "directory"`) filtering and pin admission stay as on `main` (gate A J8 below: per-turn lists equal between arms). Out of scope (follow-up): other trigger-dependent definition text, e.g. the `message` description's action list (see Risks). ### Fable D findings at `53145b8` - **M1** (owner turns lose tools after a narrowed turn): fixed by item 4. - **m2** (rewrap could bypass the gate): fixed; the production-path test "keeps a run allowlist refusal through a catalog rewrap" calls through a `dispatch_action` rewrap and gets the refusal. - **M3** (fork mismatch): gone with item 4; a fork sends the source's list unchanged (test below). - **m4** (history growth): after the split the MCP directory flips again on allowlisted turns, as on `main`: an allowlist naming no MCP server starts no MCP runtime, so a prompt-update note goes out on the cron turn and another on the next user turn. The cache is kept (notes append); the follow-up removes the flip. - **m5** (fork before the first post-upgrade turn): accepted edge case. `readSessionForkPin` ignores the policy digest, so such a fork sends the old pin plus `message` once (one miss); the source re-pins on its own next turn. Test: "lets a fork that runs before the first post-upgrade turn add message once". - **m6**: fixed by item 5. ## E2E on this head (`45ef8f8c583f`, base = merge base `3da2118f243c`) Isolated scratch Gateways (own state dir, random port, `env -i`) from source copies of each commit, real provider routes (OpenAI Responses and Claude via an Anthropic-messages proxy), a logging proxy recording provider usage per request. Both arms ran the same journeys with the same config (`visibleReplies: "message_tool"`, Tool Search on), with an unrelated chat running turns and `sessions.compact` throughout. OpenAI: `read` = `cached_tokens`, uncached = input − cached. Claude: `read` = `cache_read_input_tokens`, uncached = `input_tokens`, plus `write` = `cache_creation_input_tokens`. **J1: cron starts a chat, then the user** (cron request, then user turns) | route | arm | tool lists in the chat | cron→user request | session total | |---|---|---|---|---| | Claude | base | 2 (cron A, user B) | read 9,668 / write 16,952 | write 42,138 | | Claude | head | 1 | read 23,965 / write 3,168 | write 28,339 | | OpenAI | base | 2 | read 0 / uncached 17,007 | both user turns stopped by the model's `message` loop (below) | | OpenAI | head | 1 for the turns (see note) | read 15,667 / uncached 1,972 | `hello-j1` and `second-j1` delivered | **J2: shared-session cron with `toolsAllow: ["read"]`, then the owner asks for `exec`** | route | arm | cron listing | owner turn after the cron | session uncached (OpenAI) / write (Claude) | |---|---|---|---|---| | OpenAI | base | 4 tools | 14 tools, read 0 / uncached 19,340 | 27,413 | | OpenAI | head | 14 tools (fixed) | same list, read 13,582 / uncached 4,968 | 18,934 | | Claude | base | 4 tools | 14 tools, read 9,554 / write 21,734 | 32,060 | | Claude | head | 14 tools (fixed) | same list, read 21,976 / write 7,856 | 20,066 | Cron result on head (both routes): `exec` refused visibly ("exec is outside the tools this run allows. Do not retry exec."), `read` returned `gate-file-contents-7731`, `exec` did not run. Base: the model reports exec unavailable (not listed). The owner's later `exec` ran on both arms. **J2i: isolated cron with `toolsAllow: ["read"]`** keeps the narrowed listing, matching base: 4 tools on both arms; first request input OpenAI 6,110 (base) vs 6,145 (head), Claude 9,206 vs 9,260 total. **J11: one group, guest denied `exec` (sender policy), then owner** | route | arm | tool lists in the group | requests with read 0 after the first | uncached (OpenAI) / write (Claude) | |---|---|---|---|---| | OpenAI | base | 2 (guest 9 tools, owner 14) | 1 (owner's first turn) | 39,422 | | OpenAI | head | 1 (14) | 0 | 25,740 | | Claude | base | 2 (9, 14) | 1 | 62,158 | | Claude | head | 1 (14) | 0 | 29,511 | Guest `exec` on head: refused with "exec is outside the tools this run allows. Do not retry exec." (base: not listed, the model says it is unavailable). Guest `read` worked and both owner `exec` calls ran on both arms. **Side effects.** Every journey's replies arrived on head (J1 user replies, J2 cron + owner, J11 five group replies, J2i cron `ok`); refused tools stayed refused and never executed. The OpenAI model on this route sometimes fills every optional `message` field (a `gatewayUrl`, a made-up target) and loops; this happened on **both** arms (base: both J1 user turns and one unrelated-chat turn stopped by the 20-repeat guard; head: three unrelated-chat turns stopped the same way, and J1's first reply was kept private, then delivered by the stranded-reply retry). The stranded-reply retry runs with `toolsAllow: ["message"]` (`stranded-reply-recovery.ts`, unchanged by this PR), so it sends a message-only list and misses the cache once (OpenAI uncached 9,207) on both arms; not changed here, noted as a follow-up. **UI** (Control UI of the head and base scratch Gateways, after the journeys; chat area cropped): the J2 chat shows the cron's visible refusal, the J11 group shows the guest's refusal, J1 renders both delivered replies. | | base | head | |---|---|---| | J2 |  |  | | J11 group |  |  | | J1 (OpenAI) |  |  | The live operator Gateway was untouched during the runs (its pid and config unchanged). ## Evidence ### Tests (red on merge base `3da2118f243c`, green on this head) - `src/agents/session-tool-listing.test.ts`: one tool list across user, cron, exec-wake, subagent, steer and allowlisted turns, checked on each turn's own built list and on the sent list; one list for every sender of a group chat; a fork sends the source's list unchanged; a cron turn after `/compact` re-pins the owner turn's list (green on main too: this fixture does not reproduce the #201655 4-vs-3 case); a later user turn sends with `message` in a cron-started series. - `attempt-tool-prepare.scheduled-tools-allow.test.ts` (real `prepareEmbeddedAttemptToolBase`): refusal-equivalence table "allows exactly the calls main allowed" for cron/user/event `toolsAllow`, group guest sender and group owner sender; one tool set for every group sender with the guest refused through `dispatch_action`; refusal kept through a catalog rewrap; an allowlist matching nothing still fails (green on main and head). - `agent-tools.turn-authority.test.ts`: a turn-policy refusal and the scoped-reads split never carry the source's preparer (red on `390da1c` / before the fix). - `attempt-prompt-tool-policy.test.ts`: "leaves a listed tool the turn refuses out of the callable guidance" (main: `['message','read']`, head: `['read']`). - `attempt-session-runtime-prepare.test.ts`: production `admitNewTools` wiring (inverting it fails 2 tests). `session-prompt-state.test.ts`: one new pin after an upgrade changes the policy digest. ### Execution-based refusal equivalence `attempt.configured-mcp-lifecycle.test.ts` now runs its cataloged case with an `include` selector: the fixed listing builds every core tool, which that harness does not mock. The fixed-listing MCP path is covered by the real-route journeys (J5, J12, J13). `attempt-tool-prepare.scheduled-tools-allow.test.ts` builds tools through the production tool base, bundle pass (a mocked bundle MCP server) and catalog, then executes every listed tool through the direct path, the preparer the agent loop prefers, and a `dispatch_action` rewrap. The callable tables (cron/user/event `toolsAllow`, group guest, group owner) pass unchanged on `main` and on this head; the three paths agree for every tool. New: an MCP-only allowlist lists the full set (red on `390da1c`), sender `allow`/`deny` policies including an MCP tool, a refused tool is never delegated or captured, and only-refused-tools fails loudly (green on `main` and head, red on `390da1c`). A tool counts as callable only when a call with schema-valid placeholder arguments passes every gate, starts the tool's implementation and does not come back refused; exceptions and timeouts before the implementation starts count as not callable. ### Callable set, base vs head (`toolsAllow: ["read", "group:web", "sessions_*", "message"]`; group deny `exec, process, write, edit, apply_patch` for the guest) | case | callable on base and head | listed on head | |---|---|---| | cron / user / event `toolsAllow` | dispatch_action, message, read, sessions_create, sessions_history, sessions_list, sessions_search, sessions_send, sessions_spawn, sessions_yield, tool_describe, tool_search, web_fetch | full session list (39), the rest refused | | group guest | guest set (identical on base and head) | full session list (40), denied tools refused | | group owner | guest set + apply_patch, automations, conversations_*, edit, exec, gateway, plugins, portal, process, terminal, write | same list as the guest | ### Gate A at earlier heads (`c1160ede` / `6bbc29a2`), for history Base `3da2118`. OpenAI `gpt-6.2-astra` and cliproxy `claude-opus-5-5`. Raw results in `/tmp/pcr/gate201710/`. | journey | main | head | |---|---|---| | J1 cron starts chat, then user | list changes 2x (OpenAI incl. a message-only list), cache misses | one list, cache hits; user reply via `message` | | J2 cron `toolsAllow: ["read"]` | list 4 tools on the cron turn, 14 on the user turn (miss) | 14 throughout; `exec` refused visibly, `read` works, later user `exec` works; cache hits | | J3 reset, cron first, user | reply arrives | reply arrives; new list only at the reset (new session) | | J4 turn that may not send calls `message` | OpenAI: no refusal | OpenAI: visible refusal, nothing delivered. Claude: same as main on both arms (model replied without the message call) | | J5 MCP connect mid-chat | directory in `tool_search` | list unchanged; directory change arrives as an appended note; `dispatch_action` -> `mcp:beta:beta__beta_probe` returns `probe-ok-beta` with a cache hit (OpenAI read 30,770 / 30,949) | | J6 computer without a node | one list; call fails visibly | same | | J7 exec wake, subagent, steer | list changes (OpenAI D->B->E->D) | one list; wake, child result and steer all delivered | | J8 `toolSearch: false` | per-turn lists | identical to main on both routes | | J9 regression set | ok (OpenAI after-reset turn errored once) | ok | | J10 owner turns, `/compact`, cron, owner | one list (no 4-vs-3 repro on this config) | one list (14) before and after; cron after compaction keeps it; next owner turn cache hit | | J11 group: guest denied exec, owner | guest pins 9 tools, owner turn 14 with a miss, a prompt-update note per sender flip | one list (14) for both senders, every request a cache hit (Claude reads 23,881 -> 31,107), guest `exec` refused ("exec is outside the tools this run allows"), guest `read` and owner `exec` work | ### Gate A on this head (`d827cceb`, main `3da2118`), proxy-log excerpts, redacted Isolated scratch Gateways (`env -i`, random ports, isolated state), a concurrent second chat running turns and `sessions.compact`. Each cell: the session's tool sets in order (a letter per distinct tool-definition hash), then per request `tool count/cached input tokens`. | journey | route | main | head | |---|---|---|---| | J1 cron starts chat, then user | OpenAI | `B>A`: 14/0 **14/0** 14/16362 14/16587 | `B`: 14/0 14/14440 14/14762 14/15070 14/17039 | | | Claude | `B>A`: 14/0 **14/9668** 14/26625 | `B`: 14/0 14/23920 14/27152 | | J2 cron `toolsAllow: ["read"]`, then user `exec` | OpenAI | `C>D`: **4**/0 4/6485 **14/0** 14/19323 | `B`: 14/0 14/13046 14/13163 14/13500 14/18458; `exec` refused, `read` ok, user `exec` ok | | | Claude | `C>D`: **4**/0 4/9786 4/10049 **14/9554** 14/31223 | `B`: 14/9951 14/21608 14/21904 14/29747 | | J3 reset, cron first, user | both | new set at the reset, then back | new set only at the reset (new session) | | J4 cannot-send cron calls `message` | OpenAI | no refusal | refused: "message cannot send on this turn: its reply delivery or tool policy does not allow the message tool. Do not retry message." | | J7 exec wake, subagent, steer | OpenAI | `A>F>A` | `A` | | J10 owner, `/compact`, cron, owner | Claude | `A`: 14/9668 14/23800 14/9668 14/25198 14/26268 | `A`: 14/9554 14/23780 14/9554 14/25189 14/26302 (the 9,554 row is the cron right after compaction: history rewritten, tools kept) | | J11 group: guest denied `exec`, then owner | OpenAI | `H>I`: **9**/0 9/12866 9/13418 **14/0** 14/19652 | `E`: 14/0 14/14300 14/17481 14/17525 14/20649; guest `exec` refused ("exec is outside the tools this run allows. Do not retry exec."), guest `read` and owner `exec` ok | | | Claude | `G>H`: **9**/0 **14/0** 14/28797 14/28928 | `E`: 14/9942 14/23774 14/28261 14/28369 | | J12 owner, `/compact`, cron `toolsAllow: ["alpha__alpha_probe"]`, owner | Claude | `A>I>A`: 14/9668 14/23800 **3/0** 3/6670 3/7224 **14/9668** | `A`: 14/9554 14/23780 14/9554 14/22377 14/22989 14/23317; cron calls `alpha_probe` via `dispatch_action`, its `exec` is refused, owner `exec` ok | J12 passes on head because MCP tools live in the deferred catalog, not the tool list: the core list no longer follows the allowlist. What stays as on `main` is the MCP runtime start rule (an allowlist that names no MCP server does not start MCP, so the deferred directory changes through an appended note) and MCP discovery honoring sender/group denies. Earlier runs (J5 MCP connect mid-chat, J6 computer, J8 `toolSearch: false`, J9 regression set) are unchanged by the split and were green at `c1160ede`. Pre-existing on both arms: gpt-6.2 fills `channel`/`target` on WebChat `message` calls and loops on the rejection; `chat.abort` leaves the run status `error`; a `sessions.compact` during an active run is rejected ("has an active run; retry after it finishes"). ### Existing-session upgrade (one session, main then head on the same state dir) Isolated scratch Gateway (`env -i`, random port, isolated state dir, 250k context so compaction cannot mask the measurement), cliproxy `claude-opus-5-5`. Main `3da2118` builds the session with four owner turns (reply, `read`, `exec`, reply) and stops. Head `d827cceb` starts on the same state dir: one owner turn, a cron with `toolsAllow: ["read"]`, an owner `exec` turn, a last reply. | arm | turn | tools | cached / written | |---|---|---|---| | main | owner reply | 14 | 9,668 / 15,865 | | main | owner `read` (+ follow-up) | 14 | 25,533 / 1,148; 26,681 / 84 | | main | owner `exec` (+ follow-up) | 14 | 26,765 / 1,158; 27,923 / 104 | | main | owner reply | 14 | 28,027 / 1,152 | | head | first turn after the upgrade: **the one re-pin** | 14 | 9,554 / 20,755 (only the system prefix is cached) | | head | cron `toolsAllow: ["read"]`: `read` ok, `exec` refused ("exec is outside the tools this run allows") | 14 | 30,309 / 6,865; 37,174 / 302 (hits) | | head | owner `exec`: runs | 14 | 37,476 / 9,278; 46,754 / 161 (hits) | | head | last reply | 14 | 46,915 / 1,153 (hit) | One miss on the first head turn, then cache hits on the cron and owner turns. ### Gate C (append-only journeys from #201723) Stability journeys: head 5/5 pass, main 5/5 pass (they do not separate the arms). Randomized seeds 1-10 on head: 60/60 pass (anthropic-messages, openai-responses, openai-completions, google, bedrock, and the Tool Search opt-out surface). ### Gates - `pnpm tsgo:core`: pass. oxlint, oxfmt on changed files, `git diff --check`: clean. - Production code vs `main` (excluding tests and docs): +290 / -205 (net +85); see the size note at the top. ### Test lines Net test lines +994 against the 400 allowance. Duplicate tests were removed first (the scheduled-run table duplicate, the separate catalog-rewrap test, the sender-deny MCP case, the bundle MCP fixture, and the duplicate group-sender listing test). The remaining 594 lines are recorded in `config/test-lines-allocations/201710-session-tool-listing.txt`: refusal equivalence against `main` executed through the production tool base, bundle pass and catalog for five policy shapes across the direct, preparer and `dispatch_action` paths, plus series listing, fork and upgrade pin cases. ### Local ClawSweeper (gpt-6.1-sol, normal) Head `45ef8f8c583f`: patch is correct, no findings (exit 0). The local review reads only the committed range and its tests; the real-route journeys above are outside its inputs. An earlier P2 at `9543fde3` (sender change dropping a direct-only tool such as `computer` from a frozen group listing) is fixed by item 4: every sender builds the same list. ## Risks - `message` and allowlist-refused tools are listed (and refused visibly) on turns that cannot use them. Each costs one definition. - The `message` definition's action list still depends on the turn that starts the series (a cron-started WebChat series pins "Supports actions: send" without `react`). The pin keeps it stable; `react` is not advertised in that series until a rebuild point. Main would extend the pin (a miss) instead. Follow-up. - Upgrade: every existing session re-pins once on its first turn after the upgrade (the toolPolicy digest changes), costing one cache miss per session. This is the same accepted one-time cost as #201843. - MCP names and sanitized descriptions now enter the system prompt's deferred-tool section instead of the `tool_search` description. Co-authored-by: Ayaan Zaidi <[email protected]>
…low and a concurrent chat on five transports The prefix-stability journey now also covers a steer into a running tool call, a scheduled job that comes due in the chat, an unrelated chat whose tool results fill its window and which compacts while the target runs, on Anthropic, Chat Completions, Responses, Gemini and Bedrock. A seeded randomized journey suite runs every turn kind per transport. Breaks that main still has are listed narrowly with their owner. Co-authored-by: obviyus <[email protected]>
…break Co-authored-by: obviyus <[email protected]>
…reak Co-authored-by: obviyus <[email protected]>
Co-authored-by: obviyus <[email protected]>
…-policy transition Co-authored-by: obviyus <[email protected]>
Co-authored-by: obviyus <[email protected]>
Co-authored-by: obviyus <[email protected]>
Co-authored-by: obviyus <[email protected]>
…l Search surface Co-authored-by: obviyus <[email protected]>
…rneys, opt-out variant Co-authored-by: obviyus <[email protected]>
…an accepted gap Co-authored-by: obviyus <[email protected]>
…s owner landed Co-authored-by: obviyus <[email protected]>
The cron reply merge (#201838) and the Chat Completions silent-turn merge (#201843) are fixed on main, and the skills-after-reload rebuild no longer occurs on Anthropic seeds 1 and 6. Co-authored-by: obviyus <[email protected]>
bf13587 to
0fc75c7
Compare
A compaction excuse needs the turn after it to carry the new summary, and a model-switch excuse needs the request to come from the selected model. Co-authored-by: obviyus <[email protected]>
Co-authored-by: obviyus <[email protected]>
Co-authored-by: obviyus <[email protected]>
A known Gemini trim no longer stands in for the compaction the pressure check must perform. Co-authored-by: obviyus <[email protected]>
|
Landed in 336bc3c. The prefix journey now covers cron, steer, context overflow and a concurrent chat on five transports, and fails when a request rewrites history it already sent. Known breaks must match on every run and expire once their owner lands. A rebuild is excused only when the compaction or model switch really happened. Each guard was checked by disabling what it watches: compaction no-op, a pinned model and no automatic compaction each turn the suite red. |
…penclaw#201710) > **Size:** production code vs `main` (base `cbc12e7`, excluding tests and docs) is +290 / -205 (net +85). Not net negative: the growth is the execution-gate conversion itself (build the session's full list, then gate by turn policy in assembly and the message policy), keeping refused tools out of delegation, capture, guidance and the preparer path, the run-policy mark that keeps the empty-allowlist error identical to `main`, and the opt-out admission path `toolSearch: false` still needs. 27 added lines are a move (`session-prompt-delta.ts`) forced by the line-cap ratchet. > > **Isolated crons keep main's narrowed list.** A session whose key is an isolated cron run (`agent:<id>:cron:<job>:run:<runId>`, one run per session, `isCronRunSessionKey`) has no series to share, so it keeps the listing narrowed to its allowlist, as on `main`. Every other session, including a cron that runs in a shared session, keeps the fixed listing. Call gates apply everywhere. First request of an isolated cron with `toolsAllow: ["read"]` (tools / input tokens; Claude input = uncached + cache read + cache write): > > | | main `cbc12e7` | `a5d2e08` (fixed listing everywhere) | this head | > |---|---|---|---| > | OpenAI | 4 / 6,128 | 14 / 12,368 | 4 / 6,114 | > | Claude | 4 / 9,206 | 14 / 20,121 | 4 / 9,258 | > > A cron that runs in a named shared session (journey J2) still sends the fixed list (14 tools), which is what keeps that session's later turns on one cached prefix. > > **Scope:** this PR covers core and plugin tools. MCP and LSP keep `main`'s behavior exactly: their runtimes start only when the run's allowlist permits it, and sender/group denies still apply at MCP discovery. Because MCP tools sit in the deferred catalog, an MCP-only-allowlist cron after `/compact` (J12) no longer narrows the pinned tool list on this head; what remains (the deferred directory following the allowlist, sender denies dropping an MCP server, and starting MCP/LSP from the pin) is the follow-up: pin-owned MCP/LSP listing with a lazy runtime start. ## Problem The session prompt owner pins the tool definitions of a prompt series. A turn that built a tool the pin lacked extended the pin, so the provider tool list changed. Tools sit at the front of the request, so the whole cached prefix missed. The list changed with turn authority: - A chat whose series starts on a cron turn has no `message` tool under the `coding` profile. The next user turn in `message_tool_only` delivery builds `message`, the pin grows, and that request reads 0 cached tokens. - A run's `toolsAllow` (cron, queued follow-ups, cross-session events) narrows the list. A subagent child's spawn turn (`disableMessageTool`) lists no `message` while its follow-up turns do. - Group `tools` / `toolsBySender` policy narrows the list per sender, so a guest and an owner in one group chat send different lists. - The deferred MCP directory sat in the `tool_search` definition, so an MCP server that connected later changed a tool definition. Freezing the pin alone made the first turn's omissions permanent (an owner turn after a narrowed turn silently lost tools). This PR makes the list independent of turn authority and gates calls at execution instead. ## Solution 1. **Freeze** (`session-prompt-state.ts`, `prepareSessionToolSurface`): on a fixed listing the series' first request pins the tool set and every definition. A pinned tool a turn did not build stays listed and refuses its call. The tool policy digest's inputs changed (it now includes `config.mcp`), so every session starts one new pin after upgrade. 2. **MCP directory out of `tool_search`**: `buildToolSchemaDirectoryPrompt` appends the bounded, sanitized MCP directory to the system prompt's `### Deferred Tool Schemas` section. An MCP server that connects, disconnects or changes its tools reaches the model as an appended prompt-update note, never as a definition change. 3. **`message` always listed, gated at execution**: on a fixed listing the assembly builds `message` regardless of reply mode; `resolveTurnToolSurface` refuses it on a turn that cannot send ("message cannot send on this turn: ... Do not retry message."). 4. **Every run allowlist and group/sender policy is an execution gate** (core and plugin tools): on a fixed listing, `toolsAllow` on any trigger and the group `tools` / `toolsBySender` policy no longer narrow construction. `resolveTurnToolSurface` refuses the tools the turn's policy omits ("`<tool>` is outside the tools this run allows. Do not retry `<tool>`."), marks them unavailable and as run-policy refusals, and never hands them the source's execution preparer, so direct calls, the agent loop's preparer path and a `dispatch_action` rewrap all refuse. Turn authority, child inheritance, cron-creator capture and the catalog restriction read the same policy, so the callable set is unchanged (table below). An allowlist that leaves nothing callable still fails with "No callable tools remain", as on `main`. 5. **Guidance follows callable tools** (m6): `applyPromptBuildToolsAllow` drops listed-but-refused tools from `callableToolNames`, so a turn that cannot send is not told to "use the message tool". 6. **Docs**: `docs/reference/prompt-caching.md`, `docs/tools/tool-search.md`, `docs/concepts/experimental-features.md`. ### Authority recheck at `390da1c` (fixed in this head) - **A1** (allowlists narrowing the list): for core and plugin tools, the allowlist no longer narrows construction on a fixed listing. The attempt-level filter is skipped (the assembly's turn policy already refuses what the allowlist omits, so the old attempt-level gate was redundant and is deleted). The MCP part (J12) is out of scope; see Scope. - **A2** (refused copies carried the source's execution preparer): `copyAgentToolMetadata` no longer copies the preparer onto a target that refuses execution (the turn-policy refusal in `resolveTurnToolSurface`, including the scoped-reads split). Ring-zero tools: a ring-zero harness run has no Tool Search controls, so it is never a fixed listing and the allowlist still removes them, as on `main` (test). - **m-a**: a tool built after the session pin is logged (`tools built after the session pin wait for the next prompt series`). - **m-b / 1b** (fixed for plugins): on a fixed listing, plugin construction keeps every grant plus the default plugin tools and uses a denylist without sender, group and run denies; those refuse at execution. Children still inherit the full denylist. The MCP part (a sender deny dropping a whole MCP server at discovery) is out of scope. - **1a** (fixed): `progress_card` is built whatever the run allowlist names and refused by the turn policy. `show_widget` keeps its admission rule (a scheduled run gets it only when its allowlist names it); that rule grants a capability rather than narrowing one, and changing it would remove widget authoring from such runs. Documented, not changed. - **1c**: the bundle pass (MCP/LSP) is back to `main`, except that tools the turn refuses are not delegated or captured. - **1d** (fixed): the scoped-reads split is marked before its metadata copy, so it never inherits the source's preparer (test red before the fix). - **1e** (fixed): the built-after-pin log fires once per series and tool set. - **m4a** (accepted): a completion handoff on a fixed listing does not mark run-allowlist refusals, so they can hide an allowlist that matched nothing (`main` removed them). - **m3** (accepted): a grant that only a guest's `allow` names builds that optional plugin tool on the guest's turn only. Plugin tools are catalog entries, so the pin holds; the cost is one prompt-update note per sender flip. Same class as the `show_widget` rule. - **m6** (accepted): a refused call still runs plugin `before_tool_call` hooks; the refusal happens after them and authority is unaffected. - **m5c**: the fixed listing has no unit test of the MCP call lifecycle; the real-route journeys (J5, J12) cover it. A cataloged client tool in the restored empty-allowlist error is also not unit-tested here. - **`fixedToolListing` kept**: Copilot (`tool-bridge.ts`), Codex (`dynamic-tool-build.ts`) and agentsapi pass a run allowlist into OpenClaw tool construction; I did not verify that each of them removes `progress_card` later, so the registration flag stays. - **structured_output** (documented): swarm collectors re-add `structured_output` after policy, so it stays callable under a `toolsAllow` that omits it. `main` removed it. Benign: it only records the collector's own result. - **Restored error** (fixed): "No callable tools remain" now matches `main` exactly except for tools a run allowlist or sender/group policy refuses (these were absent on `main`). Owner-only tools and cataloged client tools count as before (test: an allowlist naming an owner-only tool on a non-owner turn does not error, on `main` and head). - **MCP/LSP startup**: unchanged from `main` (out of scope). Auth prompts: starting the MCP runtime only reads credential status; sign-in starts only when a connect tool is called from an untainted owner direct chat, so a cron start raises no prompt. - **m-c**: the empty-allowlist error counts only callable tools, so a sender `allow` typo or a `toolsAllow` that names only refused tools fails with "No callable tools remain", as on `main` (same test green on both). - **m-d**: guidance drops cataloged tools the turn refuses, not only direct ones. ### Exceptions (behavior unchanged) Items 3-5 apply only when Tool Search lists a fixed set (`listsFixedToolSet`: controls enabled, `mode: "tools"`, no `include`/`exclude`). Otherwise (`tools.toolSearch` off, `disableToolSearch` runs, memory flush, Code Mode, selectors, `mode: "directory"`) filtering and pin admission stay as on `main` (gate A J8 below: per-turn lists equal between arms). Out of scope (follow-up): other trigger-dependent definition text, e.g. the `message` description's action list (see Risks). ### Fable D findings at `53145b8` - **M1** (owner turns lose tools after a narrowed turn): fixed by item 4. - **m2** (rewrap could bypass the gate): fixed; the production-path test "keeps a run allowlist refusal through a catalog rewrap" calls through a `dispatch_action` rewrap and gets the refusal. - **M3** (fork mismatch): gone with item 4; a fork sends the source's list unchanged (test below). - **m4** (history growth): after the split the MCP directory flips again on allowlisted turns, as on `main`: an allowlist naming no MCP server starts no MCP runtime, so a prompt-update note goes out on the cron turn and another on the next user turn. The cache is kept (notes append); the follow-up removes the flip. - **m5** (fork before the first post-upgrade turn): accepted edge case. `readSessionForkPin` ignores the policy digest, so such a fork sends the old pin plus `message` once (one miss); the source re-pins on its own next turn. Test: "lets a fork that runs before the first post-upgrade turn add message once". - **m6**: fixed by item 5. ## E2E on this head (`45ef8f8c583f`, base = merge base `cbc12e7178f8`) Isolated scratch Gateways (own state dir, random port, `env -i`) from source copies of each commit, real provider routes (OpenAI Responses and Claude via an Anthropic-messages proxy), a logging proxy recording provider usage per request. Both arms ran the same journeys with the same config (`visibleReplies: "message_tool"`, Tool Search on), with an unrelated chat running turns and `sessions.compact` throughout. OpenAI: `read` = `cached_tokens`, uncached = input − cached. Claude: `read` = `cache_read_input_tokens`, uncached = `input_tokens`, plus `write` = `cache_creation_input_tokens`. **J1: cron starts a chat, then the user** (cron request, then user turns) | route | arm | tool lists in the chat | cron→user request | session total | |---|---|---|---|---| | Claude | base | 2 (cron A, user B) | read 9,668 / write 16,952 | write 42,138 | | Claude | head | 1 | read 23,965 / write 3,168 | write 28,339 | | OpenAI | base | 2 | read 0 / uncached 17,007 | both user turns stopped by the model's `message` loop (below) | | OpenAI | head | 1 for the turns (see note) | read 15,667 / uncached 1,972 | `hello-j1` and `second-j1` delivered | **J2: shared-session cron with `toolsAllow: ["read"]`, then the owner asks for `exec`** | route | arm | cron listing | owner turn after the cron | session uncached (OpenAI) / write (Claude) | |---|---|---|---|---| | OpenAI | base | 4 tools | 14 tools, read 0 / uncached 19,340 | 27,413 | | OpenAI | head | 14 tools (fixed) | same list, read 13,582 / uncached 4,968 | 18,934 | | Claude | base | 4 tools | 14 tools, read 9,554 / write 21,734 | 32,060 | | Claude | head | 14 tools (fixed) | same list, read 21,976 / write 7,856 | 20,066 | Cron result on head (both routes): `exec` refused visibly ("exec is outside the tools this run allows. Do not retry exec."), `read` returned `gate-file-contents-7731`, `exec` did not run. Base: the model reports exec unavailable (not listed). The owner's later `exec` ran on both arms. **J2i: isolated cron with `toolsAllow: ["read"]`** keeps the narrowed listing, matching base: 4 tools on both arms; first request input OpenAI 6,110 (base) vs 6,145 (head), Claude 9,206 vs 9,260 total. **J11: one group, guest denied `exec` (sender policy), then owner** | route | arm | tool lists in the group | requests with read 0 after the first | uncached (OpenAI) / write (Claude) | |---|---|---|---|---| | OpenAI | base | 2 (guest 9 tools, owner 14) | 1 (owner's first turn) | 39,422 | | OpenAI | head | 1 (14) | 0 | 25,740 | | Claude | base | 2 (9, 14) | 1 | 62,158 | | Claude | head | 1 (14) | 0 | 29,511 | Guest `exec` on head: refused with "exec is outside the tools this run allows. Do not retry exec." (base: not listed, the model says it is unavailable). Guest `read` worked and both owner `exec` calls ran on both arms. **Side effects.** Every journey's replies arrived on head (J1 user replies, J2 cron + owner, J11 five group replies, J2i cron `ok`); refused tools stayed refused and never executed. The OpenAI model on this route sometimes fills every optional `message` field (a `gatewayUrl`, a made-up target) and loops; this happened on **both** arms (base: both J1 user turns and one unrelated-chat turn stopped by the 20-repeat guard; head: three unrelated-chat turns stopped the same way, and J1's first reply was kept private, then delivered by the stranded-reply retry). The stranded-reply retry runs with `toolsAllow: ["message"]` (`stranded-reply-recovery.ts`, unchanged by this PR), so it sends a message-only list and misses the cache once (OpenAI uncached 9,207) on both arms; not changed here, noted as a follow-up. **UI** (Control UI of the head and base scratch Gateways, after the journeys; chat area cropped): the J2 chat shows the cron's visible refusal, the J11 group shows the guest's refusal, J1 renders both delivered replies. | | base | head | |---|---|---| | J2 |  |  | | J11 group |  |  | | J1 (OpenAI) |  |  | The live operator Gateway was untouched during the runs (its pid and config unchanged). ## Evidence ### Tests (red on merge base `cbc12e7178f8`, green on this head) - `src/agents/session-tool-listing.test.ts`: one tool list across user, cron, exec-wake, subagent, steer and allowlisted turns, checked on each turn's own built list and on the sent list; one list for every sender of a group chat; a fork sends the source's list unchanged; a cron turn after `/compact` re-pins the owner turn's list (green on main too: this fixture does not reproduce the openclaw#201655 4-vs-3 case); a later user turn sends with `message` in a cron-started series. - `attempt-tool-prepare.scheduled-tools-allow.test.ts` (real `prepareEmbeddedAttemptToolBase`): refusal-equivalence table "allows exactly the calls main allowed" for cron/user/event `toolsAllow`, group guest sender and group owner sender; one tool set for every group sender with the guest refused through `dispatch_action`; refusal kept through a catalog rewrap; an allowlist matching nothing still fails (green on main and head). - `agent-tools.turn-authority.test.ts`: a turn-policy refusal and the scoped-reads split never carry the source's preparer (red on `390da1c` / before the fix). - `attempt-prompt-tool-policy.test.ts`: "leaves a listed tool the turn refuses out of the callable guidance" (main: `['message','read']`, head: `['read']`). - `attempt-session-runtime-prepare.test.ts`: production `admitNewTools` wiring (inverting it fails 2 tests). `session-prompt-state.test.ts`: one new pin after an upgrade changes the policy digest. ### Execution-based refusal equivalence `attempt.configured-mcp-lifecycle.test.ts` now runs its cataloged case with an `include` selector: the fixed listing builds every core tool, which that harness does not mock. The fixed-listing MCP path is covered by the real-route journeys (J5, J12, J13). `attempt-tool-prepare.scheduled-tools-allow.test.ts` builds tools through the production tool base, bundle pass (a mocked bundle MCP server) and catalog, then executes every listed tool through the direct path, the preparer the agent loop prefers, and a `dispatch_action` rewrap. The callable tables (cron/user/event `toolsAllow`, group guest, group owner) pass unchanged on `main` and on this head; the three paths agree for every tool. New: an MCP-only allowlist lists the full set (red on `390da1c`), sender `allow`/`deny` policies including an MCP tool, a refused tool is never delegated or captured, and only-refused-tools fails loudly (green on `main` and head, red on `390da1c`). A tool counts as callable only when a call with schema-valid placeholder arguments passes every gate, starts the tool's implementation and does not come back refused; exceptions and timeouts before the implementation starts count as not callable. ### Callable set, base vs head (`toolsAllow: ["read", "group:web", "sessions_*", "message"]`; group deny `exec, process, write, edit, apply_patch` for the guest) | case | callable on base and head | listed on head | |---|---|---| | cron / user / event `toolsAllow` | dispatch_action, message, read, sessions_create, sessions_history, sessions_list, sessions_search, sessions_send, sessions_spawn, sessions_yield, tool_describe, tool_search, web_fetch | full session list (39), the rest refused | | group guest | guest set (identical on base and head) | full session list (40), denied tools refused | | group owner | guest set + apply_patch, automations, conversations_*, edit, exec, gateway, plugins, portal, process, terminal, write | same list as the guest | ### Gate A at earlier heads (`c1160ede` / `6bbc29a2`), for history Base `cbc12e7`. OpenAI `gpt-6.2-astra` and cliproxy `claude-opus-5-5`. Raw results in `/tmp/pcr/gate201710/`. | journey | main | head | |---|---|---| | J1 cron starts chat, then user | list changes 2x (OpenAI incl. a message-only list), cache misses | one list, cache hits; user reply via `message` | | J2 cron `toolsAllow: ["read"]` | list 4 tools on the cron turn, 14 on the user turn (miss) | 14 throughout; `exec` refused visibly, `read` works, later user `exec` works; cache hits | | J3 reset, cron first, user | reply arrives | reply arrives; new list only at the reset (new session) | | J4 turn that may not send calls `message` | OpenAI: no refusal | OpenAI: visible refusal, nothing delivered. Claude: same as main on both arms (model replied without the message call) | | J5 MCP connect mid-chat | directory in `tool_search` | list unchanged; directory change arrives as an appended note; `dispatch_action` -> `mcp:beta:beta__beta_probe` returns `probe-ok-beta` with a cache hit (OpenAI read 30,770 / 30,949) | | J6 computer without a node | one list; call fails visibly | same | | J7 exec wake, subagent, steer | list changes (OpenAI D->B->E->D) | one list; wake, child result and steer all delivered | | J8 `toolSearch: false` | per-turn lists | identical to main on both routes | | J9 regression set | ok (OpenAI after-reset turn errored once) | ok | | J10 owner turns, `/compact`, cron, owner | one list (no 4-vs-3 repro on this config) | one list (14) before and after; cron after compaction keeps it; next owner turn cache hit | | J11 group: guest denied exec, owner | guest pins 9 tools, owner turn 14 with a miss, a prompt-update note per sender flip | one list (14) for both senders, every request a cache hit (Claude reads 23,881 -> 31,107), guest `exec` refused ("exec is outside the tools this run allows"), guest `read` and owner `exec` work | ### Gate A on this head (`d827cceb`, main `cbc12e7`), proxy-log excerpts, redacted Isolated scratch Gateways (`env -i`, random ports, isolated state), a concurrent second chat running turns and `sessions.compact`. Each cell: the session's tool sets in order (a letter per distinct tool-definition hash), then per request `tool count/cached input tokens`. | journey | route | main | head | |---|---|---|---| | J1 cron starts chat, then user | OpenAI | `B>A`: 14/0 **14/0** 14/16362 14/16587 | `B`: 14/0 14/14440 14/14762 14/15070 14/17039 | | | Claude | `B>A`: 14/0 **14/9668** 14/26625 | `B`: 14/0 14/23920 14/27152 | | J2 cron `toolsAllow: ["read"]`, then user `exec` | OpenAI | `C>D`: **4**/0 4/6485 **14/0** 14/19323 | `B`: 14/0 14/13046 14/13163 14/13500 14/18458; `exec` refused, `read` ok, user `exec` ok | | | Claude | `C>D`: **4**/0 4/9786 4/10049 **14/9554** 14/31223 | `B`: 14/9951 14/21608 14/21904 14/29747 | | J3 reset, cron first, user | both | new set at the reset, then back | new set only at the reset (new session) | | J4 cannot-send cron calls `message` | OpenAI | no refusal | refused: "message cannot send on this turn: its reply delivery or tool policy does not allow the message tool. Do not retry message." | | J7 exec wake, subagent, steer | OpenAI | `A>F>A` | `A` | | J10 owner, `/compact`, cron, owner | Claude | `A`: 14/9668 14/23800 14/9668 14/25198 14/26268 | `A`: 14/9554 14/23780 14/9554 14/25189 14/26302 (the 9,554 row is the cron right after compaction: history rewritten, tools kept) | | J11 group: guest denied `exec`, then owner | OpenAI | `H>I`: **9**/0 9/12866 9/13418 **14/0** 14/19652 | `E`: 14/0 14/14300 14/17481 14/17525 14/20649; guest `exec` refused ("exec is outside the tools this run allows. Do not retry exec."), guest `read` and owner `exec` ok | | | Claude | `G>H`: **9**/0 **14/0** 14/28797 14/28928 | `E`: 14/9942 14/23774 14/28261 14/28369 | | J12 owner, `/compact`, cron `toolsAllow: ["alpha__alpha_probe"]`, owner | Claude | `A>I>A`: 14/9668 14/23800 **3/0** 3/6670 3/7224 **14/9668** | `A`: 14/9554 14/23780 14/9554 14/22377 14/22989 14/23317; cron calls `alpha_probe` via `dispatch_action`, its `exec` is refused, owner `exec` ok | J12 passes on head because MCP tools live in the deferred catalog, not the tool list: the core list no longer follows the allowlist. What stays as on `main` is the MCP runtime start rule (an allowlist that names no MCP server does not start MCP, so the deferred directory changes through an appended note) and MCP discovery honoring sender/group denies. Earlier runs (J5 MCP connect mid-chat, J6 computer, J8 `toolSearch: false`, J9 regression set) are unchanged by the split and were green at `c1160ede`. Pre-existing on both arms: gpt-6.2 fills `channel`/`target` on WebChat `message` calls and loops on the rejection; `chat.abort` leaves the run status `error`; a `sessions.compact` during an active run is rejected ("has an active run; retry after it finishes"). ### Existing-session upgrade (one session, main then head on the same state dir) Isolated scratch Gateway (`env -i`, random port, isolated state dir, 250k context so compaction cannot mask the measurement), cliproxy `claude-opus-5-5`. Main `cbc12e7` builds the session with four owner turns (reply, `read`, `exec`, reply) and stops. Head `d827cceb` starts on the same state dir: one owner turn, a cron with `toolsAllow: ["read"]`, an owner `exec` turn, a last reply. | arm | turn | tools | cached / written | |---|---|---|---| | main | owner reply | 14 | 9,668 / 15,865 | | main | owner `read` (+ follow-up) | 14 | 25,533 / 1,148; 26,681 / 84 | | main | owner `exec` (+ follow-up) | 14 | 26,765 / 1,158; 27,923 / 104 | | main | owner reply | 14 | 28,027 / 1,152 | | head | first turn after the upgrade: **the one re-pin** | 14 | 9,554 / 20,755 (only the system prefix is cached) | | head | cron `toolsAllow: ["read"]`: `read` ok, `exec` refused ("exec is outside the tools this run allows") | 14 | 30,309 / 6,865; 37,174 / 302 (hits) | | head | owner `exec`: runs | 14 | 37,476 / 9,278; 46,754 / 161 (hits) | | head | last reply | 14 | 46,915 / 1,153 (hit) | One miss on the first head turn, then cache hits on the cron and owner turns. ### Gate C (append-only journeys from openclaw#201723) Stability journeys: head 5/5 pass, main 5/5 pass (they do not separate the arms). Randomized seeds 1-10 on head: 60/60 pass (anthropic-messages, openai-responses, openai-completions, google, bedrock, and the Tool Search opt-out surface). ### Gates - `pnpm tsgo:core`: pass. oxlint, oxfmt on changed files, `git diff --check`: clean. - Production code vs `main` (excluding tests and docs): +290 / -205 (net +85); see the size note at the top. ### Test lines Net test lines +994 against the 400 allowance. Duplicate tests were removed first (the scheduled-run table duplicate, the separate catalog-rewrap test, the sender-deny MCP case, the bundle MCP fixture, and the duplicate group-sender listing test). The remaining 594 lines are recorded in `config/test-lines-allocations/201710-session-tool-listing.txt`: refusal equivalence against `main` executed through the production tool base, bundle pass and catalog for five policy shapes across the direct, preparer and `dispatch_action` paths, plus series listing, fork and upgrade pin cases. ### Local ClawSweeper (gpt-6.1-sol, normal) Head `45ef8f8c583f`: patch is correct, no findings (exit 0). The local review reads only the committed range and its tests; the real-route journeys above are outside its inputs. An earlier P2 at `9543fde3` (sender change dropping a direct-only tool such as `computer` from a frozen group listing) is fixed by item 4: every sender builds the same list. ## Risks - `message` and allowlist-refused tools are listed (and refused visibly) on turns that cannot use them. Each costs one definition. - The `message` definition's action list still depends on the turn that starts the series (a cron-started WebChat series pins "Supports actions: send" without `react`). The pin keeps it stable; `react` is not advertised in that series until a rebuild point. Main would extend the pin (a miss) instead. Follow-up. - Upgrade: every existing session re-pins once on its first turn after the upgrade (the toolPolicy digest changes), costing one cache miss per session. This is the same accepted one-time cost as openclaw#201843. - MCP names and sanitized descriptions now enter the system prompt's deferred-tool section instead of the `tool_search` description. 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]>
…round runs (#203568) ## What Problem This Solves On OpenAI Responses, a background run on a conversation could reset that conversation's request chain. Examples are a skill review fork, memory flush, a `/btw` side question or a compaction summary. The background run reached the transport with the conversation's `sessionId`. It replaced the conversation's continuation baseline with its own request. The conversation's next request then failed the prefix check (`history_changed`). It sent the full history instead of a `previous_response_id` delta. On a busy production host this pattern cost about 14-19M uncached tokens per day (1.75-2.5% of input). ## User Impact After a background run, the conversation's next request continues with `previous_response_id` and sends only the new input. Background runs keep the conversation's prompt-cache key, so they still read the cached prefix. Nothing changes in config or stored data. ## Why This Change Was Made `options.sessionId` did two jobs at the transport: - **Affinity:** the prompt-cache key, the `session_id` / `x-client-request-id` headers and the replay fence. A background run needs these. - **Ownership:** the key of the HTTP continuation slot, the Responses WebSocket pool and its continuation, and the ChatGPT WebSocket pool, continuation and SSE fallback latch. A background run must not touch these. The change separates the two jobs: - `sessionId` now carries **affinity only**. Every caller still sends the same value. - **Ownership** moves to a branded `ProviderStateScope`, passed as the symbol-keyed stream option `PROVIDER_STATE_SCOPE` (`packages/ai/src/session-resources.ts`). Every mutable store keys on the scope, and a store cannot take a plain string. - **Without a scope there is no mutable state.** The request sends full input on its own connection. Forks, memory flush, `/btw` and compaction summaries get this with no code at their call sites. - **Only lane admission mints a scope.** `claimRunProviderState` (`session-bootstrap.ts`) runs right after the writer claim in `lane-controller.ts`. It mints a scope for runs that write the conversation and none for detached runs. The scope reaches the attempt stream and the worker inference runtime (worker-placed turns). - An oxlint `no-restricted-imports` rule allows `claimConversationProviderState` only in `session-bootstrap.ts`. **Removed:** `cleanupProviderSessionResourcesOnDispose` and its two opt-outs. `AgentSession.dispose()` freed provider state by the transcript's session id. In a fork that id is the parent's id, so the embedded runner had to turn the cleanup off. Provider state no longer belongs to dispose. **Kept on purpose:** - **The prompt-cache tracker key stays as it is.** The tracker is fed the run's own `attempt.sessionId`. A fork's id is `internal-session-effects-<runId>`, so forks never shared the parent's tracker. The planned tracker re-key would change nothing, so it was dropped. - **`cleanupSessionResources(forkSession.sessionId)` in `session-fork-run.ts` stays.** It frees the fork's own tracker entries. **Production LOC:** +128 / −40 including the 28-line oxlint rule; TypeScript alone is +100 / −40 (net +60). The growth is the scope type, threading the scope to the attempt and worker paths, re-keying the stores, and the import guard that keeps minting in one place. This is the real number, not padded. ## Evidence **Prefix journey (#201723): new step "background fork between two parent turns", run on all five transports.** A local test plugin starts a real fork through `api.runtime.subagent.runForkedTurn` between two target turns. The fork's requests are classified apart from the parent's. The step asserts two things: 1. The fork's system prompt and tool list are byte-equal to the parent's. 2. On openai-responses, where the fake provider opts into continuation, the parent's first request after the fork carries the parent's own last response id. | Transport | base 8d1e59c | head | |---|---|---| | openai-responses | **red**: `expected undefined to be 'resp_2'` (the parent sent full input) | green | | anthropic-messages, openai-completions, google-generative-ai, bedrock-converse-stream | not run on base. These lanes hold no continuation state, so the step checks fork system/tool bytes and that parent history only appends. | green | **Transport guard:** the new test "preserves the writer continuation when a scope-less caller shares its session affinity" in `openai-responses-client.continuation.integration.test.ts`. **Mutations.** Each mutation ran in a scratch copy of head against the guard test and the openai-responses journey: | Mutation | Result | |---|---| | (a) The HTTP continuation slot falls back to keying on `options.sessionId` when no scope is present | **red**: the guard test and the journey both fail | | (b) Detached runs also get a scope | **survived**: the scope keys on the run's own `sessionId`. Every detached caller uses a private id (`internal-session-effects-<runId>`), so a fork's state stays isolated anyway. The detached rule only stops background runs from holding sockets and slots they never reuse. | | (c) The attempt does not pass its scope to the stream | **red**: the journey fails (the parent loses continuation) | **Scratch Gateway E2E.** Native `https://api.openai.com/v1`, `openai/gpt-6.2-astra`, SSE, code mode, the bundled skill-workshop background review. A scratch-only patch captured every request body and its `response.completed` usage. The driver and model are the same on base and head. Rows around the fork: | request | base: previous_response_id / items / tools / input / cached | head d8c1b56: previous_response_id / items / tools / input / cached | |---|---|---| | #15 parent, last request before the fork | yes / 4 / 7 (2b9cd1ba) / 19701 / 18530 | yes / 4 / 7 (2b9cd1ba) / 19711 / 18537 | | #16 skill-review fork | no / 29 / 6 (ccf4c23c) / 15040 / 0 | no / 29 / 6 (ccf4c23c) / 15047 / 0 | | #19 parent, next request after the fork | no / 33 / 7 (2b9cd1ba) / 20800 / 18943 | yes / 2 / 7 (2b9cd1ba) / 20814 / 18950 | | #20 parent | yes / 1 / 7 (2b9cd1ba) / 20972 / 19799 | yes / 1 / 7 (2b9cd1ba) / 20990 / 19810 | | #22 parent (T3) | yes / 3 / 7 (2b9cd1ba) / 21809 / 20969 | yes / 3 / 7 (2b9cd1ba) / 21830 / 20987 | - The parent's request after the fork changed from **full history (33 items, no `previous_response_id`) to a continuation (2 items)**. Request bytes for the whole run fell from 670,893 to 617,450. - On this short conversation, both versions read about the same number of cached tokens (base 18,943, head 18,950). A full replay of the same conversation still hits OpenAI's cache. The token loss on the production host comes from long conversations, where the full replay misses beyond instructions and tools. That number is measured after landing. - The fork itself still lists 6 tools instead of the parent's 7 (hosted `web_search` is missing), so it reads 0 cached tokens. A separate PR in this series fixes that. <details><summary>Tests changed</summary> - 15 packages/ai transport test files: the writer-contract tests now pass a scope. Each still asserts the same continuation, socket and SSE-latch behavior. - `src/agents/sessions/*` and `attempt-session.test.ts`: fixtures no longer set the removed dispose flag. </details> Co-authored-by: Ayaan Zaidi <[email protected]>
## What Problem This Solves A message steered into a running turn can carry a document attachment. The model sees the message with its media note and the rendered document text. The transcript stored only the typed text. The next run replayed the shorter message, so its bytes changed in the middle of history. That broke the provider's prompt-cache prefix from that point on, and later runs lost the document text. Normal sent turns did not have this problem. ## User Impact After you steer a message with a document into a running turn, later runs replay the same message the model first saw. They keep the document text, and the cached prefix stays intact. Nothing changes in config, and no new storage field is added: the existing `__openclaw.modelPromptProjection` field holds the text. ## Why This Change Was Made One owner already freezes what the model saw for a sent turn: `installModelPromptProjection` (`attempt-llm-boundary.ts`). It captures the text into the turn recorder's `modelPromptProjection` before the request leaves. It only ever looked at the recorder that started the attempt. A steered message has its own recorder, so its row kept plain text. The change makes the same owner capture steers too: - The attempt's transcript-context registry now keeps each queued user message's recorder (`attempt-user-transcript-context-registry.ts`, `attempt-session-prepare.ts`). - `installModelPromptProjection` walks those contexts. It captures each steered message's expanded text through that message's own recorder, with the same `captureModelPromptProjection` contract a sent turn uses. - Send and steer now share one projection path. No steer-only builder was added. - **Second cause, found once continuation was on (#203568):** on OpenAI Responses, the steered message carries a runtime-context carrier that is marked `retained`. A later prompt update moved that carrier ahead of the cached assistant tool call, so the next continued request failed the prefix check (`history_changed`) and sent full history. Retained carriers now keep their position. The carrier-anchoring logic moved into its own module (`openai-responses-carrier-anchoring.ts`) so the replay file stays under its line cap. Out of scope, recorded as a follow-up: the live steer request describes each attachment twice. `chat-attachments.ts:457` appends a portable marker, and `chat-send-message-injection.ts:305` prepends a staged note. Replay now equals the live bytes, so this PR does not change that. **Production LOC:** +112 / −43, net **+69**, measured against main after #203568. This is the real number. It covers the registry field, the projection loop over queued recorders, and the retained-carrier fix. About 40 of the added lines are the anchoring logic moved into its own module. ## Evidence **Prefix journey (#201723).** The existing steer step now steers with a `text/plain` document (`STEER-DOC-BODY`). The journey checks that the steered request contains the document text, and that every later request extends earlier ones byte for byte. | Journey | base 8d1e59c | head | |---|---|---| | anthropic-messages | **red**: break at step `cron`, message 38 (the steered message). Live: media note + text + document; replay: typed text only. | green | | openai-responses | not run on base | green (continuation stays on across the steer) | | openai-completions, google, bedrock | not run separately; CI runs all five | — | **Responses replay regression:** `openai-responses-async-replay.test.ts` adds a test where a prompt update follows a retained steering carrier. **Focused regression:** `agent-session-steering-context.test.ts`, test "replays a steered document attachment with the bytes the model first saw". It steers expanded text whose stored turn is the plain text, reopens the session from durable storage, and asserts the replay keeps the first request's bytes. Red on base (replay holds only the plain text), green on head. **Mutation:** the projection loop skips queued recorders (only the attempt's own recorder is captured, as on base). Both the focused regression and the anthropic journey turn red. Run in a scratch copy of head. **Scratch Gateway E2E.** Native `https://api.openai.com/v1`, `openai/gpt-6.2-astra`, SSE. The driver runs a turn, starts a turn with an 8-second exec, steers a message with a `text/plain` document into it, and then sends one more turn. A scratch-only capture saved every request body and its `response.completed` usage. Base is main after #203568. | request | base: `previous_response_id` / items / input / cached | head: `previous_response_id` / items / input / cached | |---|---|---| | #4 first request after the steer | no / 12 / 17,601 / 15,815 | **yes / 3** / 17,610 / 15,812 | | #6 next run | no / 17 / **17,546** / 15,815 | **yes / 2** / **18,454** / 17,796 | - On base the next run sends full history, and its input is smaller than the turn before it (17,546 < 17,787): the document text is gone. - On head every request continues. The next run keeps the document (18,454 input) and reads 17,796 of those tokens from cache. Co-authored-by: Ayaan Zaidi <[email protected]>
) ## What Problem This Solves A background session fork sends the session's request plus its own instruction at the end, so it should read the session's cached prompt prefix. When the session listed the provider-hosted `web_search` tool, a tool-free fork left it out. The fork's tool list then differed from the session's, and the request missed the cache from the first token. A tool-free fork already sends `tool_choice: none`, which stops hosted tools, so listing the tool is safe. ## User Impact A tool-free background fork now lists exactly the session's tools, including hosted search, and reads the session's cached prefix. Behavior and permissions are unchanged: hosted search still honors the fork's execution cap, and tool-free forks still block hosted tools with `tool_choice: none`. Forks that run their own tools (for example, the skill-workshop review) still omit hosted search unless they are granted it, so they keep missing the cache when the session uses hosted search (see Limitation). ## Why This Change Was Made - **One decision owner.** `sessionForkGatesHostedTools(api, allowedTools)` in `session-fork-request.ts` answers one question: can the provider stop hosted tools for this fork? The answer is yes only for a tool-free fork on an API with `tool_choice: none`. `attempt-stream-settle.ts` now lists hosted search when the execution cap allows it or when that owner says the provider gates it. - **Byte replay kept (gate failed).** The plan was to delete the fork's byte replay of a live parent's last request (about 200 lines). A new journey step forks a live turn held inside a tool call, and it passed on all five transports without the replay. But local review found a case the step does not reach: a fork during the session's first live turn, before the first response, is anchored ahead of the session's system-prompt checkpoint. There the transcript pin is missing, and only the live replay keeps the session's system prompt. So the replay stays, and the new journey step stays as a guard. - **Limitation, decided under standing authority:** a fork that has granted tools cannot list hosted search without being able to run it. The native endpoint rejects `tool_choice: allowed_tools` (`400 invalid_value`), so no provider-side gate exists, and hosted search runs before any local tool gate. The first push of this PR listed hosted search for every fork. Local review flagged that as an execution-scope regression, and it was reverted. Granting read-only `web_search` to review forks would let them hit the cache. That is a product choice and is not made here. **Production LOC:** +33 / −19, net **+14**, measured against main after #203568. The replay deletion (−200) was reverted, for the reason above. The provider prompt state now builds the fork context it owns; this keeps `attempt-stream-prepare.ts` under its line cap. ## Evidence **Prefix journey (#201723): new step "mid-turn fork".** It waits until the target run is inside a tool call, then forks through the latest persisted entry with `tools: []`. It asserts that the fork's system prompt and tools are byte-equal to the parent's, and that the fork's message list starts with the parent's last sent request. | Transport | with replay | replay deleted (reverted) | |---|---|---| | anthropic-messages | pass | pass | | bedrock-converse-stream | pass | pass | | google-generative-ai | pass | pass | | openai-completions | pass | pass | | openai-responses | pass | pass | **Transport contract** (`test/embedded-agent-attempt-stream-transport.test.ts`): - The parent lists hosted `web_search`. - A fork granted `web_search` lists it. - A tool-free fork lists it and sends `tool_choice: none`. - A fork granted only client tools does not list it. - Client tool schemas are unchanged in every case. **Mutation:** making hosted search ignore the execution cap turns the transport contract red (run in a scratch copy). **Scratch Gateway E2E** (native OpenAI, skill-workshop review): that review grants its own tools, so it still lists 6 tools where the session lists 7 and reads 0 cached tokens, as before. An earlier ungated version reached 18,532 of 19,478 cached tokens on the same request, but that version was reverted for the reason above. A tool-free fork's listing is covered by the transport contract; the journey's fake providers have no hosted search. Co-authored-by: Ayaan Zaidi <[email protected]>
…round runs (openclaw#203568) ## What Problem This Solves On OpenAI Responses, a background run on a conversation could reset that conversation's request chain. Examples are a skill review fork, memory flush, a `/btw` side question or a compaction summary. The background run reached the transport with the conversation's `sessionId`. It replaced the conversation's continuation baseline with its own request. The conversation's next request then failed the prefix check (`history_changed`). It sent the full history instead of a `previous_response_id` delta. On a busy production host this pattern cost about 14-19M uncached tokens per day (1.75-2.5% of input). ## User Impact After a background run, the conversation's next request continues with `previous_response_id` and sends only the new input. Background runs keep the conversation's prompt-cache key, so they still read the cached prefix. Nothing changes in config or stored data. ## Why This Change Was Made `options.sessionId` did two jobs at the transport: - **Affinity:** the prompt-cache key, the `session_id` / `x-client-request-id` headers and the replay fence. A background run needs these. - **Ownership:** the key of the HTTP continuation slot, the Responses WebSocket pool and its continuation, and the ChatGPT WebSocket pool, continuation and SSE fallback latch. A background run must not touch these. The change separates the two jobs: - `sessionId` now carries **affinity only**. Every caller still sends the same value. - **Ownership** moves to a branded `ProviderStateScope`, passed as the symbol-keyed stream option `PROVIDER_STATE_SCOPE` (`packages/ai/src/session-resources.ts`). Every mutable store keys on the scope, and a store cannot take a plain string. - **Without a scope there is no mutable state.** The request sends full input on its own connection. Forks, memory flush, `/btw` and compaction summaries get this with no code at their call sites. - **Only lane admission mints a scope.** `claimRunProviderState` (`session-bootstrap.ts`) runs right after the writer claim in `lane-controller.ts`. It mints a scope for runs that write the conversation and none for detached runs. The scope reaches the attempt stream and the worker inference runtime (worker-placed turns). - An oxlint `no-restricted-imports` rule allows `claimConversationProviderState` only in `session-bootstrap.ts`. **Removed:** `cleanupProviderSessionResourcesOnDispose` and its two opt-outs. `AgentSession.dispose()` freed provider state by the transcript's session id. In a fork that id is the parent's id, so the embedded runner had to turn the cleanup off. Provider state no longer belongs to dispose. **Kept on purpose:** - **The prompt-cache tracker key stays as it is.** The tracker is fed the run's own `attempt.sessionId`. A fork's id is `internal-session-effects-<runId>`, so forks never shared the parent's tracker. The planned tracker re-key would change nothing, so it was dropped. - **`cleanupSessionResources(forkSession.sessionId)` in `session-fork-run.ts` stays.** It frees the fork's own tracker entries. **Production LOC:** +128 / −40 including the 28-line oxlint rule; TypeScript alone is +100 / −40 (net +60). The growth is the scope type, threading the scope to the attempt and worker paths, re-keying the stores, and the import guard that keeps minting in one place. This is the real number, not padded. ## Evidence **Prefix journey (openclaw#201723): new step "background fork between two parent turns", run on all five transports.** A local test plugin starts a real fork through `api.runtime.subagent.runForkedTurn` between two target turns. The fork's requests are classified apart from the parent's. The step asserts two things: 1. The fork's system prompt and tool list are byte-equal to the parent's. 2. On openai-responses, where the fake provider opts into continuation, the parent's first request after the fork carries the parent's own last response id. | Transport | base 735a747 | head | |---|---|---| | openai-responses | **red**: `expected undefined to be 'resp_2'` (the parent sent full input) | green | | anthropic-messages, openai-completions, google-generative-ai, bedrock-converse-stream | not run on base. These lanes hold no continuation state, so the step checks fork system/tool bytes and that parent history only appends. | green | **Transport guard:** the new test "preserves the writer continuation when a scope-less caller shares its session affinity" in `openai-responses-client.continuation.integration.test.ts`. **Mutations.** Each mutation ran in a scratch copy of head against the guard test and the openai-responses journey: | Mutation | Result | |---|---| | (a) The HTTP continuation slot falls back to keying on `options.sessionId` when no scope is present | **red**: the guard test and the journey both fail | | (b) Detached runs also get a scope | **survived**: the scope keys on the run's own `sessionId`. Every detached caller uses a private id (`internal-session-effects-<runId>`), so a fork's state stays isolated anyway. The detached rule only stops background runs from holding sockets and slots they never reuse. | | (c) The attempt does not pass its scope to the stream | **red**: the journey fails (the parent loses continuation) | **Scratch Gateway E2E.** Native `https://api.openai.com/v1`, `openai/gpt-6.2-astra`, SSE, code mode, the bundled skill-workshop background review. A scratch-only patch captured every request body and its `response.completed` usage. The driver and model are the same on base and head. Rows around the fork: | request | base: previous_response_id / items / tools / input / cached | head d8c1b56: previous_response_id / items / tools / input / cached | |---|---|---| | openclaw#15 parent, last request before the fork | yes / 4 / 7 (2b9cd1ba) / 19701 / 18530 | yes / 4 / 7 (2b9cd1ba) / 19711 / 18537 | | openclaw#16 skill-review fork | no / 29 / 6 (ccf4c23c) / 15040 / 0 | no / 29 / 6 (ccf4c23c) / 15047 / 0 | | openclaw#19 parent, next request after the fork | no / 33 / 7 (2b9cd1ba) / 20800 / 18943 | yes / 2 / 7 (2b9cd1ba) / 20814 / 18950 | | openclaw#20 parent | yes / 1 / 7 (2b9cd1ba) / 20972 / 19799 | yes / 1 / 7 (2b9cd1ba) / 20990 / 19810 | | openclaw#22 parent (T3) | yes / 3 / 7 (2b9cd1ba) / 21809 / 20969 | yes / 3 / 7 (2b9cd1ba) / 21830 / 20987 | - The parent's request after the fork changed from **full history (33 items, no `previous_response_id`) to a continuation (2 items)**. Request bytes for the whole run fell from 670,893 to 617,450. - On this short conversation, both versions read about the same number of cached tokens (base 18,943, head 18,950). A full replay of the same conversation still hits OpenAI's cache. The token loss on the production host comes from long conversations, where the full replay misses beyond instructions and tools. That number is measured after landing. - The fork itself still lists 6 tools instead of the parent's 7 (hosted `web_search` is missing), so it reads 0 cached tokens. A separate PR in this series fixes that. <details><summary>Tests changed</summary> - 15 packages/ai transport test files: the writer-contract tests now pass a scope. Each still asserts the same continuation, socket and SSE-latch behavior. - `src/agents/sessions/*` and `attempt-session.test.ts`: fixtures no longer set the removed dispose flag. </details> Co-authored-by: Ayaan Zaidi <[email protected]>
## What Problem This Solves A message steered into a running turn can carry a document attachment. The model sees the message with its media note and the rendered document text. The transcript stored only the typed text. The next run replayed the shorter message, so its bytes changed in the middle of history. That broke the provider's prompt-cache prefix from that point on, and later runs lost the document text. Normal sent turns did not have this problem. ## User Impact After you steer a message with a document into a running turn, later runs replay the same message the model first saw. They keep the document text, and the cached prefix stays intact. Nothing changes in config, and no new storage field is added: the existing `__openclaw.modelPromptProjection` field holds the text. ## Why This Change Was Made One owner already freezes what the model saw for a sent turn: `installModelPromptProjection` (`attempt-llm-boundary.ts`). It captures the text into the turn recorder's `modelPromptProjection` before the request leaves. It only ever looked at the recorder that started the attempt. A steered message has its own recorder, so its row kept plain text. The change makes the same owner capture steers too: - The attempt's transcript-context registry now keeps each queued user message's recorder (`attempt-user-transcript-context-registry.ts`, `attempt-session-prepare.ts`). - `installModelPromptProjection` walks those contexts. It captures each steered message's expanded text through that message's own recorder, with the same `captureModelPromptProjection` contract a sent turn uses. - Send and steer now share one projection path. No steer-only builder was added. - **Second cause, found once continuation was on (openclaw#203568):** on OpenAI Responses, the steered message carries a runtime-context carrier that is marked `retained`. A later prompt update moved that carrier ahead of the cached assistant tool call, so the next continued request failed the prefix check (`history_changed`) and sent full history. Retained carriers now keep their position. The carrier-anchoring logic moved into its own module (`openai-responses-carrier-anchoring.ts`) so the replay file stays under its line cap. Out of scope, recorded as a follow-up: the live steer request describes each attachment twice. `chat-attachments.ts:457` appends a portable marker, and `chat-send-message-injection.ts:305` prepends a staged note. Replay now equals the live bytes, so this PR does not change that. **Production LOC:** +112 / −43, net **+69**, measured against main after openclaw#203568. This is the real number. It covers the registry field, the projection loop over queued recorders, and the retained-carrier fix. About 40 of the added lines are the anchoring logic moved into its own module. ## Evidence **Prefix journey (openclaw#201723).** The existing steer step now steers with a `text/plain` document (`STEER-DOC-BODY`). The journey checks that the steered request contains the document text, and that every later request extends earlier ones byte for byte. | Journey | base 735a747 | head | |---|---|---| | anthropic-messages | **red**: break at step `cron`, message 38 (the steered message). Live: media note + text + document; replay: typed text only. | green | | openai-responses | not run on base | green (continuation stays on across the steer) | | openai-completions, google, bedrock | not run separately; CI runs all five | — | **Responses replay regression:** `openai-responses-async-replay.test.ts` adds a test where a prompt update follows a retained steering carrier. **Focused regression:** `agent-session-steering-context.test.ts`, test "replays a steered document attachment with the bytes the model first saw". It steers expanded text whose stored turn is the plain text, reopens the session from durable storage, and asserts the replay keeps the first request's bytes. Red on base (replay holds only the plain text), green on head. **Mutation:** the projection loop skips queued recorders (only the attempt's own recorder is captured, as on base). Both the focused regression and the anthropic journey turn red. Run in a scratch copy of head. **Scratch Gateway E2E.** Native `https://api.openai.com/v1`, `openai/gpt-6.2-astra`, SSE. The driver runs a turn, starts a turn with an 8-second exec, steers a message with a `text/plain` document into it, and then sends one more turn. A scratch-only capture saved every request body and its `response.completed` usage. Base is main after openclaw#203568. | request | base: `previous_response_id` / items / input / cached | head: `previous_response_id` / items / input / cached | |---|---|---| | #4 first request after the steer | no / 12 / 17,601 / 15,815 | **yes / 3** / 17,610 / 15,812 | | openclaw#6 next run | no / 17 / **17,546** / 15,815 | **yes / 2** / **18,454** / 17,796 | - On base the next run sends full history, and its input is smaller than the turn before it (17,546 < 17,787): the document text is gone. - On head every request continues. The next run keeps the document (18,454 input) and reads 17,796 of those tokens from cache. Co-authored-by: Ayaan Zaidi <[email protected]>
…claw#203601) ## What Problem This Solves A background session fork sends the session's request plus its own instruction at the end, so it should read the session's cached prompt prefix. When the session listed the provider-hosted `web_search` tool, a tool-free fork left it out. The fork's tool list then differed from the session's, and the request missed the cache from the first token. A tool-free fork already sends `tool_choice: none`, which stops hosted tools, so listing the tool is safe. ## User Impact A tool-free background fork now lists exactly the session's tools, including hosted search, and reads the session's cached prefix. Behavior and permissions are unchanged: hosted search still honors the fork's execution cap, and tool-free forks still block hosted tools with `tool_choice: none`. Forks that run their own tools (for example, the skill-workshop review) still omit hosted search unless they are granted it, so they keep missing the cache when the session uses hosted search (see Limitation). ## Why This Change Was Made - **One decision owner.** `sessionForkGatesHostedTools(api, allowedTools)` in `session-fork-request.ts` answers one question: can the provider stop hosted tools for this fork? The answer is yes only for a tool-free fork on an API with `tool_choice: none`. `attempt-stream-settle.ts` now lists hosted search when the execution cap allows it or when that owner says the provider gates it. - **Byte replay kept (gate failed).** The plan was to delete the fork's byte replay of a live parent's last request (about 200 lines). A new journey step forks a live turn held inside a tool call, and it passed on all five transports without the replay. But local review found a case the step does not reach: a fork during the session's first live turn, before the first response, is anchored ahead of the session's system-prompt checkpoint. There the transcript pin is missing, and only the live replay keeps the session's system prompt. So the replay stays, and the new journey step stays as a guard. - **Limitation, decided under standing authority:** a fork that has granted tools cannot list hosted search without being able to run it. The native endpoint rejects `tool_choice: allowed_tools` (`400 invalid_value`), so no provider-side gate exists, and hosted search runs before any local tool gate. The first push of this PR listed hosted search for every fork. Local review flagged that as an execution-scope regression, and it was reverted. Granting read-only `web_search` to review forks would let them hit the cache. That is a product choice and is not made here. **Production LOC:** +33 / −19, net **+14**, measured against main after openclaw#203568. The replay deletion (−200) was reverted, for the reason above. The provider prompt state now builds the fork context it owns; this keeps `attempt-stream-prepare.ts` under its line cap. ## Evidence **Prefix journey (openclaw#201723): new step "mid-turn fork".** It waits until the target run is inside a tool call, then forks through the latest persisted entry with `tools: []`. It asserts that the fork's system prompt and tools are byte-equal to the parent's, and that the fork's message list starts with the parent's last sent request. | Transport | with replay | replay deleted (reverted) | |---|---|---| | anthropic-messages | pass | pass | | bedrock-converse-stream | pass | pass | | google-generative-ai | pass | pass | | openai-completions | pass | pass | | openai-responses | pass | pass | **Transport contract** (`test/embedded-agent-attempt-stream-transport.test.ts`): - The parent lists hosted `web_search`. - A fork granted `web_search` lists it. - A tool-free fork lists it and sends `tool_choice: none`. - A fork granted only client tools does not list it. - Client tool schemas are unchanged in every case. **Mutation:** making hosted search ignore the execution cap turns the transport contract red (run in a scratch copy). **Scratch Gateway E2E** (native OpenAI, skill-workshop review): that review grants its own tools, so it still lists 6 tools where the session lists 7 and reads 0 cached tokens, as before. An earlier ungated version reached 18,532 of 19,478 cached tokens on the same request, but that version was reverted for the reason above. A tool-free fork's listing is covered by the transport contract; the journey's fake providers have no hosted search. Co-authored-by: Ayaan Zaidi <[email protected]>
…3919) ## What Problem This Solves A background session fork that runs its own tools dropped the provider-hosted `web_search` tool from its request, even when the parent session listed it. The skill-workshop review is one example. Its tool list then differed from the session's, so on a provider with hosted search every review request missed the session's prompt cache from the first token. The review paid for the whole prompt each time. ## User Impact A background review now lists exactly the session's tools, including hosted web search, and reads the session's cached prefix. **Owner decision (security trade-off):** this was approved explicitly as a product choice. A review fork can now run a hosted web search when its session allows hosted search. Hosted search runs at the provider, before any local tool gate, and the native endpoint has no provider-side way to list a tool but block it (`tool_choice: allowed_tools` returns `400 invalid_value`). So listing the tool and allowing it are the same decision. Review forks stay read-only otherwise: no new write or exec tools are granted, exec stays owner-gated as before, and a tool-free fork still sends `tool_choice: none`. ## Why This Change Was Made - **Removed the special case.** `attempt-stream-settle.ts` no longer applies the fork's execution cap to hosted search. `sessionForkGatesHostedTools` (the "tool-free forks only" rule) is deleted. - **Byte replay of a live parent:** `applySessionForkRequest` no longer falls back to the rebuilt request when the parent lists a hosted tool. A fork with tools now replays the parent's bytes in that case too. - **Kept:** the execution cap still governs hosted search for non-fork runs that set one (for example the system agent's `toolExecutionAllow: ["openclaw"]`). Deleting the whole clause would widen those runs, which is outside this decision. **Production LOC:** +10 / −25, net **−15**. ## Evidence **Prefix journey (#201723): new step "fork of a parent that lists hosted web_search".** A parent chat runs on a hosted-search route: the router plugin's hosted route, with the real `nativeWebSearchAllowedByToolPolicy` policy input. It lists `{type: "web_search"}`. A fork with a granted client tool (like the skill review) must send tools byte-equal to the parent's, including `web_search`. Only Responses carries provider-hosted search, so the step runs on that lane. The other four lanes run the rest of the journey unchanged, with tool-free forks. | | Responses lane | |---|---| | base 096214a | **red**: `A fork with a granted client tool must preserve the parent's hosted web_search tool bytes` (the fork omits `web_search`) | | head | green (anthropic, bedrock, google and completions lanes also green) | | mutation: restore the execution cap for forks (`attempt.sessionForkRequest !== undefined ||` removed) | **red**, same assertion | **Transport contract** (`test/embedded-agent-attempt-stream-transport.test.ts`): - A fork granted only client tools (`skill_workshop`) now lists hosted `web_search`. - A capped non-fork run still does not. - Client tool schemas are unchanged, and only a tool-free fork sends `tool_choice: none`. `session-fork-request.test.ts`: a fork with tools replays a parent request that lists a hosted tool. **Scratch Gateway E2E.** Native `https://api.openai.com/v1`, `openai/gpt-6.2-astra`, SSE, code mode, with the bundled skill-workshop background review firing after a subagent settles. A scratch-only patch captured every request body and its `response.completed` usage. The driver is the same on both sides. | request | base 096214a: tools / tool hash / input / cached | head: tools / tool hash / input / cached | |---|---|---| | parent, last request before the review | 8 / `3d88f97d` / 19,830 / 18,659 | 8 / `3d88f97d` / 19,839 / 18,669 | | skill-review fork | 7 / `2dc7c3ea` / 15,169 / **0** | **8 / `3d88f97d`** / 19,615 / **18,669 (95%)** | On base the fork's tool hash differs from the parent's and the fork reads nothing from cache. On head the fork's tool list is byte-equal to the parent's, and the fork reads the parent's whole cached prefix. Co-authored-by: Ayaan Zaidi <[email protected]>
…nclaw#203919) ## What Problem This Solves A background session fork that runs its own tools dropped the provider-hosted `web_search` tool from its request, even when the parent session listed it. The skill-workshop review is one example. Its tool list then differed from the session's, so on a provider with hosted search every review request missed the session's prompt cache from the first token. The review paid for the whole prompt each time. ## User Impact A background review now lists exactly the session's tools, including hosted web search, and reads the session's cached prefix. **Owner decision (security trade-off):** this was approved explicitly as a product choice. A review fork can now run a hosted web search when its session allows hosted search. Hosted search runs at the provider, before any local tool gate, and the native endpoint has no provider-side way to list a tool but block it (`tool_choice: allowed_tools` returns `400 invalid_value`). So listing the tool and allowing it are the same decision. Review forks stay read-only otherwise: no new write or exec tools are granted, exec stays owner-gated as before, and a tool-free fork still sends `tool_choice: none`. ## Why This Change Was Made - **Removed the special case.** `attempt-stream-settle.ts` no longer applies the fork's execution cap to hosted search. `sessionForkGatesHostedTools` (the "tool-free forks only" rule) is deleted. - **Byte replay of a live parent:** `applySessionForkRequest` no longer falls back to the rebuilt request when the parent lists a hosted tool. A fork with tools now replays the parent's bytes in that case too. - **Kept:** the execution cap still governs hosted search for non-fork runs that set one (for example the system agent's `toolExecutionAllow: ["openclaw"]`). Deleting the whole clause would widen those runs, which is outside this decision. **Production LOC:** +10 / −25, net **−15**. ## Evidence **Prefix journey (openclaw#201723): new step "fork of a parent that lists hosted web_search".** A parent chat runs on a hosted-search route: the router plugin's hosted route, with the real `nativeWebSearchAllowedByToolPolicy` policy input. It lists `{type: "web_search"}`. A fork with a granted client tool (like the skill review) must send tools byte-equal to the parent's, including `web_search`. Only Responses carries provider-hosted search, so the step runs on that lane. The other four lanes run the rest of the journey unchanged, with tool-free forks. | | Responses lane | |---|---| | base 113d337 | **red**: `A fork with a granted client tool must preserve the parent's hosted web_search tool bytes` (the fork omits `web_search`) | | head | green (anthropic, bedrock, google and completions lanes also green) | | mutation: restore the execution cap for forks (`attempt.sessionForkRequest !== undefined ||` removed) | **red**, same assertion | **Transport contract** (`test/embedded-agent-attempt-stream-transport.test.ts`): - A fork granted only client tools (`skill_workshop`) now lists hosted `web_search`. - A capped non-fork run still does not. - Client tool schemas are unchanged, and only a tool-free fork sends `tool_choice: none`. `session-fork-request.test.ts`: a fork with tools replays a parent request that lists a hosted tool. **Scratch Gateway E2E.** Native `https://api.openai.com/v1`, `openai/gpt-6.2-astra`, SSE, code mode, with the bundled skill-workshop background review firing after a subagent settles. A scratch-only patch captured every request body and its `response.completed` usage. The driver is the same on both sides. | request | base 113d337: tools / tool hash / input / cached | head: tools / tool hash / input / cached | |---|---|---| | parent, last request before the review | 8 / `3d88f97d` / 19,830 / 18,659 | 8 / `3d88f97d` / 19,839 / 18,669 | | skill-review fork | 7 / `2dc7c3ea` / 15,169 / **0** | **8 / `3d88f97d`** / 19,615 / **18,669 (95%)** | On base the fork's tool hash differs from the parent's and the fork reads nothing from cache. On head the fork's tool list is byte-equal to the parent's, and the fork reads the parent's whole cached prefix. Co-authored-by: Ayaan Zaidi <[email protected]>
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
Numbers
Breaks still on main (accepted entries)
skills_read/skills_searchon turns started by a subagent completion or inter-session messageRemoved because their owners landed: the cron reply twice (#201838), the Chat Completions silent-turn merge (#201843), the cron-first
messagegrowth (#201710), and the skills rebuild afterconfig.patch(issue #202150, which no longer reproduces on Anthropic seeds 1 and 6).Bedrock refuses
cron.addfor AWS-SDK auth by design, and the journey expects that refusal.Steer signal
queueMode: "steer", as the chat composer sends it. The test waits forsessions.changedwith reasonagent.input.steering, which the Gateway emits when the active run accepts the steer into its queue. The tool is released only after that event.chat.sendsteer exposes nothing before release. Its pending input staysqueuedwith nosteerNow, andagent.input.steeringonly fires when the tool ends. So the step uses the composer's steer path.Rebuild evidence checks
sessions.compactturned into a no-op, all 10 randomized seeds failed. Withsessions.patchpinned to the first model, all 10 failed too.Cron-first red on base
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.Harness fixes
Retained subagent payload is unavailable.Gates
ocx testfrom 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.