Repository navigation
fix(anthropic-subscription): read the prompt-cache lifetime from loaded settings files (senpi#2988) - #6333
Conversation
…ed settings files (senpi#2988) The one-shot pin only saw process env and query options env, so a FORCE_PROMPT_CACHING_5M / CLAUDE_CODE_PROMPT_CACHE_TTL set in a loaded settings file was invisible: on a managed lane the pin defaulted to 1h while Claude Code used the settings 5m, and the 1h breakpoint could be rejected. Resolve the effective settings env with the SDK's own resolveSettings merge engine for the sources the attempt loads, and let it sit below explicit env and above the lane default in the pin.
|
Thanks @surlymochan. Review at MEDIUM: the precedence is the reverse of Claude Code's. LOW (non-blocking):
|
|
Concretely, for the medium point: with the process or Suggested fix: put |
…he one-shot cache pin Address review on senpi#6333: Claude Code writes each settings source's env over the process env, and launch-env keys are only protected for host-orchestrated sessions, so on an SDK spawn the settings lifetime is what Claude Code applies. Flip the pin precedence to settings env, then options/process env, then the lane default; flip the process-1h/settings-5m test row to 5m and add a settings-over-options row; fix the it.each title template (4 placeholders for 5 values); cover the empty source-selection branches of resolveQuerySettingsEnv; update the docblock and the change fragment.
|
Addressed in de9d58b:
Verification: |
|
Thanks @surlymochan, the precedence fix is right. Re-review at Remaining LOWs, fine as follow-ups:
The branch was 35 commits behind main, so I merged main into it (no conflicts) as |
|
Merged into main as |
Summary
Fixes senpi#2988 item 4 (settings-file lifetime invisible to the pin). The one-shot pin only saw process env and query-options env, so a
FORCE_PROMPT_CACHING_5M/CLAUDE_CODE_PROMPT_CACHE_TTLset in a loaded settings file was invisible: on a managed lane the pin defaulted to 1h while Claude Code used the settings 5m, and the 1h breakpoint could then be rejected by the Messages API (the exact failure senpi#2982 fixed for explicit env).claude-settings-env.ts: resolves the effective settingsenvwith the SDK's ownresolveSettingsmerge engine (same files, lookup rules and precedence as the CLI), for exactly the sources the attempt loads (explicitsettingSources, or user/project in preset-append ambient mode). Resolution failure falls back to the old pin behavior instead of failing the turn.pinOneShotPromptCacheTtltakes the settings env as a fourth input. Precedence: explicit env > settings env > lane default. The pin still writes the final lifetime into query-options env, so what Claude Code receives matches the breakpoint.stream.tsresolves the settings env once per stream and passes it to the pin only for attempts whosesettingSourcesare non-empty (managed lanes load none).Items 1 (ambient lane breakpoint) and 2 (wide tool turns) of #2988 stay open; this PR covers item 4 only.
Evidence
test/suite/regressions/2988-anthropic-subscription-settings-env-cache-ttl.test.tsfailed before the fix (missing module import).2982-anthropic-subscription-one-shot-cache-ttl,2982-anthropic-subscription-append-only-prompt-capture, and the three cold-seed suites.bun run check(root): clean — oxlint 0 warnings, fmt clean, tsc clean in both projects, install locks up to date.Notes
changes/unreleased/<PR#>.md) to follow once the PR number is assigned.Summary by cubic
Makes the one-shot prompt-cache pin read the effective
envblock of loaded settings files, so its breakpoint matches the lifetime Claude Code actually applies. Previously aFORCE_PROMPT_CACHING_5M/CLAUDE_CODE_PROMPT_CACHE_TTLin a settings file was invisible: managed lanes pinned 1h while Claude Code used the settings 5m, and the 1h breakpoint could be rejected by the Messages API.claude-settings-env.tsresolves the effective settings env with the SDK'sresolveSettingsmerge engine, matching the CLI's files, lookup rules, and precedence; resolution failures fall back to the old pin behavior.settingSourcesare non-empty; managed lanes load none, so nothing changes there.resolveSettings, and a change fragment documents the fix.Written for commit 460d1a5. Summary will update on new commits.