fix: resolve race between the chat greeting and history restore - #275
Open
cpsievert wants to merge 2 commits into
Open
fix: resolve race between the chat greeting and history restore#275cpsievert wants to merge 2 commits into
cpsievert wants to merge 2 commits into
Conversation
Resolving the app greeting used to race an independent client-side
`{id}_greeting_requested` request against the server's async history
restore: reloading into a restored conversation could flash the
greeting before the restore replaced it, and a restored conversation's
transcript had no way to suppress a stale/incoming greeting.
Greeting resolution now defers to the same "is this conversation
restored?" decision `HistoryController` already computes on init and
on `new_chat()`, instead of a separate client-driven signal. Restoring
a conversation (whether on initial load or via the history drawer)
now explicitly clears any greeting, since a restored conversation is
never a "new chat".
Mirrors the pkg-py fix: resolving the app greeting used to race an
independent client-side `{id}_greeting_requested` request against the
server's async history restore, which could flash the greeting on a
restored conversation, or leave a fresh conversation with no greeting
at all if the session began by restoring one.
Greeting resolution now defers to the same "is this conversation
restored?" decision `HistoryController` already computes on init and
on `new_chat()`. Restoring a conversation now explicitly clears any
greeting, since a restored conversation is never a "new chat".
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
When both a greeting and chat history are enabled, the greeting could show at the wrong time.
To reproduce (before this fix):
Root cause
The greeting used to resolve via an independent client-side signal (
{id}_greeting_requested, which fires whenever the chat is visible, empty, and has no greeting) that raced the server's async history-restore decision. Whichever finished first determined the (inconsistent) outcome.Fix
Greeting resolution now defers to the same "is this conversation restored?" decision
HistoryControlleralready computes — once at startup, and now also on everynew_chat()— instead of racing the client's independent request:HistoryController.replay_ui()(used both on initial restore and when switching conversations from the drawer) now explicitly clears any greeting, since a restored conversation is never a "new chat".HistoryController.new_chat()now re-resolves the greeting directly, so a fresh conversation always gets one — even in a session that began by restoring an existing conversation.Applied symmetrically in
pkg-pyandpkg-r.Testing
HistoryController.on_settled/notify_settledhook in both languages.persistent=Truegreetings — a plain-string greeting is auto-dismissed by the client regardless of this fix, so those tests passed even against the buggy code (a false negative).