Let a UI channel declare itself the preferred bridge channel - #246
Open
philipp-winterle wants to merge 1 commit into
Open
philipp-winterle wants to merge 1 commit into
philipp-winterle wants to merge 1 commit into
Conversation
The primary channel - the one that answers every MCP and CTL operation, and whose account decides isPaidUser() - was whichever UI connected first. With the desktop app and a browser tab both open, which one that is comes down to startup order, there's no way to steer it, and nothing reports which one won. The operations message now carries an optional priority. The highest one becomes primary, and connection order still breaks ties, so a UI that sends no priority behaves exactly as before. Anything that isn't a finite number is read as no preference, so a malformed message can't take the role away from a well-behaved UI. Handing the role over mid-session now emits operations-changed for the new primary, and not-ready if it has no operations yet - previously only a disconnect could change primary, so neither case could arise.
3 tasks
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.
The problem
src/api/ui-operation-bridge.ts:The primary channel is the one that answers every MCP and CTL operation, whose
operationsare the ones exposed, and whose account decidesisPaidUser(). Itis whichever UI connected first, for as long as it stays connected.
With the desktop app and a browser tab both pointed at the same server - easy to
end up with, and easy not to notice - which one wins comes down to startup order.
There is no way to steer it and nothing reports which one it is. In my case the
MCP client kept answering out of a stale second window while the app I was
actually driving sat there ignored.
The change
The
operationsmessage may now carry an optionalpriority. The highest onebecomes primary and connection order still breaks ties, so a UI that sends no
priority behaves exactly as it always did. Anything that isn't a finite number is
read as "no preference", so a malformed message can't take the role away from a
well-behaved UI.
Handing the role over mid-session now emits
operations-changedfor the newprimary, and
not-readyif that channel has no operations yet. Previously only adisconnect could change the primary, so neither case could arise.
The UI counterpart is three lines - the desktop shell sends
priority: 1, abrowser tab sends
0:Merging this one first is fine: without it the field simply defaults to 0
everywhere and nothing changes.
Test plan
test/integration/ui-operation-bridge.spec.tsunder"Channel priority": a higher-priority channel wins whether it connected
first or second, execute requests route to it, a non-numeric priority is
ignored, and the role falls back to a lower-priority channel when the
preferred one disconnects. Three of the six fail before the change; the
other three are guards that the existing tie-breaking is untouched.
when nobody declares a priority, still pass unchanged.
test:unit: 23 passing.test:integration: 68 passing, 1 pending, 16 failing.mainhere fails 16too, and 62 pass, so the six added tests are the whole difference. The 16 on
mainare all environment-dependent - Docker CLI interception, Electron,Chrome, fresh and existing terminal, and the end-to-end server API test -
none of which this machine can run. I captured that list on
mainonly andcompared failure counts rather than names, because rerunning the suite here
launches real browsers and terminal windows.
tsc --noEmitclean.