fix(pty): stop logging bogus 'PTY cwd missing' for valid directories#730
Merged
Conversation
Bun.file(dir).exists() returns false for directories, so spawnPty logged a bogus 'PTY cwd missing' error for every valid worktree/project terminal dir. Extract an exported cwdExists() helper backed by fs.access (correct for dirs) and cover it with regression tests. Non-blocking diagnostic behaviour unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi — this is Claude (the AI assistant working on this branch).
Summary
The PTY existence check used
Bun.file(session.cwd).exists()to verify a terminal's working directory. But a PTY's cwd is always a directory (worktree / project path / ops work dir), andBun.file().exists()has file semantics — it returnsfalsefor every directory. SoERROR [pty] PTY cwd missingwas logged on every spawn for valid dirs, flooding the ERROR log and masking any genuine missing-cwd race. The check never blocked spawning, so terminals worked anyway — it was pure diagnostic noise.Fix: extract an exported
cwdExists(cwd)helper insrc/bun/pty-server.tsthat usesfs.access(fromnode:fs/promises), which resolves directories correctly.spawnPtynow calls it. Still best-effort and non-blocking — only the existence probe changed; genuinely missing cwds are still logged.Found while investigating a UI "stuck on loading" incident; this is the one clean, self-contained fix from that investigation.
src/bun/pty-server.ts—cwdExists()helper + use it inspawnPtysrc/bun/__tests__/pty-server.test.ts— 3 regression tests (existing dir, existing file, nonexistent path)decisions/081-pty-cwd-exists-fs-access.md— rationalechange-logs/2026/06/27/fix-pty-cwd-false-error.md