Skip to content
Source
Sign inSign up
pingdotgg/t3code

feat(providers): add context compaction command #9293

Mergedmaria-rcksmerged 30 commits intomain fromrefs/pull/9293/headmerged by maria-rcks View on GitHub

maria-rckscommented

adds /compact to the web and mobile composer for codex, claude, cursor, grok, and opencode, with provider capability gating and remote support. codex and opencode use native compaction APIs, while claude, cursor, and grok use each harness command.

web and mobile now show a compaction icon with Compacting… while the provider is working, then replace it with the completed divider and token counts when available. correlated completion and failure activities prevent stale compaction labels.

codex, compaction in progress:

codex compaction in progress

codex, completed:

codex compaction completed

e2e recording:

real t3 code compaction e2e

verified with the focused provider suite, affected package typechecks, focused lint, and real t3 code sessions on codex and opencode. implemented with gpt-5.6-sol in the codex harness.

Note

Add /compact context compaction command across providers and clients

  • Server: Adds compactThread to the ProviderService and ProviderAdapter interfaces, with native support for Codex and OpenCode, and fallback slash-command dispatch for Cursor and other providers.
  • Orchestration: ProviderCommandReactor processes /compact user messages, invokes compactThread, and blocks ordinary turns while compaction is active.
  • Clients: Web and mobile UI expose /compact as a slash command when the selected provider supports it, display a "Compacting…" status, and render compaction activity groups in the thread feed.
  • Behavioral Change: ProviderCommandReactor.thread.session.stop now emits a provider.session.stop.failed activity and may restore the session to ready instead of unconditionally recording the thread as stopped.
  • Behavioral Change: ProviderRuntimeIngestion.buildContextWindowActivityPayload now generates a context-window activity for zero used tokens.
Macroscope summarized 6dc7149.

Note

High Risk Changes orchestration turn handling, provider session lifecycle, and pending-turn projection around compaction; race conditions or mismatched requestId correlation could block turns or leave sessions in a bad state.

Overview Adds end-to-end context compaction via /compact (and Cursor’s /compress fallback) across Codex, Claude, Cursor, Grok, and OpenCode, with a shared compactThread path on the server and optional native adapter hooks.

Server: ProviderCommandReactor treats bare /compact as compaction instead of a normal turn—validates conversation context, serializes against active turns, calls ProviderService.compactThread, and restores the session on failure. ProviderService runs one compaction per thread (native API or slash-command turn), correlates thread.state.changed / turn completion with requestId, and enforces timeouts. Projection and runtime ingestion clear pending turn starts only for the matching compaction activity and emit richer context-compaction rows (token before/after when known).

Clients: Web and mobile show Compacting… while compaction is in flight, render compaction as a dedicated timeline divider, and hide /compact in the slash menu unless the thread is compactable and the provider supports it. Web also treats correlated provider.turn.start.failed as dispatch acknowledgment so failed compacts don’t leave the UI stuck.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 6dc7149254d7e93836cf8f1f72751dd50deac31f. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).
    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    2. apps/server/src/provider/Layers/ProviderService.ts line 1010OutdatedResolvedby maria-rcks
    3. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Not approved

      Macroscope's review found this PR not approvable — This PR introduces context compaction as a new cross-provider workflow, including native integrations, fallback turns, session lifecycle recovery, event correlation, durable projection changes, and web/mobile UI states. Its asynchronous state management and effect on subsequent turns make the runtime impact too broad for automatic approval.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. apps/web/src/components/ChatView.tsx line 2947OutdatedResolvedby maria-rcks

Sign in to join this conversation.