fix(codex): stabilize OpenCode prompt caching
Summary
- Prefer client supplied Codex prompt cache keys from payload, translated body, provider options, or session headers before falling back to the API key derived key.
- Normalize the volatile OpenCode developer Current time value to a stable day-level timestamp for OpenAI Responses prompt-cache stability.
- Preserve previous_response_id for incremental Responses requests while still dropping it for full-transcript prompt-cache requests.
Why
OpenCode includes environment metadata in the first developer input item. The Current time field changes on every turn, which breaks exact-prefix prompt cache reuse shortly after the stable prefix. Keeping the date but normalizing the time removes that per-request jitter without changing user/task content.
Tests
- docker run --rm -v "/root/project/cpa":/app -w /app golang:1.26-alpine go test -run 'TestCodexExecutorCacheHelper|TestCodexExecutorExecute.*PreviousResponseID' ./internal/runtime/executor
- docker build -t cli-proxy-api:pr-check .
This pull request targeted main.
The base branch has been automatically changed to dev.
This pull request targeted main.
The base branch has been automatically changed to dev.
Any progress? I'm using CPA to proxy my GPT team into opencode, and noticing a heavy cache miss (only 18,944/134,086 hits the cache)
Rebased this PR onto current dev (3a54fb7f) and force-pushed the refreshed head 6f673d3c.
Validation:
git diff --check origin/dev...HEADgo test -run 'TestCodexExecutorCacheHelper|TestCodexExecutorExecute.*PreviousResponseID' ./internal/runtime/executorgo test ./...- GitHub checks are green:
close-when-agents-md-changed,ensure-no-translator-changes, andbuild
The previous blocking conflict around ApplyPayloadConfigWithRequest is resolved. Current compare state is ahead 4 / behind 0, and the PR reports mergeable_state: clean.
@luispater please re-review when you have a chance.
Follow-up: dev advanced again with 33983b6f (refactor(executor): consolidate Codex request translation logic) after my previous refresh, touching the Codex executor path.
I rebased again onto 33983b6f and force-pushed a95194e1.
Validation after the second rebase:
git diff --check origin/dev...HEADgo test -run 'TestCodexExecutorCacheHelper|TestCodexExecutorExecute.*PreviousResponseID|TestTranslateCodexRequestPair' ./internal/runtime/executorgo test ./internal/runtime/executor ./internal/runtime/executor/helps ./internal/translator/codex/... ./sdk/api/handlers/openaigo test ./...- GitHub checks are green again:
close-when-agents-md-changed,ensure-no-translator-changes, andbuild
Current compare state is ahead 4 / behind 0 against dev.
@luispater refresh after the latest automated review follow-ups: current head is d52f2933, rebased on dev at 33983b6f, and the PR is still mergeable_state: clean.
I fixed the two Responses prompt-cache edge cases reported after the rebase:
53a73febpreservesprevious_response_idfor incrementalfunction_call/custom_tool_callinputs.d52f2933treatscompaction/compaction_summaryinputs as full-transcript evidence and dropsprevious_response_idon that path.
Validation is green locally and on GitHub checks (close-when-agents-md-changed, ensure-no-translator-changes, build). The inline review threads have been replied to with the exact test commands. Please re-review when available.