Skip to content

fix(acp): guard invalid workdirs#1620

Merged
zerob13 merged 3 commits into
devfrom
fix/no-dir-issue
May 13, 2026
Merged

fix(acp): guard invalid workdirs#1620
zerob13 merged 3 commits into
devfrom
fix/no-dir-issue

Conversation

@zerob13
Copy link
Copy Markdown
Collaborator

@zerob13 zerob13 commented May 13, 2026

Summary

  • add universal new-thread selected-directory validation and warning icon
  • block ACP draft creation, warmup path, and send when the workdir is missing or invalid
  • make ACP process launch reject explicit missing/non-directory cwd instead of falling back to HOME
  • auto-repair the exact broken npm _npx hash directory for package.json ENOENT and retry once
  • add ACP initialization/protocol diagnostics for easier debugging

Tests

  • pnpm run format
  • pnpm run i18n
  • pnpm run lint
  • pnpm run typecheck:node
  • pnpm run typecheck:web
  • pnpm exec vitest --config vitest.config.renderer.ts test/renderer/components/NewThreadPage.test.ts
  • pnpm exec vitest --config vitest.config.ts test/main/presenter/llmProviderPresenter/acp/acpProcessManager.test.ts

Summary by CodeRabbit

  • New Features

    • Workspace directory validation with warning UI and disabled send/draft flows when ACP workdir is unavailable.
    • One-time npx cache repair retry on eligible agent startup failures.
    • Summarized protocol and session-level diagnostics during ACP startup and prompts.
  • Localization

    • Added workspace-unavailable tooltip translations across multiple locales.
  • Documentation

    • Added plans, specs, and task checklists for ACP initialization logging and workdir/npx recovery.
  • Tests

    • Added and expanded focused tests covering workdir validation, spawn/retry behavior, and logging paths.

Review Change Stack

Add universal new-thread directory validation, ACP-only send/draft blocking, explicit ACP cwd validation, npx cache repair retry, and ACP initialization diagnostics.

Tests: pnpm run format; pnpm run i18n; pnpm run lint; pnpm run typecheck:node; pnpm run typecheck:web; focused NewThreadPage and AcpProcessManager vitest suites.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 13, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5ece8d15-8b80-44d9-9a35-c0878c165929

📥 Commits

Reviewing files that changed from the base of the PR and between 9113806 and 90b7e3f.

📒 Files selected for processing (6)
  • src/main/presenter/llmProviderPresenter/acp/acpProcessManager.ts
  • src/renderer/src/i18n/fa-IR/chat.json
  • src/renderer/src/i18n/he-IL/chat.json
  • src/renderer/src/i18n/ru-RU/chat.json
  • test/main/presenter/llmProviderPresenter/acp/acpProcessManager.test.ts
  • test/setup.ts
✅ Files skipped from review due to trivial changes (3)
  • test/setup.ts
  • src/renderer/src/i18n/ru-RU/chat.json
  • src/renderer/src/i18n/he-IL/chat.json
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/renderer/src/i18n/fa-IR/chat.json
  • test/main/presenter/llmProviderPresenter/acp/acpProcessManager.test.ts
  • src/main/presenter/llmProviderPresenter/acp/acpProcessManager.ts

📝 Walkthrough

Walkthrough

This PR adds traced ACP JSON‑RPC protocol logging and initialization diagnostics (including npx-cache single-retry repair and spawn cwd validation), emits summarized session/prompt debug events, implements renderer-side workdir validation with UI warnings and send gating, adds i18n keys, and includes tests for these behaviors.

Changes

ACP Initialization Logging & Workdir Validation

Layer / File(s) Summary
Documentation: Planning & Specifications
docs/issues/acp-initialization-logging/plan.md, docs/issues/acp-initialization-logging/spec.md, docs/issues/acp-initialization-logging/tasks.md, docs/issues/acp-workdir-npx-recovery/plan.md, docs/issues/acp-workdir-npx-recovery/spec.md, docs/issues/acp-workdir-npx-recovery/tasks.md
Added planning, specification, and task checklist documents for ACP initialization logging and ACP workdir npx-recovery.
ACP Session Manager: Summaries & Debug Events
src/main/presenter/llmProviderPresenter/acp/acpSessionManager.ts
Adds helpers to summarize MCP servers/session responses and emits debug events for persisted-session load request/response/error, new-session request/response, and initialization failure.
ACP Provider: Prompt Summarization & Events
src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
Adds prompt-block summarizers and emits session/prompt request/response summaries and error debug events instead of logging full prompt content.
ACP Process Manager: Spawn, NPX Repair & Protocol Tracing
src/main/presenter/llmProviderPresenter/acp/acpProcessManager.ts
Refactors spawn to validate cwd (no HOME fallback), add single targeted npx cache repair+retry on specific ENOENT patterns, harden initialization against process-exit/stream-closure races and attach stderr to init errors, and replace ndJsonStream with a traced NDJSON/JSON‑RPC stream that correlates request/response ids and logs important methods at info level.
Renderer: NewThreadPage Directory Status & Gating
src/renderer/src/pages/NewThreadPage.vue
Introduces directory-status state machine via FileClient.isDirectory, computes isAcpWorkdirUnavailable, shows warning icons/tooltips, disables ACP send/early-returns on submit when workdir unavailable, and updates ACP draft session watch to depend on valid status.
Internationalization
src/renderer/src/i18n/{da-DK,en-US,fa-IR,fr-FR,he-IL,ja-JP,ko-KR,pt-BR,ru-RU,zh-CN,zh-HK,zh-TW}/chat.json
Added input.workspaceUnavailableTooltip translation key in all listed locales.
Tests: ACP Process Manager
test/main/presenter/llmProviderPresenter/acp/acpProcessManager.test.ts
Updated PATH-precedence test mocking; added tests for explicit workdir rejection, targeted npx cache repair with single retry and rename of only the broken hash dir, and skipping repair for unrelated ENOENT stderr patterns.
Tests: NewThreadPage
test/renderer/components/NewThreadPage.test.ts
Enhanced test harness with isDirectory FileClient mocking and richer ChatInputBox stub; added tests for invalid workdir warning, ACP draft/send blocking vs DeepChat unblocked, and resume behavior when switching to a valid workdir.
Test Setup
test/setup.ts
Added fs.renameSync mock to test environment.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Poem

A rabbit hops through logs so bright,
Tracing frames by day and night.
When workdirs vanish, warnings bloom,
And broken caches find new room. 🐰✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(acp): guard invalid workdirs' directly describes the primary change: adding validation and protection against invalid working directories in ACP sessions, which aligns with the main objectives of blocking operations when workdir is missing/invalid and rejecting invalid cwd.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/no-dir-issue

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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 and usage tips.

@zerob13 zerob13 changed the base branch from main to dev May 13, 2026 09:03
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/main/presenter/llmProviderPresenter/acp/acpProcessManager.ts`:
- Around line 759-772: The code may return and cache a dead child handle because
the child process can exit after initialization but before readyHandle is
assigned; update the logic in the routine that creates/returns the handle
(reference symbols: handleProcessExit, readyHandle, child,
removeHandleReferences, clearSessionsForAgent) to perform a final liveness check
on child.pid (or child.killed/exit code) immediately before assigning/returning
readyHandle and caching it, and if the child is not alive, run the cleanup path
(call removeHandleReferences and clearSessionsForAgent) and retry or throw so a
dead handle is never stored; apply the same final liveness check to the
analogous block around the code referenced at the second location (the block
around lines 985-993).

In `@src/renderer/src/i18n/fa-IR/chat.json`:
- Line 27: The key "workspaceUnavailableTooltip" in
src/renderer/src/i18n/fa-IR/chat.json contains an English message; replace its
value with a Persian translation while preserving the {path} placeholder exactly
(e.g., "فهرست وجود ندارد یا قابل دسترسی نیست: {path}" or similar) so the tooltip
is fully localized for fa-IR users.

In `@src/renderer/src/i18n/he-IL/chat.json`:
- Line 27: Replace the English message for the key workspaceUnavailableTooltip
with a Hebrew translation while keeping the {path} placeholder exactly as-is;
for example use: "התיקייה אינה קיימת או לא ניתנת לגישה: {path}" and update the
value in src/renderer/src/i18n/he-IL/chat.json for the
workspaceUnavailableTooltip entry.

In `@src/renderer/src/i18n/ru-RU/chat.json`:
- Line 27: The key workspaceUnavailableTooltip in the ru-RU locale is still
English; replace its value with a proper Russian translation preserving the
{path} placeholder (e.g., "Каталог не существует или недоступен: {path}"),
updating the string for functionally identical formatting and keeping the
placeholder intact so code referencing workspaceUnavailableTooltip continues to
work.

In `@test/main/presenter/llmProviderPresenter/acp/acpProcessManager.test.ts`:
- Line 461: Replace the direct reassignment of fs.renameSync (currently done via
type-cast assignment) with a vi.spyOn(fs, 'renameSync').mockImplementation(...)
in each test that mocks it (e.g., the tests around the current failing
assertions), and ensure the spy is restored after the test by calling
spy.mockRestore() in a finally block (or use afterEach to restore all spies);
also stop using mockReset() alone since it does not restore the original
function—use mockRestore() to return fs.renameSync to its original
implementation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 29568071-5124-445a-956b-eb0aee5f08b5

📥 Commits

Reviewing files that changed from the base of the PR and between eb75ac5 and 9113806.

📒 Files selected for processing (24)
  • docs/issues/acp-initialization-logging/plan.md
  • docs/issues/acp-initialization-logging/spec.md
  • docs/issues/acp-initialization-logging/tasks.md
  • docs/issues/acp-workdir-npx-recovery/plan.md
  • docs/issues/acp-workdir-npx-recovery/spec.md
  • docs/issues/acp-workdir-npx-recovery/tasks.md
  • src/main/presenter/llmProviderPresenter/acp/acpProcessManager.ts
  • src/main/presenter/llmProviderPresenter/acp/acpSessionManager.ts
  • src/main/presenter/llmProviderPresenter/providers/acpProvider.ts
  • src/renderer/src/i18n/da-DK/chat.json
  • src/renderer/src/i18n/en-US/chat.json
  • src/renderer/src/i18n/fa-IR/chat.json
  • src/renderer/src/i18n/fr-FR/chat.json
  • src/renderer/src/i18n/he-IL/chat.json
  • src/renderer/src/i18n/ja-JP/chat.json
  • src/renderer/src/i18n/ko-KR/chat.json
  • src/renderer/src/i18n/pt-BR/chat.json
  • src/renderer/src/i18n/ru-RU/chat.json
  • src/renderer/src/i18n/zh-CN/chat.json
  • src/renderer/src/i18n/zh-HK/chat.json
  • src/renderer/src/i18n/zh-TW/chat.json
  • src/renderer/src/pages/NewThreadPage.vue
  • test/main/presenter/llmProviderPresenter/acp/acpProcessManager.test.ts
  • test/renderer/components/NewThreadPage.test.ts

Comment thread src/main/presenter/llmProviderPresenter/acp/acpProcessManager.ts
Comment thread src/renderer/src/i18n/fa-IR/chat.json Outdated
Comment thread src/renderer/src/i18n/he-IL/chat.json Outdated
Comment thread src/renderer/src/i18n/ru-RU/chat.json Outdated
Comment thread test/main/presenter/llmProviderPresenter/acp/acpProcessManager.test.ts Outdated
@zerob13 zerob13 merged commit f7cbde7 into dev May 13, 2026
3 checks passed
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