Repository navigation
fix(daemon): bound cwd validation and attach-only requests on a dead share - #14966
Conversation
…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
📝 WalkthroughWalkthroughThe 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)
✅ Passed checks (3 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (17)
src/main/daemon/client.tssrc/main/daemon/daemon-client-rpc-request.test.tssrc/main/daemon/daemon-client-rpc-request.tssrc/main/daemon/daemon-errors.tssrc/main/daemon/daemon-server-async-spawn-cancellation.test.tssrc/main/daemon/daemon-server-kill-attribution.test.tssrc/main/daemon/daemon-server.tssrc/main/daemon/pty-subprocess-wsl-launch.test.tssrc/main/daemon/pty-subprocess.tssrc/main/daemon/terminal-host-agent-session-claim.tssrc/main/daemon/terminal-host-concurrent-create.test.tssrc/main/daemon/terminal-host-options.tssrc/main/daemon/terminal-host-session-create.tssrc/main/daemon/terminal-host.tssrc/main/providers/local-pty-utils.tssrc/main/providers/working-directory-validation.test.tssrc/main/providers/working-directory-validation.ts
Included review availability: Your plan includes up to 10 reviews per rolling hour; 8 remain after this review.
| const key = cwd | ||
| let validation = pendingWorkingDirectoryValidations.get(key) | ||
| if (!validation) { | ||
| validation = validateWorkingDirectoryUncached(cwd) | ||
| pendingWorkingDirectoryValidations.set(key, validation) |
There was a problem hiding this comment.
🩺 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.
| 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.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/main/providers/working-directory-validation.ts (1)
88-93: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winKeep 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
📒 Files selected for processing (4)
src/main/daemon/pty-subprocess-cwd-cancel-identity.test.tssrc/main/daemon/pty-subprocess.tssrc/main/providers/working-directory-validation.test.tssrc/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.
…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.
…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.
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
isCanceledis only polled between spawn steps (pty-subprocess.ts:865), sofs.staton 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.AbortSignalalongside the existing poll, so a canceled caller abandons the probe.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.createOrAttach; run spawn preflight only when not attach-only.Error identity
Aborting the queue wait makes the daemon reject the queued request, which races the client's own cancellation.
client_disconnectedgates 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.tsto stay under the line cap (nomax-linesdisable 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