Repository navigation
fix(acp): trigger automatic compaction from provider context usage - #64
Conversation
|
Added the configured compaction-mode tooltip in 4a4f25a, with custom descriptions preserved and both legacy modes and modern config options covered. Refactoring is separate in #67 and based on this PR. Both changes are synced to yan-ad/crabcode:yan-flavor at 62a9a4f; flavor validation passes (61 ACP, 21 compaction, 4 stdio tests, with five repeated parallel stdio runs). Existing flavor lifecycle behavior and concurrent install/upgrade commits are preserved. |
|
Confidence: 4/5The fix is correct as far as I can verify and the new end-to-end test really exercises it. I hold back one point for two reasons. The token accounting is heuristic (it only counts a provider observation once, using max() over parts). It is also stacked with #67, which rewrites the same file. Checks run (worktree of the PR head 4a4f25a, separate target dir):
Confidence bumps:
SummaryACP auto-compaction used only the persisted-transcript estimate, so sessions whose real provider-reported context was above the threshold never auto-compacted. Only
Scope is limited to Mapflowchart LR
P[prompt in service.rs] --> SP[compose system prompt]
SP --> M[maybe_auto_compact_session]
M --> C[acp_context_tokens]
C --> K[session::compaction totals and markers]
M --> N[notify_compaction: text + usage_update]
P --> R[acp_request_messages: filter archived history]
P --> S[receive_prompt_stream: stamps acp_prompt_tokens on usage parts]
T[tests/acp_stdio.rs mock provider] -.-> P
Start at Regressions
MigrationsNone. A new optional Before merging
|
Resolve tests/acp_stdio.rs against Blankeos#64's mock provider harness and pass the new prompt-token argument in the provider failure tests.
Summary
Fix ACP automatic compaction using the context usage reported by the provider, rather than only the persisted transcript estimate. Sessions could show usage beyond the configured threshold while never automatically compacting;
/compactstill worked because it bypasses that threshold gate.ACP versus TUI context and credit analysis
ACP does not have a separate larger model context limit or credit allowance. Both paths use the model's configured/discovered limits, the shared compaction threshold (
context_window - reserved), and the same provider/tool loop.Before this fix:
Delayed compaction can increase billed input because each model/tool request resends a larger context; cached input still occupies the context window and can carry provider-dependent charges. Cumulative billed usage is not the same thing as current context size. This change does not claim measured cost savings or change provider pricing.
Remaining differences outside this focused fix: TUI scopes prompt tool guidance to the active agent, whereas ACP composes it from the full registry. Both paths still check automatic compaction at turn boundaries, not midway through a running tool loop. Auto-compaction still requires known model limits and a sufficiently large compactable head, and compaction failures remain logged rather than making the prompt fail.
Validation
cargo test acp:: --bin crabcode: 75 passed.cargo test session::compaction:: --bin crabcode: 21 passed.cargo test --test acp_stdio: 8 passed, including the local mock-provider regression (also run repeatedly on its own).cargo fmt --all -- --checkandgit diff --check: passed.cargo test --bin crabcode -- --test-threads=1: 1,850 passed, 3 ignored, 1 unrelated existing failure:ui::components::chat::tests::test_edit_tool_renders_codex_style_diff_summaryexpects a basename from a hardcoded/Users/carlo/Desktop/Projects/crabcodepath on another checkout. The parallel full-unit run additionally exposes existing catalog/Ollama shared-state test failures.Built the required remote-client assets using the existing
remote-client-buildrecipe's Bun commands before Rust validation; no dependency or generated-asset changes are included.Follow-up: compaction mode tooltip
A configured visible
compactionagent without a description now advertisesCompaction agent. Summarizes conversation context for continued work.in both legacyavailableModesand modern modeconfigOptions. Explicit descriptions remain unchanged. This does not add a built-in selectable compaction agent, expose hidden/subagents, or change how automatic compaction runs.