[BUG] Plugin loses prompt cache after tool execution (native OpenAI works)
Summary
When using GPT models through oc-codex-multi-auth, prompt caching works during tool calls but consistently fails on the subsequent assistant continuation (function_call_output). The same test works correctly with OpenCode's native OpenAI OAuth integration.
Reproduction
- Use OpenCode 2.0.32 with
oc-codex-multi-auth,gpt-6-luna, and default plugin settings (native,fastSession: false). - Start a new session and ask the model to respond with
CACHE A. - Ask it to execute
printf 'CACHE B\n'using the shell tool, then respond withCACHE B. - Compare per-message
tokens.cache.readin OpenCode SQLite. Repeat using native OpenAI OAuth without the plugin.
Expected Behavior
The assistant continuation after tool execution should reuse the cached conversation prefix.
Actual Behavior
Table shows % of cached tokens used.
| Request | Plugin | Native OpenAI |
|---|---|---|
| Initial response | 0% | 37.2% |
| Shell tool call | 96.3% | 97.1% |
| Continuation after shell | 0% | 95.9% |
The plugin's developer instructions, 11 tool definitions, and previous conversation history remain identical across the tool call and continuation.
An experimental workaround that my model proposed to remove replayed reasoning.encrypted_content did not help.
Environment
opencode --version:2.0.32oc-codex-multi-auth --version: Installed via@latest; exact version not verified- OS: Ubuntu 26
- Node.js: 24
- Model:
gpt-6-luna - Authentication: Codex OAuth
Diagnostic Outputs
Logs (Optional)
Compliance Confirmation
- [x] I am using this plugin for personal development only, with an active ChatGPT Plus/Pro subscription.
- [x] This report does not request policy bypasses or commercial-use workarounds.
- [x] I reviewed the FAQ and Troubleshooting docs.
- [x] I removed any secrets/tokens from this report.
My model prepared a test script to investigate the problem.
#!/usr/bin/env bash
set -euo pipefail
SID="${1:?Usage: oc-cache-watch.sh ses_ID}"
DB="$(opencode debug paths db)"
sqlite3 -readonly -header -column "$DB" "
WITH events AS (
SELECT
seq,
type,
data,
json_extract(data, '$.tokens.input') AS input_tokens,
json_extract(data, '$.tokens.cache.read') AS cache_read,
json_extract(data, '$.tokens.cache.write') AS cache_write,
json_extract(data, '$.tokens.output') AS output_tokens
FROM session_message
WHERE session_id = '$SID'
)
SELECT
seq,
type,
COALESCE(json_extract(data, '$.model.modelID'),
json_extract(data, '$.model.id'),
'-') AS model,
input_tokens AS uncached,
cache_read AS cached,
cache_write AS written,
output_tokens AS output,
ROUND(
100.0 * cache_read /
NULLIF(input_tokens + cache_read, 0), 1
) AS hit_pct,
CASE
WHEN type = 'assistant'
AND COALESCE(cache_read, 0) = 0
THEN 'MISS'
WHEN type = 'assistant'
AND cache_read > 0
THEN 'HIT'
ELSE '-'
END AS cache_status
FROM events
ORDER BY seq;
"
echo
echo "=== SESSION TOTALS ==="
sqlite3 -readonly -header -column "$DB" "
SELECT
tokens_input AS uncached,
tokens_cache_read AS cached,
tokens_cache_write AS written,
tokens_output AS output,
ROUND(
100.0 * tokens_cache_read /
NULLIF(tokens_input + tokens_cache_read, 0), 1
) AS hit_pct
FROM session_v2
WHERE id = '$SID';
"
To test it, I open a new session, switch to GPT-family model and run two prompts:
Respond exactly: CACHE A.
Do not use any tools.
Execute shell: printf 'CACHE B\n'.
Then respond: CACHE B.
Result when connected to the openai with this plugin:
seq type model uncached cached written output hit_pct cache_status
--- --------- ---------- -------- ------ ------- ------ ------- ------------
4 user - -
5 assistant gpt-6-luna 6612 0 0 6 0.0 MISS
10 idle - -
16 user - -
17 assistant gpt-6-luna 246 6400 0 25 96.3 HIT
26 assistant gpt-6-luna 6802 0 0 6 0.0 MISS
31 idle - -
=== SESSION TOTALS ===
uncached cached written output hit_pct
-------- ------ ------- ------ -------
14294 6400 0 43 30.9
Result with native OpenCode v2 auth
seq type model uncached cached written output hit_pct cache_status
--- --------- ---------- -------- ------ ------- ------ ------- ------------
4 user - -
7 assistant gpt-6-luna 3485 2048 0 7 37.0 HIT
12 idle - -
16 user - -
17 assistant gpt-6-luna 192 5376 0 25 96.6 HIT
26 assistant gpt-6-luna 259 5376 0 7 95.4 HIT
31 idle - -
=== SESSION TOTALS ===
uncached cached written output hit_pct
-------- ------ ------- ------ -------
4469 12800 0 45 74.1