Skip to content

fix: refresh context ring after compression - #2188

Merged
1 commit merged into
nesquena:masterfrom
LumenYoung:fix/compression-context-ring-refresh
May 13, 2026
Merged

1 commit merged into
nesquena:masterfrom
LumenYoung:fix/compression-context-ring-refresh

Conversation

@LumenYoung

@LumenYoung LumenYoung commented May 13, 2026

Copy link
Copy Markdown
Contributor

Summary

Refresh the context progress indicator immediately when automatic context compression completes.

Before this change, the auto-compression compressed SSE event only updated the compression card/toast. The context progress ring continued to show the pre-compression token usage until a later metering/done update or the next message. This made the UI look like compression had completed but the session was still near the context limit.

Problem

When a turn triggers automatic context compression:

  1. The backend emits compressing.
  2. The backend performs compression and emits compressed.
  3. The UI switches the compression card to the completed state.
  4. The context progress ring can still display stale pre-compression usage.

This is confusing because the compression status and the token indicator disagree immediately after compression finishes.

Fix

The backend now includes a live usage snapshot in the compressed SSE payload:

  • session_id
  • usage

The frontend compressed event handler now:

  • ignores events for inactive sessions
  • merges d.usage into S.lastUsage
  • calls _syncCtxIndicator(S.lastUsage) before rendering the completed compression card

This keeps the progress ring in sync as soon as compression completes, without waiting for a later event.

Summary

Fix the context progress ring staying stale after automatic context compression completes.

Before this change, the WebUI showed the automatic compression completion card/toast when the compressed SSE event arrived, but the context indicator still reflected the pre-compression token usage. It only refreshed later when another usage-bearing event arrived, usually after the next assistant/model step. This made compression look incomplete even though the backend had already compacted the session.

Problem

Automatic compression updates the persisted session state immediately, but the compressed SSE payload did not include the refreshed token usage snapshot.

The frontend compressed event handler only updated the compression UI state:

  • marks the compression card as done
  • clears the compression session lock
  • re-renders messages
  • shows a toast

It did not call _syncCtxIndicator(), so the context progress ring could remain at the old high-water usage until a later metering or done event.

Fix

This PR makes the compression completion event carry enough state for the UI to refresh immediately.

Backend:

  • Adds session_id to the compressed SSE payload so the frontend can ignore stale/cross-session events.
  • Adds usage: _live_usage_snapshot() to the compressed SSE payload after auto-compression is detected.

Frontend:

  • The compressed listener now ignores events whose session_id does not match the active session.
  • When d.usage is present, it merges the usage into S.lastUsage.
  • It calls _syncCtxIndicator(S.lastUsage) before rendering the compression completion card.

This keeps the context ring in sync as soon as compression completes, without waiting for the next model/tool/metering event.

Testing

pytest -q tests/test_auto_compression_card.py tests/test_issue1617_tps_message_header.py tests/test_issue2028_compression_anchor_helpers.py

@nesquena-hermes nesquena-hermes closed this pull request by merging all changes into nesquena:master in f5be6e3 May 13, 2026
pull Bot pushed a commit to TKaxv-7S/hermes-webui that referenced this pull request May 13, 2026
fix: refresh context ring after compression (LumenYoung)
SysAdminDoc pushed a commit to SysAdminDoc/hermes-webui that referenced this pull request Jun 26, 2026
fix: refresh context ring after compression (LumenYoung)
bernyforce pushed a commit to bernyforce/hermes-webui that referenced this pull request Jul 29, 2026
fix: refresh context ring after compression (LumenYoung)
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.

2 participants