Repository navigation
fix: let background reviews reuse their session's cached prompt - #203601
Merged
Merged
Conversation
A session fork dropped the provider-hosted web search tool from its request because the listing followed the fork's execution cap. Its tool list then differed from the session's, so every fork request missed the cached prefix. Hosted search now follows the session's own policy; the fork's cap still gates client tools and tool-free forks still send tool_choice none. Co-authored-by: obviyus <[email protected]>
…quest The fork's own rebuilt request already extends the parent's sent bytes on every transport (new journey step: a fork of a live, mid-tool-call turn), so the prepared-request capture, storage and replay are gone. The fork keeps the transcript pin and the live prompt-cache key. Co-authored-by: obviyus <[email protected]>
Contributor
|
🦞👀 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. |
Hosted search runs at the provider before any local tool gate, and the native endpoint rejects tool_choice allowed_tools. A fork lists hosted search only when its execution cap allows it or it is tool-free (tool_choice none stops it); sessionForkGatesHostedTools owns that decision. Co-authored-by: obviyus <[email protected]>
Co-authored-by: obviyus <[email protected]>
A fork during the session's first live turn is anchored before the session's system-prompt checkpoint, so only the live replay keeps the session's system prompt there. Restores the replay and its docs; the mid-turn journey step stays. The provider prompt state now builds the fork context it owns. Co-authored-by: obviyus <[email protected]>
Co-authored-by: obviyus <[email protected]>
Collaborator
Author
|
Landed. A tool-free background fork now lists the session's hosted search (tool_choice none still blocks it), so its tool list matches the session's. The byte-replay deletion was tried and reverted after review found a first-live-turn case only the replay covers; the new mid-turn journey step stays as a guard. Forks that run their own tools still omit hosted search unless granted it (no provider-side gate exists). |
github-actions Bot
pushed a commit
to Desicool/openclaw
that referenced
this pull request
Nov 23, 2026
…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]>
tideclaw-bot
pushed a commit
that referenced
this pull request
Nov 24, 2026
Plugin session forks (`runForkedTurn`, `forkSession`; for example Better Prompt and Skill Workshop reviews) always ran on the built-in runtime. On a Claude CLI chat signed in with a Claude subscription:
- With only the CLI's own `claude` login, `runForkedTurn` failed with `No API key found for provider "claude-cli"`.
- With a Claude subscription token stored in OpenClaw, `runForkedTurn` sent the token to the Anthropic API directly, which bills metered extra usage instead of the plan (`cliBackendDispatch` notes in `run/params.ts`).
- `forkSession` refused every CLI runtime: `Session forks are not supported for CLI runtime claude-cli.`
OpenClaw already has one owner for "run this embedded run on the subscription CLI": `cliBackendDispatch: "subscription-auth"` (Active Memory's recall uses it). The fork owner opts into it; no new path:
- `runSessionFork` sets `cliBackendDispatch: "subscription-auth"`. Eligibility is unchanged: subscription (oauth/token) or unresolvable credentials go to the CLI; API keys keep the request replay and its prompt cache.
- Dispatch accepts the fork's in-memory conversation (`sessionManager`), and sends the CLI only the tools that may execute (`toolExecutionAllow`; an empty list is a tool-free run).
- Dispatch now picks the CLI account the way a new CLI session does. Before, it passed only an explicit pin, so a stored Claude token never reached the CLI (`Not logged in · Please run /login`); Active Memory recalls had the same gap.
- Runs that grant the plugin's own tools or set `maxTokens` keep the direct route: neither reaches a CLI process.
- Dispatch carries the run's policy facts to the CLI: a run under another session's policy (a fork's `sandboxSessionKey`) passes that session's entry, the requester fields and `internal_system` provenance into the CLI's Gateway tool grant, so restricted-sender limits apply to the fork as to the chat's own turns.
Accepted: a CLI fork starts a fresh CLI session with the conversation as context, so it does not reuse the chat's cache, and each fork leaves one Claude session file under `~/.claude/projects`, as Active Memory's CLI recalls already do. The source chat's native session is never resumed or written.
Permission modes (maintainer decision, now in `docs/gateway/permission-modes.md`): the `sessionRoot` boundary is enforced on the built-in runtime; CLI-backed chats use the CLI's own controls, and owner turns' Gateway tools are not limited to `sessionRoot`. Live, on a Claude CLI chat in `workspace` mode, an ordinary turn and a fork both read a file outside the workspace through `mcp__openclaw__read`, and the same chat on the built-in runtime refuses both with `Path escapes sandbox root`. A CLI fork therefore has the same file access as the chat's own CLI turns.
Not covered: Gemini CLI on a Google login (OpenClaw cannot limit its tools under OAuth), and harnesses that own their login with no limited one-shot turn (Copilot, Muse, `acp-*`).
Real product, tier source (`ocx src`), isolated foreground Gateway, no API key in the environment or auth store; profiles: Claude subscription setup token, ChatGPT OAuth, Grok OAuth. Each chat: one turn ("Remember PELICAN-42"), then forks through a probe plugin.
| Route | `runForkedTurn` `[read, ls]` | `forkSession` | `runForkedTurn` cache read |
|---|---|---|---|
| `claude-cli`, Claude token | `PELICAN-42 \| FORK-READ-OK 7f3a` (dispatched to Claude CLI) | `PELICAN-42` | 6,985 |
| ChatGPT OAuth, built-in | `PELICAN-42 \| FORK-READ-OK 7f3a` | `PELICAN-42` (cache read 9,856) | 10,112 |
| Codex app-server | `PELICAN-42 \| FORK-READ-OK 7f3a` | `PELICAN-42` (19,584) | 8,704 |
| Grok OAuth | `PELICAN-42 \| FORK-READ-OK 7f3a` | `PELICAN-42` (1,152) | 1,152 |
- `main` on the same Claude chat: `runForkedTurn` ran on the Anthropic API with the token (cache read 0, cache write 23,872), `forkSession` refused.
- Every route: source transcript hash, message count and native binding unchanged; the Claude source session file holds only the chat's own turn.
- Better Prompt 0.2.2 (`start` → `take` through `plugins.sessionAction`) produced an improved prompt on the Claude CLI chat and on the ChatGPT chat.
- Dispatch tests: a fork runs on the CLI with only its own tools from its in-memory session; plugin tool grants and output caps keep the passthrough.
Co-authored-by: Ayaan Zaidi <[email protected]>
(cherry picked from commit b7bf937)
Release adaptation: retain staged Gateway permission-mode documentation and enforcement; omit the superseded upstream documentation exception.
Companions: #202941 and #202646 are present-equivalent (9ec8d08 and 087c816); #201554 is staged as 5647120. #202957 is not applicable (reverts a separate native-tools path). #204219, #203999, #203901, #203919, #203601 and #203271 are independent prewarm, lifecycle, recovery, review or default-routing changes; not required for the selected fork path.
Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit 8a592a33b7866a1306c60468e4aaf2c9fb23a93f)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_searchtool, 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 sendstool_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
sessionForkGatesHostedTools(api, allowedTools)insession-fork-request.tsanswers one question: can the provider stop hosted tools for this fork? The answer is yes only for a tool-free fork on an API withtool_choice: none.attempt-stream-settle.tsnow lists hosted search when the execution cap allows it or when that owner says the provider gates it.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-onlyweb_searchto 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.tsunder 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 contract (
test/embedded-agent-attempt-stream-transport.test.ts):web_search.web_searchlists it.tool_choice: none.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.