CLIProxyAPI icon indicating copy to clipboard operation
CLIProxyAPI copied to clipboard

fix(codex): stabilize OpenCode prompt caching

Open wozhenbang2004 opened this issue 7 months ago • 6 comments

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 .

wozhenbang2004 avatar Apr 24 '26 07:04 wozhenbang2004

This pull request targeted main.

The base branch has been automatically changed to dev.

github-actions[bot] avatar Apr 24 '26 07:04 github-actions[bot]

This pull request targeted main.

The base branch has been automatically changed to dev.

github-actions[bot] avatar Apr 24 '26 07:04 github-actions[bot]

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)

StageDog avatar Apr 29 '26 18:04 StageDog

Rebased this PR onto current dev (3a54fb7f) and force-pushed the refreshed head 6f673d3c.

Validation:

  • git diff --check origin/dev...HEAD
  • go test -run 'TestCodexExecutorCacheHelper|TestCodexExecutorExecute.*PreviousResponseID' ./internal/runtime/executor
  • go test ./...
  • GitHub checks are green: close-when-agents-md-changed, ensure-no-translator-changes, and build

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.

wozhenbang2004 avatar May 31 '26 06:05 wozhenbang2004

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...HEAD
  • go test -run 'TestCodexExecutorCacheHelper|TestCodexExecutorExecute.*PreviousResponseID|TestTranslateCodexRequestPair' ./internal/runtime/executor
  • go test ./internal/runtime/executor ./internal/runtime/executor/helps ./internal/translator/codex/... ./sdk/api/handlers/openai
  • go test ./...
  • GitHub checks are green again: close-when-agents-md-changed, ensure-no-translator-changes, and build

Current compare state is ahead 4 / behind 0 against dev.

wozhenbang2004 avatar May 31 '26 13:05 wozhenbang2004

@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:

  • 53a73feb preserves previous_response_id for incremental function_call / custom_tool_call inputs.
  • d52f2933 treats compaction / compaction_summary inputs as full-transcript evidence and drops previous_response_id on 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.

wozhenbang2004 avatar May 31 '26 13:05 wozhenbang2004