Skip to content

Emit and render threshold and manual compaction events - #765

Open
baixinghao wants to merge 1 commit into
huggingface:mainfrom
baixinghao:fix/auto-compaction-events
Open

baixinghao wants to merge 1 commit into
huggingface:mainfrom
baixinghao:fix/auto-compaction-events

Conversation

@baixinghao

Copy link
Copy Markdown

Summary

Fixes #506.

Threshold-based automatic compaction ran silently: when the context estimate crossed the auto-compact threshold, CodingSession issued the summarization request at a turn boundary with no events at all, so the TUI showed a finished answer followed by an unexplained spinner. Only the overflow path emitted CompactionStartEvent / CompactionEndEvent, even though CompactionReason already defines "manual" | "threshold" | "overflow".

Changes

src/tau_coding/session.py

  • Split _maybe_auto_compact into _auto_compact_plan() (threshold + plan checks) and _auto_compact_events() (execution). The latter is an async generator that yields CompactionStartEvent(reason="threshold") and CompactionEndEvent(reason="threshold", ...) around a real compaction run, and also forwards them to the extension runtime — mirroring how the overflow path both yields and emits. No plan means no events, so routine threshold checks stay silent.
  • A swallowed summarization exception now also yields CompactionEndEvent(reason="threshold", aborted=True, error_message=...), so failures are observable instead of only appearing in the diagnostic log.
  • All three auto-compact call sites (auto_compact_before_prompt, auto_compact_after_prompt, auto_compact_after_continue) forward the events into the prompt/continue streams. Compaction stays inside the enclosing turn: no extra AgentSettledEvent, so no extra turn-finished notification.
  • compact_detailed() (manual compaction) now emits CompactionStartEvent(reason="manual") / CompactionEndEvent(reason="manual", ...) through the extension runtime, including an aborted end event on failure, so extensions and non-TUI frontends get one consistent signal for every compaction kind. The TUI's own /compact flow is unchanged.

TUI rendering (tui/adapter.py, tui/app.py)

  • A … Compacting context transcript status item explains the post-answer wait while threshold compaction runs.
  • A failed threshold compaction shows … Auto-compaction failed: <error> instead of passing silently.
  • Overflow rendering is untouched.

Docs (website/content/guides/context.md): document the new status items.

Tests

  • test_threshold_auto_compaction_emits_exactly_one_start_end_pair — one adjacent start/end pair with reason="threshold" across the prompts that trigger compaction, and exactly one AgentSettledEvent per prompt.
  • test_auto_compact_check_without_work_emits_no_compaction_events — threshold checks that find no work emit nothing.
  • test_threshold_auto_compaction_failure_emits_aborted_end_event — a failing summary provider yields an aborted end event with the error message, the turn still completes, and nothing is persisted.
  • test_manual_compaction_emits_events_for_extensions — manual compaction emits one start/end pair with reason="manual" and the result attached.
  • test_tui_adapter_renders_threshold_compaction_status — status item on start, silence on success, failure status on aborted end.
  • test_tui_prompt_worker_explains_threshold_compaction_pause — end-to-end prompt-worker flow: answer renders, compaction status explains the pause, running state and notification bookkeeping stay owned by the turn.

uv run pytest tests/test_coding_session.py tests/test_tui_adapter.py tests/test_tui_app.py passes; ruff check / ruff format --check / mypy are clean on the touched files.

Note: this Windows checkout has ~40 pre-existing test failures on a clean main (TUI layout, updater, file-drop path handling, etc.). The failure list before/after this change is identical — no regressions.

This branch has not been deployed

No deployments
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.

Automatic threshold compaction is invisible in the TUI (no compaction events emitted)

1 participant