Repository navigation
fix(chat): keep the first message on screen when a new session starts - #257
Merged
Merged
Conversation
Sending the first message of a new session made it vanish for a second or two. When session-created arrived, the load effect correctly skipped the fetch, but then reset isSystemSessionChange. That flag is one of the effect's dependencies, so the effect ran again for the same session and fetched the transcript from the server. The CLI often has not written the question yet, so the empty result replaced the messages on screen until a later update brought them back. - The load effect now remembers which session (and socket) it is showing. A re-run for that same session keeps what is on screen instead of fetching again. A different session, or a reconnected socket, still loads. - The external-update reload only runs when its counter moves. Before, it also ran whenever the selected session object changed identity after any earlier external update, which could do the same overwrite. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The first message sent in a new session disappears for a second or two, then comes back.
Cause
In
useChatSessionState:session-createdsetsisSystemSessionChangeand selects the new session. The load effect sees the flag, skips the fetch (the message is already on screen) and resets the flag tofalse.isSystemSessionChangeis a dependency of that same effect, so it runs again for the same session. This time the flag is gone and it fetches the transcript from the server.sessionMessages→chatMessagessync until a later update restores them.The external-update reload effect had a similar path. After any earlier external update the counter stays above 0, and the effect re-ran whenever the selected session object changed identity, for example on a projects refresh.
Fix
displayedSessionRef).decideSessionMessageLoadinchatSessionTransition.tsreturns:adopt: the session we just created; keep the messages on screen.keep: the effect re-ran for the session already shown over the same socket; no fetch.load: a different session, or a reconnected socket that may have missed events.externalMessageUpdatechanges (isNewExternalMessageUpdate).Test plan
decideSessionMessageLoadandisNewExternalMessageUpdate(chatSessionTransition.test.ts).npm test: all pass exceptcodexCli.test.js, which fails only because this worktree'snode_modulesis a symlink to another checkout.npm run typecheck🤖 Generated with Claude Code