Skip to content

fix(compaction): keep compaction_trigger as final input item - #546

Open
ImogeneOctaviap794 wants to merge 1 commit into
james-6-23:mainfrom
ImogeneOctaviap794:fix/compaction-trigger-final-item
Open

fix(compaction): keep compaction_trigger as final input item#546
ImogeneOctaviap794 wants to merge 1 commit into
james-6-23:mainfrom
ImogeneOctaviap794:fix/compaction-trigger-final-item

Conversation

@ImogeneOctaviap794

@ImogeneOctaviap794 ImogeneOctaviap794 commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

What happened

Codex Responses requests can carry a compaction_trigger before a later input item. This showed up repeatedly with the Codex VS Code client build 26.814.41407 and was rejected upstream with:

The 'compaction_trigger' item must be the final input item.

Fix

  • Normalize direct compaction_trigger items after response-context expansion.
  • Keep one trigger and move it to the end of input while preserving all other items in order.
  • Apply the same check at the final Codex HTTP/WS and OpenAI Responses relay send boundaries.
  • Leave nested objects in tool output untouched.
  • Preserve object and string input when the legacy compact endpoint is rewritten.

Tests

  • Added request-body, response-cache continuation, Codex WebSocket, Codex HTTP, and OpenAI Responses relay coverage.
  • go test ./...
  • go vet ./...
  • frontend build, tests, typecheck, and audit gate

Summary by CodeRabbit

  • Bug Fixes

    • Ensured compaction triggers are unique and consistently placed at the end of request input.
    • Improved handling of string and object-form inputs while preserving valid request data.
    • Ignored nested tool-output values when detecting existing triggers.
    • Applied consistent behavior across HTTP, WebSocket, cached-history, Codex, and OpenAI Responses requests.
  • Tests

    • Added coverage for trigger ordering, deduplication, input preservation, and cached histories.

@coderabbitai

coderabbitai Bot commented Aug 18, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 01fcedf7-a4bd-4988-85c5-fff6ccb46a0d

📥 Commits

Reviewing files that changed from the base of the PR and between 89cd930 and 8a6a2d3.

📒 Files selected for processing (7)
  • proxy/compact_via_responses.go
  • proxy/compact_via_responses_test.go
  • proxy/executor.go
  • proxy/executor_test.go
  • proxy/response_cache_handler_test.go
  • proxy/translator.go
  • proxy/translator_test.go

Included review availability: Your plan includes up to 4 reviews per rolling hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

The change normalizes Responses request bodies so direct compaction_trigger items are unique and final. Codex and OpenAI preparation paths, cached histories, WebSocket execution, and HTTP execution now apply this ordering. Tests cover duplicate, nested, object-form, preparation, cache, and transport cases.

Changes

Compaction trigger finalization

Layer / File(s) Summary
Trigger normalization
proxy/compact_via_responses.go, proxy/compact_via_responses_test.go
Normalization removes direct duplicate triggers, preserves non-trigger items, handles string and object inputs, and appends one final trigger when required.
Response-body preparation
proxy/translator.go, proxy/translator_test.go
Codex and OpenAI Responses preparation moves the trigger to the final input position. Cached previous-response histories retain the normalized trigger in prepared and expanded input output.
Transport enforcement
proxy/executor.go, proxy/executor_test.go, proxy/response_cache_handler_test.go
WebSocket and HTTP execution normalize forwarded request bodies. Tests verify final trigger placement in transport and compaction fallback requests.

Estimated code review effort: 4 (Complex) | ~45 minutes

Merge Risk: ⚪ Minimal · up to 8a6a2

The change normalizes compaction triggers at request boundaries while preserving other input items and legacy input forms. No actionable merge-blocking risk remains beyond normal checks and review.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant PrepareResponsesBody
  participant normalizeCompactionTriggerFinal
  participant ResponsesExecutor
  participant UpstreamResponsesAPI
  Client->>PrepareResponsesBody: prepare Responses request body
  PrepareResponsesBody->>normalizeCompactionTriggerFinal: normalize input items
  normalizeCompactionTriggerFinal-->>PrepareResponsesBody: one final compaction_trigger
  PrepareResponsesBody->>ResponsesExecutor: forward prepared body
  ResponsesExecutor->>normalizeCompactionTriggerFinal: enforce final trigger ordering
  normalizeCompactionTriggerFinal-->>ResponsesExecutor: normalized request body
  ResponsesExecutor->>UpstreamResponsesAPI: send normalized request
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: keeping compaction_trigger as the final input item.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant