fix(desktop): preserve turn-elapsed timer across session switches - #61518
fix(desktop): preserve turn-elapsed timer across session switches#61518yingliang-zhang wants to merge 2 commits into
Conversation
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Comment
Overview
- 5 files changed, +36/-2 lines
- Preserves turn-elapsed timer across desktop session switches
- Fixes a UX issue where the timer would reset
Looks Good
- Well-scoped fix targeting the session switch path
- Proper state preservation in the desktop state manager
- No security concerns
Reviewed by Hermes Agent
242e02f to
735725f
Compare
|
Thanks for tracing the cold-resume path; the implementation targets a real current-main gap. Problems
Suggested changes
Automated hermes-sweeper review. |
829290e to
627f6d5
Compare
|
Addressed in commit 97bb62b4a7cfd604cf43d03e7ecf737f9c945219: added a shared, JSON-round-tripped active-turn session.resume fixture/contract across gateway and Desktop. The Desktop now restores the elapsed timer only for running responses with a valid numeric turn_started_at; invalid or absent values clear stale state instead of synthesizing Date.now(). Focused gates: Python 84 passed; Desktop 28 passed; Node 22 typecheck passed. |
9e03a5b to
d33bbfd
Compare
7f6f129 to
f9dd16a
Compare
bf56942 to
69b295c
Compare
92d51fe to
bf56942
Compare
Rebased onto latest origin/main. Resolved conflicts in: - use-session-actions.test.tsx: kept both HEAD's image-attachment test and PR's turn-clock restoration test (orthogonal features) - use-session-actions/index.ts, gateway-event.ts, server.py, test_tui_gateway_server.py, test_protocol.py: adapted to HEAD's refactored structure while preserving PR's turn-origin tracking
bf56942 to
c1041d5
Compare
|
Salvaged and merged in #87237 — both your commits landed on main with authorship preserved (c1041d5 + fb27c1a → rebase-merged), including the gateway |
Problem
The desktop status bar's turn-elapsed timer (
running-timer) resets to0:00every time the user switches away from a busy session and switches back.Root Cause
Gateway never reports
turn_started_at: Neithersession.resumeresponses norsession.infoevents include the turn start timestamp, so the desktop has no way to restore the clock after a session switch.Cold-resume path loses the timer:
use-session-actions/index.tscreates a newClientSessionStatewithturnStartedAt: null(the default). When the subsequentsession.infoevent arrives withrunning: true,gateway-event.tsfalls back tostate.turnStartedAt ?? Date.now()→Date.now()→ timer resets to zero.The warm-cache path correctly preserves
turnStartedAtviasyncSessionStateToView, but ifsession.usageRPC fails (e.g. pooled backend idle-reaped), the cache is purged and the cold path takes over — resetting the timer.Fix
Gateway side (
tui_gateway/server.py):_session_info(): extractturn_started_atfrominflight_turn.started_atand include it in the info dict_live_session_payload(): includeturn_started_atin the resume response payloadDesktop side (3 files):
types/hermes.ts: addturn_started_at?: number | nulltoSessionResumeResponselib/chat-messages.ts: addturn_started_at?: number | nulltoGatewayEventPayloaduse-session-actions/index.ts: cold-resume path usesresumed.turn_started_at(converted to ms) to restore the timer instead of defaulting tonullgateway-event.ts:session.infobusy-transition handler prefers gateway-reportedturn_started_atoverDate.now()fallbackVerification
npx tsc --noEmit— PASS (0 errors)py_compile tui_gateway/server.py— PASSvitest run src/app/session/hooks/— 117/121 pass; 4 failures are pre-existing onorigin/main(confirmed by stashing changes and re-running)git log --oneline origin/main..HEADshows only this commitChanges
tui_gateway/server.pyturn_started_atin_session_info()and_live_session_payload()apps/desktop/src/types/hermes.tsturn_started_atfield onSessionResumeResponseapps/desktop/src/lib/chat-messages.tsturn_started_atfield onGatewayEventPayloadapps/desktop/src/app/session/hooks/use-session-actions/index.tsresumed.turn_started_atin cold-resume pathapps/desktop/src/app/session/hooks/use-message-stream/gateway-event.tsturn_started_atinsession.infohandlerTotal: +36/-2 across 5 files. No new config knobs — the field is purely additive.