Repository navigation
fix(automations): start a fresh external probe after a cancelled one - #49727
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Severity of issue fixed: Medium Merge Risk:
|
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]>
7508091 to
de4107d
Compare
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
ExternalAutomationProbeScheduler.cancelWhere(used byretainScopes/cancelAll) aborted active probes. The abort listener rejected the probe's promise right away, but thesharedmap entry for that key was only removed in the provider's.finally, after the provider actually settled. Local providers such aslistLocalManagerignore the signal, so that window can be long. A same-keyschedule()during the window returned the already-rejected promise.sharedentry, but only if it still points to this probe, and then rejects. Abort listeners run synchronously insidecontroller.abort(), so the entry is gone beforecancelWherereturns. The next same-keyschedule()starts a fresh probe. The provider's.finallycalls the same identity-checkedreleaseShared()closure, so a stale settle cannot evict the replacement's entry.sharedmap shape (Map<string, Promise<unknown>>) and theschedule()reuse line are unchanged from main, so there is no new type assertion.external-automation-probe-scheduler.test.ts: hold an active probe, cancel it withretainScopes([]), schedule the same key again, and expect'fresh'instead ofExternalAutomationProbeCancelledError.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, theretainExternalScopesIPC) 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, becauseabort()is idempotent and the listener isonce.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, includingscoped-external-automations.test.ts.Extra adversarial probes, run ad hoc and not committed, all pass:
retainScopeskeep does not cancelStatic 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 onedelete, 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):
Old and new are equal within noise. After a cancel, a fresh probe now does real work (one
whichlookup 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
Notes
Original fix by @Afloat16 in #49727. Their authorship is kept through a
Co-authored-bytrailer.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)