fix(coding): don't expose primary worktree path in coding context - #44545
Merged
Conversation
Contributor
🔎 Lint report:
|
| 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
approved these changes
Jun 12, 2026
tonydwb
left a comment
There was a problem hiding this comment.
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_pathverifies 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
force-pushed
the
hermes-worktree-code
branch
from
June 12, 2026 00:27
56ddd92 to
96cc7ee
Compare
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The workspace snapshot emitted to the system prompt for linked git worktrees included the primary tree's absolute path:
The agent sees two absolute paths and — often gravitating toward the word 'primary' — sometimes runs terminal commands, edits files, or runs
gitoperations 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.
Tests
Added
TestProjectFacts.test_worktree_detected_without_primary_path: creates a real linked worktree viagit 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, makinggitnot work. now we pass the binary explicitly.