Skip to content

Use remote compaction for compatible providers - #1

Open
lawrencecchen wants to merge 1 commit into
mainfrom
feat/subrouter-remote-compaction
Open

lawrencecchen wants to merge 1 commit into
mainfrom
feat/subrouter-remote-compaction

Conversation

@lawrencecchen

@lawrencecchen lawrencecchen commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Treat providers speaking the OpenAI Codex Responses API, including the local Subrouter alias, as Codex-compatible for remote compaction and checkpoint reinjection.

Tests: npm test; npm run check.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Summary by cubic

Enable Codex remote compaction and checkpoint reinjection for any model using the OpenAI Codex Responses API. Previously this ran only when provider was "openai-codex"; it now also runs when model.api is "openai-codex-responses" (e.g., local subrouter aliases).

  • Adds an isOpenAICodexModel type guard (provider === "openai-codex" OR api === "openai-codex-responses") and applies it in session_before_compact, before_provider_request, and before_provider_headers.
  • Extends fast mode service tier and x-codex-turn-state header to compatible providers.
  • No config changes required; providers set to api="openai-codex-responses" are treated as Codex-compatible automatically.

Written for commit 6ff93bd. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • Improvements
    • Expanded support for OpenAI Codex-compatible models across supported connection configurations.
    • Improved handling of remote context compaction for eligible models.
    • Enhanced request processing and retry behavior for Codex interactions.
    • Increased reliability when continuing interrupted or retried turns.

@coderabbitai

coderabbitai Bot commented Aug 13, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

OpenAI Codex protocol handling

Layer / File(s) Summary
Expand Codex model detection
extensions/pi-codex.ts
isOpenAICodexModel is now a type guard. It recognizes the openai-codex provider and the openai-codex-responses API.
Apply the expanded protocol check
extensions/pi-codex.ts
Remote compaction, fast-mode requests, remote checkpoints, and retry turn-state headers now use the expanded model check.

Estimated code review effort: 2 (Simple) | ~10 minutes

Mergeability Score: ⚪ Minimal · up to 6ff93

This localized provider-detection change is merge-ready after normal checks; no actionable merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: enabling remote compaction for providers that use compatible Codex protocols.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/subrouter-remote-compaction

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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6ff93bdc12

ℹ️ 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".

Comment thread extensions/pi-codex.ts
// Codex-compatible providers can be local/subrouter aliases while still
// speaking the OpenAI Responses protocol. Keep the remote compaction and
// checkpoint lifecycle attached to the protocol, not only the provider name.
return model?.provider === "openai-codex" || model?.api === "openai-codex-responses";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Gate remote compaction on an explicit capability

For a custom provider that uses openai-codex-responses for ordinary Responses requests but does not implement Codex RemoteCompactionV2 or use a ChatGPT OAuth JWT, this predicate now intercepts automatic compaction instead of leaving it to Pi's local summarizer. The handler subsequently calls buildCompactHeaders, which extracts a ChatGPT account claim from the token, and posts a compaction_trigger; an API-key proxy or partial implementation therefore throws when the context reaches the compaction boundary and prevents the session from continuing. Restrict this to known compatible aliases or an explicit remote-compaction capability rather than treating the transport API as sufficient.

Useful? React with 👍 / 👎.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 `@extensions/pi-codex.ts`:
- Around line 105-109: Add regression coverage for isOpenAICodexModel using a
model with a non-"openai-codex" provider and api set to
"openai-codex-responses". Exercise the relevant remote compaction, checkpoint
reinjection, and retry turn-state paths to verify API-only Codex detection
preserves all lifecycle 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: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 9d81a28a-0c5d-47e7-b536-438c127ff36c

📥 Commits

Reviewing files that changed from the base of the PR and between c4774c9 and 6ff93bd.

📒 Files selected for processing (1)
  • extensions/pi-codex.ts

Comment thread extensions/pi-codex.ts
Comment on lines +105 to +109
function isOpenAICodexModel(model: Model<any> | undefined): model is Model<any> {
// Codex-compatible providers can be local/subrouter aliases while still
// speaking the OpenAI Responses protocol. Keep the remote compaction and
// checkpoint lifecycle attached to the protocol, not only the provider name.
return model?.provider === "openai-codex" || model?.api === "openai-codex-responses";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Add regression coverage for API-only Codex detection.

The supplied tests keep provider: "openai-codex", including the remote-compaction test. They do not prove that a different provider using api: "openai-codex-responses" receives compaction, checkpoint reinjection, and retry turn-state handling. Add one API-only model case to prevent regression to provider-only detection.

🤖 Prompt for 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.

In `@extensions/pi-codex.ts` around lines 105 - 109, Add regression coverage for
isOpenAICodexModel using a model with a non-"openai-codex" provider and api set
to "openai-codex-responses". Exercise the relevant remote compaction, checkpoint
reinjection, and retry turn-state paths to verify API-only Codex detection
preserves all lifecycle behavior.

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