fix(desktop): cancel stale session resume on new chat - #66376
Conversation
teknium1
left a comment
There was a problem hiding this comment.
Thanks for targeting the stale-resume generation race. The invalidation is the right mechanism, but it needs one more guard to cover the gateway-swap path described in the PR.
Problems
- At
apps/desktop/src/app/session/hooks/use-session-actions/index.ts:224, the PR invalidates a resume when New Chat starts. However,resumeSessionchecks the token only beforeawait ensureGatewayProfile(sessionProfile)(PR-head lines 507-511). A New Chat during that await can still reach the warm-cache write at lines 538-544 or the cold-path selection at lines 578-598 and revive the old session.
Suggested changes
- Re-check
isCurrentResume()immediately afterawait ensureGatewayProfile(sessionProfile)and return beforetakeWarmCache()or any session-state writes. - Add a deferred gateway-profile test alongside the profile-lookup case, with New Chat occurring while the gateway swap is pending.
Automated hermes-sweeper review.
| // user starts a new chat. Invalidate that request before clearing the | ||
| // view; otherwise its stale continuation can select and paint the old | ||
| // session over this fresh draft. | ||
| resumeRequestRef.current += 1 |
There was a problem hiding this comment.
This invalidates the lookup phase, but resumeSession does not re-check the token after await ensureGatewayProfile(sessionProfile). A New Chat during that gateway-swap await can still enter the warm/cold paths and reselect the old session; add an isCurrentResume() guard immediately after that await and cover it with a deferred-swap test.
There was a problem hiding this comment.
You're right: the prior invalidation covered only the profile lookup. I added isCurrentResume() immediately after await ensureGatewayProfile(sessionProfile), before either the warm or cold resume path. The new deferred-swap regression covers: resume A -> wait until its profile swap is pending -> New Chat -> resolve the swap -> assert A cannot issue session.resume or restore active, selected, or message state. The targeted use-session-actions suite now passes: 20/20 tests. Pushed in 93fea22.
Summary
Testing