Skip to content

feat(agent): add provider-native Codex compaction - #733

Open
paralin wants to merge 1 commit into
PrimeIntellect-ai:mainfrom
paralin:feat/codex-native-compaction
Open

feat(agent): add provider-native Codex compaction#733
paralin wants to merge 1 commit into
PrimeIntellect-ai:mainfrom
paralin:feat/codex-native-compaction

Conversation

@paralin

@paralin paralin commented Aug 6, 2026

Copy link
Copy Markdown

Use provider-native OpenAI Codex compaction instead of always producing a local plaintext summary.

The provider API exposes optional native compaction. Codex uses the normal V2 Responses stream with the compaction method and falls back to the legacy compact endpoint when required. Requests reuse the existing conversion, authentication, account, session, compatibility, and custom-header handling, and are cancellable and bounded.

The coding agent persists provider-tagged opaque replacement history in its append-only session journal, replays it only for the matching provider, and restores the newest compatible portable boundary when models change or native compaction fails. Manual, automatic, and overflow compaction use the same native-first policy; unsupported providers and explicit opt-out continue using the local summarizer.

The branch includes the fixes from prior review for active-model replay guards, compaction entry identity, active-turn model switching, the placeholder assertion, and portable-boundary fallback.

Validation: 126 focused tests passed, 2 skipped; npm run check passed.

Note

Add provider-native compaction for OpenAI Codex with fallback to local summarization

  • Implements a compactNative function that calls a provider-registered compact capability (via compactOpenAICodexResponses) using the Codex V2 SSE endpoint, falling back to the V1 /compact endpoint on failure.
  • Provider-native compaction results carry opaque replacementHistory that is stored in CompactionEntry.providerNativeCompaction and replayed verbatim into subsequent Responses API requests via providerPayload on user messages.
  • buildSessionContext is now provider-aware: it selects the most recent compatible compaction boundary and, when a native result is present, injects it as an openaiResponsesHistory payload instead of a text summary.
  • Switching models (via setModel, cycleAvailableModels, etc.) triggers a provider-aware message rebuild; during active streaming, this rebuild is deferred until streaming and queued events quiesce.
  • A new compaction.native setting (default true) controls preference for native compaction; setting it to false forces local LLM-based summarization.
  • Risk: sessions restored with a native compaction boundary will silently fall back to re-expanding raw history if the active provider does not match the stored compaction provider.

Macroscope summarized b62e26b.

Comment thread packages/coding-agent/src/core/session-manager.ts Outdated
Comment thread packages/coding-agent/src/core/compaction/compaction.ts
Comment thread packages/coding-agent/src/core/agent-session.ts
Comment thread packages/coding-agent/test/suite/agent-session-compaction.test.ts
@paralin
paralin force-pushed the feat/codex-native-compaction branch from ef40999 to b4383d7 Compare August 6, 2026 12:19

@cursor cursor 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.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit b4383d7. Configure here.

Comment thread packages/coding-agent/src/core/compaction/compaction.ts Outdated
@paralin
paralin force-pushed the feat/codex-native-compaction branch from b4383d7 to 00ced4e Compare August 6, 2026 17:33
@paralin

paralin commented Aug 6, 2026

Copy link
Copy Markdown
Author

All findings addressed.

@paralin
paralin force-pushed the feat/codex-native-compaction branch from 00ced4e to 6f9fab5 Compare August 6, 2026 22:07
zhengr pushed a commit to zhengr/prime-agent that referenced this pull request Aug 8, 2026
zhengr pushed a commit to zhengr/prime-agent that referenced this pull request Aug 8, 2026
- Add OpenAI Codex official support entry
- Add pi-internal:// URL scheme
- Add ctx.shutdown() fix (PrimeIntellect-ai#756)
- Add OpenAI Codex retry logic (PrimeIntellect-ai#733)
- Add third-party contributions:
  - PrimeIntellect-ai#702 by @aliou (custom tool HTML export)
  - PrimeIntellect-ai#728 by @richardgill (frontmatter parsing, SelectList fix)
  - PrimeIntellect-ai#747 by @kaofelix (tree filter shortcuts)
  - PrimeIntellect-ai#752 by @richardgill (keymap expansion)
@paralin
paralin force-pushed the feat/codex-native-compaction branch from 6f9fab5 to b62e26b Compare August 12, 2026 22:30
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