fix: seed MCP sidebar state on a timer to fix stuck "None" panel#3289
Open
albatrossflyon-coder wants to merge 1 commit into
Open
fix: seed MCP sidebar state on a timer to fix stuck "None" panel#3289albatrossflyon-coder wants to merge 1 commit into
albatrossflyon-coder wants to merge 1 commit into
Conversation
mcp.Initialize runs in a goroutine concurrently with the TUI starting up. A fast-connecting MCP server can reach StateConnected and publish its one and only EventStateChanged before the TUI's event subscription is live, so the event is missed. mcpStates is never seeded any other way, so the sidebar shows "None" for that server for the rest of the session even though its tools work fine (they're registered in a separate global registry, independent of mcpStates). Adds a 2-second re-seed tick that re-reads MCPGetStates() into mcpStates, so a missed initial event self-heals within a couple of seconds instead of never recovering. Also picks up later connects/disconnects the same way. Fixes charmbracelet#3279
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.
Summary
mcp.Initializeruns in a goroutine concurrently with the TUI starting up (internal/app/app.go:140)StateConnectedand publish its one and onlyEventStateChangedbefore the TUI's event subscription is live, so the event is missedmcpStatesis never seeded any other way (Init()doesn't seed it, and for a stable connection no further state event ever fires), so the sidebar shows None for that server for the rest of the session even though its tools work fine (they're registered in a separate global registry, independent ofmcpStates)MCPGetStates()intomcpStatesvia a newrefreshMCPStates()(deliberately skipshandleStateChanged'sUpdateAgentModelside effect, so it's safe to call on a timer) — self-heals a missed initial event within a couple of seconds, and also picks up later connects/disconnects the same wayFixes #3279
Root-caused by the issue reporter with exact file/line references and a manually-verified patch; this PR implements their proposed periodic re-seed approach.
Test plan
go build ./...go test ./internal/ui/...— all packages pass, no regressionsTestRefreshMCPStates— confirmsrefreshMCPStates()returns amcpStateChangedMsgreflecting the workspace's currentMCPGetStates(), simulating a state that was set before the sidebar'smcpStatesmap was ever seededp/security-audit,p/secrets,p/golang, Trail of Bits Go rules) on the changed files — 0 findings