Skip to content

feat(efficiency): cut prompt-cache misses and background token spend - #555

Merged
astyfx merged 1 commit into
mainfrom
fix/efficiency-prompt-cache
Sep 17, 2026
Merged

astyfx merged 1 commit into
mainfrom
fix/efficiency-prompt-cache

Conversation

@astyfx

@astyfx astyfx commented Sep 17, 2026

Copy link
Copy Markdown
Member

Summary

Removes session/thread rotations and background requests that cost tokens without producing anything a user can see. Turn behavior is unchanged; what changes is how often a cached prefix is thrown away and which lanes get to spend a request.

Changes

Features

  • efficiency: MCP change detection compares a content hash of the MCP-relevant config sections instead of file mtime+size, so unrelated rewrites of settings.json, CLI state, or an identical manifest no longer discard task sessions
  • efficiency: Codex thread keys drop the developer-instructions hash; a resumed thread whose instructions changed gets a one-time [Stave Instructions Update] block on its next turn instead of a cold start
  • efficiency: Auto routing keeps the previous model when the primary route would only step down within the same provider, preserving the cached context
  • efficiency: stave:current-task-awareness is deduplicated to a one-line pointer when unchanged; the ACP runtime applies the same dedup
  • efficiency: the local MCP server publishes a short instructions string naming tool families and the injected-context rule
  • usage: message usage badges show the likely cause of a prompt-cache miss (provider / model / native session change, or rebuilt context) and the tokens re-cached

Fixes

  • provider: the prompt-suggestions setting can only turn suggestions off; aux lanes, secondary runs, and control queries that pass false no longer get re-enabled by the user's setting
  • background-ai: auxiliary lanes, turn summaries, and kickoff suggestions no longer request provider fast modes
  • background-ai: inline completion defaults to off for new policies (stored policies are untouched)

Refactors / Chores

  • workspace guidance drops the plan-directory lines already present in [Stave Workspace Context]
  • docs: provider runtimes, auto routing, background AI policy, and local MCP guide updated to match

Test Evidence

  • bun run typecheck
  • bun run check:doc-paths, bun run check:max-lines-ratchet
  • bun test on the touched areas (mcp-config-refresh, retrieved-context-dedup, current-task-awareness, auxiliary-inference-policy, auto-routing-profile, usage-cache, message-usage-summary, codex-app-server-runtime, codex-app-server-mcp-lifecycle, codex-app-server-secret-env, claude-sdk-runtime, worker-mode-adapters, stave-mcp-server-instructions, stave-collaboration-tools, provider-runtime-options, ipc-schemas): all pass, 0 failures

Notes

  • Codex: verified against the Codex source that developer_instructions are rendered only when a new context window is built (first turn / compaction), not on thread/resume; the refresh block exists because of that. The instruction profile is tracked in memory, so the first resumed turn after an app restart refreshes once.
  • Auto routing stickiness only applies to same-provider step-downs; upgrades and the cheapestAt ceiling behave as before.
  • Not included (documented as follow-ups in the audit): per-workspace MCP server allowlist UI; conditional loading of the Lens/browser instruction blocks.

🤖 Generated with Claude Code

Sessions and threads were being rotated, and background lanes were paying
for premium or invisible requests, in ways that never reached the user as a
feature. This change removes those costs without changing what a turn does.

Cache-preserving session identity
- MCP change detection compares a content hash of the MCP-relevant sections
  (`*mcp*` keys, `[mcp_servers.*]` tables, manifest/.mcp.json) instead of
  mtime+size, so CLI permission saves, state rewrites, and manifest rewrites
  with identical content no longer discard every task session.
- Codex thread keys no longer include the developer-instructions hash. Codex
  only re-renders `developer_instructions` when it builds a new context
  window, so the runtime now remembers the instruction profile each thread
  last saw and prepends a one-time `[Stave Instructions Update]` block to the
  next turn when it differs, instead of cold-starting the thread.
- Auto routing keeps the previous model when the primary route would step
  down to a weaker rung of the same provider, so a cheaper-looking turn does
  not throw away the cached context.

Per-turn injection
- `stave:current-task-awareness` joins the dedup set and collapses to a
  one-line pointer when unchanged; the duplicated plan-directory lines leave
  workspace guidance; the ACP runtime applies the same dedup and commits after
  the prompt is accepted.
- The local MCP server publishes a short `instructions` string naming the tool
  families and the injected-context rule, so hosts that defer tool schemas can
  still pick the right family without probing.

Background lanes
- Auxiliary lanes, turn summaries, and kickoff suggestions no longer request
  provider fast modes.
- Inline completion defaults to off for new policies.
- The prompt-suggestions setting can only turn suggestions off; callers that
  pass `false` (aux lanes, secondary runs, control queries) stay off even when
  the setting is on.

Observability
- Message usage badges tag a cache miss with its likely cause (provider,
  model, or native session change; otherwise a rebuilt context) and the
  number of tokens re-cached.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@astyfx
astyfx requested a review from a team as a code owner September 17, 2026 08:21
@astyfx
astyfx requested review from JongSikLim and png-1105 and removed request for a team September 17, 2026 08:21
@upwind-code-us

upwind-code-us Bot commented Sep 17, 2026

Copy link
Copy Markdown

Upwind Upwind Code Scan - ✅ Passed

0 newly introduced vulnerabilities · 0 resolved · 57 total in this PR vs main

Total breakdown: 🔶 6 High | 🟡 48 Medium | 🟢 3 Low

View full analysis in Upwind Console

Scan completed in 10s

Scan history (1 scan)
Commit Scanned at New Resolved Net
8825e9d < 2026-09-17 08:21 UTC 0 0 0

Last scanned: 8825e9d · 2026-09-17 08:21 UTC

@upwind-code-us

upwind-code-us Bot commented Sep 17, 2026

Copy link
Copy Markdown

Upwind Upwind IaC Scan - ✅ Passed

0 newly introduced misconfigurations · 0 resolved · 0 total in this PR vs main

View full analysis in Upwind Console →

Scan completed in 3s

Scan history (1 scan)
Commit Scanned at New Resolved Net
8825e9d < 2026-09-17 08:21 UTC 0 0 0

Last scanned: 8825e9d · 2026-09-17 08:21 UTC

@heath-s heath-s left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved

@astyfx
astyfx merged commit abfd870 into main Sep 17, 2026
6 checks passed
@astyfx
astyfx deleted the fix/efficiency-prompt-cache branch September 17, 2026 10:20
@astyfx astyfx mentioned this pull request Sep 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants