Skip to content

fix(console): report an unusable remote working directory before minting (CHOO-1416) - #373

Open
abeldantas wants to merge 2 commits into
mainfrom
fix/remote-dir-preflight
Open

fix(console): report an unusable remote working directory before minting (CHOO-1416)#373
abeldantas wants to merge 2 commits into
mainfrom
fix/remote-dir-preflight

Conversation

@abeldantas

@abeldantas abeldantas commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

Context

That branch had a bunch of dead code and got sort of deprecated.

Summary

  • Creating a remote agent no longer strands a gateway identity when the working directory's parent doesn't exist: the directory is checked before anything is minted, and the refusal names the path and the host instead of a raw FileSystemError.
  • inspectRemoteDir decides in two stats from a host-rooted fs: directory and creatable (missing leaf, parent exists) proceed exactly as before; file and missing are refused up front.
  • The sandbox boundary in SshFileSystem is untouched: an fs rooted at a working directory still cannot create that directory's ancestors — the fix is ordering, not permission.

…ing (CHOO-1416)

Creating a remote agent whose directory's parent didn't exist failed at the
first credentials write with a raw FileSystemError, after the identity was
already minted on the gateway — leaving an agent that exists in Switch and
nowhere else. The directory is the one free-text input in the flow and was
only ever touched at write time.

inspectRemoteDir answers it in two stats from an fs rooted at the host (one
rooted at a missing directory cannot stat its way out): directory and
creatable proceed, file and missing are refused before anything is minted,
and the modal says which and names the parent to create.

Ported from #137 (pre-rename branch); fix only, without that branch's
dead-code sweep.

Copilot AI 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.

🟡 Changes recommended

The new missing status is documented and messaged as “parent doesn’t exist,” but it can also mean “parent exists but is a file,” producing incorrect user-facing guidance.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR improves the remote-agent creation flow in Switch Console by validating a remote agent’s working directory before minting a gateway identity, preventing orphaned Switch-side agents when the directory is unusable.

Changes:

  • Introduces a shared remote working-directory inspection model (RemoteDirInspection) plus a usability predicate (isUsableRemoteDir).
  • Adds a main-process SSH-based inspectRemoteDir() check and wires it into addAgent ahead of identity registration, returning a typed directory-missing failure.
  • Extends renderer error handling and telemetry enums to represent the new failure mode, with tests covering the new behavior.
File summaries
File Description
console/apps/switch-console-desktop/src/shared/core/switch-servers/switch-servers.ts Extends shared provisioning result union with a typed directory-missing failure payload.
console/apps/switch-console-desktop/src/shared/core/remote-hosts/remote-dir.ts Adds shared inspection/status types and a helper to decide if a remote dir is usable.
console/apps/switch-console-desktop/src/renderer/features/locations/components/add-agent-modal/add-agent-modal.tsx Surfaces directory-missing as a user-facing toast in the add-agent modal.
console/apps/switch-console-desktop/src/main/core/telemetry/events.ts Adds directory_missing as a structured failure reason for agent creation telemetry.
console/apps/switch-console-desktop/src/main/core/agents/remote-dir.ts Implements inspectRemoteDir() via an SSH filesystem rooted at / to inspect the target dir and its parent.
console/apps/switch-console-desktop/src/main/core/agents/remote-dir.test.ts Adds focused unit tests for all inspection outcomes and error/cleanup behavior.
console/apps/switch-console-desktop/src/main/core/agents/add-agent.ts Performs the remote dir inspection before minting and returns directory-missing when unusable.
console/apps/switch-console-desktop/src/main/core/agents/add-agent.test.ts Verifies refusal happens before minting and that local adds don’t probe SSH.
Review details
  • Files reviewed: 8/8 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread console/apps/switch-console-desktop/src/shared/core/remote-hosts/remote-dir.ts Outdated
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.

2 participants