Skip to content

fix(daemon): bound cwd validation and attach-only requests on a dead share - #14966

Merged
nwparker merged 2 commits into
mainfrom
neil/sta-4541-dead-share-cwd-cancel
Aug 16, 2026
Merged

nwparker merged 2 commits into
mainfrom
neil/sta-4541-dead-share-cwd-cancel

Conversation

@nwparker

@nwparker nwparker commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​275 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​273
Prod 11 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​296 $\color{#cf222e}{\Huge{\mathbf{−}}}$​131 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​165

Follow-up hardening on #14848 (merged, not reverted).

#14848 made cwd validation async so one dead share could not freeze every terminal. Two ways for a single unreachable path to strand work remained. Both claims in STA-4541 were verified against the code before fixing.

1. Cancel did not abort the probe

isCanceled is only polled between spawn steps (pty-subprocess.ts:865), so fs.stat on a dead SMB/NFS/UNC path ran to completion. The create stayed in flight, later creates for that session queued behind it (terminal-host.ts:55-61), and shutdown/idle waited on it.

  • Carry an AbortSignal alongside the existing poll, so a canceled caller abandons the probe.
  • Make the per-session queue wait abortable, so a canceled queued request stops waiting too.
  • The shared probe keeps running for whoever still wants it — an aborting caller never breaks another waiter (pinned by a test).
  • Evict the dedupe entry on a hard cap. Found while fixing: the map only evicted on settle, so a never-settling probe permanently poisoned that path for any session, turning a per-session stall into a cross-session one.

2. Attach-only lost its only timeout

Attach-only registered no cancellable preparation (daemon-server.ts:1089), so the daemon could not match the client's cancel, and the client had already cleared its timer — neither side bounded the request.

  • Register the preparation for every createOrAttach; run spawn preflight only when not attach-only.
  • Give the client a bounded grace window when the daemon reports an unmatched cancel.

Error identity

Aborting the queue wait makes the daemon reject the queued request, which races the client's own cancellation. client_disconnected gates mobile terminal rollback (orca-runtime.ts:27719), so the wrong error would close terminals it should keep (#7718). The cancellation reason now wins deterministically — but scoped to the daemon's own attach-cancellation, so a genuine disconnect still surfaces as itself. A test caught this.

Notes

Splits working-directory validation out of local-pty-utils.ts to stay under the line cap (no max-lines disable added).

Testing

Daemon + providers suites: 2254 passed. New coverage for abort-during-probe, dedupe eviction, shared-probe survival, canceled queued caller, and attach-only cancel. Typecheck and lint clean.

STA-4541

…share

#14848 made cwd validation async so one dead share could not freeze every
terminal, but left two ways for a single unreachable path to strand work.

Canceling a create did not abort the probe: `isCanceled` is only polled between
spawn steps, so `fs.stat` on a dead SMB/NFS/UNC path ran to completion. The
create stayed in flight, later creates for that session queued behind it, and
shutdown/idle waited on it. Carry an AbortSignal next to the existing poll so a
canceled caller abandons the probe, and make the per-session queue wait abortable
so a canceled queued request stops waiting too. The shared probe is left running
for whoever still wants it, and the dedupe entry is evicted on a hard cap so a
never-settling mount cannot poison that path across sessions forever.

Attach-only requests registered no cancellable preparation, so the daemon could
not match the client's cancel and the client had already cleared its timer —
neither side bounded the request. Register the preparation for every
createOrAttach and run spawn preflight only when it is not attach-only, and give
the client a bounded grace window when the daemon reports an unmatched cancel.

The cancellation reason now wins over a racing daemon rejection: callers key
recovery off `client_disconnected`, and letting the race pick would roll back
terminals it should keep (#7718).

Splits working-directory validation out of local-pty-utils to stay under the
line cap.

STA-4541
@coderabbitai

coderabbitai Bot commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The change propagates abort signals from daemon spawn preparations through terminal session creation and PTY working-directory validation. Working-directory validation is centralized with shared asynchronous probes and caller cancellation. Daemon RPC requests now bound unmatched cancellation waits and preserve terminal attach cancellation errors. Tests cover daemon, host, validation, PTY, and RPC cancellation behavior.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 53.85% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description explains the changes and testing, but it omits most required template sections and does not provide the required Linked Issue format. Add the required ELI5, What Changed, Why, Linked Issue, Visual Proof, AI Disclosure, Review, boundary, checklist, and author sections.
✅ Passed checks (3 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly summarizes the main changes: bounding cwd validation and attach-only requests on dead shares.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

@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: Pro Plus

Run ID: 93133191-913a-4603-879a-4b910cbfbc55

📥 Commits

Reviewing files that changed from the base of the PR and between 9e3e583 and 0825f9d.

📒 Files selected for processing (17)
  • src/main/daemon/client.ts
  • src/main/daemon/daemon-client-rpc-request.test.ts
  • src/main/daemon/daemon-client-rpc-request.ts
  • src/main/daemon/daemon-errors.ts
  • src/main/daemon/daemon-server-async-spawn-cancellation.test.ts
  • src/main/daemon/daemon-server-kill-attribution.test.ts
  • src/main/daemon/daemon-server.ts
  • src/main/daemon/pty-subprocess-wsl-launch.test.ts
  • src/main/daemon/pty-subprocess.ts
  • src/main/daemon/terminal-host-agent-session-claim.ts
  • src/main/daemon/terminal-host-concurrent-create.test.ts
  • src/main/daemon/terminal-host-options.ts
  • src/main/daemon/terminal-host-session-create.ts
  • src/main/daemon/terminal-host.ts
  • src/main/providers/local-pty-utils.ts
  • src/main/providers/working-directory-validation.test.ts
  • src/main/providers/working-directory-validation.ts

Included review availability: Your plan includes up to 10 reviews per rolling hour; 8 remain after this review.

Comment on lines +84 to +88
const key = cwd
let validation = pendingWorkingDirectoryValidations.get(key)
if (!validation) {
validation = validateWorkingDirectoryUncached(cwd)
pendingWorkingDirectoryValidations.set(key, validation)

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.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Do not start a probe for an already aborted caller.

Line 87 starts validateWorkingDirectoryUncached(cwd) before Line 111 checks signal.aborted. A pre-aborted request can therefore start a stalled WSL or filesystem probe and place it in pendingWorkingDirectoryValidations. Later requests for the same path then wait for that abandoned probe until the 30-second eviction.

Check options.signal?.aborted before reading or populating the dedupe map. Extend the pre-aborted test to assert that wslUncDirectoryExistsAsyncMock was not called.

Proposed fix
 export function validateWorkingDirectoryAsync(
   cwd: string,
   options: { signal?: AbortSignal } = {}
 ): Promise<void> {
+  const signal = options.signal
+  if (signal?.aborted) {
+    return Promise.reject(new WorkingDirectoryValidationAbortedError(cwd))
+  }
   const key = cwd
   let validation = pendingWorkingDirectoryValidations.get(key)
 ...
-  const signal = options.signal
   if (!signal) {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const key = cwd
let validation = pendingWorkingDirectoryValidations.get(key)
if (!validation) {
validation = validateWorkingDirectoryUncached(cwd)
pendingWorkingDirectoryValidations.set(key, validation)
const signal = options.signal
if (signal?.aborted) {
return Promise.reject(new WorkingDirectoryValidationAbortedError(cwd))
}
const key = cwd
let validation = pendingWorkingDirectoryValidations.get(key)
if (!validation) {
validation = validateWorkingDirectoryUncached(cwd)
pendingWorkingDirectoryValidations.set(key, validation)
}
if (!signal) {

Review follow-ups on this PR.

The 30s dedupe eviction retired an entry whose probe was still running. `fs.stat`
is uninterruptible, so that freed no libuv thread — it only let the next caller
pin another. A few retries against one dead mount exhaust the default pool of 4
and stall every other async fs read in the daemon, which is the cross-session
freeze #14848 set out to remove. Drop the timer and clear on settle only: the
AbortSignal added here already lets callers escape a shared hung probe, so
sharing one no longer strands them, and a mount whose stat eventually returns
still re-probes on the next call.

The abort also introduced a second cancellation identity on the wire.
WorkingDirectoryValidationAbortedError propagated out of createPtySubprocess as
the request's error, and the client's mapping only recognizes the attach-cancel
message — so a canceled create could reach the rollback branch that closes a
terminal the user still has (#7718). Translate it at the daemon boundary so the
wire carries one identity.

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

🧹 Nitpick comments (1)
src/main/providers/working-directory-validation.ts (1)

88-93: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Keep the new comments to one line.

  • src/main/providers/working-directory-validation.ts#L88-L93: retain only the reason that hung probes must remain shared.
  • src/main/daemon/pty-subprocess-cwd-cancel-identity.test.ts#L1-L3: retain only the attach-cancellation wire-contract reason.

As per coding guidelines, “Comments must be concise, non-obvious, and brief—prefer one line.”

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 02cbe4e3-05df-44b0-892c-c10da2492170

📥 Commits

Reviewing files that changed from the base of the PR and between 0825f9d and 561f888.

📒 Files selected for processing (4)
  • src/main/daemon/pty-subprocess-cwd-cancel-identity.test.ts
  • src/main/daemon/pty-subprocess.ts
  • src/main/providers/working-directory-validation.test.ts
  • src/main/providers/working-directory-validation.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/providers/working-directory-validation.test.ts

Included review availability: Your plan includes up to 10 reviews per rolling hour; 4 remain after this review.

@nwparker
nwparker merged commit 1580ba1 into main Aug 16, 2026
51 checks passed
AmethystLiang pushed a commit that referenced this pull request Aug 17, 2026
…share (#14966)

* fix(daemon): bound cwd validation and attach-only requests on a dead share

#14848 made cwd validation async so one dead share could not freeze every
terminal, but left two ways for a single unreachable path to strand work.

Canceling a create did not abort the probe: `isCanceled` is only polled between
spawn steps, so `fs.stat` on a dead SMB/NFS/UNC path ran to completion. The
create stayed in flight, later creates for that session queued behind it, and
shutdown/idle waited on it. Carry an AbortSignal next to the existing poll so a
canceled caller abandons the probe, and make the per-session queue wait abortable
so a canceled queued request stops waiting too. The shared probe is left running
for whoever still wants it, and the dedupe entry is evicted on a hard cap so a
never-settling mount cannot poison that path across sessions forever.

Attach-only requests registered no cancellable preparation, so the daemon could
not match the client's cancel and the client had already cleared its timer —
neither side bounded the request. Register the preparation for every
createOrAttach and run spawn preflight only when it is not attach-only, and give
the client a bounded grace window when the daemon reports an unmatched cancel.

The cancellation reason now wins over a racing daemon rejection: callers key
recovery off `client_disconnected`, and letting the race pick would roll back
terminals it should keep (#7718).

Splits working-directory validation out of local-pty-utils to stay under the
line cap.

STA-4541

* fix(daemon): keep a hung cwd probe to one thread and one cancel identity

Review follow-ups on this PR.

The 30s dedupe eviction retired an entry whose probe was still running. `fs.stat`
is uninterruptible, so that freed no libuv thread — it only let the next caller
pin another. A few retries against one dead mount exhaust the default pool of 4
and stall every other async fs read in the daemon, which is the cross-session
freeze #14848 set out to remove. Drop the timer and clear on settle only: the
AbortSignal added here already lets callers escape a shared hung probe, so
sharing one no longer strands them, and a mount whose stat eventually returns
still re-probes on the next call.

The abort also introduced a second cancellation identity on the wire.
WorkingDirectoryValidationAbortedError propagated out of createPtySubprocess as
the request's error, and the client's mapping only recognizes the attach-cancel
message — so a canceled create could reach the rollback branch that closes a
terminal the user still has (#7718). Translate it at the daemon boundary so the
wire carries one identity.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…share (stablyai#14966)

* fix(daemon): bound cwd validation and attach-only requests on a dead share

stablyai#14848 made cwd validation async so one dead share could not freeze every
terminal, but left two ways for a single unreachable path to strand work.

Canceling a create did not abort the probe: `isCanceled` is only polled between
spawn steps, so `fs.stat` on a dead SMB/NFS/UNC path ran to completion. The
create stayed in flight, later creates for that session queued behind it, and
shutdown/idle waited on it. Carry an AbortSignal next to the existing poll so a
canceled caller abandons the probe, and make the per-session queue wait abortable
so a canceled queued request stops waiting too. The shared probe is left running
for whoever still wants it, and the dedupe entry is evicted on a hard cap so a
never-settling mount cannot poison that path across sessions forever.

Attach-only requests registered no cancellable preparation, so the daemon could
not match the client's cancel and the client had already cleared its timer —
neither side bounded the request. Register the preparation for every
createOrAttach and run spawn preflight only when it is not attach-only, and give
the client a bounded grace window when the daemon reports an unmatched cancel.

The cancellation reason now wins over a racing daemon rejection: callers key
recovery off `client_disconnected`, and letting the race pick would roll back
terminals it should keep (stablyai#7718).

Splits working-directory validation out of local-pty-utils to stay under the
line cap.

STA-4541

* fix(daemon): keep a hung cwd probe to one thread and one cancel identity

Review follow-ups on this PR.

The 30s dedupe eviction retired an entry whose probe was still running. `fs.stat`
is uninterruptible, so that freed no libuv thread — it only let the next caller
pin another. A few retries against one dead mount exhaust the default pool of 4
and stall every other async fs read in the daemon, which is the cross-session
freeze stablyai#14848 set out to remove. Drop the timer and clear on settle only: the
AbortSignal added here already lets callers escape a shared hung probe, so
sharing one no longer strands them, and a mount whose stat eventually returns
still re-probes on the next call.

The abort also introduced a second cancellation identity on the wire.
WorkingDirectoryValidationAbortedError propagated out of createPtySubprocess as
the request's error, and the client's mapping only recognizes the attach-cancel
message — so a canceled create could reach the rollback branch that closes a
terminal the user still has (stablyai#7718). Translate it at the daemon boundary so the
wire carries one identity.
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