Skip to content

fix(tools): recover wrong-home absolute paths from non-Claude models#35

Merged
BOBER3r merged 1 commit into
mainfrom
bober/deepseek-path-recovery
Jun 10, 2026
Merged

fix(tools): recover wrong-home absolute paths from non-Claude models#35
BOBER3r merged 1 commit into
mainfrom
bober/deepseek-path-recovery

Conversation

@BOBER3r

@BOBER3r BOBER3r commented Jun 8, 2026

Copy link
Copy Markdown
Owner

What & why

Follow-up to #34 (DeepSeek provider support). When running the pipeline on DeepSeek, the curator called glob with an absolute path built from a hallucinated home directory:

warn Tool "glob" threw: Path "/Users/boberik/agent-bober-workspace/agent-bober-ide/src" resolves outside the project root. Access denied.

The real home is /Users/bober4ik/… — the model invented boberik. Two mistakes compounded: it passed an absolute path at all (the tool contract says relative), and it guessed the home dir wrong. The sandbox correctly denied it, but the warning is non-fatal, so the agent silently continued with empty exploration results — degrading the run without failing it. Same class of "non-Claude model guesses its environment" problem as #34's host-environment injection.

Fix (three reinforcing layers)

  • A — sandboxPath re-anchoring. When an absolute path lands outside the root but still contains the root's basename (agent-bober-ide), re-anchor the suffix (src) relative to the real root and retry. This never widens the sandbox: the re-anchored path is resolve(projectRoot, suffix) and is re-validated to be inside the root, so a genuinely-foreign path (/etc/passwd) and traversal (../..) still fail closed. Exported for direct unit testing.
  • B — tighten tool path descriptions. The read/write/edit/glob/grep schemas said "relative to project root or absolute" — actively inviting the bug. Changed to "pass a relative path, not an absolute one" with an example.
  • C — surface the real project root. Inject the absolute project root + an explicit "pass paths RELATIVE … do not construct absolute paths" note into every agent prompt that has a path-bearing tool, so models stop guessing the home dir at the source.

A makes it robust to the mistake; B + C reduce the mistake.

Verification

  • npm run build ✅ · npm run lint
  • npm test1787 passed, 3 skipped, 1 failed (+14 new tests). The single failure (skill-bundles › package.json version › is 0.14.0) is a pre-existing stale assertion on main, unrelated to this PR.
  • New tests: handlers.test.ts (9 sandboxPath cases incl. re-anchoring + security boundaries), environment.test.ts (project-root line + relative-path guidance gating).

🤖 Generated with Claude Code

…ive paths

Non-Claude models (DeepSeek) ignore the "path is relative to project root"
tool contract and invent an ABSOLUTE path with the wrong home dir — e.g. the
curator called glob with /Users/boberik/.../agent-bober-ide/src when the real
root is /Users/bober4ik/.../agent-bober-ide. The path sandbox correctly rejected
it ("resolves outside the project root"), but the warn is non-fatal so the agent
silently continued with degraded (empty) exploration results.

Three reinforcing fixes:

- sandboxPath (A): when an absolute path lands outside the root but still
  contains the root's basename, re-anchor the suffix after it relative to the
  real root and retry. Never widens the sandbox — the re-anchored path is
  resolve(projectRoot, suffix) and is re-validated to be inside the root, so a
  genuinely-foreign path (/etc/passwd) and traversal (../..) still fail closed.
  Exported for direct unit testing.
- tool schemas (B): the read/write/edit/glob/grep path descriptions said
  "relative to project root or absolute", actively inviting the bad behavior.
  Tighten them to "pass a relative path, not an absolute one" with an example.
- environment context (C): inject the absolute project root and an explicit
  "pass paths RELATIVE to the project root, do not construct absolute paths"
  instruction into every agent prompt that has a path-bearing tool, so models
  stop guessing the home directory in the first place.

Adds handlers.test.ts (9 sandboxPath cases incl. re-anchoring + security) and
environment.test.ts (project-root line + relative-path guidance gating).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@BOBER3r BOBER3r merged commit 9d1759e into main Jun 10, 2026
1 of 2 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