Repository navigation
fix(opencode): keep mid-conversation system messages in place - #200
Open
salty-flower wants to merge 1 commit into
Open
salty-flower wants to merge 1 commit into
salty-flower wants to merge 1 commit into
Conversation
Claude Code appends a system message mid-conversation on most turns (output-style notices, hook context, environment updates). The Chat Completions translator hoisted each one into the leading system message, so the start of the prompt changed on every request and the upstream prefix cache could only reuse the part before it: Claude Code sessions on OpenCode Go hit about 8% cache, against 97% for the same model from OpenCode itself. Each such message now stays at its position as a user message wrapped in <system-reminder>, so the upstream prompt is append-only. It is not kept as a system message because chat templates such as DeepSeek's gather every system message to the front, which would void the cache again. A reminder that lands between an assistant tool call and its results waits until those results are in place. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Claude Code sessions routed to OpenCode Go now reuse the upstream prompt cache instead of re-reading almost the whole conversation on every request.
Why: Claude Code appends a
role: "system"message mid-conversation on most turns (output-style notices, hook context, environment updates). The Chat Completions translator moved each of them into the leading system message → the start of the prompt changed on every request → the upstream prefix cache could only reuse what came before the change. In practice, Claude Code sessions onopencode-go/deepseek-v4.1-flashhit about 8% cache, while the same model called from OpenCode itself hits about 97%. The cached part grew only in 128-token steps, matching the old system string's length, and a near-full hit appeared only after turns that added no system message.What changes in
build_messages:systemfield.<system-reminder>(left as-is if it is already wrapped), so the upstream prompt is append-only.What to check: whether a user-role reminder is the shape you want for these messages, compared with the Kimi translator, which keeps them as system messages outside K3 mode.
Validation:
cargo test: all suites pass (1,141 tests), including two new regressions. One asserts that the translated messages of a later turn start with the earlier turn's messages exactly. The other covers the deferred reminder.cargo fmt --checkandcargo clippy --all-targets -- -D warningsare clean.cached_tokens7552 of 7689. I have not run it against OpenCode Go itself yet.🤖 Generated with Claude Code