Skip to content

feat(tui): surface compaction-model context-limit cap in the TUI - #3811

Merged
dgageot merged 8 commits into
mainfrom
feat/context-compaction-limit-visibility
Jul 24, 2026
Merged

feat(tui): surface compaction-model context-limit cap in the TUI#3811
dgageot merged 8 commits into
mainfrom
feat/context-compaction-limit-visibility

Conversation

@aheritier

@aheritier aheritier commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Summary

When an agent configures a dedicated compaction_model whose context window is smaller than the primary model's, the runtime silently caps the session's effective context limit to that smaller window. Until now the TUI attributed the reduced limit entirely to the primary model, with no indication that a different model imposed it — so users were misled about how much context they actually had before compaction was forced.

This PR makes that cap explicit across the TUI, without changing any runtime capping behavior.

What changed

  • /context dialog — when (and only when) the compaction model actually caps the limit, a dedicated second header line appears:
    compaction cap: <model> • <N> tokens
    In the edge case where only the compaction window is resolvable (primary window unknown), the main limit line is re-attributed as limit: <N> tokens (from compaction model).
  • Sidebar gauge — shows a minimal ⚠ capped marker (no model name / figure) when capped; the /context header remains the authoritative source of the model and number.
  • Live-sessions rows — carry no cap wording (deliberately, to avoid on-screen redundancy).
  • RuntimeContextBreakdown, LiveSession, and AgentInfoEvent gained additive, cap-attribution fields (json omitempty); the effective ContextLimit semantics are unchanged so the usage bar, percentages, and free-space stay truthful.

Notes

  • No config or schema changes — compaction_model already exists.
  • The suspected "transposed values" in an earlier screenshot were investigated and confirmed not a bug: the cap values were correct; only the wording was ambiguous, which this PR fixes.
  • The scroll/selection math in the /context dialog now derives the header height from the actually-rendered header (rather than a hardcoded line count) so the variable-height header does not break navigation.

Validation

  • task build, task test, task lint all pass.
  • Unit tests cover capped / equal-or-larger / no-compaction-model / unresolvable-window cases across runtime and TUI.
  • Reviewed locally over multiple rounds; branch rebased onto latest main.

Screenshots

Before

Screenshot 2026-07-23 at 15 53 46 Screenshot 2026-07-23 at 13 59 39

After

Screenshot 2026-07-23 at 21 54 16 Screenshot 2026-07-23 at 21 54 10 Screenshot 2026-07-23 at 20 25 18

… model

When an agent's dedicated compaction model has a smaller context window
than the primary model, the effective context limit is silently capped
with no indication of why. Surface the cap's source by adding
CompactionModel, CompactionContextLimit and PrimaryContextLimit to
ContextBreakdown, LiveSession and AgentInfoEvent, populated only when
the compaction model actually caps the effective limit (strictly
smaller than the primary window).
Render the compaction-model cap attribution added in the runtime: a
dedicated warning-styled second header line in the /context dialog
(shown only when capped, reading "compaction cap: <model> • <N>
tokens"), a Q4 fallback that re-attributes the main meta line when
only the compaction window is resolvable, and a short "⚠ capped"
marker next to the sidebar context gauge. The /context header is the
sole authority on the cap’s model and figure; Live-sessions rows and
the sidebar marker intentionally stay silent on both to avoid
repeating (and risking mis-attributing) that detail elsewhere. The
header block’s height is now derived from its actual rendered content
instead of a hardcoded constant, since the extra line makes it
variable.
Note the /context dialog’s "compaction cap: <model> • <N> tokens"
header line and the sidebar’s "⚠ capped" marker, and cross-reference
them from the compaction guide’s context-window-mismatch callout.
Live-sessions rows carry no cap wording of their own — the /context
header is the sole authority on it.
@aheritier
aheritier requested a review from a team as a code owner July 23, 2026 20:02
@aheritier aheritier added area/docs Documentation changes area/runtime Runtime engine, agent loop execution, tool dispatch, loop detection area/tui For features/issues/fixes related to the TUI kind/feat PR adds a new feature (maps to feat:). Use on PRs only. labels Jul 23, 2026
…egment width

The Token Usage section's click zone used to span the whole tab,
including the "Token Usage" title line, so clicking the title opened
the cost dialog just like clicking the reading below it.

Replace the half-open usageZoneStart/usageZoneEnd range with
usageReadingLine (the exact reading-line index) and usageSectionEnd
(covering any budget lines below it), excluding the title line from
the click zone. Also record usageContextSegWidth, the rendered width
of the reading line's context segment (glyph, token count, and context
%/compacting marker) — unused for now, but needed by the next commit
to split the reading line's click target between the context and cost
dialogs.
Split the Token Usage reading line's click target: an offset within
usageContextSegWidth (the glyph, token count, and context %/compacting
marker) now reports the new ClickUsageContext, while the rest of the
line (cost figure, ⚠ capped marker, sub-session count) keeps
reporting ClickUsage. Budget lines below the reading stay ClickUsage.

Apply the same offset split in both the vertical branch and the
collapsed band's shared-line/own-line branches of HandleClickType.
Add TargetSidebarUsageContext to the hit-test enum, map
sidebar.ClickUsageContext to it, and open ShowContextDialogMsg on a
left click, mirroring the existing ClickUsage -> ShowCostDialogMsg
routing for the cost segment.
Update the sidebar usage-click description in the TUI feature doc and
add a changelog entry for the new /context click target.
dgageot
dgageot previously approved these changes Jul 24, 2026
feat(tui): open /context or /cost from the sidebar token-usage reading
@dgageot
dgageot merged commit a85e111 into main Jul 24, 2026
18 checks passed
@dgageot
dgageot deleted the feat/context-compaction-limit-visibility branch July 24, 2026 05:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/docs Documentation changes area/runtime Runtime engine, agent loop execution, tool dispatch, loop detection area/tui For features/issues/fixes related to the TUI kind/feat PR adds a new feature (maps to feat:). Use on PRs only.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants