Skip to content

fix(desktop): reset telemetry and context panel after /clear#4327

Closed
ashishexee wants to merge 1 commit into
esengine:main-v2from
ashishexee:fix/4186-clear-token-info-stale
Closed

fix(desktop): reset telemetry and context panel after /clear#4327
ashishexee wants to merge 1 commit into
esengine:main-v2from
ashishexee:fix/4186-clear-token-info-stale

Conversation

@ashishexee

Copy link
Copy Markdown
Contributor

Closes #4186

Problem

After /clear, the context panel still shows stale token counts and workspace context.

Two sub-bugs:

  • (a) /clear sometimes fails to clear context — stale usage events from the previous session re-populate state after the reset action zeros it.
  • (b) Token info and workspace context are not refreshed after /clear.

Root Causes

  1. ClearSession() resets the executor session but NOT tab.usageTelemetry/tab.readTelemetry. ContextPanel reads from telemetry, returns stale data.
  2. dockRefreshKey only bumps on turn_done, so ContextPanel doesn't refresh after /clear.
  3. ContextPanel.tsx line 212 falls back to info.usedTokens when context.used === 0, showing stale values.
  4. The usage event handler doesn't check turnActive, so stale events arriving after reset re-accumulate into session tokens.

Fix

  1. Add resetTelemetry() on WorkspaceTab — called from App.ClearSession() after clearing the executor session.
  2. Bump dockRefreshKey in confirmClearContext to force ContextPanel refresh.
  3. Clear stale info state in ContextPanel when context.used === 0 && sessionTokens === 0.
  4. Guard usage handler with turnActive check — stale events from a cleared session are dropped.
  5. Add sessionGen counter to State, incremented on reset — for future use to discard stale events by generation.

Files Changed

  • desktop/tabs.goresetTelemetry() method
  • desktop/app.go — calls tab.resetTelemetry() after ClearSession()
  • desktop/frontend/src/App.tsx — bumps dockRefreshKey after clear
  • desktop/frontend/src/components/ContextPanel.tsx — clears stale info
  • desktop/frontend/src/lib/useController.tssessionGen counter, usage guard on turnActive

Verification

go build ./cmd/reasonix
go vet ./...
go test ./internal/control/ -run TestSubmitClear -v -count=1
go test ./internal/agent/ -count=1
go test ./internal/config/ -count=1

Fixes esengine#4186

Sub-bug (a): /clear sometimes fails to clear context (stale events
re-populate state after reset). Fix: guard usage handler with
turnActive check so stale events from the previous session are dropped
after the reset action zeros the state.

Sub-bug (b): token info and workspace context not refreshed after
/clear. Three causes:
1. Tab telemetry not reset — ClearSession() resets the executor session
   but tab.usageTelemetry/readTelemetry accumulate forever. Fix: add
   resetTelemetry() and call it from App.ClearSession().
2. ContextPanel not refreshed — dockRefreshKey only bumps on turn_done,
   so the panel keeps showing stale data. Fix: bump dockRefreshKey in
   confirmClearContext.
3. Stale info fallback — ContextPanel line 212 falls back to
   info.usedTokens when context.used is 0, which is stale. Fix: clear
   info state when context.used and sessionTokens are both 0.
@github-actions github-actions Bot added v2 Go rewrite (1.x) — main-v2 branch, active development desktop Wails desktop app (desktop/**) labels Jun 13, 2026
@SivanCola

Copy link
Copy Markdown
Collaborator

Closing as superseded by #4329, which integrates the final #4186 /clear telemetry/context-panel fix.

Thank you @ashishexee for the original implementation and regression focus in this PR; the retained PR includes a contribution note acknowledging your work as part of the shared repository fix.

@SivanCola SivanCola closed this Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

desktop Wails desktop app (desktop/**) v2 Go rewrite (1.x) — main-v2 branch, active development

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: /clear 指令有时执行异常

2 participants