Fix first message not sent to model on new session creation#270
Merged
bra1nDump merged 1 commit intoslopus:mainfrom Dec 7, 2025
Merged
Fix first message not sent to model on new session creation#270bra1nDump merged 1 commit intoslopus:mainfrom
bra1nDump merged 1 commit intoslopus:mainfrom
Conversation
bra1nDump
requested changes
Dec 7, 2025
When creating a new session with prefilled text, the initial message was not delivered to the CLI/model despite being displayed in the UI. This was caused by a race condition: the app sent the message before the CLI had connected its WebSocket, so the server broadcast went nowhere. Fix: sendMessage now waits for agentStateVersion > 0 before sending over the network. This field starts at 0 and increments when CLI connects and calls updateAgentState(), serving as a reliable ready signal. Co-authored-by: Kirill Dubovitskiy <kirill2003de@gmail.com>
8582d52 to
adb51f9
Compare
JoeLuker
pushed a commit
to JoeLuker/happy
that referenced
this pull request
Feb 1, 2026
When creating a new session with prefilled text, the initial message was not delivered to the CLI/model despite being displayed in the UI. This was caused by a race condition: the app sent the message before the CLI had connected its WebSocket, so the server broadcast went nowhere. Fix: sendMessage now waits for agentStateVersion > 0 before sending over the network. This field starts at 0 and increments when CLI connects and calls updateAgentState(), serving as a reliable ready signal. Co-authored-by: Kirill Dubovitskiy <kirill2003de@gmail.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.
Bug: First Message Not Sent to Agent on New Session Creation
Symptoms
When creating a new session with prefilled text, the first message appears in the UI but the agent never responds. User must copy and resend the message manually.
When Claude starts the binary via spawn, it is more likely to be triggered because spawn is time-consuming.
Root Cause
Race condition between app sending message and agent WebSocket connection.
Fix
The app now waits for
agentStateVersion > 0before sending the first message. This field starts at 0 when a session is created and increments when the CLI connects and callsupdateAgentState(), serving as a reliable signal that the agent's WebSocket is ready to receive messages.Timeline Diagrams
Before fix (message lost)
After fix (message delivered)
Testing
To reproduce the bug, a 5-second delay was added in
happy-cli/src/claude/runClaude.tsbefore the WebSocket connects:Steps to verify:
Expected behavior: