Skip to content

Fix #285: make 1h prompt caching reachable via config#317

Open
ericleepi314 wants to merge 1 commit into
feature/issue-283-research-budgetfrom
fix/issue-285-cache-state-latches
Open

Fix #285: make 1h prompt caching reachable via config#317
ericleepi314 wants to merge 1 commit into
feature/issue-283-research-budgetfrom
fix/issue-285-cache-state-latches

Conversation

@ericleepi314

Copy link
Copy Markdown
Collaborator

Closes #285

Stacked on #316 (deep stack down to #304). Merge in order; GitHub retargets automatically.

Summary

The 1h prompt-cache path was end-to-end dormant: evaluate_prompt_cache_1h_eligibility had zero production callers (the latch stayed None forever) and prompt_cache_1h_allowlist was never populated — every cache_control emitted ttl: '5m' regardless of model or config.

What's wired

  • Config-backed allowlist (the issue's non-GrowthBook channel): new settings.prompt_cache_1h_sources (list, e.g. ["repl_main_thread"]) with CLAWCODEX_PROMPT_CACHE_1H_SOURCES env 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).
  • Eligibility latch wired: initialize_prompt_cache_state() runs from init.pre_action (env-signal backed: CLAUDE_CODE_USER_TYPE=ant / CLAUDE_CODE_IS_CLAUDE_AI_SUBSCRIBER / CLAUDE_CODE_IS_USING_OVERAGE) and lazily from should_1h_cache_ttl when the latch is unevaluated — exact TS parity (claude.ts:420-425 evaluates at the consumer). The lazy path covers SDK embedders that skip pre_action and a /clear that resets the latch singleton, which would otherwise have silently downgraded the rest of the session to 5m (critic-found gap).
  • The TTL decision stays the TS AND-gate: eligibility and source-in-allowlist; everything else stays 5m (the Phase-1 default).

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

  • 10 new tests: sticky populate + garbage rejection; env+eligibility activates 1h end-to-end through the real should_1h_cache_ttl; sources-without-eligibility stays 5m (AND-gate); settings-backed sources; empty-env kill switch; no-config dormant; idempotence; 1h recovers after clear_beta_header_latches() (the /clear downgrade fix)
  • 133 tests across session_start / cache_state / init / prompt_assembly / settings / clear-sections files pass
  • Full suite on the stack: 7888 passed, 0 failed, 5 skipped
  • Critic review loop: APPROVE after 1 revision round (the stale-docstring contradiction and the /clear silent-downgrade both came from it; the lazy-consumer fix was verified for singleton-aliasing safety)

🤖 Generated with Claude Code

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>
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.

1 participant