Skip to content

fix(gateway): follow a session into the worktree it settled in - #71864

Merged
OutThisLife merged 1 commit into
mainfrom
bb/worktree-follow
Jul 26, 2026
Merged

fix(gateway): follow a session into the worktree it settled in#71864
OutThisLife merged 1 commit into
mainfrom
bb/worktree-follow

Conversation

@OutThisLife

Copy link
Copy Markdown
Collaborator

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.info carrying a moved cwd runs followActiveSessionCwd, 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_tool already 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 same session.info that already tells the desktop the turn ended now carries the new cwd and branch — no new event type, no extra round trip.

A plain cd stays exactly what it was — not a workspace move. cd /tmp to 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.

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
OutThisLife enabled auto-merge July 26, 2026 09:05
@github-actions

github-actions Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

૮ >ﻌ< ა ci review

ran on 0158569

ℹ️ Info

Desktop E2E visual evidence · View test artifacts · View job

1 visual diff.

inline evidence is publishing...

@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/tui Terminal UI (ui-tui/ + tui_gateway/) sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state labels Jul 26, 2026
@OutThisLife
OutThisLife merged commit 651c093 into main Jul 26, 2026
73 of 76 checks passed
@OutThisLife
OutThisLife deleted the bb/worktree-follow branch July 26, 2026 09:47
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/tui Terminal UI (ui-tui/ + tui_gateway/) P3 Low — cosmetic, nice to have sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants