Skip to content

fix(agent): preserve prompt cache stability across providers and GPT-6.2 Responses - #7099

Merged
M4n5ter merged 4 commits into
rust-previewfrom
fix/openai-responses-prompt-caching
Nov 20, 2026
Merged

M4n5ter merged 4 commits into
rust-previewfrom
fix/openai-responses-prompt-caching

Conversation

@M4n5ter

@M4n5ter M4n5ter commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Summary

Aligns Maka's OpenAI Responses / ChatGPT Codex wire format with GPT-6.2 prompt caching rules and fixes three cross-provider prompt cache invalidation bugs:

Cross-provider prompt cache stability

  • Inherit skill catalog on background wake-ups in driver_model (plugins/agent/native/src/owner/driver_model.rs, plugins/agent/native/src/owner/driver_executor.rs, plugins/agent/native/src/owner/skills.rs): Background wake-ups (Goal, ScheduledTask, SessionCompletion, CheckpointHandoff, ContextCompact) bypass prepare_skills. Previously only driver_executor inherited the most recent prepared run's skill catalog, while native driver_model dropped it — flipping system.text twice (once on wakeup, once on the next user message) and busting 100% of the prompt cache across all providers. Both drivers now share resolve_input_skills, stopping at any prepared run (even if its catalog is empty) so cleared skills are not resurrected.
  • Deduplicate skill catalog sections in driver_model::append_skill (plugins/agent/native/src/owner/driver_model.rs): Repeated merges during steering or ancestry replay previously appended duplicate copies of the same available-skills catalog to system.text, mutating the leading system message and invalidating prefix caches across all providers.
  • Keep static tool prefix invariant and append tool_search-loaded tools in activation order (platform/session-state/src/lib.rs, plugins/agent/state/src/cells.rs, plugins/agent/state/src/cells/sql.rs, plugins/agent/tool-catalog/src/availability.rs, plugins/agent/native/src/owner/driver.rs): Persist loaded tool names in activation order instead of alphabetical BTreeSet order, and emit wire tool definitions as [direct tools..., tool_search, loaded deferred tools in activation order...] so discovering a tool never shifts the preceding static or previously-loaded tool prefix.

OpenAI Responses / ChatGPT Codex (GPT-6.2)

Starting with GPT-6.2 (Astra and Sol), OpenAI's Responses API appends top-level instructions after the input array and after all cache breakpoints, billing those tokens at full uncached input rates on every turn. Reusable instructions must live in leading developer messages inside input.

  • Use role: "developer" for OpenAI Responses system messages (plugins/agent/provider-protocol/src/responses/request.rs, plugins/agent/model/src/adapters/wire/responses.rs): Encode Message::System as role: "developer" for OpenaiResponses while keeping role: "system" for third-party plaintext OpenResponses.
  • Stop duplicating the system prompt into top-level instructions for ChatGPT Codex (plugins/agent/model/src/adapters/codex.rs): codex::prepare previously copied Message::System into top-level instructions without removing it from input[0], sending the system prompt twice and burning an uncached copy on every turn. Live probes against chatgpt.com/backend-api/codex/responses confirm omitted top-level instructions works across gpt-5.6-sol, gpt-6-sol, gpt-6.1-sol, and gpt-6.2-sol over both HTTP SSE and WebSocket previous_response_id continuations. Explicit caller-supplied instructions are still preserved.
  • Add GPT-6.1 / GPT-6.2 model catalog entries (plugins/agent/providers/data/catalog-facts.json, plugins/agent/providers/tests/integration/api/mod.rs): Add gpt-6.1-sol, gpt-6.1-terra, gpt-6.2-astra, and gpt-6.2-sol to openai and openai-codex matching verified API and Codex inventory metadata.

Verification

  • Live OpenAI Responses API probe (gpt-6.2-sol):
    • Leading developer message multi-turn: T1 cache_write_tokens: 6176, T2 cached_tokens: 6176 / 6196.
    • Top-level instructions multi-turn: T1 & T2 cache_write_tokens: 0, cached_tokens: 0.
    • Verified reasoning.effort support on gpt-6.2-sol and gpt-6.2-astra (low..max, rejecting none and ultra).
  • Live ChatGPT Codex subscription probe (chatgpt.com/backend-api/codex/responses):
    • Omitted top-level instructions with leading developer message returned 200 OK on gpt-5.6-sol, gpt-6-sol, gpt-6.1-sol, and gpt-6.2-sol.
    • gpt-6.2-sol HTTP SSE 2-turn: cached_tokens: 4224 / 4370.
    • gpt-6.2-sol WebSocket previous_response_id continuation without top-level instructions: preserved turn-1 developer instructions and hit cached_tokens: 2688 / 2875.
  • Local Rust checks:
    • cargo test -p maka-provider-protocol -p maka-providers -p maka-model — passed
    • cargo test -p maka-session-state -p maka-agent-state -p maka-tool-catalog — passed
    • cargo test -p maka-tools learning_a_nested_tool — passed
    • cargo test -p maka-agent-native --lib driver_model — 9 passed
    • cargo test -p maka-agent-native --lib codex — 11 passed
    • rustfmt --edition 2024 --check on all modified Rust files — passed
    • cargo clippy on all modified crates — zero warnings in modified lines
  • Not run locally: full workspace test matrix (just check), UI/workbench suites.

AI use

Select exactly one:

  • No generative tool made a substantive contribution
  • Generative tooling made a substantive contribution

Tool(s) and scope: Google Antigravity — audited OpenAI GPT-6.2 and cross-provider prompt caching, ran live API/Codex probes, implemented the fixes, and added unit/integration tests.

Checklist

  • Tests cover the change and fail without it
  • Format, typecheck and the affected suites pass locally

Does this PR entail a change in behavior?

  • Yes — described under Summary above
  • No

Encode OpenAI Responses system messages as leading developer input messages, stop duplicating the system prompt into top-level instructions on ChatGPT Codex subscriptions, deduplicate repeated skill catalog sections in driver_model::append_skill, and add GPT-6.1/6.2 models to catalog-facts.json.

Generated-by: Google Antigravity
… loaded tool order

Share prior-run skill catalog inheritance between driver_model and driver_executor so Goal, ScheduledTask, SessionCompletion, and compaction runs do not drop the skills catalog and bust prompt caches. Preserve activation order for dynamically discovered tools and append them after the static direct + tool_search prefix.

Generated-by: Google Antigravity
@M4n5ter M4n5ter changed the title fix(agent): preserve OpenAI Responses prompt caching for GPT-6.2 fix(agent): preserve prompt cache stability across providers and GPT-6.2 Responses Nov 20, 2026
…d map chatgpt catalog

Anchor inherited skill resolution inside inherited_messages so continuation admission and first dispatch compute identical system prompts; read prior RunSource.spec.input directly without view_at folding or a 16-run cap; map live chatgpt Snapshot lookups to openai-codex bundled/public entries; replace trivial helper test with end-to-end continuation and provider tests.

Generated-by: Google Antigravity
…p interactive history scan

Restore continuation skill inheritance in project_step_input's view.baseline branches so post-compaction tool continuations retain the same system prompt. Short-circuit interactive runs that already passed through prepare_skills (by Trigger::Message + interactive MessageOrigin) to avoid O(N^2) history walks when no skill library is configured.

Generated-by: Google Antigravity
@M4n5ter
M4n5ter merged commit 6142508 into rust-preview Nov 20, 2026
@M4n5ter
M4n5ter deleted the fix/openai-responses-prompt-caching branch November 20, 2026 17:06
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