Skip to content

fix: a pull-request session follows the pull request's head - #126

Draft
fiddur wants to merge 7 commits into
developfrom
session-follows-pr-head
Draft

fiddur wants to merge 7 commits into
developfrom
session-follows-pr-head

Conversation

@fiddur

@fiddur fiddur commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

An old session showed old code, sent the attendant to the old head, and only found out at posting time. Now the Sessions page and the review page move a session to the current head (open findings carry over), the review page offers Update when the head moves while it's open, and posting to an outdated head asks: update, or post to the reviewed commit anyway.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Bwp5QefjsjMFeq6CK6cT6w

The Sessions page moves a row's session to the current head (findings carry over), a review page
opened on an old head moves on by itself and offers Update when the head moves while open, the
attendant is always handed the current head, and posting to an outdated head asks first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Bwp5QefjsjMFeq6CK6cT6w
@fiddur
fiddur requested a balanced review from Copilot November 10, 2026 12:36

@diffity diffity Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One P3; the rest checks out. advanceSession reuses createSession/carryForward, the 409 now carries a code that the dialog acts on, and both review triggers hand the routine the advanced session.

— diffity review, requested by @fiddur

}
checked.current = true;
if (movedOn) {
void update();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: Suppose an agent is still reviewing the old session when the page loads. The page moves to the new head anyway, and the agent keeps writing findings to the old session. The new session then has no review-in-progress banner, so the reader can post while findings are still arriving somewhere they can't see. Suggestion: skip the automatic move while info.review is in progress and show the Update banner instead.

…head instead of leaving

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Bwp5QefjsjMFeq6CK6cT6w

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Session migration can leave open findings behind or prematurely remove them from active reviews, causing findings to disappear and replies or status changes to fail with 404s.

3 open issues
What changed in this PR

This PR makes pull-request review sessions follow the current head across the Sessions page, review UI, and agent review requests. It also lets users explicitly post to the reviewed commit after the pull request changes.

Changes:

  • Add head detection, session advancement, and current-head routing for review requests.
  • Add update prompts and preserve posting drafts across session navigation.
  • Extend API contracts, documentation, and tests for moved-head behavior.
File Description
README.md Document head-following sessions and outdated posting choices.
packages/​ui/​tests/​follow-head.test.tsx Test navigation, update prompts, and draft restoration.
packages/​ui/​src/​lib/​session-head.ts Add session navigation and draft storage helpers.
packages/​ui/​src/​lib/​api.ts Handle moved-head refusals and advancement requests.
packages/​ui/​src/​hooks/​use-info.ts Navigate to the session receiving an agent review.
packages/​ui/​src/​hooks/​use-follow-head.ts Manage automatic and reader-requested updates.
packages/​ui/​src/​components/​layout/​toolbar.tsx Reopen the posting dialog for restored drafts.
packages/​ui/​src/​components/​layout/​moved-on-banner.tsx Display the newer head and Update action.
packages/​ui/​src/​components/​layout/​github-dialog.tsx Offer update or outdated posting and save drafts.
packages/​ui/​src/​components/​diff/​diff-page.tsx Integrate head-following behavior and banner.
packages/​server/​tests/​service.test.ts Test advancement, carryover, caching, and failures.
packages/​server/​tests/​routine.test.ts Test current-head sessions in agent requests.
packages/​server/​tests/​posting.test.ts Test outdated posting and session advancement endpoints.
packages/​server/​tests/​mcp.test.ts Verify actionable moved-head refusals for agents.
packages/​server/​tests/​helpers.ts Support closed pull requests in fixtures.
packages/​server/​src/​ui-api.ts Expose advancement and structured moved-head responses.
packages/​server/​src/​service.ts Implement head lookup, advancement, and posting override.
packages/​server/​src/​github.ts Read pull-request closed state.
packages/​server/​src/​app.ts Route Sessions-page review requests to the current head.
packages/​api/​tests/​requests.test.ts Test validation of the outdated-posting flag.
packages/​api/​src/​requests.ts Parse the outdated-posting flag.
packages/​api/​src/​info.ts Define head-movement and advancement response types.
packages/​api/​src/​github.ts Define outdated-posting and refusal contracts.

Review effort: Balanced

Comment thread packages/server/src/service.ts Resolved
Comment thread packages/server/src/service.ts Resolved
…ab follows it when nothing would be lost

Advancing onto an existing session carries the source's open findings over too, and posting anyway
needs something to post.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Bwp5QefjsjMFeq6CK6cT6w

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Automatic head advancement can discard draft edits or leave pending reviews behind, while the blocking GitHub lookup can exceed the page-load timeout.

2 open issues
3 previously missed issues

In code that hasn't changed since last review

Medium severity Prevent optional GitHub lookup from blocking page load

packages/​server/​src/​ui-api.ts:136

On a cache miss, /api/info now waits for GitHub, and the review page's loader waits for this response even when the diff is already available locally. GitHub's 60-second request timeout (github.ts:214) exceeds the load balancer's documented 30-second timeout (live.ts:10), so a stalled lookup can prevent the page from loading before the fallback runs. Give this optional lookup a shorter timeout or load head drift separately from the page's required data.

Medium severity Save the latest draft edits before navigating

packages/​ui/​src/​components/​layout/​github-dialog.tsx:178

This callback captures the summary and selection from when Update was clicked, but the textarea and comment toggles remain editable while advancement is pending. Edits made during the fetch/reanchoring wait are visible in the dialog, then the callback saves the older values and navigation discards the edits. Disable draft editing while updating, or read the latest draft from a ref when saving it immediately before navigation.

Medium severity Preserve saved drafts when following an updated head

packages/​ui/​src/​hooks/​use-follow-head.ts:58

If Update saves a post-dialog draft for head B and B's initial /api/info already reports head C, this branch advances again without carrying the saved draft to C. The summary, verdict, and deselections are then missing from the destination dialog. Block initial auto-follow when a saved draft exists or the restored dialog is open, including before GitHub details finish loading.

3 resolved since last review

Review effort: Balanced

…eaves, and the page never waits long on GitHub's head

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Bwp5QefjsjMFeq6CK6cT6w

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved head-advancement and navigation issues can discard drafts, break active replies or agent work, and leave readers on outdated sessions without an Update control.

2 open issues
6 previously missed issues

In code that hasn't changed since last review

Medium severity Check cached PR heads for sessions created during a push

packages/​server/​src/​service.ts:270

A push after createSession fetches the head but before it inserts the session leaves an outdated session whose createdAt is later than the PR's updatedAt. This filter then skips head checks on every Sessions refresh until another PR update, continuing to display the old SHA. Consult the cached pull head for all rows with a session instead of treating insertion time as proof of freshness.

Medium severity Block auto-advance while an Ask Claude response is pending

packages/​ui/​src/​components/​diff/​diff-page.tsx:95

An agent answering an Ask Claude question is counted in liveStatus.working, not as a pending review, so a hidden tab can automatically advance while that answer is in progress. Advancement moves the thread and live request, but the routine agent's token remains scoped to the old session and its reply fails with “belongs to another session”. Wait for live status before deciding to follow, and block automatic advancement while question work is outstanding.

Medium severity Show the update banner for empty diffs

packages/​ui/​src/​components/​diff/​diff-page.tsx:518

When a PR with an empty diff receives a new commit while the tab stays visible, the hook detects the new head but the reader remains on “No changes found” without an Update control. The diff.files.length === 0 branch returns before this banner is rendered. Render the banner in that empty-state branch too.

Medium severity Save the latest draft before navigating

packages/​ui/​src/​components/​layout/​github-dialog.tsx:178

This callback captures the summary and selection from the render in which Update was clicked. The summary textarea and comment controls remain editable while /advance waits for GitHub and Git, so edits made during that wait are visible locally but the older draft is saved before navigation, silently discarding the later edits. Read the latest draft from a ref when beforeLeaving runs, or disable all draft-editing controls while updating.

Medium severity Recheck pending reviews before navigating

packages/​ui/​src/​hooks/​use-follow-head.ts:60

If an info poll reports a pending review while /advance is in flight, its final safety check still captures the earlier reviewing = false and navigates away from the session receiving the findings. The initial-load predicate also omits a pending-review recheck. Read the latest reviewing flag at navigation time rather than the value from the render that initiated the request.

Medium severity Preserve drafts before redirecting outdated sessions

packages/​ui/​src/​hooks/​use-info.ts:25

When a review is requested from an outdated session, this unconditional document replacement discards any inline comment or reply draft on the page, including text entered while the request was pending. Unlike automatic head following, it never checks safeToLeave. Recheck page safety before redirecting; if a draft or write is present, keep the page and offer Update, or preserve that work across navigation.

1 resolved since last review

Review effort: Balanced

Comment thread packages/ui/src/lib/session-head.ts Resolved
… only once the page is still free to leave

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Bwp5QefjsjMFeq6CK6cT6w

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Prepared sessions can omit carried-over findings, and stale pending-review checks can navigate users away just as an agent starts work, leaving later findings on the old session.

3 open issues
1 resolved since last review

Review effort: Balanced

Comment thread packages/server/src/service.ts Resolved
… and an automatic move reads the latest review state

The Sessions page links the session still holding open findings, so a prepared session that was
left empty is never shown without them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Bwp5QefjsjMFeq6CK6cT6w

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unbounded waits for optional GitHub head probes can block the entire Sessions page for multiple timeout batches instead of promptly displaying existing session rows.

1 open issue
3 resolved since last review

Review effort: Balanced

Comment thread packages/server/src/service.ts Resolved
… request heads

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Bwp5QefjsjMFeq6CK6cT6w

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human assessment is needed to evaluate session-advancement risks involving omitted open findings and loss of unsaved review drafts.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

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.

2 participants