Skip to content

Add manual context compaction across providers - #1152

Open
ymichael wants to merge 13 commits into
mainfrom
bb/investigate-linked-issue-thr_55qgqrvxee
Open

Add manual context compaction across providers#1152
ymichael wants to merge 13 commits into
mainfrom
bb/investigate-linked-issue-thr_55qgqrvxee

Conversation

@ymichael

@ymichael ymichael commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • add provider-aware manual context compaction through the app, public API, SDK, and bb thread compact
  • use native provider operations for Codex, Claude Code, and Pi, and OpenCode's provider-local /compact control through ACP
  • model compact requests as acceptance: validation/transport failures reject immediately, while eventual success, failure, or interruption is reported by the thread timeline
  • keep compaction maintenance prompts and output out of the conversation transcript, while showing their lifecycle as a normal visible maintenance turn
  • leave Cursor ACP and undeclared ACP agents unsupported until they expose a verified provider-local compaction control; custom ACP agents can explicitly configure an exact prompt
  • add pnpm dev:stop for stopping this worktree's dev server and desktop processes
  • bump the host daemon protocol to 82 for the compact command and its acceptance-result semantics

Provider behavior

Provider Strategy
Codex Native thread compaction
Claude Code Provider /compact command
Pi Direct SDK compaction
OpenCode ACP Provider-local /compact maintenance prompt
Cursor ACP Unsupported: Cursor's interactive /compress is not an ACP compaction control
Custom ACP Explicit provider-local prompt configuration
Other ACP agents Manual compaction unavailable by default

Request and lifecycle semantics

The compact endpoint returns after the provider accepts the maintenance operation; it does not wait for the provider to finish. The provider bridge emits the start event before acknowledging OpenCode/ACP, and both ACP and Pi report terminal status through their existing compaction lifecycle events. This keeps the HTTP result and timeline from contradicting each other when a provider rejects or interrupts work after it has started.

The composer therefore uses its normal submit behavior: accepted /compact actions stay cleared, while genuine pre-acceptance failures restore the draft. The UI and CLI no longer claim that compaction completed based only on the request response.

This branch does not summarize or reseed provider sessions.

Validation

  • agent runtime: 839 tests passed; typecheck passed
  • app: 2,418 tests passed; typecheck passed
  • CLI: 375 tests passed; typecheck passed
  • templates: 22 tests passed; typecheck passed
  • host daemon contract: 49 tests passed; typecheck passed
  • affected-package lint passed with pre-existing warnings only
  • ACP bridge tests verify that the request is acknowledged before completion and that a later provider rejection becomes a failed timeline lifecycle rather than an HTTP failure
  • Pi bridge tests verify that the request is acknowledged before the SDK's terminal outcome
  • earlier live CLI checks against this worktree verified Pi native compaction and OpenCode's provider-local /compact flow

Diff shape after cleanup

The current diff is 2,204 additions / 119 deletions across 81 files:

  • 803 handwritten product and contract lines
  • 1,043 test lines
  • 332 generated SDK/template lines
  • 26 documentation lines

The cleanup removed the unused public provider capability, the alternate compaction-through-threads.send path, repeated test setup, a stale 20-minute request timeout, and two-boolean ACP prompt state. The ACP bridge now uses one explicit turn / compaction / idle state.

Fixes #1103

@ymichael
ymichael marked this pull request as ready for review August 7, 2026 20:00
@SawyerHood

SawyerHood commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

🚨 SLOP COP 🚨 · review

I am SlopCop. I am reviewing this pull request for security, code quality, performance, architecture, and end-to-end behavior.

I will post one final review after the parallel checks finish.

@ymichael
ymichael force-pushed the bb/investigate-linked-issue-thr_55qgqrvxee branch from 9a63de9 to 041b652 Compare August 7, 2026 20:03
Comment thread packages/agent-runtime/src/acp/bridge/bridge.ts Outdated
Comment thread apps/server/src/routes/projects.ts
Comment thread apps/host-daemon/src/command-dispatch.ts Outdated
Comment thread packages/agent-runtime/src/claude-code/bridge/bridge.ts
Comment thread packages/domain/src/shared-types.ts
Comment thread apps/app/src/hooks/mutations/thread-runtime-mutations.ts Outdated
Comment thread apps/host-daemon/src/command-router.ts
Comment thread packages/agent-runtime/src/pi/adapter.ts

@SawyerHood SawyerHood left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🚨 SLOP COP 🚨 · review

ELI5: This change adds a context clean-up command for several providers. Some providers finish incorrectly, block other work, or expose the command too early.

I reviewed the requested SHA 9a63de9699e8a5beea001a336df9fb6fedcb87eb. The pull request later moved to 041b652e, but these code paths remain unchanged.

I found these defects:

  • [P1] Non-Codex compaction takes a shared provider write lane. A stalled request can block unrelated sessions for 20 minutes.
  • [P1] ACP prompt compaction hides tool activity but still permits file reads and writes.
  • [P2] The daemon does not retain the runtime during compaction.
  • [P2] Claude returns success when the SDK consumes /compact, before compaction completes.
  • [P2] Pi emits thread/compacted for aborted and failed compactions.
  • [P2] New-thread composers offer /compact before a thread exists.
  • [P2] Invalid mention ranges can replace a normal prompt with compaction.
  • [P3] Failed UI compactions refresh broad, unrelated query groups.

The implementation also repeats compact detection and draft recovery in four UI paths. One shared action can reduce this duplication.

The provider adapters use different completion rules. A shared terminal contract and the existing compaction lifecycle can prevent these differences.

I ran the branch dev app and used the browser command surface. Codex returned 200, showed compaction, and reduced context use from 7% to 2%.

The source CLI also compacted the same thread. Ten changed packages passed type checks, and 129 focused tests passed.

The full local run passed nine package tasks. One unrelated machine-install test failed, while GitHub checks passed.

@ymichael
ymichael force-pushed the bb/investigate-linked-issue-thr_55qgqrvxee branch from dc6f9f8 to 203228a Compare August 7, 2026 21:05
@ymichael

ymichael commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator Author

Review triage complete at 78396d4.

  • Fixed: ACP file-operation isolation, new-thread command scoping, runtime retention, invalid mention ranges, failure-only query churn, and shared-provider lane contention.
  • Already fixed on the current tip: Pi aborted/failed compactions no longer emit thread/compacted, with explicit regressions.
  • Intentional contract: Claude acknowledges when the SDK consumes the maintenance input; terminal outcome remains event-driven. HOST_DAEMON_PROTOCOL_VERSION 82 documents that acceptance boundary.

For the two general observations: compact detection is now centralized in isStandaloneBuiltinCompactCommand and shared by both submission controllers. Draft ownership remains controller-specific because the full thread composer and plugin/embedded composer have different persistence and callback lifecycles; combining those controllers is outside this feature. Provider-specific signals are already normalized into the shared compaction lifecycle, while command settlement consistently means accepted rather than terminally completed.

Verification on the new tip: all affected typechecks pass; full suites pass for domain (129), agent-runtime (840), host-daemon (493), and app (2,419).

@ymichael
ymichael force-pushed the bb/investigate-linked-issue-thr_55qgqrvxee branch from 78396d4 to c8a320c Compare August 7, 2026 23:04
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.

pi provider: no way to manually compact a thread's context

2 participants