Skip to content

Cancel abandoned file searches and prevent stale results - #25370

Merged
nwparker merged 24 commits into
mainfrom
nwparker/file-search-cancellation
Oct 6, 2026
Merged

nwparker merged 24 commits into
mainfrom
nwparker/file-search-cancellation

Conversation

@nwparker

@nwparker nwparker commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 21 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1342 $\color{#cf222e}{\Huge{\mathbf{−}}}$​32 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1310
Prod 46 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1099 $\color{#cf222e}{\Huge{\mathbf{−}}}$​769 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​330

ELI5

Part 2 of 3; stacks on #25369 and precedes #25371.

Abandoning a search stops its host work. Switching the workspace root or owner immediately hides obsolete results and prevents opening them.

What Changed

Carries cancellation through connection setup, capability waits, host searches and both subscription routes. Saved results retain their root and owner; shortcuts and Escape keep their application behavior.

Shares the native text-search runner between desktop IPC and runtime requests, removing 171 net production lines. Callers still own authorization and request identity. An aborted subscription setup closes any host subscription, including a late acknowledgement.

Why

One process runner preserves identical parsing, deadlines and cleanup across callers. Host cancellation releases actual work, while ownership checks keep stale UI results from activating against a new workspace.

Linked Issue

Fixes #12292. Fixes #20758.

Visual Proof

Replacing a workspace root under the same ID previously retained root A results under root B. The corrected panel refreshes to B; result activation loads B content. These are controlled original-component before/after comparisons on the same fixture.

Before: root B shows root A result

Before: root B shows root A result

After: root B shows root B result

After: root B shows root B result

Testing

  • Automated regressions added and verified.
  • Hidden rendered-app and real host checks completed.

Cancellation layer typecheck and focused request/subscription/search suites passed. Combined-stack verification passed 88 suites (888 tests, one existing skip), full typecheck and changed-code quality checks. Added failing-before/passing-after setup-abort coverage and a real bundled-ripgrep Unicode/CRLF/result-limit check.

Real SSH compatibility checks passed nine client/host pairings. Native Windows focused search and Markdown checks passed; actual Ubuntu 24.04 WSL guest termination passed abort, timeout and invalid-output probes.

Two hidden native Windows Electron checks also passed on final head e44c29d019e0: linked-folder refresh through retargeting and Quick Open rendered filename/path results.

All tests/apps used ORCA_BACKGROUND_LAUNCH=1. Fresh hosted CI on the rewritten heads is queued; merge remains gated on required checks.

Review

A fresh independent reviewer rated the final combined source e44c29d019e0 low risk, with no unresolved concrete blocker after adversarial review, compatibility repairs, real SSH latency checks and native WSL cleanup evidence. Their focused stable-source rerun passed 20 suites / 155 tests. Counts above overlap and are not summed.

The final production TypeScript is 58 net lines smaller than the previous candidate; additional tests preserve the behavior that the simplification must keep.

Agent skill upstream boundary

  • Not applicable.

Notes

Authorization remains canonical, while returned workspace paths preserve their lexical identity. Shared capability waits keep subscriber cancellation separate. Historical spinner issue #14488 remains outside this change.

Checklist

  • User-facing before/after, mechanism and approach explained
  • Existing before/after visual proof preserved
  • Independent correctness, ownership and performance review
  • Cross-platform, folder, SSH and mixed-version behavior checked
  • Local typecheck, affected tests, fresh app/CLI build and changed-code gates
  • Fresh required hosted CI complete

@pullfrog pullfrog 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.

ℹ️ No critical issues — one small consistency gap inline. The cancellation plumbing itself checks out end to end.

Reviewed changes

This run reviews the full PR against its stack base nwparker/file-search-memory-bounds.

  • Host-owned cancellation for file search — AbortSignal is threaded renderer → preload → main IPC (token-scoped fs:search/fs:cancelSearch), the SSH provider, the runtime files.search RPC, and the shared remote-runtime transport, so an abandoned search stops the actual rg child on the host.
  • Coalesced ripgrep termination — new stopBundledRipgrep bounds Windows/WSL process-tree termination and de-duplicates repeated stops for the same child.
  • Stale-result scoping — result owners now carry rootPath/executionHostId; useFileSearchScope invalidates saved results when the root, runtime, or execution host changes and re-runs the saved query, including while hidden and after remount.
  • Search-field shortcut policy — fileSearchClaimsTextKey lets app chords through while keeping text-editing keys in the search inputs; composition/AltGr are handled.
  • Runtime subscription lifecycle extraction — subscription handlers now track pending subscriptions and abort setup on owner unsubscribe or renderer teardown.
  • Legacy quick-open rg guidance — accepts the retired local-scan wording from older peers.

ℹ️ subscribeRuntimeEnvironment's new signal is dropped on the support-routed branch

files.search is not support-routed, so this does not affect the feature in this PR — but the new signal parameter is only forwarded on the non-support branch, and subscribeSupportRoutedRuntimeEnvironment has no signal member at all. Since the subscription handler passes setupController.signal for every method, aborting setup of a support-routed subscription (files.watch, session.tabs.subscribe, runtime.clientEvents.subscribe, accounts.subscribe, notifications.subscribe) currently has no effect on the host connect.

Technical details
# subscribeRuntimeEnvironment drops `signal` on the support-routed branch

## Affected sites
- `src/main/ipc/runtime-environment-transport-routing.ts:189` — new `signal?: AbortSignal` parameter.
- `src/main/ipc/runtime-environment-transport-routing.ts:225-235` — `subscribeSupportRoutedRuntimeEnvironment({...})` is invoked without `signal`.
- `src/main/ipc/runtime-environment-support-routing.ts:114-165` — `subscribeSupportRoutedRuntimeEnvironment` has no `signal` member, and neither its `supported` nor `unsupported` branch forwards one.
- `src/main/ipc/runtime-environment-subscription-handlers.ts:166-167` — every method passes `setupController.signal`, including the support-routed ones.

## Required outcome
- Aborting setup for a support-routed subscription should stop the in-flight `supportsSharedControl` probe / connect instead of letting it run to completion.

## Open questions for the human
- Is wiring `signal` through `subscribeSupportRoutedRuntimeEnvironment` in scope for this stack, or intentionally deferred to a follow-up?

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker force-pushed the nwparker/file-search-cancellation branch from 13a87ff to c05f4e1 Compare October 5, 2026 04:18
@nwparker
nwparker force-pushed the nwparker/file-search-memory-bounds branch from 7910655 to 17066ec Compare October 5, 2026 04:18

@pullfrog pullfrog 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.

✅ No new issues found. The delta since the prior review addresses both earlier findings and extends cancellation safely across the paired-web and support-routed/shared-control paths.

Reviewed changes

This run re-reviews the 4 rebased commits since the prior pullfrog review at 13a87ff (a3195045, 2571ece3, 69ceed45, c05f4e1).

  • Support-routed + shared-control cancellation — signal now threads through subscribeSupportRoutedRuntimeEnvironment, subscribeRemoteRuntimeSharedControlRequest, RemoteRuntimeSharedControlConnection.subscribe, and startSharedControlSubscription (pre/post throwIfSignalAborted); the support probe is awaited via waitForPromiseWithSignal so aborting one waiter leaves siblings untouched.
  • Paired-web search cancellation — web-filesystem-api.ts tracks a searches map keyed by requestToken and runs files.search through callAbortableRuntimeEnvironment; web-runtime-environments-api.ts tracks pendingSubscriptions and implements cancelSubscription; WebRuntimeClient aborts its child socket on signal and waits through the signal on connect.
  • Stale-error gating fix — useFileSearchPanel now gates error by resultsAreCurrent, closing the one stale surface flagged previously.
  • Runtime local search abort — searchLocalRuntimeFiles now awaits authorization through waitForPromiseWithSignal and binds abort to stopBundledRipgrep.
  • isRuntimeScopeForbiddenError relocation — moved from runtime-rpc-client.ts to runtime-rpc-result.ts, with import updates in the forbidden-toast and setup-script call sites.
  • Regression coverage — new tests prove sibling isolation on a shared support probe, signal forwarding on both support routes, no connection for a pre-aborted shared-control subscribe, and immediate socket close on abort in the web client.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker force-pushed the nwparker/file-search-cancellation branch from c05f4e1 to 252a6df Compare October 5, 2026 04:41
@nwparker
nwparker force-pushed the nwparker/file-search-memory-bounds branch from 9726328 to d4eeb8c Compare October 5, 2026 05:48
@nwparker
nwparker force-pushed the nwparker/file-search-cancellation branch from 252a6df to d36f171 Compare October 5, 2026 05:48

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

This run re-reviews the delta since the prior pullfrog review at c05f4e1 (rebased onto base tip d4eeb8c9). The range-diff is noisy from base movement and the re-split of the series; isolating the branch-authored files between the two heads shows the feature tree is unchanged from the approved run and the only new work is CI repair.

  • Search handler uses the shared process type — filesystem-content-search-handler.ts now imports ChildProcessHandle from shared/child-process/process-spec instead of node:child_process, keeping the spawn-chokepoint rule intact without a new allowlist entry.
  • Retired allowlist entry — removed the migrated filesystem-search-handlers.ts line from child-process-import-allowlist.txt, which the "no stale allowlist entry" guard requires once the search code moved out.
  • Dedicated owner-boundary route test — file-explorer-runtime-owner-boundary.test.ts now asserts useFileSearchRunner.ts routes content search through both owner selectors (getRuntimeEnvironmentIdForWorktree / getExecutionHostIdForWorktree) and avoids the raw useAppStore.getState().settings read.
  • Subscription cancellation fixture — github-pr-checks-fetch.test.ts and github-slice-test-harness.ts now exercise the new subscriptionId / cancelSubscription contract.

I re-ran the affected suites (filesystem-content-search-cancellation, runtime-environment-support-routing, runtime-environments-subscription-lifecycle, remote-runtime-shared-control-connection, useFileSearchPanel.lifecycle, useFileSearchRunner, file-explorer-runtime-owner-boundary, github-pr-checks-fetch, child-process-import-boundary): 100 tests passing.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker force-pushed the nwparker/file-search-memory-bounds branch from d4eeb8c to 2f2058f Compare October 5, 2026 08:02
@nwparker
nwparker force-pushed the nwparker/file-search-cancellation branch 2 times, most recently from 94ae722 to fad7480 Compare October 5, 2026 09:01
Credits @OrcaWin for the original bounded-record proposal.
Apply mobile limits before transport, list Markdown through its semantic producer, and retain complete directory results only within explicit capacity budgets. Stream SFTP directory packets and reject oversized transfer plans before reporting success; preserve narrow older-peer fallbacks and validate streamed response retention.
Keep one current document snapshot per consumer and attach completion candidates to the actual editor model lifetime. Resolve folder workspace roots through existing workspace identities so their previews and completions receive the same authorized listing as worktrees.
Leave unqualified inventories complete beyond 20,000 files. Charge retained paths and serialized bytes at local and relay producers, reject oversized full inventories explicitly, and bound old-peer response reassembly; keep caller-specific mobile and explicit result limits.
Send CLOSE even after cancellation, stop waiting after five seconds without an acknowledgement, and ignore late callbacks. Preserve the original capacity or cancellation error and close handles returned after an aborted OPENDIR.
@nwparker
nwparker force-pushed the nwparker/file-search-cancellation branch from fad7480 to e639b82 Compare October 6, 2026 04:06
@nwparker
nwparker force-pushed the nwparker/file-search-memory-bounds branch from 70112b5 to d06a8fb Compare October 6, 2026 04:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant