Repository navigation
perf(mcp): read the credential store once per MCP server list, check and switch - #49123
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
…ot tools list Listing the host's MCP servers or a bot's tools opened every saved credential once per credentialed row, and each write did the same for every row's sign-in check. One read now serves every row. The writer finds each entry's previous one by name instead of scanning, and a servers-only edit no longer derives extras it throws away.
The tools check (mcpServers.problems, bots tools problems) asked the credential store whether each credentialed server was an Orca sign-in, opening the whole store per row. It now uses the same one-read sign-in lookup as the lists and the writer, which takes its read lazily.
A write that replaced saved values read the whole credential store once per replaced credential to keep the old values for a rollback. The writer's one store read now answers those too.
49d03ee to
3bd2c17
Compare
ELI5
Opening the MCP servers list made Orca unlock every saved MCP password once per server that had one. With 50 such servers that's 2,550 unlocks for one list. Checking the servers' health and turning one server on or off did the same, and a switch also searched the whole list once per server. Now one unlock serves the whole list, and each server finds its old saved entry straight away.
What Changed
mcpServers.list, a bot's tools list) reads the encrypted credential store once and looks up every row's sign-in state from that one read (botToolCredentialsReader, taken lazily so a list with no credentials reads nothing). Before, every row with a credential re-read and re-decrypted the whole store (botOwnTool→botToolSignInState→readBotToolOAuth).writeServers) finds each entry's previous one through a name map built once per write, not an array search per row. It also checks every row's sign-in address from one store read, not one read per credentialed row. This is the path every host MCP switch takes (agent on/off, workspaces, shared process), since those pass every entry with its extras.mcpServers.problems, a bot's tools check) asks whether each credentialed server is an Orca sign-in from one store read, not one per row.changeBotToolServers(bot tool edits, removals, package apply) gives its change the snapshot's servers directly. It no longer builds and filters every row's extras just to drop them. The writer still carries each row's extras over from its previous entry, as before.Nothing visible changes and stored files are byte-for-byte the same.
Why
The bot-tools layer answered per-row questions with whole-store work.
botOwnToolandwriteServerswere written for a bot's own tools list, usually a handful of servers edited now and then, where a store read per row didn't matter. The per-host MCP list put every host server on that layer, listed it from every client and switched rows one at a time. That turned the per-row reads quadratic.The fix is where the per-row decision lives, so the MCP list, the bots tools list and every write path all get it, on local, SSH and paired-server hosts alike. Callers don't need to change. A cache of the decrypted store was rejected: it would be a second copy of secrets in memory with its own invalidation, when reading once per request is enough.
Linked Issue
Linear: STA-18109, STA-18111, STA-18115
Visual Proof
N/A: no visible change. The lists and the saved files are identical; only the amount of work behind them changes.
Testing
Counted on macOS against unfixed
mainand this branch:The perf contract
mcp-host-list.performance.test.tspins all five decrypt counts at N and 10N. On unfixedmainit fails (expected 110 to be 20). The search and extras counts came from a scratch instrumented run, because neither is visible from outside the writer. The existing host list, bot tools file, credentials, OAuth, relay, plugin sync and launch tests (13 files) pass unchanged.Performance
This removes work. Every list, tools check and write now does a fixed number of credential-store reads instead of one per credentialed server. Each switch does one name-map build instead of a quadratic search. Servers-only edits skip a discarded pass over every row. See the table above.
Risk
Low. The riskiest part is the writer reading every sign-in, and every old value kept for a rollback, from one store read instead of one read per row. Nothing writes the store between that read and the writer's own credential changes, which come after it inside the same per-folder transaction. So every row sees the same state it saw before, and a rollback restores the same values. A plain revert backs it out.
Level: Low
AI Disclosure
Review
Agent skill upstream boundary
Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
No wire, file-format or platform-specific change. SSH and paired hosts run the same host-side code.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)