fix(desktop): stream live context usage - #39370
Conversation
cd42bc0 to
c0f51aa
Compare
c0f51aa to
cbcd8e7
Compare
|
Maintainer-ready after refresh. I merged current Verification:
Note: a broader local run of MeshBoard merge dry-run passes with green checks and no stale-overlap risk. I attempted the actual merge through |
2051f0c to
ad5d0a3
Compare
fceb571 to
3b094b7
Compare
teknium1
left a comment
There was a problem hiding this comment.
Thanks for tracing the usage flow through the agent, gateway, Desktop, and TUI. The live-update premise is still valid on current main: tui_gateway/server.py:9164-9174 supplies usage only in message.complete, while the clients merge that final payload.
Problems
agent/conversation_loop.py:174-176on the PR head turnslast_prompt_tokens=-1into0and overwrites it with a rough estimate. Current main explicitly preserves that sentinel inagent/turn_context.py:401-405;tests/agent/test_context_compressor.py:2990-3018documents that clobbering it can re-trigger compression from schema-inflated estimates.- The PR labels
estimate_request_tokens_rough()ascontext_tokens, but current main definescontext_usedas real current-window occupancy and leaves it unknown otherwise (tui_gateway/server.py:3219-3243). The estimator intentionally overestimates schema-heavy requests (agent/context_compressor.py:1239-1245).
Suggested changes
- Emit a distinct preflight estimate without mutating
last_prompt_tokens; retain the sentinel/defer guards. - Add regressions for the
-1sentinel and deferred post-compression preflight before salvage.
Automated hermes-sweeper review.
| return | ||
|
|
||
| try: | ||
| previous = getattr(compressor, "last_prompt_tokens", 0) or 0 |
There was a problem hiding this comment.
last_prompt_tokens = -1 is a post-compression sentinel. or 0 converts it to a writable value, so line 176 overwrites it with a rough estimate and reintroduces the repeat-compaction regression guarded by current agent/turn_context.py:401-405. Do not mutate this field here; emit a distinct estimate or preserve the sentinel/defer logic.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
467bab7 to
f1e530a
Compare
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Summary
This fixes the desktop footer context meter staying at
0/contextwhile an agent turn is already running. The backend now emits a structuredtoken_usagestatus update immediately after the high-accuracy preflight token estimate, the gateway forwards it astoken.usage, and the desktop/TUI clients merge it into live usage state beforemessage.complete.The status bar keeps the main text grey and applies semantic capacity color only to the small bracket meter: muted at 0%, green while comfortably under capacity, yellow/orange as it fills, and red near max.
Verification
/Users/obaradei/.hermes/hermes-agent/venv/bin/python -m pytest tests/run_agent/test_run_agent.py::TestRunConversation::test_preflight_token_usage_emits_before_api_response tests/test_tui_gateway_server.py::test_status_update_emits_structured_token_usage -qnpm --prefix apps/desktop exec vitest run src/lib/usage-events.test.ts src/lib/statusbar.test.ts -- --environment jsdomnpm --prefix ui-tui exec vitest run src/__tests__/createGatewayEventHandler.test.tsnpm --prefix apps/desktop run type-checknpx prettier --check apps/desktop/src/lib/usage-events.ts apps/desktop/src/lib/usage-events.test.ts apps/desktop/src/lib/statusbar.ts apps/desktop/src/lib/statusbar.test.ts apps/desktop/src/app/session/hooks/use-message-stream.ts apps/desktop/src/app/shell/hooks/use-statusbar-items.tsx ui-tui/src/app/createGatewayEventHandler.ts ui-tui/src/__tests__/createGatewayEventHandler.test.ts ui-tui/src/gatewayTypes.tsgit diff --check HEAD^..HEADLive install checked locally: packaged
/Applications/Hermes.appwas rebuilt and swapped to commit7ed069c16b9b6c2d6317814658eb920d76896a00; install stamp reports that commit and the desktop backend is running on127.0.0.1:9120.Note:
npm --prefix ui-tui run type-checkstill fails on existing unrelatedpackages/hermes-ink/src/utils/execFileNoThrow.tsreadonly stdio / child-process typing debt.