feat(tui): auto-fork read-only same-route children onto the parent's cached prefix#4600
Conversation
…efix Token-cost driver #1: every subagent cold-started by default, re-prefilling system prompt + tools + a re-discovery crawl of context the parent already paid for, even though the fork mechanism (engine per-turn snapshot + with_fork_context) was fully wired — the only fork_context: true in the tree was a unit test. fork_context is now tri-state at the tool boundary: explicit true/false still wins, and an omitted field resolves at spawn time via auto_fork_context_default. The auto policy forks only when it is both cheaper and coherent: the spawner is the engine turn itself (a nested spawner's snapshot is the root prefix, not its own conversation), the child resolved to the exact parent provider+model route (any other route pays a full cold prefill of the parent context), the child posture is read-only (explore/plan/review/verifier, or an explicit read_only write authority), and the child stays in the parent workspace without worktree or cwd isolation. Write-capable, isolated, or re-routed children keep the fresh-brief default. The agent tool schema documents the tri-state; the Agent mode prompt and the fork-context contract test moved from 'Fresh sessions are the default' to the auto-chosen contract. Verified locally: 398 subagent tests (new parse tri-state coverage and the auto-fork decision matrix: postures, authority upgrade, worktree/cwd isolation, cross-model, cross-spawner), 102 prompt+fork tests, strict all-target/all-feature locked clippy, fmt. Signed-off-by: Hunter B <hmbown@gmail.com>
Forking is only economical while the provider's cached-read rate on the parent prefix stays below the cost of a fresh brief plus re-discovery; every child step re-reads the whole forked prefix. Above an estimated 200K-token parent prefix the auto policy now keeps the fresh default. Explicit fork_context: true is deliberately not subject to the ceiling. The estimate walks the snapshot's text/thinking/tool blocks with the conservative compaction estimator. Matrix regression added. Verified: 399 subagent tests, strict locked clippy, fmt. Signed-off-by: Hunter B <hmbown@gmail.com>
…mode Merges origin/main (post #4597 compression) and keeps the auto-chosen fork_context sentence in the compressed style; token ceiling moves 1350 -> 1360 for the added contract sentence. Signed-off-by: Hunter B <hmbown@gmail.com>
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
|
Claude finished @Hmbown's task in 2m 27s —— View job Claude finished reviewing
SummaryThis is a clean, well-scoped fix for a real cost bug: No correctness bugs found. Highlights:
Minor, non-blocking notes
Verification caveatI was not able to run |
The auto-fork policy now (correctly) forks explorer children onto the parent prefix, so their requests carry the parent conversation — which broke this harness's content-based mock dispatch (child matcher excluded requests containing the parent prompt). The crafted tool call now passes fork_context: false explicitly, which always wins over the auto policy, keeping the harness deterministic and exercising the explicit-fresh path. Verified locally: release_runtime_qa 5 passed/1 ignored; qa_pty 17/1, tool_lifecycle 4, plugin_e2e 43, integration_mock_llm 3 all green. Signed-off-by: Hunter B <hmbown@gmail.com>
|
Claude finished @Hmbown's task in 1m 36s —— View job Claude finished reviewing
SummaryThis sync added two small commits on top of what I reviewed in my previous pass (
No correctness bugs, no provider/route-safety issues, nothing to add to my earlier findings from the core Still open from the previous review (non-blocking, unchanged by this sync)
Verification caveatSame as before: I could not run |
Token-cost driver #1 from the 2026-07-19 investigation: every subagent cold-started by default, re-prefilling system prompt + tools + a re-discovery crawl of context the parent already paid for (~100K input per child observed), even though the fork mechanism (per-turn engine snapshot +
with_fork_context) was fully wired — the onlyfork_context: truein the tree was a unit test.Design
fork_contextis now tri-state at theagenttool boundary:true/false— unchanged, always wins;auto_fork_context_default, which forks only when it is both cheaper and coherent:read_onlywrite authority);Everything else keeps the fresh-brief default. The tool schema documents the tri-state so the model is aware of the tradeoff in one sentence; the Agent-mode prompt contract moved from "Fresh sessions are the default" to the auto-chosen contract (test updated with it).
Related findings (no code needed)
client/anthropic.rs::apply_anthropic_cache_breakpointsplaces tools/system + latest-user-turn breakpoints with the 4-cap at the wire layer.Evidence
read_onlyauthority upgrade, worktree/cwd isolation, cross-model, cross-spawner, oversized-prefix ceiling.inherit_context/ omitted → None).