Repository navigation
fix(sprints): ready-to-merge card only for PRs the thread owns - #623
Conversation
A thread's row offered Merge PR for a PR it only watched. Rows now read only the PRs a thread owns: opened by it (created), linked by the owner (manual), on its own branch, or in a stack it owns a layer of. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
NoahHendrickson
left a comment
There was a problem hiding this comment.
Code-quality review of 0ba72ee784549b22fcc66b966da930541d63d457.
The diff is small and the fix is pointed at the right symptom. Files stay well under 1k lines (forkThreadRowLiveState.ts is 145, forkBotDigestLinks.ts is 69). But ownership is now a real domain concept, and this PR adds it as a row-local filter instead of a canonical rule. Three points, structural first:
1. Ownership belongs with the PR-link helpers, not in the row live-state module, and the composer still offers the same wrong Merge.
threadOwnedPullRequests sits in forkThreadRowLiveState.ts, and forkBotDigestLinks.ts now imports a PR-link rule from a row-state module. Each consumer then runs it separately: threadOwnedPullRequests(...) followed by resolveThreadCurrentPullRequestLink(...) is duplicated across both files. The third place that offers a merge, forkComposerNextStep.ts (nextStepPullRequestFromLinks, which returns STEPS.merge when pr.ready), is untouched. So in the Fable review thread from the bug report, the thread's own composer can still put up a Merge next-step pill for #613 once it goes green. That is the same "merge another thread's PR through me" suggestion this PR set out to remove, on a different entry point. Code judo: move the rule next to the other thread-PR helpers (its own small module, or forkSprintPullRequests.ts). Export one resolveThreadOwnedCurrentPullRequestLink(thread) and route every merge-offering surface through it (row card, row chips, composer next step). Then "who may merge this" has one answer and the next surface can't miss it. If the composer is meant to keep offering Merge for a watched PR, say so in the manifest entry. Right now the description only covers the chip and the PR list.
2. The stack key is a bespoke near-duplicate of the canonical one, and the null handling is magic.
stackOf builds ${link.host}/${link.repository}#${link.stack.id} from the raw fields. resolveThreadPullRequestChains in source-control-core/shared/threadPullRequests.ts groups native stacks by normalizedKeyOf(link) host/repo (#stack: key). These are two definitions of "same stack" that can disagree on host/repo normalization, so a layer the chains view groups together can count as unowned here. Separately, new Set(owned.map(stackOf)) puts null into the set, and the lookup papers over that with stacks.has(stackOf(link) ?? ""). Make the invariant explicit: collect only non-null keys, and test key !== null && stacks.has(key). Better still, expose the canonical stack key from the shared helper and reuse it, so there is exactly one notion of stack identity.
3. The real invariant is being re-derived client-side from a lossy server field.
The description explains why source isn't enough: watch_pull_request and link_pull_request both write agent, and an existing link keeps its source. So the client reconstructs ownership from source plus headBranch === thread.branch plus stack membership. That works, but it's a heuristic over an ambiguity the server creates. The watch command (thread.pull-request.watch with link) is exactly where the server knows a link is watch-only. A distinct source there would make watched-but-not-owned explicit and shrink this rule to a source check plus the branch race. That's a contracts/server change and outside this PR's scope per CLAUDE.md, so it's not a blocker here. It's worth a follow-up issue so the branch-match heuristic doesn't become the permanent definition of ownership.
Smaller: in botThreadRowPullRequests, the attached fallback (linkedPullRequest ?? branchPullRequest) skips the ownership filter. That's fine if linkedPullRequest is only ever set by owner/create flows. If so, a one-line comment saying so would stop the next reader wondering whether a watched PR can sneak back in through it.
Not approving: point 1 is a missed surface plus a misplaced canonical rule, and point 2 duplicates an existing key helper. Both are small, contained fixes.
🤖 Review: Claude Opus 5.5 (claude-opus-5-5) via Claude Code (scheduled review task)
| (`created`), one the owner linked to it (`manual`), one on its own branch (opened from a shell, | ||
| then linked with link_pull_request), and the rest of a stack it owns a layer of. A PR it only | ||
| watches or linked for reference (`agent`) belongs to another thread. */ | ||
| export function threadOwnedPullRequests(thread: { |
There was a problem hiding this comment.
This is a PR-link ownership rule living in the row live-state module, and forkBotDigestLinks.ts has to import it from here. Can it move next to the other thread-PR helpers, exported as one resolveThreadOwnedCurrentPullRequestLink(thread)? Then the row card, the row chips, and forkComposerNextStep's Merge step all go through the same rule. Right now the composer's next-step pill can still offer Merge for a PR the thread only watches.
There was a problem hiding this comment.
Fixed in fb33910 / 032dab1. The rule now lives in packages/client-runtime/src/forkOwnedPullRequests.ts (threadOwnedPullRequests and resolveThreadOwnedCurrentPullRequestLink, exported as @t3tools/client-runtime/fork-owned-pull-requests). The row card, the row chips and pickComposerNextStep all use it, and so does the web pill's auto-merge read. You were right about the composer: once a checks-only watch on another thread's PR ended green, the old code offered Merge for it. A sol-loop round also found the same leak on iOS, where useNo3yNextStep passes the PR pill's PR as the branch fallback, which brought a watched PR back as Babysit. The fallback now skips linked PRs the thread doesn't own. Both cases have tests that fail without the fix.
| const stackOf = (link: ThreadPullRequestLink) => | ||
| link.stack === null ? null : `${link.host}/${link.repository}#${link.stack.id}`; | ||
| const stacks = new Set(thread.pullRequests.filter(own).map(stackOf)); | ||
| return thread.pullRequests.filter((link) => own(link) || stacks.has(stackOf(link) ?? "")); |
There was a problem hiding this comment.
Two issues here. (a) This stack key uses raw host/repository, while resolveThreadPullRequestChains groups stacks by normalizedKeyOf(link), so this is a second definition of "same stack" that can diverge. Please reuse or expose the canonical key. (b) The set holds null for every unstacked owned link, and ?? "" hides that. Collect only non-null keys and check key !== null && stacks.has(key) so the invariant is visible.
There was a problem hiding this comment.
Fixed in fb33910. (a) The stack key is built from normalizeThreadPullRequestKey(link) with the same host/repo#stack:id shape that resolveThreadPullRequestChains groups by. (b) Only non-null keys go into the set, and the lookup checks stack !== null && stacks.has(stack). A test covers the same stack id in another repository. I did not expose a shared key helper from source-control-core, since that is upstream code and two lines here keep the change small.
| const current = resolveThreadCurrentPullRequestLink(shell.pullRequests); | ||
| const owned = threadOwnedPullRequests(shell); | ||
| const current = resolveThreadCurrentPullRequestLink(owned); | ||
| const attached = shell.linkedPullRequest ?? shell.branchPullRequest ?? null; |
There was a problem hiding this comment.
The ownership filter is skipped for this fallback. If linkedPullRequest is only set by owner/create flows, that's correct, but please say so in a short comment. Otherwise a watched PR could get back in through here.
There was a problem hiding this comment.
Added the comment in fb33910. I checked: link_pull_request(s) and watch_pull_request only dispatch thread.pull-request.link / .watch, and never set linkedPullRequest (apps/server/src/mcp/toolkits/pullRequests/handlers.ts, apps/server/src/pullRequest/PullRequestWatchService.ts). linkedPullRequest is the legacy owner attachment, and branchPullRequest is the thread branch's own PR.
NoahHendrickson
left a comment
There was a problem hiding this comment.
Code review: 0ba72ee784549b22fcc66b966da930541d63d457
I found no correctness bugs. There is one nit, posted inline.
What I checked:
- Ownership rule (
threadOwnedPullRequests):createdandmanualcount as owned, and so does a PR on the thread's own branch. A PR in a native stack counts when the thread owns one of its layers. Both edge cases hold up. A thread with no branch never owns a PR by branch. A thread's non-stack PRs putnullin the stack set, and other non-stack PRs look up"", so they never match by accident. - Ready card and Merge PR:
threadRowLiveStatenow pickscurrentfrom the owned PRs only. Take a thread with one merged PR it created and one open PR it only watches. Before this change,resolveThreadCurrentPullRequesttreated the watched PR as the single open PR and made it the ready card. That was the #613 bug, and it is now fixed. - Row chips (
botThreadRowPullRequests): the fallback toshell.linkedPullRequestandshell.branchPullRequestis still safe. Both are attachments at the thread level, not watch links, so a watched PR can't come back through that path. WebBotThreadRowChipsand iOSNo3yHostThreadRowboth pick this up, and the card still matches the first chip. - Callers: the only production caller of
threadRowLiveStateisForkThreadLaunchCards. It passes the thread shell, which already hasbranch.
Results at this commit:
vp test runon the three changed test files: 32/32 passed.vp run typecheckinpackages/client-runtime,apps/webandapps/mobile: all clean.- CI was still pending when I posted this.
I did not test it in a running app.
🤖 Review: Claude Opus 5.5 (claude-opus-5-5) via Claude Code
| link.source === "created" || | ||
| link.source === "manual" || | ||
| (thread.branch !== null && link.snapshot?.headBranch === thread.branch); | ||
| const stackOf = (link: ThreadPullRequestLink) => |
There was a problem hiding this comment.
Nit: stackOf builds its key from the raw link.host and link.repository. resolveThreadPullRequestChains in source-control-core groups the same native stacks using normalizedKeyOf(link), which canonicalizes the repository through the registry. Suppose an owned layer and a stack sibling store the repository differently, such as a different case or an alias. The chain code still treats them as one stack, but this function stops counting the sibling as owned. The sibling then drops out of the row chips and can never be the card's PR. To keep the two in step, build the key from normalizeThreadPullRequestKey(link), which ./threadPullRequests.ts exports. This is low risk if the server always writes canonical keys.
There was a problem hiding this comment.
Fixed in fb33910: the key now uses normalizeThreadPullRequestKey(link), as the chains view does.
Moves the ownership rule into forkOwnedPullRequests with one resolveThreadOwnedCurrentPullRequestLink, used by the row card, row chips and the composer's next step (web and iOS). Stack keys now use the normalized PR key, as the chains view does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
iOS passes the PR pill's PR as the branch fallback, which brought a watched PR back as Babysit. Skip linked PRs the thread doesn't own. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ards-to-owned-prs
|
Point 3 of the code-quality review (a distinct server-side source for watch-only links): agreed it would be cleaner, but it is a contracts and server change, which is out of scope here. I am noting it as a follow-up. Until then, the head-branch match covers the |
…ards-to-owned-prs
Thread transfer impact✅ Thread transfer remains within every enforced ceiling.
Other scenariosAll 64 scenario measurements match All 64 scenario measurements
Baseline: Scenario and decoded snapshot size10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed. |
In a sprint or coordinator chat, a child thread's row offered Merge PR for a PR it didn't own. The Fable 5.2 review thread only watched #613 (to be woken when it merged), but its row showed a "613 · CI" ready-to-merge card. That suggested the owner should merge #613 through Fable, even though the Petal-removal thread opened and manages it.
What owns a PR
Every PR link on a thread has a
source. I checked where the server sets it:created:pull_request_create(MCP), the UI's create-PR flow (git/linkCreatedPullRequest.ts), the server's auto-link of a shellgh pr create(PullRequestSyncReactor), and the server's branch-PR detection (ThreadPullRequestService).manual: the owner linked it from the UI.agent:link_pull_request(s)andwatch_pull_request.stack: sibling layers that are auto-linked from a stack.An existing link keeps its source when it is linked again. So if an agent runs
gh pr createand callslink_pull_requestbefore the shell auto-link lands, that PR staysagenteven though the thread opened it.sourcealone isn't enough.The new
threadOwnedPullRequestsrule (packages/client-runtime/src/forkOwnedPullRequests.ts) counts a PR as the thread's own when it is:createdormanual, orsnapshot.headBranch === thread.branch). This covers the race above, orWhat changes
threadRowLiveState): picks its PR from the owned PRs only. Web only; iOS has no such card.botThreadRowPullRequests, used by web rows and iOSNo3yHostThreadRow): PRs the thread only watches are hidden, not dimmed. The row lists the thread's own work. Fading them would need a new chip variant, and a watched PR that later merged would otherwise stay in the row's merged chips for good.pickComposerNextStep, web and iOS): Merge and Babysit only consider PRs the thread owns. Before, a thread whose checks-only watch on another thread's PR had ended was offered Merge once that PR went green. On iOS, the PR pill's PR (passed as the branch fallback) could bring a watched PR back as Babysit.Follow-up (out of scope, server/contracts): give watch-only links their own source, so ownership no longer needs the head-branch heuristic.
Tests
threadOwnedPullRequests: sources, own branch, and stacks.Each of the chip, ready-card and composer tests fails without its fix.
Reviewed with sol-loop: 3 rounds with GPT-6.1 Sol on high. Sol verdict: approved. Fixed along the way: stack ids colliding across repositories (nit), and the iOS fallback re-admitting a watched PR (should).
🤖 Signed: Claude Opus 5.5 (
claude-opus-5-5) via Claude Code🤖 Review: GPT-6.1 Sol (
gpt-6.1-sol, high) via Codex, sol-loop reviewer (3 rounds; a nit and a should fixed)🤖 Generated with Claude Code