fix(agent): namespace prompt_cache_key with logical session scope - #78956
fix(agent): namespace prompt_cache_key with logical session scope#78956StanleyStetson wants to merge 1 commit into
Conversation
|
This was generated by AI during triage. Fresh interactive sessions now get a per-session prompt_cache_key (session:), dropping the previously-tested same-key-across-session-ids guarantee — while the issue's retest table shows the shared key delivering 77.23% cross-session reuse and could not reproduce the eviction this isolates against. The diff removes test_cache_key_stable_across_session_ids — whose docstring calls same-key-across-session-ids "the whole point of the fix: repeated fires reuse the warm prefix" — and adds test_cache_key_independent_interactive_sessions_different_keys asserting the opposite for interactive sessions; only the cron case keeps a stable key. For a parentless CLI session get_conversation_root returns the session id unchanged, so the scope is the fresh session id itself. Checked against |
|
Thanks — intent is intentional hardening per #78941, not a regression of #52295.
Happy to adjust wording or scope logic if maintainers prefer any further tuning to the isolation boundaries. |
|
Thanks for the careful work here — the scenario-test coverage (9 precedence tests) and the explicit 1. Superseded by #79161 (merged this morning, closed #78941). Main now scopes 2. Two of the four scope rules don't behave as documented in production wiring (verified empirically):
3. The cron regex's speculative branches introduce the bug class this PR fixes. The 4. The genuinely novel pieces belong in #79017. Rotation-stable scoping (your gateway-key and lineage-root rules) is exactly the open design question there — with two constraints your current shape hits: Appreciate the engagement on this one — the design conversation continues in #79017. |
What does this PR do?
Hardens
prompt_cache_keyrouting by adding logical session scope isolation:prompt_cache_key = hash(logical_scope + "\0" + static_prefix)Note
This is routing-scope hardening and collision protection between unrelated interactive sessions, NOT a proven cache eviction hit-rate fix.
Key Details & Scope Rules
cron:<job_id>as logical scope (parsing job IDs and ignoring per-fire timestamps) to preserve warm cache hits across job executions (fix(cache): content-address prompt_cache_key so recurring cron jobs reuse the warm prefix #52295 / Recurring cron jobs are prompt-cache-cold on every fire (session_id is the cache key) #51395).session:<child_session_id>scope so subagents differ from parent sessions and sibling subagents.gateway_session_key/conversation_idwhen available, or walks context-compression lineage root (parent_session_id) to maintain warm cache hits across compression turns.prompt_cache_key) and length bounding (_bounded_prompt_cache_key). Leaves real transcriptsession_idheaders (session_id,x-client-request-id,x-grok-conv-id) untouched.Fixes #78941
Verification
pytest tests/agent/transports/test_codex_transport.py tests/agent/transports/test_chat_completions.py(117 passed)npm run fix