fix(gateway): follow a session into the worktree it settled in - #71864
Merged
Conversation
An agent told to work in a fresh git worktree does exactly that — creates it, cds in, and runs every later command there — but the session stayed pinned to the checkout it started in. The desktop kept labelling the chat with the primary branch while all the work landed somewhere else. The desktop half already existed: session.info carrying a moved cwd runs followActiveSessionCwd, which refreshes the project tree and scopes the sidebar into the new project. The backend just never reported the move. Reconcile the session's cwd against terminal_tool's per-session record at the end of a turn, when the agent has stopped moving and its recorded cwd is a stable answer. A plain cd stays what it always was — not a workspace move — so the reconcile only fires when the recorded cwd sits in a different git working tree than the session's workspace.
OutThisLife
enabled auto-merge
July 26, 2026 09:05
Contributor
૮ >ﻌ< ა ci reviewran on 0158569 ℹ️ InfoDesktop E2E visual evidence · View test artifacts · View job1 visual diff. inline evidence is publishing... |
randlee
pushed a commit
to randlee/hermes-agent
that referenced
this pull request
Aug 11, 2026
…ollow fix(gateway): follow a session into the worktree it settled in
33hodl
pushed a commit
to 33hodl/hermes-agent
that referenced
this pull request
Aug 12, 2026
…ollow fix(gateway): follow a session into the worktree it settled in
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.
An agent told to work in a fresh git worktree does exactly that — creates it,
cds in, and runs every later command there — but the session stayed pinned to the checkout it started in. The desktop kept labelling the chat with the primary checkout's branch and filing it under that lane in the sidebar, while all the work landed somewhere else entirely. Across a handful of parallel worktrees, the sidebar stops describing reality.The desktop half of this was already built: a
session.infocarrying a moved cwd runsfollowActiveSessionCwd, which refreshes the project tree and scopes the sidebar into the session's new project. Its comment even names the case — "the agent relocated itself (created/entered another repo or worktree via the terminal)". The backend simply never reported the move, so that path had no way to fire.terminal_toolalready keeps a durable per-session record of where each session's commands actually run. This reconciles the gateway's session cwd against that record at the end of a turn, when the agent has stopped moving and its recorded cwd is a stable answer to "where does this session work". The samesession.infothat already tells the desktop the turn ended now carries the new cwd and branch — no new event type, no extra round trip.A plain
cdstays exactly what it was — not a workspace move.cd /tmpto read a log must never re-home the chat, so the reconcile fires only when the recorded cwd sits in a different git working tree than the session's workspace, comparing worktree roots rather than the folded common root. Remote backends are skipped: their cwd names a path on the host, which this gateway can neither stat nor probe.Verified by reverting the server change and re-running the new tests — all nine fail without it and pass with it. Real git worktrees on disk, no mocked git.