-
Notifications
You must be signed in to change notification settings - Fork 410
fix(compact): sanitize plaintext compaction replays #1720
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Komzpa
wants to merge
7
commits into
Soju06:main
Choose a base branch
from
Komzpa:fix/sanitize-encrypted-compaction-replays
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f77e0e4
fix(compact): sanitize plaintext compaction replays
Komzpa 4b47c75
fix(compact): preserve opaque compaction replays
Komzpa 23513c5
fix(compact): preserve tool search pairs
Komzpa edde0b1
fix(proxy): accept compact tool-search replay state
Komzpa c5b5f9d
fix(http-bridge): switch silent account-neutral retries
Komzpa 0ff7778
test(compact): avoid stack conflict for replay coverage
Komzpa db7ce90
fix(proxy): reject owner-bound replay state
Komzpa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
17 changes: 17 additions & 0 deletions
17
openspec/changes/preserve-opaque-compaction-replays/proposal.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| ## Why | ||
|
|
||
| PR #1720 rewrites plaintext compaction replays before forwarding them upstream, but the current branch still treats only one ciphertext shape as provider-authored. Any other non-empty `encrypted_content` string is rewritten into synthetic assistant text, which drops the authoritative compact item identity and ciphertext even though the proxy's own compaction output normalizer preserves opaque encrypted strings unchanged. | ||
|
|
||
| The branch also synthesizes assistant replacements after request validation, so compact replays forwarded as plaintext summaries can bypass the canonical assistant-content normalization path and still reach upstream with raw string `content`. | ||
|
|
||
| ## What Changes | ||
|
|
||
| - Preserve any compaction item that already carries string `encrypted_content`; only rewrite plaintext summary/text/content shapes that lack encrypted payload. | ||
| - Emit rewritten plaintext compact-state summaries in canonical assistant `output_text` form so both standard and compact Responses payloads stay upstream-compatible. | ||
| - Document the replay-sanitization contract under `responses-api-compat`. | ||
|
|
||
| ## Impact | ||
|
|
||
| - Prevents compact replay continuity loss for opaque provider envelopes. | ||
| - Keeps plaintext local summaries replay-safe without relying on post-validation string content. | ||
| - Aligns PR #1720's behavior change with the repository's OpenSpec-first merge gate. |
19 changes: 19 additions & 0 deletions
19
...c/changes/preserve-opaque-compaction-replays/specs/responses-api-compat/spec.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| ## ADDED Requirements | ||
|
|
||
| ### Requirement: Compaction replay sanitization preserves opaque encrypted state | ||
|
|
||
| When a standard or compact Responses request replays a historical compaction item, the proxy MUST preserve that item unchanged whenever it already carries string `encrypted_content`. The proxy MUST NOT infer local plaintext provenance from ciphertext prefix or length heuristics, and MUST NOT replace such an item with synthetic assistant text solely because the encrypted payload shape is unfamiliar. | ||
|
|
||
| When the replayed compaction item instead carries plaintext `summary`, `text`, or text-bearing `content` without string `encrypted_content`, the proxy MAY rewrite it into assistant context for upstream compatibility. Any assistant replacement synthesized during request serialization MUST use the canonical assistant content schema (`output_text` content parts), not a raw string `content` field. | ||
|
|
||
| #### Scenario: compact replay keeps opaque encrypted content | ||
|
|
||
| - **WHEN** `/backend-api/codex/responses/compact` receives a replayed `compaction` item whose `encrypted_content` is a non-empty opaque string | ||
| - **THEN** the forwarded upstream payload preserves that compaction item unchanged | ||
| - **AND** its `id`, `status`, and `encrypted_content` remain intact | ||
|
|
||
| #### Scenario: plaintext compact summary rewrites to canonical assistant content | ||
|
|
||
| - **WHEN** a replayed compact request contains a historical `compaction` item with plaintext `summary` and no string `encrypted_content` | ||
| - **THEN** the proxy rewrites it to an assistant item with `content` as an `output_text` array | ||
| - **AND** the synthesized text begins with the compact-state prefix used for local plaintext summaries |
13 changes: 13 additions & 0 deletions
13
openspec/changes/preserve-opaque-compaction-replays/tasks.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| ## 1. Spec | ||
|
|
||
| - [x] 1.1 Add a `responses-api-compat` delta for compact replay sanitization requirements. | ||
|
|
||
| ## 2. Implementation | ||
|
|
||
| - [x] 2.1 Preserve opaque encrypted compaction items instead of inferring ciphertext provenance from prefix shape. | ||
| - [x] 2.2 Normalize synthesized plaintext compact-state assistant replacements to canonical `output_text` content arrays. | ||
|
|
||
| ## 3. Verification | ||
|
|
||
| - [x] 3.1 Run focused unit/integration pytest coverage for compact replay handling. | ||
| - [x] 3.2 Run `ruff check` and `ruff format --check` on touched files. |
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.