Skip to content

Revert "fix(agents): keep session forks on the parent's cached prompt prefix" - #197175

Merged
obviyus merged 1 commit into
mainfrom
revert/fork-cache-reuse
Nov 11, 2026
Merged

obviyus merged 1 commit into
mainfrom
revert/fork-cache-reuse

Conversation

@obviyus

@obviyus obviyus commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator

Reverts #197074.

#197074 claimed Advisor forks would reuse the parent's Anthropic prompt cache. The proof was a loopback mock showing that fork request bodies matched byte for byte, and I described that as cutting Peanutto reviews from about $3 to about $0.10. Live providers don't support that.

Measured on an isolated Gateway against real providers, before and after the fix:

  • Thinking off, haiku-5-5 on direct anthropic, a custom provider pointed at api.anthropic.com, and cliproxy: forks already read the parent's full cached prefix before the fix. That held even when tool-call IDs differed and tool_choice was none.
  • Thinking on, haiku-5-5 and opus-5-5: each fork request was replayed in its own cache namespace with only one field changed.
Fork request haiku opus
Parent's tool_choice (the change) 523 950
tool_choice: none 523 950
Tool-call IDs not matching the parent 523 950
Parent's thinking config, thinking blocks removed 4763 5221

With thinking on, tool-call IDs were already identical before the fix.

The real causes, measured:

  • On Anthropic, the fork's thinking config differs from the parent's. The fork reads thinking only from the per-session override, sessionEntry.thinkingLevel (src/gateway/server-plugin-subagent-runtime.ts:324), so the agent's thinkingDefault never reaches it. A follow-up PR will fix that.
  • On OpenAI, the fork deletes prompt_cache_key. Replaying the parent's request without the key dropped cached tokens from 3443 to 2615.

Also removed: the pending-call "still running" fix only repaired a regression introduced by #197074 itself, and scripts/perf/advisor-fork-prefix-gateway.ts was proof for the reverted claim. Test lines net −1 (one restored assertion is compacted).

Tests: session-fork.test.ts, embedded-agent-runner.session-fork.test.ts, and attempt-execution-phase.test.ts pass (40 tests).

… prefix (#197074)"

This reverts commit 2706a18.

Live provider measurements showed no cache gain. On Anthropic (haiku-5-5 and
opus-5-5, thinking off and on, direct and custom routes), forks read the same
parent prefix before and after: replaying one fork with the parent's
tool_choice, with tool_choice none, and with mismatched tool IDs differed by
0-2 cached tokens. With thinking on, both tool IDs were already identical.

The measured cause of fork cache misses is the fork's thinking config (it sends
thinking disabled or a different effort and keeps or drops thinking blocks
differently from the parent), and on OpenAI the deleted prompt_cache_key.

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

clawsweeper Bot commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation scripts Repository scripts agents Agent runtime and tooling plugin: file-transfer size: M labels Nov 11, 2026
@obviyus
obviyus merged commit 3ef64ea into main Nov 11, 2026
116 of 117 checks passed
@obviyus
obviyus deleted the revert/fork-cache-reuse branch November 11, 2026 10:39
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 12, 2026
… prefix (openclaw#197074)" (openclaw#197175)

This reverts commit 9cae7fa.

Live provider measurements showed no cache gain. On Anthropic (haiku-5-5 and
opus-5-5, thinking off and on, direct and custom routes), forks read the same
parent prefix before and after: replaying one fork with the parent's
tool_choice, with tool_choice none, and with mismatched tool IDs differed by
0-2 cached tokens. With thinking on, both tool IDs were already identical.

The measured cause of fork cache misses is the fork's thinking config (it sends
thinking disabled or a different effort and keeps or drops thinking blocks
differently from the parent), and on OpenAI the deleted prompt_cache_key.

Co-authored-by: obviyus <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation plugin: file-transfer scripts Repository scripts size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant