1jehuang / 1jehuang/jcode

fix(swarm): validate spawn working_dir, expand ~ in tool paths, clearer write errors

Open
#1,198 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

autonomous: no bug triage: needs-decision
Dominant language
Rust
Stars
19.9k
Forks
2.3k
Avg merge
2d 7h
Merged PRs (30d)
30

Description

PRs are restricted to collaborators on this repo, so opening an issue per CONTRIBUTING convention instead.

Problem

Three related rough edges hit in real swarm usage on v0.84.0:

  1. Bad working_dir at swarm spawn produces a broken worker. The session starts fine, then every bash call fails with a cryptic os error 2 (the shell cannot spawn with a nonexistent cwd). The worker burns a full turn rediscovering its sandbox is broken.
  2. File tools reject ~/... paths. read/edit/write only handle absolute or working-dir-relative paths, so workers writing ~/.config/... get File not found.
  3. write hides the real cause of parent-dir failures. A wrong username in an absolute path makes create_dir_all fail under /Users, surfacing as a bare Permission denied (os error 13) with no path named.

Proposed changes (5 commits, tested, green)

Branch: https://github.com/JJ245-JJ/jcode/tree/pr/swarm-spawn-validation (fork, based on current master @ 4e85d4423, ahead by 5, +203/-17 across 9 files)

  1. resolve_spawn_working_dir tilde-expands and validates the directory up front, rejecting the spawn with working_dir does not exist: <path>. Check the path (watch for username typos) and spawn again. Same check in create_headless_session as defense in depth.
  2. ToolContext::resolve_path expands a leading ~/~/... to home (non-tilde and ~otheruser forms fall through to existing handling).
  3. write names the parent directory and hints at path spelling when create_dir_all fails.
  4. Lean swarm worker toolset adapted to the registration-based session tool policy API (the old set_session_tool_policy call no longer exists on master, so set_lean_swarm_worker_tools fails to compile without this).
  5. Tests: nonexistent-dir rejection, tilde expansion (spawn + resolve_path), existing-dir fixtures for the resolution preference tests. cargo test -p jcode-app-core --lib resolve_spawn_working_dir -> 4 passed; crate compiles clean on master.

Verified end-to-end on a live server: spawn with a bad dir is rejected immediately with the clear error; workers successfully use write/read tools and ~ paths.

Happy to open a proper PR if given collaborator access or if you prefer I re-push the branch somewhere convenient.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with resolve_spawn_working_dir and create_headless_session for spawn validation, then inspect ToolContext::resolve_path and the write tool's parent-directory error handling. Run cargo test -p jcode-app-core --lib resolve_spawn_working_dir and check the session tool policy entry point. Done means invalid directories are rejected early, leading ~ paths work, and write failures identify the affected path.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.