Skip to content

fix(skills): evict removed runtime discovery cache - #11489

Merged
nwparker merged 6 commits into
stablyai:mainfrom
bbingz:fix/evict-removed-runtime-skill-cache
Sep 13, 2026
Merged

nwparker merged 6 commits into
stablyai:mainfrom
bbingz:fix/evict-removed-runtime-skill-cache

Conversation

@bbingz

@bbingz bbingz commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

When you remove or re-pair a server, Orca now forgets its old cached skill list and prevents a late scan from restoring it. Other servers and local skill lists keep their caches.

Details

Removed and re-paired runtime environments left their skill-discovery results in the renderer cache. Retired entries could also displace useful local/WSL entries from its 256-target capacity, and a late scan could restore a removed entry.

The existing catalog removal/re-pair boundary now evicts the exact runtime-scoped cache entry and detaches its pending scan. Completion writes use the existing current-promise identity check, so a retired scan cannot restore the cache or overwrite its replacement. This needs no additional invalidation collection. Surviving runtimes, local/WSL targets, scan coalescing, forced refresh behavior, and the 15-second freshness policy are preserved; unchanged catalog updates do not trigger scans.

Validation against main fa3d29fa11e3, with ORCA_BACKGROUND_LAUNCH=1:

  • 119 tests passed across ten suites, covering cache/discovery, mounted hooks, runtime status/catalog identity, and removal wiring.
  • A 512-runtime retirement workload leaves exactly the two surviving local/WSL cache entries. Pending work for a surviving runtime remains shared.
  • Both completion orders around same-ID re-pairing preserve the replacement's result and pending slot.
  • The original baseline fails four retirement regressions. Removing the promise-identity fence fails three late-result regressions. The restored fix passes again.
  • Web typecheck and all three changed-code quality gates passed.

Original contributor history is preserved. These are local unit/component checks on macOS; no live Electron or remote-host run is claimed. No layout, wire, filesystem, or provider API changed.

Fixes #11429.

@coderabbitai

coderabbitai Bot commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 7fa6af46-e76f-4882-ba3a-39c1524f7b86

📥 Commits

Reviewing files that changed from the base of the PR and between 20672d2 and eb36a4a.

📒 Files selected for processing (3)
  • src/renderer/src/hooks/useInstalledAgentSkills.react.test.tsx
  • src/renderer/src/hooks/useInstalledAgentSkills.ts
  • src/renderer/src/store/slices/runtime-status-skill-cache-eviction.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

Runtime environment removal and re-pairing now evict installed-agent skill discovery cache entries. Pending discoveries for evicted environments are invalidated, so stale results cannot repopulate the cache. Runtime target changes reset hook state and trigger fresh discovery. Tests cover selective rescans, preserved scans, re-pairing, suspended renders, and in-flight discovery behavior.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to eb36a

Re-pairing no longer allows a retired runtime’s skill results to appear for the replacement runtime. No actionable merge risk remains.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 9.09% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 22 functions across 7 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the primary change: evicting discovery cache entries for removed runtime environments.
Description check ✅ Passed The description is detailed and relevant. It includes an ELI5 summary, implementation details, rationale, linked issue, testing results, platform scope, and compatibility considerations. It does not u…
Linked Issues check ✅ Passed Issue #11429 requires eviction for removed runtime IDs, safe same-ID re-pairing, stale scan protection, store-free discovery code, no status-only rescans, and preservation for surviving runtimes. The …
Out of Scope Changes check ✅ Passed The changes stay within Issue #11429. The cache eviction helpers, pending-scan guards, runtime lifecycle integration, re-pair target handling, and regression tests directly implement or verify runtime…
  • Fix all pre-merge checks with AI

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

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Jul 30, 2026 •

Copy link
Copy Markdown

Greptile Summary

This PR fixes a bug where skill-discovery cache entries for a removed or re-paired runtime environment would persist in renderer memory, causing stale skills to be served for that environment's next connection. It also prevents any in-flight discovery scan from repopulating the cache after its owning environment has been retired.

  • Adds deleteInstalledAgentSkillDiscoveryCache(key) for per-key eviction, and a WeakSet to mark invalidated in-flight promises so their .then() handlers skip the writeInstalledAgentSkillDiscoveryCache call.
  • Adds evictInstalledAgentSkillDiscoveryForRuntimeEnvironments(ids) called from the existing setRuntimeEnvironments boundary, covering both outright removal and same-id re-pairing, without touching caches for surviving environments.
  • Includes three targeted regression tests (removal-only rescan, re-pair eviction without churning, in-flight suppression) that were red before the fix and green after.

Confidence Score: 5/5

Safe to merge — the change is scoped entirely to renderer-memory bookkeeping, with no IPC, network, or persistence surface touched.

All four changed files are straightforward: a new per-key delete helper, a WeakSet-based invalidation guard on in-flight promises, one call-site wired into an existing retirement boundary, and three targeted regression tests. The self-referential closure on discovery inside the .then() guard is a valid JS pattern. Surviving environment caches are untouched, WeakSet entries are garbage-collected naturally, and the finally cleanup correctly skips the evicted key.

Files Needing Attention: No files require special attention.

Important Files Changed

Filename Overview
src/renderer/src/hooks/installed-agent-skill-discovery-cache.ts Adds deleteInstalledAgentSkillDiscoveryCache(key) to enable per-key eviction without clearing the entire LRU map; minimal and correct.
src/renderer/src/hooks/installed-agent-skill-discovery.ts Introduces invalidatedPendingDiscoveries WeakSet and evictInstalledAgentSkillDiscoveryForRuntimeEnvironments; the self-referential closure on discovery in the .then() guard is a valid JS pattern and correctly prevents stale in-flight scans from writing to cache.
src/renderer/src/store/slices/runtime-status.ts Calls evictInstalledAgentSkillDiscoveryForRuntimeEnvironments at the correct setRuntimeEnvironments boundary for both removed and re-paired environments, before other retired-state teardown.
src/renderer/src/store/slices/runtime-status-skill-cache-eviction.test.ts Three regression tests covering targeted removal, re-pair eviction without churning unchanged runtimes, and in-flight scan suppression; all three cases are red/green validated per PR notes.

Reviews (2): Last reviewed commit: "fix(skills): evict removed runtime disco..." | Re-trigger Greptile

@bbingz
bbingz force-pushed the fix/evict-removed-runtime-skill-cache branch from aa2255c to 5d44ad7 Compare August 11, 2026 19:23
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@bbingz

bbingz commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

Contributor hygiene: rebased onto current main and resolved the runtime-status.ts import conflict (kept main's disconnect-toast/hydration/refresh imports + this PR's skill-cache eviction call). Force-pushed to fix/evict-removed-runtime-skill-cache.

Still needs a maintainer to Approve and run workflows for full CI.

@nwparker nwparker removed the P1 label Aug 19, 2026
m4air and others added 3 commits September 11, 2026 22:46
… same id

- Fold the pairing revision into useActiveSkillDiscoveryRuntimeTarget's
  selector so a same-id re-pair yields a new runtime target and every
  mounted useInstalledAgentSkillNames effect re-runs instead of holding
  the retired peer's installed list after the module cache is evicted.
- Reset hook-local result/loading state on runtime target identity change,
  which also bumps the refresh generation so an in-flight scan issued to
  the retired peer can no longer commit its result into React state.
- Add mounted-hook regression tests covering the re-pair rescan and the
  in-flight stale-scan fence.

@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

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 0a55ab92-5122-490c-a908-f5cfcb10296f

📥 Commits

Reviewing files that changed from the base of the PR and between 1c44dbc and 20672d2.

📒 Files selected for processing (3)
  • src/renderer/src/hooks/use-active-skill-discovery-runtime-target.ts
  • src/renderer/src/hooks/useInstalledAgentSkills.react.test.tsx
  • src/renderer/src/hooks/useInstalledAgentSkills.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 1 remains after this review.

stateResetInputRef.current.discoveryTargetKey !== discoveryTargetKey ||
stateResetInputRef.current.enabled !== enabled
stateResetInputRef.current.enabled !== enabled ||
stateResetInputRef.current.runtimeTarget !== runtimeTarget

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.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Fence retired scans by runtime target identity.

React can run the retired request’s promise continuation after the re-pair render but before the replacement passive effect increments refreshGenerationRef. The unchanged discoveryTargetKey and generation then let the retired request queue a stale setResult update. If the replacement scan fails, its catch path does not clear that result. The current test resolves the retired scan after act flushes passive effects, so it does not cover this ordering.

Capture and compare the request’s runtimeTarget, and add a regression test that settles the retired request before passive effects run.

Proposed stale-result guard
 const refresh = useCallback(
   async (force = true, showLoading = true): Promise<boolean> => {
     const requestDiscoveryTargetKey = discoveryTargetKey
+    const requestRuntimeTarget = runtimeTarget
     const requestGeneration = ++refreshGenerationRef.current
     const writeIfCurrent = (write: () => void): void => {
       if (
         mountedRef.current &&
         requestGeneration === refreshGenerationRef.current &&
         currentDiscoveryTargetKeyRef.current === requestDiscoveryTargetKey &&
+        stateResetInputRef.current.runtimeTarget === requestRuntimeTarget
       ) {
         write()
       }

@nwparker nwparker closed this Sep 13, 2026
@nwparker nwparker reopened this Sep 13, 2026
…ef write

React Doctor flagged the render-phase write to stateResetInputRef. React can
discard a render after the write, in which case the next render sees "already
reset" and keeps painting the previous target's skill list until a rescan.
Track the reset inputs in useState and adjust it during render instead, which
React replays safely.

Also drop the `as never` / `as GlobalSettings` casts from the tests this PR
added, since main now enforces consistent-type-assertions on changed lines.
@nwparker
nwparker merged commit 599e669 into stablyai:main Sep 13, 2026
33 checks passed
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.

Skill discovery cache is not evicted when a runtime environment is removed

4 participants