Skip to content

Studio: show automatic compaction count in context meter - #12759

Closed
Yudeeswaran wants to merge 7 commits into
unslothai:mainfrom
Yudeeswaran:fix/issue-12625-context-compaction-meter
Closed

Yudeeswaran wants to merge 7 commits into
unslothai:mainfrom
Yudeeswaran:fix/issue-12625-context-compaction-meter

Conversation

@Yudeeswaran

@Yudeeswaran Yudeeswaran commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes #12625

Adds an automatic compaction count to the Unsloth Studio Context Length meter.

Changes

  • Add countAutomaticCompactions() using the existing compaction notice semantics and high-water boundary.
  • Derive the count from persisted assistant-message contextTruncation metadata.
  • Register the count inside the Assistant UI runtime and pass it to the chat header.
  • Display the count as Automatic compactions in the Context Length meter tooltip.
  • Add focused tests covering repeated boundaries, boundary rollback, checkpoint starts, empty records, and UI wiring.

Verification

  • node --experimental-strip-types --test tests/rolling-context-window.test.ts
    • 27 passed, 0 failed
  • git diff --check passed.

Note

The count represents recorded compaction notices/checkpoint starts in the assistant transcript. Multiple internal refits occurring within a single streamed assistant response are merged into one truncation metadata record, so they cannot be counted individually from the persisted frontend metadata.

Before / after

Qwen3.5-0.8B GGUF (UD-Q4_K_XL) loaded at a 2,048 token window, Max Tokens 256, temperature 0. Three chat turns produce two "Context compacted" notices on both builds; then the header meter is hovered. Before = main at fcee6485f, after = this PR plus the follow-up fixes in Yudeeswaran#1 at a758c95d9.

The tooltip gains an Automatic compactions 2 row, matching the two notices in the transcript. Everything else in the tooltip is unchanged.

Context meter tooltip before and after two automatic compactions

danielhanchen added a commit that referenced this pull request Oct 5, 2026
…test made (#12771)

socket.getaddrinfo is patched process-wide, so a lookup from any other thread in
the xdist worker also reached the fake and was counted: 'assert 33 == 32' in
test_stalled_lookups_do_not_pile_up (#12759) and 'assert 3 == 2' in
test_a_timed_out_lookup_is_not_remembered (#12750), on PRs that do not touch the
provider code. Route this file's .example hosts to the fake and everything else
to the real resolver in the five tests that count calls, and pin the routing.
@Yudeeswaran
Yudeeswaran force-pushed the fix/issue-12625-context-compaction-meter branch from 8f14f41 to 0b445d3 Compare October 8, 2026 06:51
@danielhanchen

Copy link
Copy Markdown
Member

Thanks for the PR! This branch conflicts with main now and maintainer edits are off, so I opened Yudeeswaran#1 into your branch with the fixes:

  1. Merges main (conflict in runtime-provider.tsx, both sides kept).
  2. Counts from compactionNoticeMessageIds(thread.messages).size, the same set the transcript uses to render the "Context compacted" notices, instead of a second walk over the metadata.
  3. Shows the row only once a chat has compacted, so the tooltip is unchanged for chats that never compact.
  4. Mounts the counter for project views too: a chat started from a project landing page shows the meter but never got a count.

Could you merge it (or enable "Allow edits by maintainers")? Checked live against a real llama-server at a 2,048 window: two notices in the transcript, Automatic compactions 2 in the tooltip (screenshot in the description).

danielhanchen added a commit that referenced this pull request Oct 12, 2026
Adds a Compactions row to the chat header's context meter tooltip, counted from the same set of messages the transcript renders "Context compacted" notices for. The row only appears once a chat has compacted; single-chat and project views are both counted.

Fixes #12625. Supersedes #12759.

Co-authored-by: Yudeeswaran <[email protected]>
@danielhanchen

Copy link
Copy Markdown
Member

Merged in #13355, which keeps your commits (you are credited as co-author) plus the follow-ups from Yudeeswaran#1 and a rename of the row to "Compactions". Thanks for the PR!

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Unsloth Studio Context Length meter #2: Add a count for automatic compactions.

2 participants