Fix #285: make 1h prompt caching reachable via config#317
Open
ericleepi314 wants to merge 1 commit into
Open
Conversation
The 1h cache path was end-to-end dormant: the eligibility primitive had no production caller (the latch stayed None forever) and the query-source allowlist was never populated, so every cache_control emitted ttl: 5m regardless of model or config. - populate_prompt_cache_1h_allowlist: sticky once-per-session install from settings.prompt_cache_1h_sources (new schema field) or CLAWCODEX_PROMPT_CACHE_1H_SOURCES (comma-separated; set-but-empty is a kill switch) — the config-backed, non-GrowthBook channel - initialize_prompt_cache_state wired from init.pre_action AND lazily from should_1h_cache_ttl when the latch is unevaluated (TS parity: claude.ts evaluates at the consumer) — covering SDK paths that skip pre_action and a /clear that resets the latch singleton, which would otherwise silently downgrade the rest of the session to 5m - the three remaining toggle latches (afk/cache-editing/thinking-clear) stay documented dead stores: their source features (TUI AFK toggle, cache-editing config, extended-thinking request param) are not built in this port; the audit notes now state the precise reasons - stale audit docstrings updated to match the wired reality Closes #285 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
4 tasks
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.
Closes #285
Summary
The 1h prompt-cache path was end-to-end dormant:
evaluate_prompt_cache_1h_eligibilityhad zero production callers (the latch stayedNoneforever) andprompt_cache_1h_allowlistwas never populated — everycache_controlemittedttl: '5m'regardless of model or config.What's wired
settings.prompt_cache_1h_sources(list, e.g.["repl_main_thread"]) withCLAWCODEX_PROMPT_CACHE_1H_SOURCESenv override (comma-separated; set-but-empty is a documented kill switch; list settings REPLACE across config layers). Installed once per session — sticky, like every field in this module (a mid-session flip would bust the cached prefix).initialize_prompt_cache_state()runs frominit.pre_action(env-signal backed:CLAUDE_CODE_USER_TYPE=ant/CLAUDE_CODE_IS_CLAUDE_AI_SUBSCRIBER/CLAUDE_CODE_IS_USING_OVERAGE) and lazily fromshould_1h_cache_ttlwhen the latch is unevaluated — exact TS parity (claude.ts:420-425evaluates at the consumer). The lazy path covers SDK embedders that skippre_actionand a/clearthat resets the latch singleton, which would otherwise have silently downgraded the rest of the session to 5m (critic-found gap).Scope decision (matches the issue's "as the corresponding feature lands")
The three remaining toggle latches (
afk_mode/cache_editing/thinking_clear) stay as documented dead stores: their source features (TUI AFK toggle, cache-editing config, extended-thinking request parameter) don't exist in this port, and adding caller-less setters would recreate the exact dead API the original audit flagged. The audit notes now state the precise feature-not-built reasons, and all stale "no production caller / future WI" docstrings were brought in line with the wired reality.Test plan
should_1h_cache_ttl; sources-without-eligibility stays 5m (AND-gate); settings-backed sources; empty-env kill switch; no-config dormant; idempotence; 1h recovers afterclear_beta_header_latches()(the /clear downgrade fix)🤖 Generated with Claude Code