refactor(coding-agent): read messageCount instead of a shadow flag - #1739
Closed
snimu wants to merge 8 commits into
Closed
refactor(coding-agent): read messageCount instead of a shadow flag#1739snimu wants to merge 8 commits into
snimu wants to merge 8 commits into
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 194b7ce. Configure here.
This was referenced Aug 27, 2026
Contributor
Author
| } | ||
| case "message_end": { | ||
| const wasNewChat = this.isNewChat(); | ||
| this.patchConnectionState({ messageCount: this.connectionState.messageCount + 1 }); |
Contributor
There was a problem hiding this comment.
🟡 Medium interactive/interactive-mode.ts:2662
messageCount is incremented for every message_end, so a transient durable-command error result makes an otherwise empty session appear non-new. This suppresses fresh-session hints and deferred startup notices until a snapshot or rebind corrects the state; only increment the count for messages that were actually persisted, or expose that distinction on the event.
🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file @packages/coding-agent/src/modes/interactive/interactive-mode.ts around line 2662:
`messageCount` is incremented for every `message_end`, so a transient durable-command error result makes an otherwise empty session appear non-new. This suppresses fresh-session hints and deferred startup notices until a snapshot or rebind corrects the state; only increment the count for messages that were actually persisted, or expose that distinction on the event.
Evidence trail:
packages/coding-agent/src/modes/interactive/interactive-mode.ts:2660-2666,6056-6057 @ 786da59ea9f208faada21c519a826ced622d011f
packages/coding-agent/src/core/agent-session.ts:6095-6116,6139-6149 @ 786da59ea9f208faada21c519a826ced622d011f
packages/coding-agent/src/modes/agent-connection/snapshot.ts:27-48 @ 786da59ea9f208faada21c519a826ced622d011f
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.

What was wrong
The TUI kept a private
sessionHasMessagesboolean that shadowedconnectionState.messageCount— seeded from a separately rendered transcript and updated by a hand-picked subset of events. Two answers to "does this session have messages?", which had already diverged in definition (the flag ignored some message kinds the count includes).The fix
The flag and its setter are deleted.
isNewChat()and startup notices readconnectionState.messageCount, seeded from the authoritative connection snapshot.message_startevents bump the count following the exact existing event-patch pattern (snapshots overwrite and self-correct, same as isStreaming/isCompacting), with fresh-chat UI invalidated only on the zero→nonzero transition. Stale test mocks of the deleted setter removed.How it's verified
Reviewer confirmed the event increment replaces the flag's event-edge maintenance rather than adding a second writer (snapshot remains authoritative), and the count's semantics now match the snapshot definition. Affected suites 202/202; full CI-style suite: no new failures vs stack base. Two-model implement/review loop.
Stacked on #1738 (test the whole stack at the leaf; merge base-first).
Note: intentionally no Linear ticket for this cleanup stack, so that check stays red.
Note
Low Risk
UI-only refactor for hints and startup notices; behavior now follows connection state semantics, with snapshots still authoritative for the count.
Overview
Removes the private
sessionHasMessagesflag andsetSessionHasMessagesso “fresh chat” behavior usesconnectionState.messageCount(from the connection snapshot) instead of a second, transcript-driven boolean.isNewChat()now means zero committed messages and not streaming; shortcut tray hints, startup notices, and related guards call that instead of the removed flag.updateConnectionStateFromEventbumpsmessageCountonmessage_endand refreshes the built-in header / subagent summary when the session was still treated as new atagent_startormessage_end, including mid-turn runs with no committed messages yet.Tests and mocks are updated to seed
connectionState.messageCountand cover the streaming-with-zero-messages case.Reviewed by Cursor Bugbot for commit 786da59. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Replace
sessionHasMessagesflag withconnectionState.messageCountinInteractiveModesessionHasMessagesboolean field and derives new-chat status fromconnectionState.messageCountandisStreamingviaInteractiveMode.isNewChat()messageCountonmessage_endand invalidates the built-in header and subagent summary onagent_startandmessage_endwhen transitioning from a new chatconnectionState.messageCountandisStreaminginstead ofsetSessionHasMessagesisNewChat()now returns true only whenmessageCountis 0 andisStreamingis not true, which may alter notice visibility for sessions that previously setsessionHasMessagesvia initial context length📊 Macroscope summarized 786da59. 3 files reviewed, 1 issue evaluated, 0 issues filtered, 1 comment posted
🗂️ Filtered Issues
Linear ticket: ENG-5659
(ticket linked above)