Skip to content

feat(agent): add automatic compaction#82

Open
hakula139 wants to merge 13 commits into
mainfrom
feat/auto-compaction
Open

feat(agent): add automatic compaction#82
hakula139 wants to merge 13 commits into
mainfrom
feat/auto-compaction

Conversation

@hakula139
Copy link
Copy Markdown
Owner

@hakula139 hakula139 commented May 12, 2026

Summary

Adds default-on automatic context compaction on top of /compact: streaming usage from completed turns now acts as the trigger signal, and the agent compacts before recording the next user prompt when the active model is near its safe window.

Design decisions

  • Use response usage as the trigger signal. Auto-compaction listens to the API usage values already returned during streaming, keeping the trigger tied to actual request pressure.
  • Compact at prompt boundaries. The trigger runs before the next prompt is recorded, so tool results have already been consumed by the assistant before any transcript replacement.
  • Share the manual compaction boundary. Manual and automatic compaction both persist Entry::Compact, reset the file tracker, and replace the live transcript through the same boundary helper.
  • Keep thresholds model-aware. Defaults come from known context windows, percent overrides are capped by the safe trigger, and explicit token thresholds are rejected when they are too low or unsafe for the active model.
  • Bound automatic failures. Automatic compaction logs failures and stops retrying after repeated errors, while manual /compact remains available.

Changes

File Description
agent.rs, agent/compaction.rs, agent/compact_boundary.rs, main.rs Track streaming usage, compact before prompt recording, preserve queued prompts during summarization, reset the automatic failure breaker on config swaps, and isolate compact-boundary side effects.
config.rs, config/file.rs, client/anthropic.rs, slash/config.rs, slash/status.rs Add model-aware threshold policy, merge threshold modes as one setting, improve percent-threshold diagnostics, re-resolve compaction on model swaps, and display resolved auto-compaction state.
tui/app.rs, agent/event.rs Show automatic compaction as an active compacting state, preserve the triggering prompt after the compact boundary, render stdio compact boundaries, and keep queued prompts from draining early.
docs/design/agent/auto-compaction.md, docs/research/agent/auto-compaction.md, docs/guide/configuration.md, docs/roadmap.md, CLAUDE.md Document the implemented trigger flow, threshold limits, user-facing behavior, and module layout.

Test plan

  • cargo fmt --all --check
  • cargo build
  • cargo clippy --all-targets -- -D warnings: zero warnings
  • cargo test: 2001 tests pass
  • cargo llvm-cov --ignore-filename-regex 'main\\.rs': 98.64% line coverage
  • pnpm lint
  • pnpm spellcheck

@hakula139 hakula139 added documentation Improvements or additions to documentation enhancement New feature or request labels May 12, 2026
@hakula139 hakula139 self-assigned this May 12, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 12, 2026

Codecov Report

❌ Patch coverage is 99.73457% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/oxide-code/src/config.rs 99.39% 2 Missing ⚠️
crates/oxide-code/src/tui/app.rs 99.24% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant