fix(desktop): use activeSessionIdRef.current for restore/edit/reload/steer - #66695
Automata-intelligentsia wants to merge 1 commit into
Conversation
…steer The restore, edit, reload, and steer actions were reading the closure-captured activeSessionId, which can be stale when the actions bag is a stable ref. This caused rewind/truncate operations to be sent to the wrong session, deleting messages in the previously-active session instead of the current one. Read from activeSessionIdRef.current, matching the existing cancelRun pattern.
Related to merged #66485: both eliminate stale session-ID reads in Desktop actions, but this PR covers restore/edit/reload/steer rather than the Stop action. |
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Comment
+12/-11 desktop fix to use activeSessionIdRef.current for restore/edit/reload/steer. Fixes session state tracking in the desktop app. No concerns.
Reviewed by Hermes Agent
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Comment
+12/-11 desktop fix to use activeSessionIdRef.current for restore/edit/reload/steer. Fixes session state tracking in the desktop app. No concerns.
Reviewed by Hermes Agent
|
Thanks for tracing this to the stable actions bag. The premise is verified on current main: Problems
Suggested changes
Automated hermes-sweeper review. |
|
Thanks for this — your diagnosis was correct and it's now on Your read of the root cause was exactly right: the actions bag is a stable ref mutated in place, the pane surfaces are memoized on it, so the closure-captured Your branch had gone CONFLICTING against current
One thing worth flagging for context: #59305 landed a day before the merge and fixed the mechanism (the ref now mirrors synchronously during render instead of a lagging Closing as landed. Appreciated. |
Problem
In
usePromptActions, several actions that mutate session history were reading the closure-capturedactiveSessionIdprop. Because the actions bag is a stable ref that does not re-render when the active session changes, those closures could hold a stale session ID and sendprompt.submit/session.steerrequests to the previously-active session.This led to data loss: restoring/rewinding a message in the current chat would instead truncate the history of the previously-active session. The user would then see the restored prompt appear in the wrong session, and all messages after the restore point in that session were deleted.
Fix
Read the current session ID from
activeSessionIdRef.current, matching the existing pattern used bycancelRun(which already has a comment explaining exactly this issue). Updated:steerPromptreloadFromMessagerestoreToMessageeditMessageThis makes all of these actions target the actual currently-active session instead of a stale closure value.
Verification
The diff is minimal: it replaces
activeSessionId || activeSessionIdRef.currentwithactiveSessionIdRef.currentin the affected callbacks, and updates theuseCallbackdependency arrays accordingly.