fix(proxy): support remote compaction v2 passthrough - #1404
Conversation
📝 WalkthroughWalkthrough本次变更支持远程压缩 v2。代理识别 Changes远程压缩 v2 请求处理
Estimated code review effort: 3 (Moderate) | ~30 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/app/v1/_lib/proxy/remote-compaction.ts`:
- Line 1: Replace the relative imports with the `@/` path alias: update
src/app/v1/_lib/proxy/remote-compaction.ts lines 1-1 to import endpoint-paths
from `@/app/v1/_lib/proxy/endpoint-paths`; update src/app/v1/_lib/proxy/session.ts
lines 38-38 similarly, and lines 51-51 to import remote-compaction from
`@/app/v1/_lib/proxy/remote-compaction`.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 05b4fb56-f2ac-4add-b791-43a60ecfb9e6
📒 Files selected for processing (12)
src/app/v1/_lib/proxy/message-service.test.tssrc/app/v1/_lib/proxy/message-service.tssrc/app/v1/_lib/proxy/remote-compaction.tssrc/app/v1/_lib/proxy/response-handler.tssrc/app/v1/_lib/proxy/session.tssrc/app/v1/_lib/proxy/stream-gate/frame-classifier.tstests/unit/proxy/proxy-forwarder-raw-passthrough-regression.test.tstests/unit/proxy/proxy-handler-public-success.test.tstests/unit/proxy/remote-compaction-v2.test.tstests/unit/proxy/response-handler-bill-non-success.test.tstests/unit/proxy/stream-gate-content-gate.test.tstests/unit/proxy/stream-gate-frame-classifier.test.ts
🧪 测试结果
总体结果: ✅ 所有测试通过 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5a4f2dff0d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Code Review Summary
I found one high-confidence defect in the new remote-compaction classification path. A supported /v1/responses input shape is still routed through the normal conversation policy, which means this PR does not fully preserve the /v1/responses/compact raw-passthrough and non-billing semantics it is introducing.
PR Size: M
- Lines changed: 295
- Files changed: 12
Issues Found
| Category | Critical | High | Medium | Low |
|---|---|---|---|---|
| Logic/Bugs | 0 | 1 | 0 | 0 |
| Security | 0 | 0 | 0 | 0 |
| Error Handling | 0 | 0 | 0 | 0 |
| Types | 0 | 0 | 0 | 0 |
| Comments/Docs | 0 | 0 | 0 | 0 |
| Tests | 0 | 0 | 0 | 0 |
| Simplification | 0 | 0 | 0 | 0 |
Critical Issues (Must Fix)
None.
High Priority Issues (Should Fix)
src/app/v1/_lib/proxy/remote-compaction.ts:12—isRemoteCompactionV2Request()rejects single-objectinputpayloads even though the proxy already supports that/v1/responsesshape vianormalizeResponseInput()/rectifyResponseInput(). As a result,{ input: { type: "compaction_trigger" } }keeps the normal/v1/responsespolicy instead of the managed/v1/responses/compactraw-passthrough/non-billing behavior.
Review Coverage
- Logic and correctness
- Security (OWASP Top 10)
- Error handling
- Type safety
- Documentation accuracy
- Test coverage
- Code clarity
Automated review by Codex AI
There was a problem hiding this comment.
- Reviewed PR
#1404, applied thesize/Mlabel, and submitted the GitHub review summary. - Posted 1 inline high-priority comment on
src/app/v1/_lib/proxy/remote-compaction.ts:12. - The defect:
isRemoteCompactionV2Request()only recognizes array-shapedinput, but the proxy already supports single-object/v1/responsesinputs via the response-input rectifier, so{ input: { type: "compaction_trigger" } }stays on the normal/v1/responsespolicy instead of the managed/v1/responses/compactraw-passthrough/non-billing path. - I also called out the needed regression test for that object-form request shape.
If you want, I can do a follow-up review pass after the author pushes a fix.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/app/v1/_lib/proxy/session.ts`:
- Around line 1203-1211: Update syncRequestBodyFromMessage so the serialization
failure uses the existing server-side next-intl error-message mechanism instead
of a hardcoded English ProxyError message. Add the corresponding translation key
and values for zh-CN, zh-TW, en, ja, and ru, while preserving the 400 status and
existing error behavior.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: a7311991-ccf7-458e-bfc1-acdeb8088451
📒 Files selected for processing (8)
src/app/v1/_lib/proxy-handler.tssrc/app/v1/_lib/proxy/remote-compaction.tssrc/app/v1/_lib/proxy/response-input-rectifier.tssrc/app/v1/_lib/proxy/session.tstests/unit/proxy/proxy-forwarder-raw-passthrough-regression.test.tstests/unit/proxy/proxy-handler-public-success.test.tstests/unit/proxy/remote-compaction-v2.test.tstests/unit/proxy/response-input-rectifier.test.ts
🧪 测试结果
总体结果: ✅ 所有测试通过 |
|
@coderabbitai review |
|
@codex review |
|
|
Codex Review: Didn't find any major issues. Nice work! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@coderabbitai review\n\n@codex review |
|
|
|
Codex Review: Didn't find any major issues. Breezy! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
🧪 测试结果
总体结果: ✅ 所有测试通过 |
Summary
compaction_triggeritems onPOST /v1/responses, including the repository-supported single-objectinputformrequest.message, raw wirebuffer, and auditlogsynchronized/v1/responsespath, query, headers, and native SSE while reusing the managed/v1/responses/compactendpoint policyraw_passthroughendpoints so opaque compaction streams are never parsed as unary JSONcompactionitems with non-emptyencrypted_contentas valid Responses stream contentnext-intlerror-code path for all five supported localesRoot Cause
Remote Compaction v2 uses a normal Responses stream with a
compaction_triggerinput item. The initial implementation classified only array-form input. BecauseProxySessionchooses its immutable endpoint policy before input rectification, object-form compaction requests remained on the conversation policy. Raw compaction requests could also enter fake streaming, where the fake-streaming path mutated only the parsed message while the raw forwarder sent the original buffer, causing a successful upstream SSE response to be parsed as unary JSON.Compatibility
compaction_triggerinput: [{...}]andinput: {...}are supportedcompaction, nested markers, strings, and future item names remain normal Responses requestsThe implementation also reviews Wei-Shaw/sub2api#5297. We retain its transparent wire/SSE invariants, but intentionally do not add its DeepSeek lossy-summary bridge, model-name heuristics, Base64 envelope, or cross-provider semantic conversion. Compaction state remains opaque and is forwarded unchanged.
Validation
bun run buildbun run lint:fixbun run lintbun run typecheckgit diff --checkAcceptance
Official protocol reference: https://developers.openai.com/api/docs/guides/compaction
Closes #1398
Greptile Summary
The PR adds Remote Compaction v2 passthrough while retaining the public Responses wire endpoint and reusing compact-endpoint management semantics.
compaction_triggeritems in array and object input forms.Confidence Score: 5/5
The PR appears safe to merge.
No blocking failure remains.
Important Files Changed
Sequence Diagram
Reviews (4): Last reviewed commit: "test(proxy): cover localized normalizati..." | Re-trigger Greptile
Context used: