Skip to content

fix(coding): don't expose primary worktree path in coding context - #44545

Merged
OutThisLife merged 1 commit into
mainfrom
hermes-worktree-code
Jun 12, 2026
Merged

fix(coding): don't expose primary worktree path in coding context#44545
OutThisLife merged 1 commit into
mainfrom
hermes-worktree-code

Conversation

@ethernet8023

@ethernet8023 ethernet8023 commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

Problem

The workspace snapshot emitted to the system prompt for linked git worktrees included the primary tree's absolute path:

- Root: /home/user/project-worktree
- Worktree: linked (primary tree at /home/user/project)

The agent sees two absolute paths and — often gravitating toward the word 'primary' — sometimes runs terminal commands, edits files, or runs git operations against the main tree instead of the worktree it was asked to operate on.

Fix

Drop the primary tree path from the output. The agent still learns it's in a linked worktree (so it knows branches/stashes are shared state), but sees only one absolute path — the one it should operate in.

- Root: /home/user/project-worktree
- Worktree: linked (git state shared with primary tree)

Tests

Added TestProjectFacts.test_worktree_detected_without_primary_path: creates a real linked worktree via git worktree add, confirms the "Worktree: linked" marker is present, and asserts that the primary tree path does NOT appear anywhere in the output.

Also fixed a pre-existing latent bug in the test helper _git_init, which deleted path from env, making git not work. now we pass the binary explicitly.

@github-actions

github-actions Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

🔎 Lint report: hermes-worktree-code vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 10765 on HEAD, 10764 on base (🆕 +1)

🆕 New issues (1):

Rule Count
no-matching-overload 1
First entries
tests/agent/test_coding_context.py:24: [no-matching-overload] no-matching-overload: No overload of function `run` matches arguments

✅ Fixed issues: none

Unchanged: 5637 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

@tonydwb tonydwb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review Summary

Verdict: Approved

Security Fix - Looks Good

  • agent/coding_context.py — No longer exposes the absolute path to the primary git tree in worktree contexts. This prevents the model from running commands in the wrong directory.
  • Good comment explaining the rationale for the change.
  • New test test_worktree_detected_without_primary_path verifies the path is not exposed.

Code Quality

  • Clean, minimal change with focused intent.
  • No security concerns.

Reviewed by Hermes Agent

this makes the agent frequently edit files in the wrong worktree.
what the agent doesn't know can't hurt it.
@ethernet8023
ethernet8023 force-pushed the hermes-worktree-code branch from 56ddd92 to 96cc7ee Compare June 12, 2026 00:27
@OutThisLife
OutThisLife merged commit afe5370 into main Jun 12, 2026
28 checks passed
@OutThisLife
OutThisLife deleted the hermes-worktree-code branch June 12, 2026 00:35
alt-glitch pushed a commit that referenced this pull request Jun 14, 2026
fix(coding): don't expose primary worktree path in coding context
AIalliAI pushed a commit to AIalliAI/Hermes that referenced this pull request Jun 14, 2026
…ee-code

fix(coding): don't expose primary worktree path in coding context
T02200059 pushed a commit to T02200059/hermes-agent that referenced this pull request Jun 18, 2026
…ee-code

fix(coding): don't expose primary worktree path in coding context
waefrebeorn pushed a commit to waefrebeorn/slermes that referenced this pull request Jul 2, 2026
…ee-code

fix(coding): don't expose primary worktree path in coding context
santhreal pushed a commit to santhreal/hermes-agent that referenced this pull request Jul 13, 2026
…ee-code

fix(coding): don't expose primary worktree path in coding context
Gravezzz pushed a commit to Gravezzz/hermes-agent that referenced this pull request Jul 21, 2026
…ee-code

fix(coding): don't expose primary worktree path in coding context
leewenjie pushed a commit to leewenjie/hermes-agent that referenced this pull request Aug 7, 2026
…ee-code

fix(coding): don't expose primary worktree path in coding context
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.

3 participants