Skip to content

perf(bots): open one credential per tool call and stop rereading closed tool views - #49171

Merged
AmoabaKelvin merged 5 commits into
mainfrom
w-rb-bots-perf-followups
Nov 25, 2026
Merged

AmoabaKelvin merged 5 commits into
mainfrom
w-rb-bots-perf-followups

Conversation

@AmoabaKelvin

@AmoabaKelvin AmoabaKelvin commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

ELI5

Bots tool code did extra work that grew with the number of bots and saved credentials. Each HTTP call a bot's agent made to a tool unlocked every credential the bot had saved, twice. Every bots change re-read the tool lists of bots nobody had open. Two name checks and the error redaction scanned a whole list once per server. Now each step does work only for what it uses.

Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​208 $\color{#cf222e}{\Huge{\mathbf{−}}}$​5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​203
Prod 9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​122 $\color{#cf222e}{\Huge{\mathbf{−}}}$​77 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​45

What Changed

Nothing looks different. The costs, each confirmed on main with a count at N and 10N first:

  • Relay call opened every credential, twice. botToolCredentialsReader (and every store read and write through parseStored) decrypted every entry in the bot's credential file even when one id was asked for. The relay source then opened two readers per call, and an OAuth call read the store a third time inside botToolAccessToken. Store slots now open on first read. The relay source uses one reader and passes the sign-in it read into botToolAccessToken / refreshBotToolAccessToken. Per relay call: 20 → 1 opens at 10 credentials, 200 → 1 at 100. A token refresh commit now opens only the sign-in it saves, not every entry.
  • Bots changes reread closed tool views. bot-tool-checks.ts kept a reads entry for every bot any view had shown, and each botsChanged (settings/bot) re-ran bots.tools.list for all of them, open or not, ignoring the notice's bot scope. Now a change rereads only bots a view still shows and the notice concerns (botChangeConcerns). A closed bot is forgotten, unless it holds a finished check its host still lists: then it's marked stale so the next view rereads only its tools, and the Needs you badge keeps the check's problem. Before: 10 closed views → 10 RPCs per change, then 100 more → 110. After: 0, and only the shown bot is reread.
  • Codex name scans. codexToolProblems and isTakenByCodexStdio used Array.includes per server. They now use Sets: name reads go from 5,150 to 200, and owner-name reads from 10,000 to 100, at 100 servers. readCodexStdioToolNames returns the parser's Set rather than copying it into an array.
  • Redaction. redactBotToolProblems re-collected and re-sorted every server's secrets once per problem. It now collects each distinct value once per list, and only when some problem has a detail to scrub: header reads go from 10,000 to 100 at 100 servers, and to 0 for a list with no details.

The envelope parsing moved into bot-tool-credential-envelope.ts, next to the schema it parses.

Why

All four came in with the bots merge (a6918ec). Credential reads were written for one-off lookups (open the whole file, pick an id) and then reused on the relay's per-call path. The tools cache was written as "shared by every row until the next change", with no notion of rows that had gone away. The list scans were fine at a few servers.

Fixing the store's slot to open lazily, rather than adding a per-caller cache, makes every reader and writer pay only for the ids it touches with one change. Dropping closed bots at the moment a change arrives, instead of evicting on unmount, avoids rereading when a view's effect simply re-runs. The relay still reads the tools file and the credential file once per call. Both are shared with other Orca processes on the same home and with token refreshes, so a call has to see current bytes. That cost no longer grows with the number of credentials.

Linked Issue

No issue: found by a performance pass over the bots tool code after #49123.

Visual Proof

N/A. No visible change: the same tool lists, problems, badges and relay answers, with less work behind them.

Testing

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

  • Every added test fails without this change and avoids the test anti-patterns

  • Counted each cost on main at N and 10N with scratch probes against real code (decrypts via the secret store, host RPCs via callBotRpc), then again after the fix: numbers above.

  • Two perf contracts, each shown failing with its fix reverted:

    • bot-tool-credential-source.performance.test.ts: one decrypt per relay call for saved headers and for a sign-in, at 10 and 100 credentials, and one per token commit.
    • bot-tool-checks.performance.test.ts: zero rereads for closed views and for a change scoped to another bot. A closed bot's finished check survives a change for the next badge, and a bot its host no longer lists is forgotten.
  • The mcp-host-list switch contract drops from 4C to 3C+1 opens, because the answer's sign-in lookup now opens only its own entry.

  • Focused suites pass: bot tool credentials, OAuth, tools file, Codex tools, MCP host list. check:changed passes. Run on macOS. The change has no platform-specific paths or processes.

Performance

Less work everywhere it touches, as counted above. Relay calls do 1 decrypt instead of 2C. A bots change rereads only the open bots it names, instead of every bot ever shown. Codex name checks and redaction are linear instead of quadratic. Nothing runs more often. The only retained state is a closed bot's finished check, kept only while its host lists the bot.

Risk

Level: Low

The riskiest part is the tools cache in bot-tool-checks.ts. If a host scoped a tools change to the wrong bot, an open tool view would miss that reread until the next change. Every settings/bot notice the host sends today is host-wide or names its bots, and an older host's unscoped notice still rereads everything. Lazy store opening keeps the folder/id binding check, the unreadable-file error and the older-layout warning. The only difference is that an entry that fails to open is warned about when it's asked for, not on every read. A plain revert backs it all out.

AI Disclosure

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

The credential binding (folder and id sealed with each entry) is unchanged. Remote hosts benefit the most from the reread fix, since each skipped bots.tools.list is a round trip to the paired server.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • I stated the risk: what could break, for whom, and how to back it out
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

…ereading closed tool views

A relay call opened every credential the bot had saved, twice. The store
reader now opens only the entries asked for, and the relay asks once.

A host's bots change reread the tools of every bot any view had shown
since the last change, open or not. Bots no view shows are now forgotten
instead, and the next view to open reads them fresh.

The Codex name checks and the tool problem redaction no longer scan a
list per server.
A host change dropped a closed bot's reads with its finished check, so the
Needs you badge lost a tool problem it had shown. Such a bot now keeps its
check and rereads only its tools when the next view opens. The store's
envelope parsing moves next to the envelope schema.
…n-in once

A host's bots change now rereads only the shown bots it concerns. A relay
call to an app Orca signs in to reads the store once instead of twice, and
redaction collects each distinct saved value once, only when some problem
has a detail to scrub.
…d bots' checks

Every store read and write opened all of a bot's credentials; a token
refresh commit now opens only the sign-in it saves. A closed bot keeps its
finished tools check only while its host still lists it.
@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Walkthrough

Credential parsing now uses a shared envelope parser, and the credential reader opens entries on demand. OAuth calls pass loaded entries to token acquisition and refresh. Codex tool-name APIs use read-only sets. Secret redaction reuses deduplicated values, and bot tool checks filter host changes and track stale reads.

Merge Risk: Low · up to 8dd93

Redaction of secrets now leaves a configured value in output for a narrow input pattern where a replacement pass used to hide it. Other changes reduce credential and tool-list work without visible behavior change. Merge risk is low and the redaction edge case can be followed up.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names two of the main changes: opening one credential per tool call and stopping rereads of closed tool views. It is specific and matches the changeset, but it does not mention the Codex Set…
Description check Passed The description follows the template and fills every required section. It gives an ELI5, a detailed before-and-after with measured counts, the mechanism, the reason for the approach, and a Testing lis…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names two of the main changes: opening one credential per tool call and stopping rereads of closed tool views. It is specific and matches the changeset, but it does not mention the Codex Set-based name checks or the redaction dedup. Those are secondary changes.

Full details: Description check

Explanation

The description follows the template and fills every required section. It gives an ELI5, a detailed before-and-after with measured counts, the mechanism, the reason for the approach, and a Testing list. The Performance section is filled in, and the Risk section names the riskiest part and a revert path. The Linked Issue section explains that no issue exists, which the template allows for maintainers. Some gaps remain. The AI Disclosure section is empty, the final lint, typecheck, test, and build checkbox is unchecked, and the Review section is empty. The Linked Issue section also has no 'Fixes #' reference, though the author gives a reason for omitting it.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f70525e8-8bf3-4275-96b1-a5324787a2bb
Commits

Reviewing files that changed from the base of the PR and between 3518e7b and 8dd93ec.

Files selected for processing: 13

  • config/main-blocking-helper-baseline.txt
  • src/main/bots/bot-tool-credential-envelope.ts
  • src/main/bots/bot-tool-credentials.ts
  • src/main/bots/bot-tool-redaction.ts
  • src/main/bots/bot-tools-codex.test.ts
  • src/main/bots/bot-tools-codex.ts
  • src/main/bots/bot-tools-host.ts
  • src/main/bots/tool-oauth/bot-tool-credential-source.performance.test.ts
  • src/main/bots/tool-oauth/bot-tool-credential-source.ts
  • src/main/bots/tool-oauth/bot-tool-oauth-tokens.ts
  • src/main/mcp-servers/mcp-host-list.performance.test.ts
  • src/renderer/src/components/bots/bot-tool-checks.performance.test.ts
  • src/renderer/src/components/bots/bot-tool-checks.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

const values = servers.flatMap((server) =>
Object.values(('url' in server ? server.headers : server.env) ?? {})
)
return [...new Set(values.filter(Boolean))].sort((a, b) => b.length - a.length)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor · Security & Privacy · Heavy lift

Deduplicating secrets removes the second replacement pass for repeated values.

Before this change, a value listed by two servers was replaced once per entry. The second pass could remove residue that the first pass created. For example, with the secret hunter2[ listed twice and the text hunter2hunter2[, the old output was [redacted]redacted], which does not contain the secret. The new code runs one pass per distinct value and returns hunter2[redacted], which still contains hunter2[.

Redacted output must not contain any configured secret value. Choose a replacement that guarantees this, such as repeating replacement until no configured value remains. Keep the replacement safe for secrets that appear inside [redacted], such as red, because a naive repeat loop does not terminate for that case. Restoring duplicate passes does not fix the issue, because a single occurrence leaks in the same way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant