Skip to content

fix(session): keep a session connected when a reload leaves out a noted file - #1131

Open
andrewloux wants to merge 1 commit into
modem-dev:mainfrom
andrewloux:fix/reload-keeps-session
Open

andrewloux wants to merge 1 commit into
modem-dev:mainfrom
andrewloux:fix/reload-keeps-session

Conversation

@andrewloux

@andrewloux andrewloux commented Sep 29, 2026 •

Copy link
Copy Markdown

Problem

reloading onto a diff that leaves out a file with a live note drops the session. with hunk show HEAD open on a commit that changes lab.go and notes.txt:

SID=$(hunk session list --json | jq -r '.sessions[0].sessionId')
hunk session comment add "$SID" --file notes.txt --new-line 2 --summary "a note on notes.txt"
hunk session reload "$SID" -- diff HEAD~1..HEAD -- lab.go
# hunk: The targeted session disconnected.   (exit 1)
hunk session list --json
# { "sessions": [] }

the TUI keeps running, but no hunk session command reaches it again. agents reload after each commit, so a commit that reverts a noted file cuts the agent off from a window that still looks alive. reproduces on 0.22.0 from Homebrew and on main, and #1138 hits it through --watch and r too.

Cause

after that reload the window sends liveCommentCount: 1 with an empty liveComments:

Approach

liveCommentCount now counts the published list, the way reviewNoteCount counts reviewNoteSummaries. the note stays in the store, so reloading back to show HEAD lists it on notes.txt:2 again.

the counts hunk session prints stay the same, because the daemon's parser already rejects any count that differs from the list and stores liveComments.length. this does undo #723's comment on that line ("notes on a file a reload retired still count as tracked"), since the published count now follows the published list.

hunkCount and reviewNoteCount are built from the same source as their lists, so liveCommentCount was the only count that could drift.

non-goals: listing notes on retired files in comment list, and recovering a window after the daemon rejects a snapshot.

Why core

the terminal review hook builds the session snapshot, and every reload goes through it. the snapshot keeps its shape and only sends counts the v16 daemon already accepts, so HUNK_SESSION_DAEMON_VERSION stays at 16 and wire.snapshot.test.ts passes as is. the TUI renders the same diff before and after.

Tests

  • useTerminalReview.test.tsx: a note on beta.ts, a reload to alpha.ts alone, then a reload back to both. the count matches the summaries after each step, and the note returns
  • test/session/cli.test.ts: the same flow through the daemon. the reload away exits 0, the session stays listed, and the reload back lists the note

both fail on main at 0a67560c without the fix: the hook test gets count 1 beside an empty list, and the session test gets hunk: The targeted session disconnected.

bun run typecheck                  # clean
bun run lint                       # 0 warnings, 0 errors
bun run format:check               # clean
bun run deps:check                 # no violations (480 modules, 2023 dependencies)
bun test packages/hunk/src/ui/hooks/useTerminalReview.test.tsx   # 58 pass
bun test packages/hunk/src/session/broker/wire.snapshot.test.ts  # 3 pass
bun run test:session-broker-node   # 4 pass
bun test test/session/cli.test.ts  # 8 pass, in oven/bun:1.4.2 on Linux arm64
bun run test                       # 4555 pass, 53 skip, 1 fail

test/session skips on macOS because BSD script has no -f, so i ran it in a Linux container. main at 0a67560c gives 4554 pass, 52 skip, 1 fail, and the one failure is the same jj test on both (#1146 fixes it). i didn't run test:integration or test:tty-smoke, since this touches no rendering, layout or PTY behavior.

tested on macOS 26 arm64, plus Linux arm64 in Docker for test/session. not run on Windows.

Limitations

  • while a noted file is out of the diff, comment list leaves out its note, and a reply to it exits 1 with Review note <id> is no longer available as a reply parent.
  • a window whose snapshot gets rejected for another reason stays disconnected, and its reconnects log rejected registration from session <id>: the payload parses; the broker refused it for another reason. that recovery is follow-up work

Fixes #1138

@vercel

vercel Bot commented Sep 29, 2026

Copy link
Copy Markdown

@andrewloux is attempting to deploy a commit to the Modem Team on Vercel.

A member of the Team first needs to authorize it.

@greptile-apps

greptile-apps Bot commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

PR author is not in the allowed authors list.

…ed file

A `hunk session reload` whose new diff leaves out a file that holds a live
note disconnected the session. The window's next snapshot carried
`liveCommentCount: 1` beside an empty `liveComments` list: the count came
from every live note in the review store, and the list came from the files
in the current diff. The daemon's snapshot parser requires the two to
match, so it rejected the snapshot and dropped the session. The TUI kept
running, and no `hunk session` command could reach it.

The count now comes from the published summaries, as `reviewNoteCount`
already does. The note stays in the store and returns to both when a later
reload brings its file back.
@andrewloux
andrewloux force-pushed the fix/reload-keeps-session branch from 1e18b04 to 34c220d Compare October 5, 2026 15:36

This branch has not been deployed

No deployments
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.

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

1 participant