fix: support Codex remote compaction v2 for DeepSeek models - #7
Open
skychentian wants to merge 1 commit into
Open
fix: support Codex remote compaction v2 for DeepSeek models#7skychentian wants to merge 1 commit into
skychentian wants to merge 1 commit into
Conversation
DeepSeek's Responses API does not emit the 'compaction' output item that Codex remote compaction v2 requires, so automatic compaction failed on every retry for DeepSeek-bound sessions. The router now intercepts requests containing compaction_trigger: it strips tools and the trigger, asks the same V4 Flash model for a compact handoff summary, and returns exactly one synthetic compaction output item before response.completed. The summary is sealed with AES-256-GCM using a key derived from the stable router token; later DeepSeek requests decrypt only DSCodex-prefixed compaction items and restore them as assistant summary context. Compaction never falls back to GPT and the summary is never stored as plaintext in the rollout file.
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.
Problem
When Codex triggers automatic context compaction (remote compaction v2) on a DeepSeek-bound session, DSCodex previously just renamed the model and forwarded the request unchanged. DeepSeek's Responses API answers with ordinary output items, but the Codex client requires exactly one
compactionoutput item — so automatic compaction failed on every retry and the session got stuck (502 / reconnect loop).Fix
The router now implements the compaction protocol for DeepSeek instead of forwarding the trigger raw:
compaction_triggeris detected; tools and the trigger are stripped.compactionoutput item, encrypted with AES-256-GCM using a key derived from the stable router token, and streamed back beforeresponse.completed.Compaction never falls back to GPT (a GPT-sealed blob would be undecryptable across providers anyway), and the summary is never stored as plaintext in the rollout JSONL.
Tests
compactionitem → next request decrypts and restores the summary as readable context.\\//separators) unrelated to this change.Docs
README (zh/en) and AGENTS.md updated with the new compaction behavior and its boundaries.