Skip to content

fix(cache): scope auxiliary Codex adapter's prompt_cache_key by session - #11

Closed
JoaoMarcos44 wants to merge 1 commit into
fix/78941-prompt-cache-key-session-scopefrom
fix/79012-aux-cache-scope
Closed

JoaoMarcos44 wants to merge 1 commit into
fix/78941-prompt-cache-key-session-scopefrom
fix/79012-aux-cache-scope

Conversation

@JoaoMarcos44

Copy link
Copy Markdown
Owner

Summary

Fixes NousResearch#79012. Split out of NousResearch#78959's continuation so it can be reviewed on its own -- see that PR's comment for why this exists.

compression/flush_memories/MoA/session_search route through _CodexCompletionsAdapter (agent/auxiliary_client.py), which derived prompt_cache_key from instructions+tools only -- no session scope at all. Two unrelated sessions whose auxiliary calls share instructions/tools (the common case -- most auxiliary tasks use a small fixed set of system prompts) collapsed onto the same cache bucket, reproducing NousResearch#78941 on this second, less-visible code path.

Fix

set_runtime_main() now accepts session_id (threaded from agent/turn_context.py's existing call, one line). _CodexCompletionsAdapter.create() reads it back via _runtime_main_value("session_id") and scopes the key through the same _cache_scope_from_session_id() helper the main transport uses.

Test plan

  • tests/agent/test_auxiliary_client.py::TestCodexAuxiliaryAdapterCacheScope — different sessions get different keys; cron re-fires of the same job share one
  • Full auxiliary_client suite green
%%{init: {'theme': 'dark', 'themeVariables': { 'primaryColor': '#8b0000', 'mainBkg': '#0a0204', 'primaryTextColor': '#ffccd5', 'primaryBorderColor': '#ff0038', 'lineColor': '#ff0038'}}}%%
graph TD
    A[Session A<br/>compression call] -->|Before fix| X[Shared Cache Bucket<br/>content-only key]
    B[Session B<br/>flush_memories call] -->|Before fix| X
    X --> R1[Risk: Cross-Session<br/>Bucket Sharing]

    A2[Session A] -->|set_runtime_main session_id| Y1[Scoped Key: pck_hash_A]
    B2[Session B] -->|set_runtime_main session_id| Y2[Scoped Key: pck_hash_B]
    Y1 --> S1[Isolated Bucket]
    Y2 --> S2[Isolated Bucket]

    style X fill:#8b0000,stroke:#ff0038,color:#ffccd5
    style R1 fill:#8b0000,stroke:#ff0038,color:#ffccd5
    style S1 fill:#3a0000,stroke:#ff0038,color:#ffccd5
    style S2 fill:#3a0000,stroke:#ff0038,color:#ffccd5
Loading

Fixes NousResearch#79012. compression/flush_memories/MoA/session_search calls went
through _CodexCompletionsAdapter, which derived prompt_cache_key from
instructions+tools only -- no session scope -- reproducing the NousResearch#78941
bucket-sharing bug on this second code path even after the main
transport fix in this PR.

set_runtime_main() now threads session_id through (turn_context.py
passes agent.session_id); the adapter reads it back via
_runtime_main_value("session_id") and scopes the key the same way the
main transport does (_cache_scope_from_session_id).
@JoaoMarcos44

Copy link
Copy Markdown
Owner Author

Folded back into the upstream PR (NousResearch#78959) so maintainers review everything in one visible upstream PR instead of fork-only ones. Closing.

@JoaoMarcos44
JoaoMarcos44 deleted the fix/79012-aux-cache-scope branch August 5, 2026 02:17
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