Skip to content

fix(agent-cli-update): drop update groups for hosts that were removed - #48517

Merged
nwparker merged 1 commit into
mainfrom
bugbash/issue-48464
Nov 24, 2026
Merged

nwparker merged 1 commit into
mainfrom
bugbash/issue-48464

Conversation

@nwparker

@nwparker nwparker commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

The status bar's CLI updates list kept showing a server after you removed it (or re-paired that slot to a different server), until the window reloaded. Now a removed server drops off the list right away.

Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​83 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​81
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​31 $\color{#cf222e}{\Huge{\mathbf{−}}}$​3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​28

What Changed

Before: the agentCliUpdates store slice only ever added hosts. Removing a paired server, or re-pairing the same environment id to another peer, left its group in the CLI updates popover. An answer or run result from the old host that arrived later could also put it back.

After: when setRuntimeEnvironments retires environment ids (removed, or a same-id re-pair), it calls the new forgetAgentCliUpdateHosts(ids). This runs next to the other per-host purges (purgeStaleRuntimeHostState, clearHostWorkspaceStatuses). It:

  • deletes those hosts' entries from agentCliUpdates, and returns the same state when nothing changed, so there's no re-render;
  • clears their check timestamps and in-flight checks, so a re-paired peer gets asked again instead of reusing the old peer's pending promise;
  • stops late results from adding the host back. An in-flight check only writes if it is still the current check for that key, and writeHost ignores ids listed in removedRuntimeEnvironmentIds, so a late runAgentCliUpdate result can't re-add a removed host either.

A host that is disconnected but still configured keeps its entry. This computer ('' key) is never touched.

Why

Hooking into the existing retirement point in setRuntimeEnvironments reuses the same signal every other per-host cache already uses. It needs no polling, no new RPCs and no new subscriptions.

This is a partial fix. The issue's other half, asking paired servers that are used only through terminals (servers this window never asked), is still open and needs a separate change.

Linked Issue

Refs #48464

Visual Proof

N/A. This is a store-level change: an entry leaves the popover once its environment is removed. Showing it needs two paired remote servers and a GUI run, which aren't available for this landing step. The behavior is covered by the store tests below, which drive the same setRuntimeEnvironments path the UI uses.

Testing

  • pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/store/slices/runtime-host-updates/: 4/4 pass.

  • The 2 new tests fail when the source change is reverted and the tests are kept. Without the fix the removed host stays in the map, and the old peer's late answer overwrites the re-paired one.

    • drops removed hosts and their late answers and run results, keeping this computer and remaining hosts
    • asks a re-paired peer afresh and drops the old peer answer that arrives late
  • pnpm run tc:web, oxlint, oxfmt, anti-slop, code-quality native plugins, ast-grep and check-changed-code-quality.mjs all pass on the touched files.

  • Platform: macOS (unit and store level). The logic has no platform-specific paths.

  • 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

Performance

None. forgetAgentCliUpdateHosts runs only when setRuntimeEnvironments retires ids, which is rare (the user removes or re-pairs a server). The writeHost guard is one Set.has. Micro-benchmark (Node, 20k iterations): writeHost 0.139 µs old vs 0.124 µs new with 3 hosts, and 28.6 µs vs 27.8 µs with 1000 hosts (within noise). Forgetting 1 of 1000 hosts takes 27 µs, and forgetting all 1000 takes 51 µs, far under a 16 ms frame. There is no new polling, I/O, subprocess or RPC work.

Risk

Level: Low

Renderer store only. The worst case is that a host's update group disappears when it shouldn't, and it comes back on the next check. Only retired ids are dropped, and a disconnected but still-configured host is kept. Nothing changes over the wire, so older paired servers are unaffected. Back out with a plain revert.

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.

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)

Reported by @mmarabel

A removed or re-paired server stayed in the status bar CLI updates list
until reload, because nothing told the agentCliUpdates slice when an
environment was retired. setRuntimeEnvironments now calls
forgetAgentCliUpdateHosts with the retired ids (removed, or a same-id
re-pair to another peer), next to the other per-host purges. It drops
their entries, check times and in-flight checks, so a late answer,
failure or run result from the old host can't list it again. A recheck
still pending for a removed host asks nothing, because its runtime
status was purged with it. A disconnected but still-configured host
keeps its entry. No polling or new RPCs.

Tests use the shared publicRuntimeEnvironment and agentCliUpdateHostTarget
fixtures, and cover a failed run result that resolves after its host is
removed.

Refs #48464 (asking paired hosts the list never asked stays open)
@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Walkthrough

When runtime environments are removed or replaced, the runtime status slice now clears agent CLI update state for those hosts. The update slice ignores writes for removed hosts and applies check results only when the request is still current. Tests cover removal, late results, and peer re-pairing.

Merge Risk: Moderate · up to ae6cf

Removed paired servers now drop out of the CLI update status promptly. When a server ID is re-paired to a different peer, a late result from the old peer's update run can still overwrite the new peer's state and allow a second update to start. A queued refresh can also be dropped. Both gaps should be fixed before merge.

Pre-merge checks: Passed 3 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Description check Inconclusive The description follows the template well. It covers ELI5, What Changed (before and after with mechanism), Why (including why this hook and that the fix is partial), Linked Issue (Refs #48464, not Fix… Confirm whether the author is a stablyai maintainer. If not, link an actual issue with 'Fixes #' instead of 'Refs #48464'. Fill in or mark the AI Disclosure section. Mark the Review section if it applies. Run pnpm lint, pnpm typecheck, pnpm…
Passed Passed checks: 3 passed

Check name Status Explanation
Title check Passed The title names the main change: removing CLI update groups for hosts that were removed. The change clears the agentCliUpdates entries, check timestamps, and in-flight checks for retired runtime envir…
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 the main change: removing CLI update groups for hosts that were removed. The change clears the agentCliUpdates entries, check timestamps, and in-flight checks for retired runtime environments. The title uses the fix prefix and a specific scope, and it matches the changeset.

Full details: Description check

Explanation

The description follows the template well. It covers ELI5, What Changed (before and after with mechanism), Why (including why this hook and that the fix is partial), Linked Issue (Refs #48464, not Fixes), Visual Proof (N/A with reason), Testing with named tests and platform, Performance with measurements, Risk with level and back-out, and the Agent skill boundary checkbox. Gaps: the template asks for a Linked Issue with 'Fixes #', but the author used 'Refs #' and the template says Refs is not sufficient for outside contributors. The AI Disclosure and Review sections are left blank or unaddressed. The 'pnpm lint, typecheck, test, build' checkbox is unchecked, and the author did not report full runs of those commands. The author should confirm whether the contributor is a maintainer, since that changes the linked-issue requirement.

Resolution

Confirm whether the author is a stablyai maintainer. If not, link an actual issue with 'Fixes #' instead of 'Refs #48464'. Fill in or mark the AI Disclosure section. Mark the Review section if it applies. Run pnpm lint, pnpm typecheck, pnpm test, and pnpm build, or state that CI will cover them, and update the checklist to match. The Testing section also reports platform as macOS only, which the template asks the author to state explicitly, so this is already covered.

  • 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: 2

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: e122681d-89f4-431f-b525-716e63f73060
Commits

Reviewing files that changed from the base of the PR and between 0cd805f and ae6cfe0.

Files selected for processing: 4

  • src/renderer/src/store/slices/runtime-host-updates/agent-cli-updates.test.ts
  • src/renderer/src/store/slices/runtime-host-updates/agent-cli-updates.ts
  • src/renderer/src/store/slices/runtime-status/create-runtime-status-slice.ts
  • src/renderer/src/store/slices/runtime-status/runtime-status-types.ts

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

const writeHost = (key: string, write: (host: AgentCliUpdateHost) => AgentCliUpdateHost) =>
set((state) => {
// A run result from a removed host must not list it again.
if (state.removedRuntimeEnvironmentIds.has(key)) {

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.

Major · Stability & Availability · Quick win

Fence run completions against same-ID peer replacement.

If peer A has a pending run when its environment ID is re-paired to B, cleanup removes A's running marker. B can then start a run under the same ID. Because that ID is not tombstoned, A's completion still passes this guard.

A's failure overwrites B's running marker with failed. A's success removes B's running marker and update. Either path permits another B run while B's first run is pending. A transport rejection also reaches the failure write.

Capture a host-incarnation token when each run starts. Invalidate that token in forgetAgentCliUpdateHosts, and check it before either completion write. Preserve normal completion for an unchanged host.

Based on learnings, delayed writes need an identity check when an ID can be reused.

Source: Learnings

Comment on lines +188 to +189
checkedAt.delete(id)
checks.delete(id)

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 · Functional Correctness · Quick win

Clear queued rechecks when a host is forgotten, and stop stale rechecks from changing the replacement host's tracking.

forgetAgentCliUpdateHosts removes checkedAt and checks for a retired environment ID, but leaves rechecking set. If a recheck was queued for the old peer, the replacement peer's recheck returns at the rechecking.has(key) guard and is dropped. When the old check settles first, its continuation calls checkAgentCliUpdates. That call joins the replacement check that is still pending, so no check runs after the replacement's answer. An update finished on the replacement can stay out of the status bar until another check runs.

Forgetting a host should also clear its queued recheck. The recheck continuation should run only while it still owns the key, using the same identity check as the check callbacks.

Source: Learnings

@nwparker
nwparker merged commit 9020e0b into main Nov 24, 2026
54 checks passed
@nwparker
nwparker deleted the bugbash/issue-48464 branch November 24, 2026 22:51
Jinwoo-H pushed a commit that referenced this pull request Nov 24, 2026
…#48517)

A removed or re-paired server stayed in the status bar CLI updates list
until reload, because nothing told the agentCliUpdates slice when an
environment was retired. setRuntimeEnvironments now calls
forgetAgentCliUpdateHosts with the retired ids (removed, or a same-id
re-pair to another peer), next to the other per-host purges. It drops
their entries, check times and in-flight checks, so a late answer,
failure or run result from the old host can't list it again. A recheck
still pending for a removed host asks nothing, because its runtime
status was purged with it. A disconnected but still-configured host
keeps its entry. No polling or new RPCs.

Tests use the shared publicRuntimeEnvironment and agentCliUpdateHostTarget
fixtures, and cover a failed run result that resolves after its host is
removed.

Refs #48464 (asking paired hosts the list never asked stays open)
MBA3000 added a commit to MBA3000/orca that referenced this pull request Nov 26, 2026
…, spawning nothing

Review on stablyai#49232: an automatic agentCliUpdate.check on every connected host
spawns --version for each installed CLI (and a login-shell capture on
SSH/WSL), the pattern decided against in stablyai#48287/stablyai#48517.

The host now keeps each agent's last check answer and serves it for
agentCliUpdate.check with `cached: true`, without resolving, spawning or
fetching anything; an update run drops the agent's answer. Hosts advertise
agent-cli-update.cached.v1, and the renderer reads the cache only from
those (older hosts ignore unknown params and would run a full check), once
per connection. A cached answer never counts as a check, so the next
user-triggered check still asks the host for real.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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