Repository navigation
fix(chat): a resume that answers after the user moved leaves them where they are - #23321
Conversation
First Principles Review (Opus 5.5, fork) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS The fix removes a reproduced defect (10/10 runs, base-failing tests). The one premise left unchecked is the repeat-click drop, which is easy to reverse. Notes
What this change shipsInventory (10 items) — 8 justifiedIntent: A slow resume no longer drags the user off a session they opened while it loaded, and the last click wins. FIX.
[FIRST-PRINCIPLES-REVIEWED] 6f51588 Description read[DESCRIPTION-READ] d70eb75902b3175624494a0d10f1ba47dbd511abe1d1e02c6601ea3c9a437add That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the fix is in the reducer, where both the resume race and the cross-kind race start, and nothing outside the patch reads the new rejection of a repeated resume and breaks. Notes
[DESIGN-REVIEWED] 6f51588 Description read[DESCRIPTION-READ] 7247e5508603dd89083995193649e5a6bce29fb3a950392369dde69688c946ea That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
UX Review (Opus 5.5, fork) — ✅ PASSUX-level review of UX-Verdict: PASS Nothing to check. The diff adds and changes no controls, labels, strings or element states. It only changes which session a late resume, fork or create may open. Without a blind read, this lane cannot confirm how users perceive that difference. [UX-REVIEWED] 6f51588 Description read[DESCRIPTION-READ] af2fec0486b6cf3e66ecda5a6a6a1ffae69c888486d010cdd776e65bf27105a6 That sha256 names everything this verdict read: the PR description, plus the 3 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
GPT 6.1 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
Opus 5.5 Review (fork) — ✅ no blocking findingsReviewed |
c016211 to
4ae7ac1
Compare
issue (blocking): upheld and fixed as described above. |
issue (blocking): upheld and fixed as described above. |
4ae7ac1 to
5aef44e
Compare
issue (blocking, security): upheld and fixed as described above. |
5aef44e to
3aab6c2
Compare
|
note: rebased on main 4643565, head 3aab6c2, no behaviour change. Frontend Tests (3) on 5aef44e failed in |
|
HOLD at
The rest looks sound: resumes now use the same — crew-pr-reviewer (r124) |
issue (non-blocking): upheld and fixed as described above. |
|
@iamwhatever thanks, both items are handled on 071030d, which pushes in the next CI slot.
|
d90289a to
071030d
Compare
|
note: Bundle Size Gate on 071030d fails with |
…re they are resumeFromHistory now records the origin with captureForkOrigin and its fulfilled reducer opens the session only for the latest resume and only when forkMayOpen allows it, the rule creates and forks follow. A repeat of the resume on its way is dropped by the thunk's condition, and the chat page treats a pending resume like a pending create or fork. handleResumeSession retires the origin tab only when the resume took the view.
071030d to
4a9fcd9
Compare
|
note: rebased on main 9e9c87c, head 4a9fcd9, no behaviour change. The Bundle Size Gate red on 071030d was the |
…ume did not open The repeat guard keeps one entry per pending resume, keyed by requestId, so H1, H2, H1 sends one H1. An entry stops blocking its row after PENDING_OPEN_LEASE_MS, the bound the chat page's wait already uses, so a hung POST does not leave the row dead. A dropped repeat hands the latest-click token back to the resume it repeats, with the origin re-taken at that click. The ?sid short-name callback and the palette focus check the live active slot, so a resume the reducer declined releases URL sync, rewrites ?sid to the session on screen, and moves no caret.
issue (blocking): upheld and fixed as described above. |
4a9fcd9 to
6f51588
Compare
|
note: readiness passed on 6f51588. green_age.py reports it stale: main gained 60 commits since 9e9c87c, two of them in files this PR also edits, |
bolichen97
left a comment
There was a problem hiding this comment.
[operator: bolichen97] Approved at 6f51588: readiness passed, PR Readiness success, mergeable, no open blocking requests.
Problem / Motivation
Goal: A resume from Older sessions, History, the palette or a short-name link that is still loading no longer pulls the user off a session they opened in the meantime, and two quick resumes end on the one clicked last.
Resume a closed session from Older sessions and, before it loads, open another session. When the resume answers, the dashboard switches to the resumed session. On a pod with the resume POST held for 2000 ms, the user opened S1 100 ms in and ended on the resumed session in 10 of 10 runs. Clicking S1 and then back to S0 ended on the resumed session in 10 of 10 runs. Clicking a slow row and then a fast row 100 ms later ended on the slow one in 10 of 10 runs, after briefly showing the fast one.
Why it matters
A resume rebuilds the session from its transcript and can take seconds. A user who opens another session while it loads has made a choice, and the late answer overrides it. In the two-row case the user's last click loses to whichever request answers last.
Not a goal
captureForkOriginandforkMayOpennow that resumes use them as well as creates and forks.What changed (motivation → approach → change)
resumeFromHistory.fulfilledinwebsite/src/store/chat/lifecycle.tscalledenterActiveSlotfor every successful resume, at line 520 on origin/main. It had no switched-away check, no check that it was the latest resume, and no guard against a repeat. Creates and forks already have the first two throughcaptureForkOriginandforkMayOpen, from #22818 and #22989.Resumes now use the same rule. The pending reducer records each resume in
pendingResumes, keyed byrequestId, with its history key, its start time and the origin fromcaptureForkOrigin. The fulfilled reducer still lists the session and consumes the Older sessions row. It takes the view only when the action'srequestIdequalslastResumeRequestIdandforkMayOpenallows it against that origin.lastResumeRequestIdalready ordered the "can't be opened" notice, so the latest click wins by the same token.Across kinds, a create, fork or resume opening its session moved the view, and
forkMayOpenread that as the user moving away, so a resume clicked after New lost to the create. Such a move now counts inactiveSlotRequestMoves, apart from user moves. Each create, fork and resume start bumpsrequestSeq, the origin records it, andforkMayOpenrefuses only when a request started later has already opened its session, recorded inactivatedRequestSeq. A request's own switch names its number: both fork paths, inhooks/useSessionActions.tsandpages/useChatPageSlotSwitches.ts, the foreground-tab create inpages/chat-sidebar/create.ts, andpages/chat/memoryModeSwitch.ts. Creates clicked back to back are one request made several times, so the first to open keeps the view, as on origin/main. The mobile drawer inpages/chat/page/sessionsDrawer.tscounts request moves as the user's picks.The thunk's
conditiondrops a second resume of a key that has an entry younger thanPENDING_OPEN_LEASE_MS, whatever rows were resumed in between. That is the 10 s bound the chat page already uses for a pending create or fork, moved from the page controller tostore/chat/state.tsso the store can read it. A hung POST stops blocking its row after 10 s, and the next pending action prunes entries past that age. The dropped repeat is dispatched as a rejection withmeta.condition. Its reducer makes the resume it repeats the latest again and re-takes the origin at that click, so after H1, H2, H1 the first H1 opens when it answers.useChatPageSessionController.tscounts a resume still within its lease inopenPending, beside a pending create or fork, so the page does not auto-open another session while a resume that will open one is on its way. Three callers used to treat a successful resume as one that took the view. Each now reads the live active slot.handleResumeSessioncloses a tab only whenlastResumeActivationshows its own resume replaced the tab the click started on. The short-name?sid=callback returns at once if ChatPage has unmounted, and releases its URL-sync hold when the resume did not open, and replaces?sid=with the session on screen.focusComposerForResumedSessioninpages/chat/composerFocus.tsnow takes the store, which both palette providers inwebsite/src/components/commandPalette/providers/pass, and moves no caret when the view did not move.Backwards compatibility
Compatible. A resume with no session change while it loads opens the session exactly as before.
pendingResumes, the request counters, the new meta fields and the rejected repeat action are internal to the chat slice. Dropping a repeat of a row within the 10 s lease is new: origin/main has noconditiononresumeFromHistoryand sends the second resume. A caller that awaitsunwrap()on such a repeat now gets a rejection withmeta.conditionset. Every in-tree caller either does not await it or catches it.Tests
website/src/test/resumeRespectsSwitchAway.test.tsruns the realresumeFromHistorythunk against deferredapi.resumeChatSlotanswers. It covers a move to another session, a move away and back, two resumes where the earlier one answers last, a repeated click, a failed resume clearing its entry, staying on the origin, and the page auto-selecting another session after it dropped the origin. It adds H1, H2, H1 with the first H1 still pending, which sends one H1 and opens it, and a move after that repeat, which leaves the view alone. A second block fakesDateonly and pins the clock. A repeat at 9999 ms sends nothing, one at 10000 ms sends a fresh POST, and the hung one answering late does not take the view. On origin/main 5 of the first 7 cases fail. On the first commit of this branch the H1/H2/H1 and lease cases fail, and the repeated-click case fails because it reads the renamed field. With both commits all 11 pass.website/src/test/ChatPage.sid.test.tsxadds a?sid=chat-7link whose resume is held while the user switches to another session. After the resume answers, the URL must name that session, the "Opened" notice must clear, a later switch must update the URL, and Back must return to the session the user was on. It fails on the first commit, where the URL keeps naming chat-7-50, and passes with the fix. A second case switches session and then routes to/developerwhile the resume is held. The URL must stay/developerafter the resume answers. It failed on 4ae7ac1, where the URL returned to the chat route.website/src/test/composerFocus.test.tsadds a resume that answered but did not take the view, which must focus nothing. It fails on the first commit and passes with the fix.website/src/test/ChatPage.resumeSurfaceGate.test.tsxadds a resume that answers after the user moved. The origin tab and its draft must survive. It fails on origin/main and passes with the fix. A second case switches to chat-2 and clicks the same row again before the resume answers. chat-9 opens, and chat-1 and its draft must survive. It failed on 4ae7ac1, where chat-1 was deleted.website/src/test/latestClickAcrossKinds.test.tsruns the realcreateSlotandresumeFromHistorythunks against deferred answers. New then an Older sessions row, with the create answering first, must end on the row. A resume then New, with the resume answering first, must end on the new chat. A sidebar Fork then New, with the fork answering first, must end on the new chat. Three controls, where the later click answers first or the user moves while both are pending, keep their outcome. The three cross-kind cases fail on 9c99331c3a and pass with the fix.ChatPage.resumeSurfaceGate.test.tsxadds New, then Continue a previous chat, with the create opening first: chat-1 and its draft must survive, since the resume replaced the new chat.website/src/test/ChatPage.waitsForPendingOpen.test.tsxadds a hung resume. Within its lease it holds the pick. Past the lease its entry is still there, yet a later loss of the chat picks at once. The second case fails on 9c99331c3a.website/src/test/forkRespectsSwitchAway.test.tsxadds a resume clicked before a transcript Fork that answers after the fork opened: the child must keep the view. It fails on 9cda2a8, where the fork carried the resume's number.latestClickAcrossKinds.test.tsadds two creates in a row, which keep the first, and a foreground-tab switch carrying the create's number, after which a later resume still opens.website/src/hooks/useSessionActions.cov80.test.tsx, the four sidebar tab tests and the memory-chip test's switch recorder now expect a request's switch to carry its number.resumeFromHistory/fulfilledto seed a resumed session,chatSlice.sidePanelAlwaysOpen.test.tsfrom main among them. A real resume always dispatchespendingfirst, sowebsite/src/test/resumeLanded.tsdispatches both, with the origin taken from the current state.Proof: PROVEN latestClickAcrossKinds.test.ts (3 cross-kind cases) and ChatPage.waitsForPendingOpen.test.tsx "a resume past its lease does not hold a later pick" fail on 9c99331c3a, and the forkRespectsSwitchAway transcript-Fork case fails on 9cda2a8, the create, resume, create case fails on e0bdbc2, and the same clicks answering create, create, resume fail on d90289a; the three-creates case fails on 4a9fcd9; all pass on this head (head 6f51588)
Manual verification
On a pod, Playwright held the resume POST and clicked sessions during the hold, 10 runs per case. Before is origin/main 0be5bcd for the Older sessions cases and the first commit, deb2dea, for the short-name cases. After is the head of this branch.
/chat?sid=<H1 short name>, resume held 2000 ms, open S1 during the hold/chat?sid=<H1 short name>, no other click (control)The six F20 cases and the New-then-resume case were rerun 10 times each on a build of 9cda2a8, the head of this branch, with the results above.
The fork and create cases from #22818 and #22989 ran on the same build to check that the shared rule did not move. Sidebar Fork and message Fork with a click on S1 during an 800 ms hold kept the user's choice 10/10 each. Sidebar Fork with no click opened the child 10/10. Header New and folder "+" with S1 then S0 during a 1500 ms hold kept the user's choice 10/10 each. Header New with no click opened the new chat 10/10. No pod case drives a repeated click or a hung resume. The unit tests above cover those.
Screenshots / video
Why no screenshot: No pixel changes. The fix only skips a session switch and corrects the URL, and the table above records the behaviour.
Related Issues
Closes #23320
Sibling sweep
Siblings: none --
createSlotand every fork path already gate their switch onforkMayOpen(#22818, #22989), and this PR movesresumeFromHistory, the last slot-entry thunk that skipped it, onto the same rule.Pattern harvest
Rule candidate: review-prompt
Pattern: every async action that switches the active session when it settles must capture the origin at its start and ask
forkMayOpen, and a repeatable one must also check it is the latest request. A caller that acts on the result must read the live active slot rather than infer the switch from a fulfilled action.Checklist
Contribution License Agreement
Contributions are accepted under the project's Apache-2.0 license.