Skip to content

Session drops from the daemon when a commented file leaves a --watch diff #1138

Description

@LandonSchropp

When a file that has comments drops out of a --watch review (for example, right after committing it), Hunk's session disappears from the daemon. The TUI keeps running and still shows the comments, but agents can no longer reach the session.

Steps to Reproduce

mkdir /tmp/hunk-drop && cd /tmp/hunk-drop && git init
printf 'one\n' > a.txt && printf 'one\n' > b.txt
git add . && git commit -m init
printf 'two\n' >> b.txt

# In another terminal, in the same directory:
hunk diff --watch

hunk session list --json    # one session
hunk session comment add --repo . --file b.txt --new-line 2 --summary "note"

git commit -am "commit b"   # b.txt leaves the diff
printf 'two\n' >> a.txt     # keep something in the diff

hunk session list --json    # {"sessions": []}
hunk session comment list --repo . --json   # hunk: protocol-validation-failed

Expected

The session stays registered, and the comment on the file that left the diff is either kept or dropped, without taking the session with it.

Actual

The session vanishes from hunk session list, and every hunk session command against the repository fails. The TUI gives no sign that anything went wrong.

Environment

  • Hunk 0.22.0 (Homebrew)
  • macOS 26

Activity

  1. shllg commented on Oct 1, 2026

    @shllg

    Still reproduces on 0.23.0 (Linux, mise install, fresh daemon, no extensions loaded). Two additions:

    It isn't specific to --watch. Any reload that leaves out a noted file does it, including pressing r. The everyday version is a review note like "drop this change" that the fix answers by reverting the file:

    git init -q -b main repro && cd repro
    for f in a b c; do printf '%s1\n%s2\n%s3\n' $f $f $f > $f.txt; done
    git add . && git commit -qm base
    git switch -qc feature
    sed -i 's/b2/b2 feature/' b.txt && sed -i 's/c2/c2 feature/' c.txt
    git commit -qam "feature work"
    
    # In another terminal, in the same directory:
    hunk diff "$(git merge-base main HEAD)"
    
    hunk session comment add --repo . --file b.txt --new-line 2 --summary "drop this change"
    git checkout main -- b.txt                   # the fix: revert b.txt to base
    # press r in the Hunk window
    hunk session list --json                     # {"sessions": []}
    hunk session comment list --repo . --json    # hunk: protocol-validation-failed (exit 1)

    The new status-line hint doesn't recover the window. 0.23.0 shows Session daemon rejected this window. Run `hunk daemon restart`. After hunk daemon restart --yes, the window stayed out of hunk session list (checked 20+ seconds later) and kept showing the same hint. I think that's the "window whose snapshot gets rejected stays disconnected" limitation #1131 lists as follow-up work. Until that lands, it might be worth not suggesting the restart when the rejection was a snapshot validation failure, since it can't help there.

    For context: we use Hunk as the human side of an agent review loop. The agent annotates the plan, the reviewer leaves notes, and the agent reads them with hunk session comment list, fixes, and replies with comment add. The revert case comes up all the time in that loop, and the drop lands right when the agent posts its replies. For now we tell people to open Hunk on the fork point, leave --watch off, and reload by hand after the agent is done. #1131 would make most of that unnecessary.

  2. shllg commented on Oct 2, 2026

    @shllg

    A correction to my comment above: the trigger is narrower than "a noted file". In my script the note on b.txt came from hunk session comment add, so it was a live (agent) comment. A note typed in the TUI on a file that later leaves the diff does not drop the session. I checked that on 0.23.0 with the same revert-and-r steps. This matches the diagnosis in #1131: liveCommentCount counts live comments only.

    So in an agent review loop, the trigger is the agent's own reply on a file that the fix then reverts. Removing those replies with hunk session comment rm before the revert keeps the session connected. That's the workaround we use until #1131 lands.

  3. andrewloux commented on Oct 5, 2026

    @andrewloux
    Contributor

    @shllg sharp catch on live comments only, that's the bug #1131 fixes

    after the revert, the window still holds the agent's note on b.txt, so its snapshot sends liveCommentCount: 1. liveComments only lists files still in the diff, so it's empty. the daemon rejects a snapshot where those two disagree and closes the window's socket

    #1131 counts the list instead. the note stays in the window and comes back if b.txt returns to the diff

    i ran both repros from this thread on main and on #1131. on main the window drops out of hunk session list after r and after the --watch commit. on #1131 it stays listed and comment list works

    agreed on the hunk daemon restart hint: it can't recover a rejected window. i think that's follow-up work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions