Skip to content

fix(automations): start a fresh external probe after a cancelled one - #49727

Merged
nwparker merged 1 commit into
stablyai:mainfrom
Afloat16:fix/external-probe-cancel
Nov 26, 2026
Merged

nwparker merged 1 commit into
stablyai:mainfrom
Afloat16:fix/external-probe-cancel

Conversation

@Afloat16

@Afloat16 Afloat16 commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

If you left the Automations page and came back quickly, or toggled a host filter, Orca could hand you the leftover "cancelled" answer from the check it had just stopped. You saw "External automation probe was cancelled." instead of your automations. Now Orca notices the old check was cancelled and starts a new one, so you get real results.

What Changed

  • Before: ExternalAutomationProbeScheduler.cancelWhere (used by retainScopes / cancelAll) aborted active probes. The abort listener rejected the probe's promise right away, but the shared map entry for that key was only removed in the provider's .finally, after the provider actually settled. Local providers such as listLocalManager ignore the signal, so that window can be long. A same-key schedule() during the window returned the already-rejected promise.
  • After: the abort listener first drops the shared entry, but only if it still points to this probe, and then rejects. Abort listeners run synchronously inside controller.abort(), so the entry is gone before cancelWhere returns. The next same-key schedule() starts a fresh probe. The provider's .finally calls the same identity-checked releaseShared() closure, so a stale settle cannot evict the replacement's entry.
  • The shared map shape (Map<string, Promise<unknown>>) and the schedule() reuse line are unchanged from main, so there is no new type assertion.
  • New external-automation-probe-scheduler.test.ts: hold an active probe, cancel it with retainScopes([]), schedule the same key again, and expect 'fresh' instead of ExternalAutomationProbeCancelledError.

Why

The stale rejection came from tying cleanup of the shared entry to the provider settling instead of to the cancel. Releasing it on abort fixes the cause in the scheduler, so callers (scoped-external-automations.ts, the retainExternalScopes IPC) need no workaround. The contributor's first version stored { promise, signal } in the map and skipped aborted entries on reuse. That works too, but it changes the map shape and keeps a dead entry around. The identity check makes deleting on abort safe: a repeat cancel of an already-aborted probe does nothing, because abort() is idempotent and the listener is once.

The cancelled provider still holds its concurrency slot until it really settles, the same as on main. So old and new work can overlap only within the existing limit of 4.

Linked Issue

Fixes #49694

Visual Proof

N/A. This is main-process scheduler logic with no UI or layout change. The visible symptom (the "cancelled" error text) is covered by the regression test, which fails on main and passes here.

Testing

  • Reproduced on main: the new scheduler test fails with promise rejected "ExternalAutomationProbeCancelledError..." instead of resolving. With this change it passes.

  • src/main/automations/external-managers/: 3 files, all tests pass, including scoped-external-automations.test.ts.

  • Extra adversarial probes, run ad hoc and not committed, all pass:

    • concurrency 1: the replacement queues behind the cancelled provider
    • a stale settle does not evict the replacement entry
    • normal same-key sharing still dedupes
    • a retainScopes keep does not cancel
    • cancelling the replacement and then sending a third request resolves fresh
  • Static gates on both files are clean: oxlint, oxfmt --check, anti-slop --deny-warnings, code-quality native plugins --deny-warnings, ast-grep, and the changed-code quality gate (0 new findings).

  • Platform: macOS (unit level). The logic has no platform, SSH or WSL specifics. SSH scopes reject immediately with SshHostNotServedError.

  • 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. This path is cold: a few IPC calls per Automations page view or host filter change, with no polling. The only new work is one Map.get, plus possibly one delete, per active-probe abort. There is no new I/O, subprocess or sync work.

Microbenchmark (node, warmed, old and new alternated, median of 9, µs per schedule, old vs new):

Case Old New
n=24 0.29 0.29
n=500 3.3–4.0 3.0–4.0
n=24 with cancels 17–39 8–40
n=500 with cancels 13–19 16–18

Old and new are equal within noise. After a cancel, a fresh probe now does real work (one which lookup plus a jobs.json read) instead of returning the stale rejection. That work is capped by the existing concurrency limit of 4.

Risk

Level: Low. The riskiest part is the brief overlap after a cancel: the old provider is still settling while the replacement runs. It is bounded by the concurrency limit, and the identity checks keep the two from clobbering each other's shared entry. If this went wrong, users would see duplicate or missing probe results on the Automations page. To back it out, revert this commit.

Review

Reviewed for cancel/share state-machine invariants (queued vs active cancel, repeat cancel, stale settle), caller behavior, and concurrency accounting.

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

Original fix by @Afloat16 in #49727. Their authorship is kept through a Co-authored-by trailer.

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)

@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The scheduler now releases a shared probe key when its probe is aborted, before the provider call settles. Cleanup removes the key only if it still maps to that probe’s promise. A test verifies that the canceled probe rejects and a new probe with the same key resolves to its own result while the canceled provider call is still settling.

Severity of issue fixed: Medium

Merge Risk: Minimal · up to de410

Canceled external automation probes no longer cause a later request for the same key to inherit the cancellation, and uncanceled same-key requests still share one probe. The old provider keeps its concurrency slot until it settles. No actionable merge-blocking risk remains after review.

Pre-merge checks: Passed 4

Check name Status Explanation
Linked Issues check Passed [#49694] requires three behaviors. The head code in external-automation-probe-scheduler.ts meets each one.

(1) Do not inherit a canceled promise. The new releaseShared helper deletes the shared e…
Out of Scope Changes check Passed The change from the merge base to head touches two files. The scheduler file adds the releaseShared helper, calls it from the abort listener and from the finally cleanup, and replaces the inline i…
Title check Passed The title names the main change: the scheduler now starts a fresh external automation probe after a cancelled one, which matches the raw summary and objectives. The title uses the conventional fix(sco…
Description check Passed The description follows the repository template closely. It has ELI5, What Changed, Why, Linked Issue (Fixes #49694), Visual Proof (N/A with reason), Testing, Performance (None, because...), Risk with…
Full details: Linked Issues check

Explanation

[#49694] requires three behaviors. The head code in external-automation-probe-scheduler.ts meets each one.

(1) Do not inherit a canceled promise. The new releaseShared helper deletes the shared entry when the controller aborts (abort listener in start). A later schedule call with the same key no longer finds the canceled promise. cancelWhere aborts active entries, so the release runs for scope cancellation.

(2) Identity-based cleanup. releaseShared deletes the key only when this.shared.get(job.key) === settled. The old provider's finally calls the same guard, so it cannot delete a replacement entry.

(3) Physical concurrency ownership. The old entry stays in this.active until job.run settles (this.active.delete(entry) runs in finally). pump() admits a new entry only while active.size &lt; concurrency. With one slot, the replacement waits for the old provider.

Uncanceled same-key requests still share through the unchanged existing path in schedule.

Evidence gap: the committed test uses concurrency: 2. It asserts that the abandoned request rejects with ExternalAutomationProbeCancelledError and that the new request resolves to fresh while the old provider resolves to stale. No committed test asserts the one-slot wait or uncanceled sharing. Those behaviors rest on code reading of pump() and active. The author's reproduction was not re-run in this review.

The previous assessment described a signal-based check in schedule (!existing.signal.aborted). That code is absent at head. The previous conclusion does not apply to the current mechanism, so this result replaces it.

Full details: Out of Scope Changes check

Explanation

The change from the merge base to head touches two files. The scheduler file adds the releaseShared helper, calls it from the abort listener and from the finally cleanup, and replaces the inline identity check. The test file adds one test for a canceled key whose provider is still settling. Every hunk maps to the #49694 expected correction. No public declarations change, and no unrelated files appear in the change set. The PR description's CI and verification notes are not code changes. The SAFETY comment mentioned in the earlier review is not present in the head scheduler file. This does not affect scope.

Full details: Title check

Explanation

The title names the main change: the scheduler now starts a fresh external automation probe after a cancelled one, which matches the raw summary and objectives. The title uses the conventional fix(scope) form and is 68 characters, so it is concise and specific.

Full details: Description check

Explanation

The description follows the repository template closely. It has ELI5, What Changed, Why, Linked Issue (Fixes #49694), Visual Proof (N/A with reason), Testing, Performance (None, because...), Risk with level Low and a revert path, AI Disclosure section, Review, Agent skill boundary, Notes, and Checklist. It explains the before and after behavior and the mechanism. Minor gaps: the AI Disclosure section is left blank, which the template allows for internal contributors but which is unclear here. The final pnpm checklist item is unchecked. The description also names the original contributor and a PR number, which is acceptable.

  • 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

Recent 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: 670f6ca5-75e6-4afe-b968-63a4b7ac13fb
Commits

Reviewing files that changed from the base of the PR and between 7508091 and de4107d.

Files selected for processing: 2

  • src/main/automations/external-managers/external-automation-probe-scheduler.test.ts
  • src/main/automations/external-managers/external-automation-probe-scheduler.ts

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

Cancelling an active external automation probe rejected its promise
right away, but the shared entry for its key stayed in place until the
provider settled. A same-key request in that window reused the rejected
promise, so returning to the Automations page or toggling a host filter
showed "External automation probe was cancelled." instead of results.

The abort listener now drops the shared entry (only when it still points
to this probe) before rejecting, so the next same-key schedule starts a
fresh probe. The provider's settle uses the same identity-checked
release, so a stale settle cannot evict the replacement.

Fixes stablyai#49694

Co-authored-by: Afloat <[email protected]>
@nwparker
nwparker force-pushed the fix/external-probe-cancel branch from 7508091 to de4107d Compare November 26, 2026 18:22
@nwparker nwparker changed the title fix(automations): stop sharing canceled external probes fix(automations): start a fresh external probe after a cancelled one Nov 26, 2026
@nwparker
nwparker merged commit 2421110 into stablyai:main Nov 26, 2026
56 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.

[Bug]: stop sharing canceled external probes

2 participants