fix(agent): preserve mid-turn steer messages across tab switches (#4044)#4074
Merged
esengine merged 2 commits intoJun 12, 2026
Merged
Conversation
61e18bd to
d6c35eb
Compare
Owner
|
Excellent root-cause writeup. The fix is exactly right: |
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.
Closes #4044
Problem
Mid-turn guidance injected via Steer disappeared from the conversation after switching to another tab and back. The steer was visible during the live turn (as a
↪ textnotice) but gone after tab switch.Root Cause
internal/control/input.goincluded the steer prefix insyntheticPrefixes. Desktop'shistoryMessages()calledIsSyntheticUserMessage()on every user-role message during history replay and skipped synthetic ones. This contradicted the agent's stated intent (agent.go:507-510) that steer messages be persisted to "survive tab switches and history replay."The CLI TUI and HTTP/SSE frontends had the same class of bug: they replayed steer messages as raw user bubbles with the full prefix visible.
Changes
Commit 1 — Core fix (desktop):
internal/agent/agent.go— ExportMidTurnSteerPrefix; addSteerText(content) (string, bool)to extract the original user text from a steer-wrapped message without trimming (preserving exact character fidelity with the live Steer event).internal/control/input.go— Remove steer prefix fromsyntheticPrefixes. Steer messages are no longer classified as synthetic.desktop/app.go— InhistoryMessages(), detect steer messages using rawm.Content(beforeresolveUserContentappliesStripComposePrefixeswhich trims whitespace) and emit them asrole: "notice"entries with the↪prefix — matching the live Steer event appearance.internal/agent/steer_test.go— New table-driven tests forSteerText(11 cases) + round-trip test formidTurnSteerMessage.internal/control/input_test.go— Updated test expectation.Commit 2 — CLI TUI + HTTP/SSE parity:
internal/cli/chat_tui.go—replaySectionsFornow detects steer messages viaagent.SteerText()before rendering user bubbles. Steer messages are rendered as↪ textnotice lines instead of raw› [Mid-turn steer...]user bubbles.internal/serve/serve.go—historyMessagesnow detects steer messages and emits them asrole: "notice"with the↪prefix, consistent with the desktop behaviour. Web clients reconnecting see clean notice text instead of the raw prefix.internal/control/input_test.go— Hardcoded prefix string replaced withagent.MidTurnSteerPrefixconstant reference so the test automatically tracks prefix changes.Design
All three frontends (desktop, CLI TUI, HTTP/SSE) now share the same pattern: before processing a
RoleUsermessage for display, callagent.SteerText()to detect steer messages and convert them to a notice-style rendering. The model still sees the raw user message (with the prefix) for context; only the display layer transforms it.Verification
go test ./internal/agent/— 80+ tests passgo test ./internal/control/— all pass (1 pre-existing failure inTestRemoveMCPServerRemovesUnconnectedLazyPlaceholder, confirmed on cleanmain-v2)go build ./internal/cli/ ./internal/serve/— cleango vet ./desktop/...+go build ./desktop/...— cleanAffected areas
↪ textnotice↪ textnotice↪ textnotice↪ textnotice line/historyendpointrole:"user"with raw prefixrole:"notice"with↪ text