Repository navigation
fix(tui): wait for the session create before switching a session's model - #57361
Bearmancer wants to merge 2 commits into
Conversation
|
The following comment was made by an LLM, it may be inaccurate: |
There was a problem hiding this comment.
The fix works. With the #57354 drive script and network jitter, the base showed the Session not found toast in 3 of 4 runs and this branch in 0 of 4. The new test fails on the base and passes here, and the tui and client typechecks pass. Waiting on the create the same way sendAdmission does is the right approach, and it does nothing in the prompt path, where prepare already runs after the create.
Public API: unchanged. data.session.creation() is a new internal method on the Solid data layer, and nothing is removed or changed.
The only thing worth changing is in the test (see inline).
| // the switch may not leave before the create was answered. | ||
| const early = await Promise.race([ | ||
| switched.promise, | ||
| new Promise<undefined>((resolve) => setTimeout(() => resolve(undefined), 2000)), |
There was a problem hiding this comment.
This adds a fixed 2 s wait to every run, and it only checks that nothing happened during that window. That makes the test slower, and it could pass on the base if the switch were just slow. The order check at the end (sent.createAnswered === true, with the create held until create.resolve()) already covers the fix by itself: you could release the create once the empty Enter has been handled and drop the Promise.race. The toUpperCase check on line 93 has nothing to do with this bug and can be dropped.
|
@opencode-agent — Addressed the review in commit 211ae90: removed the 2s |
The client creates a session optimistically, so a model switch taken from the composer selection can reach the server before the session is stored. The server answers 404 SessionNotFoundError and the TUI shows a Failed to prepare session toast. Gate the agent and model switch on the in-flight create, the way the prompt path already gates on it.
211ae90 to
06d99ef
Compare
|
Rebased onto origin/dev: |


Issue for this PR
Fixes #57354
Type of change
What does this PR do?
The client creates a session optimistically, so the session exists in the TUI before the server has stored it. A model switch taken from the composer selection (blank Enter in the session tab, or a slash command) is sent right away, the server answers
404 SessionNotFoundError, and the TUI shows a redFailed to prepare sessiontoast.This gates the agent and model switch on the in-flight create, the way
session.promptis already gated on it insendAdmission.The switch that raced the create is
commitModel; it is reached from the composer selection without a create gate, while the prompt path is gated.From the server log of the reported case, the switch left 152 ms before the session was created (
time.created= 07:40:36.919Z):How did you verify your code works?
packages/tui/test/prompt-model-switch.test.tsxholds the create response back and asserts that the model switch does not leave before the create was answered, and that it carries the session id unchanged.The test fails on the base revision (the switch leaves with the create still pending) and passes with this change.
@opencode/tuiand@opencode/clienttypechecks pass.Screenshots / recordings
No visual change.
Checklist