Skip to content

Fix workspace switch race condition, gh auth detection, and file open perf#593

Open
RajPabnani03 wants to merge 1 commit intoathasdev:masterfrom
RajPabnani03:fix/workspace-switch-perf-gh-auth
Open

Fix workspace switch race condition, gh auth detection, and file open perf#593
RajPabnani03 wants to merge 1 commit intoathasdev:masterfrom
RajPabnani03:fix/workspace-switch-perf-gh-auth

Conversation

@RajPabnani03
Copy link
Copy Markdown

Summary

Fixes three open bugs (#581, #551, #572) and adds project MCP servers and skills for streamlined development.


Bug Fixes

1. Bug #581 — Workspace State Not Preserved When Switching Folders

Root Cause: In switchToProject(), the old project's buffers were closed after the new project's background initialization (including session restore) was kicked off via void (async () => { ... })(). This created a race condition where closing old terminal buffers could kill PTY processes that the new project's restored terminals were trying to use, or vice versa.

Fix: Move closeBuffersBatch() to execute before the new project's directory reading and session restore, ensuring old workspace state is cleanly torn down before new state is loaded.

2. Bug #551 — Athas not detecting that GitHub CLI is authenticated

Root Cause: gh auth status can return exit code 0 even when the token is expired or invalid (known upstream issue cli/cli#8845). The original code only checked output.status.success(), so it would report "authenticated" for invalid/expired tokens.

Fix: Parse stderr output to check for authentication failure indicators ("not logged in", "token is invalid", "Failed to log in", etc.) even when exit code is 0. Also check for "Logged in to" as positive confirmation when exit code is 0.

3. Bug #572 — Athas Lags on CachyOS / File Opening Performance

Root Causes:

  1. readDirectoryContents() called getSymlinkInfo() (a stat syscall via Tauri IPC) for every single entry in a directory. For large projects with hundreds/thousands of files, this meant hundreds of sequential I/O calls just to list a directory.
  2. handleFileSelect() read files twice — once for binary sniffing (readFile) and once for content (readFileContent), doubling I/O for every file open.

Fixes:

  1. Remove per-entry symlink resolution from readDirectoryContents(). Symlinks are still resolved lazily when a file is opened (in handleFileSelect) or when a directory is expanded. This eliminates hundreds of stat syscalls during directory listing.
  2. Combine binary sniffing and content reading into a single readFile() call. The raw bytes are read once, checked for binary content, and then decoded to UTF-8 text using TextDecoder instead of reading the file a second time.

Changed Files

File Change
crates/github/src/api.rs Parse gh auth status stderr for auth state instead of relying on exit code alone
src/features/file-system/controllers/file-operations.ts Remove per-entry symlink resolution from readDirectoryContents()
src/features/file-system/controllers/store.ts Move closeBuffersBatch() before project switch; combine binary sniff + content read into single I/O pass

Testing

  • TypeScript type-check passes (tsc --noEmit)
  • oxlint passes on changed files
  • rustfmt passes on crates/github/src/api.rs

MCP Servers & Skills

MCP Servers (.factory/mcp.json)

Server Type Purpose
GitHub HTTP Full GitHub API access — repos, issues, PRs, code search, actions
Sequential Thinking Stdio Structured step-by-step reasoning for debugging and planning
Playwright Stdio Browser testing and automation
Sentry HTTP Error tracking and performance monitoring
Linear HTTP Issue tracking and project management

Skills (.factory/skills/)

Skill Purpose Invocation
athas-bug-fix Standardized bug diagnosis and fix workflow Auto (mentions "bug", "fix", "issue")
athas-performance Performance bottleneck identification and optimization Auto (mentions "lag", "slow", "performance")
athas-release Release process following project conventions Manual only (/athas-release)
athas-contribution Contribution standards and commit conventions Auto (mentions "contribute", "PR", "commit")

… perf

Fix three open bugs (athasdev#581, athasdev#551, athasdev#572):

1. Bug athasdev#581 - Workspace State Not Preserved When Switching Folders:
   Move closeBuffersBatch() before new project loading in switchToProject()
   to prevent race conditions between session save and restore. Old
   terminal PTY processes are now cleaned up before new ones are spawned.

2. Bug athasdev#551 - Athas not detecting that GitHub CLI is authenticated:
   Parse gh auth status stderr for authentication indicators instead of
   relying solely on exit code. gh auth status can return exit code 0 even
   when the token is expired or invalid (see cli/cli#8845). Now checks for
   'Logged in to' as positive confirmation and 'not logged in',
   'token is invalid', 'Failed to log in' as failure indicators.

3. Bug athasdev#572 - Athas Lags on CachyOS / File Opening Performance:
   Remove per-entry symlink resolution from readDirectoryContents() that
   caused hundreds of stat syscalls during directory listing. Symlinks are
   still resolved lazily when files are opened. Also combine binary
   sniffing and content reading into a single readFile() call, eliminating
   the double-read that occurred for every file open.

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
@RajPabnani03 RajPabnani03 force-pushed the fix/workspace-switch-perf-gh-auth branch from 2b95d5c to e871e77 Compare April 10, 2026 07:47
@mehmetozguldev mehmetozguldev self-requested a review April 12, 2026 22:27
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