Skip to content

fix(sprints): ready-to-merge card only for PRs the thread owns - #623

Merged
NoahHendrickson merged 7 commits into
customfrom
t3/restrict-merge-cards-to-owned-prs
Nov 30, 2026
Merged

NoahHendrickson merged 7 commits into
customfrom
t3/restrict-merge-cards-to-owned-prs

Conversation

@NoahHendrickson

@NoahHendrickson NoahHendrickson commented Nov 30, 2026 •

Copy link
Copy Markdown
Owner

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 shell gh pr create (PullRequestSyncReactor), and the server's branch-PR detection (ThreadPullRequestService).
  • manual: the owner linked it from the UI.
  • agent: link_pull_request(s) and watch_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 create and calls link_pull_request before the shell auto-link lands, that PR stays agent even though the thread opened it. source alone isn't enough.

The new threadOwnedPullRequests rule (packages/client-runtime/src/forkOwnedPullRequests.ts) counts a PR as the thread's own when it is:

  • created or manual, or
  • on the thread's own branch (snapshot.headBranch === thread.branch). This covers the race above, or
  • part of a native stack in which the thread owns a layer (keyed by host/repo/stack id).

What changes

  • Ready-to-merge card and Merge PR (threadRowLiveState): picks its PR from the owned PRs only. Web only; iOS has no such card.
  • Row PR chips (botThreadRowPullRequests, used by web rows and iOS No3yHostThreadRow): 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.
  • Composer next step (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.
  • The thread's own composer PR chip and PR list still show every linked PR.

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.
  • Row chips leave out watched PRs, open or merged.
  • The ready card ignores a watched PR, but shows it when it is on the thread's branch.
  • The composer offers no Merge for a watched PR, and no Babysit when iOS passes it as the branch PR.

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

xxxxxxxxxxxxx and others added 3 commits November 29, 2026 20:38
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>
@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:M labels Nov 30, 2026

@NoahHendrickson NoahHendrickson left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

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: {

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

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) ?? ""));

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

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;

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

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 NoahHendrickson left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Code review: 0ba72ee784549b22fcc66b966da930541d63d457

I found no correctness bugs. There is one nit, posted inline.

What I checked:

  • Ownership rule (threadOwnedPullRequests): created and manual count 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 put null in the stack set, and other non-stack PRs look up "", so they never match by accident.
  • Ready card and Merge PR: threadRowLiveState now picks current from the owned PRs only. Take a thread with one merged PR it created and one open PR it only watches. Before this change, resolveThreadCurrentPullRequest treated 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 to shell.linkedPullRequest and shell.branchPullRequest is still safe. Both are attachments at the thread level, not watch links, so a watched PR can't come back through that path. Web BotThreadRowChips and iOS No3yHostThreadRow both pick this up, and the card still matches the first chip.
  • Callers: the only production caller of threadRowLiveState is ForkThreadLaunchCards. It passes the thread shell, which already has branch.

Results at this commit:

  • vp test run on the three changed test files: 32/32 passed.
  • vp run typecheck in packages/client-runtime, apps/web and apps/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) =>

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Fixed in fb33910: the key now uses normalizeThreadPullRequestKey(link), as the chains view does.

xxxxxxxxxxxxx and others added 3 commits November 29, 2026 20:50
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>
@NoahHendrickson

Copy link
Copy Markdown
Owner Author

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 gh pr create + link_pull_request race. Everything else is fixed in fb33910 and 032dab1, and replied to inline. Sol-loop ran 3 rounds with GPT-6.1 Sol and approved.

@github-actions github-actions Bot added size:L and removed size:M labels Nov 30, 2026
@github-actions

Copy link
Copy Markdown

Thread transfer impact

✅ Thread transfer remains within every enforced ceiling.

Provider Metric Main baseline This PR Impact PR ceiling
Codex Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅
Codex Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅
Codex Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅
Codex Live turn WebSocket decoded 21.5 KiB 21.5 KiB 0 B (0.0%) 24.4 KiB ✅
Codex Live turn messages 1 1 0 (0.0%) 8 ✅
Claude Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅
Claude Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅
Claude Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅
Claude Live turn WebSocket decoded 21.9 KiB 21.9 KiB 0 B (0.0%) 24.4 KiB ✅
Claude Live turn messages 1 1 0 (0.0%) 8 ✅

Other scenarios

All 64 scenario measurements match main.

All 64 scenario measurements
Provider Scenario Metric Main baseline This PR Impact PR ceiling
Codex short turn resume WebSocket decoded 10.5 KiB 10.5 KiB 0 B (0.0%) 12.7 KiB ✅
Codex short turn resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Codex long turn running, cold open HTTP decoded 281.7 KiB 281.7 KiB 0 B (0.0%) 302.7 KiB ✅
Codex long turn running, cold open rows 75 75 0 (0.0%) 75 ✅
Codex long turn running, history page HTTP decoded 92.4 KiB 92.4 KiB 0 B (0.0%) 107.4 KiB ✅
Codex long turn running, history page rows 75 75 0 (0.0%) 75 ✅
Codex long turn finished, cold open HTTP decoded 381.5 KiB 381.5 KiB 0 B (0.0%) 410.2 KiB ✅
Codex long turn finished, cold open rows 151 151 0 (0.0%) 151 ✅
Codex long turn finished, socket cold open WebSocket decoded 381.6 KiB 381.6 KiB 0 B (0.0%) 410.2 KiB ✅
Codex long turn finished, socket cold open WebSocket messages 2 2 0 (0.0%) 2 ✅
Codex long turn finished, socket cold open rows 151 151 0 (0.0%) 151 ✅
Codex long turn finished, work page HTTP decoded 186.2 KiB 186.2 KiB 0 B (0.0%) 200.2 KiB ✅
Codex long turn finished, work page rows 150 150 0 (0.0%) 150 ✅
Codex idle thread resume WebSocket decoded 65 B 65 B 0 B (0.0%) 200 B ✅
Codex idle thread resume WebSocket messages 1 1 0 (0.0%) 1 ✅
Codex fleet shell snapshot HTTP decoded 42.4 KiB 42.4 KiB 0 B (0.0%) 53.7 KiB ✅
Codex fleet shell snapshot rows 27 27 0 (0.0%) 27 ✅
Codex fleet shell subscribe WebSocket decoded 65 B 65 B 0 B (0.0%) 200 B ✅
Codex fleet shell subscribe WebSocket messages 1 1 0 (0.0%) 1 ✅
Codex fleet shell resume check HTTP decoded 18 B 18 B 0 B (0.0%) 100 B ✅
Codex fleet shell resume check rows 0 0 0 0 ✅
Codex stale shell reload HTTP decoded 42.4 KiB 42.4 KiB 0 B (0.0%) 53.7 KiB ✅
Codex stale shell reload rows 27 27 0 (0.0%) 27 ✅
Codex stale shell resume WebSocket decoded 140 B 140 B 0 B (0.0%) 400 B ✅
Codex stale shell resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Codex stale todo list cold open HTTP decoded 72.4 KiB 72.4 KiB 0 B (0.0%) 83.0 KiB ✅
Codex stale todo list cold open rows 75 75 0 (0.0%) 75 ✅
Codex stale todo list cold open nodes 2 2 0 (0.0%) 4 ✅
Codex stale todo list cold open subagents 2 2 0 (0.0%) 4 ✅
Codex stale todo list cold open plans 1 1 0 (0.0%) 2 ✅
Codex stale todo list cold open providerTurns 1 1 0 (0.0%) 2 ✅
Codex stale todo list cold open checkpoints 1 1 0 (0.0%) 2 ✅
Claude short turn resume WebSocket decoded 10.6 KiB 10.6 KiB 0 B (0.0%) 12.7 KiB ✅
Claude short turn resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Claude long turn running, cold open HTTP decoded 283.3 KiB 283.3 KiB 0 B (0.0%) 302.7 KiB ✅
Claude long turn running, cold open rows 75 75 0 (0.0%) 75 ✅
Claude long turn running, history page HTTP decoded 93.4 KiB 93.4 KiB 0 B (0.0%) 107.4 KiB ✅
Claude long turn running, history page rows 75 75 0 (0.0%) 75 ✅
Claude long turn finished, cold open HTTP decoded 384.2 KiB 384.2 KiB 0 B (0.0%) 410.2 KiB ✅
Claude long turn finished, cold open rows 151 151 0 (0.0%) 151 ✅
Claude long turn finished, socket cold open WebSocket decoded 384.3 KiB 384.3 KiB 0 B (0.0%) 410.2 KiB ✅
Claude long turn finished, socket cold open WebSocket messages 2 2 0 (0.0%) 2 ✅
Claude long turn finished, socket cold open rows 151 151 0 (0.0%) 151 ✅
Claude long turn finished, work page HTTP decoded 188.1 KiB 188.1 KiB 0 B (0.0%) 200.2 KiB ✅
Claude long turn finished, work page rows 150 150 0 (0.0%) 150 ✅
Claude idle thread resume WebSocket decoded 66 B 66 B 0 B (0.0%) 200 B ✅
Claude idle thread resume WebSocket messages 1 1 0 (0.0%) 1 ✅
Claude fleet shell snapshot HTTP decoded 43.0 KiB 43.0 KiB 0 B (0.0%) 53.7 KiB ✅
Claude fleet shell snapshot rows 27 27 0 (0.0%) 27 ✅
Claude fleet shell subscribe WebSocket decoded 66 B 66 B 0 B (0.0%) 200 B ✅
Claude fleet shell subscribe WebSocket messages 1 1 0 (0.0%) 1 ✅
Claude fleet shell resume check HTTP decoded 18 B 18 B 0 B (0.0%) 100 B ✅
Claude fleet shell resume check rows 0 0 0 0 ✅
Claude stale shell reload HTTP decoded 43.0 KiB 43.0 KiB 0 B (0.0%) 53.7 KiB ✅
Claude stale shell reload rows 27 27 0 (0.0%) 27 ✅
Claude stale shell resume WebSocket decoded 140 B 140 B 0 B (0.0%) 400 B ✅
Claude stale shell resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Claude stale todo list cold open HTTP decoded 73.4 KiB 73.4 KiB 0 B (0.0%) 83.0 KiB ✅
Claude stale todo list cold open rows 75 75 0 (0.0%) 75 ✅
Claude stale todo list cold open nodes 2 2 0 (0.0%) 4 ✅
Claude stale todo list cold open subagents 2 2 0 (0.0%) 4 ✅
Claude stale todo list cold open plans 1 1 0 (0.0%) 2 ✅
Claude stale todo list cold open providerTurns 1 1 0 (0.0%) 2 ✅
Claude stale todo list cold open checkpoints 1 1 0 (0.0%) 2 ✅

Baseline: f8c4493 · PR result: d185403 · Source CI: success

Scenario and decoded snapshot size

10 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.

  • Codex decoded thread snapshot: 108.5 KiB
  • Claude decoded thread snapshot: 108.8 KiB

Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

@NoahHendrickson
NoahHendrickson merged commit b48260a into custom Nov 30, 2026
32 checks passed
@NoahHendrickson
NoahHendrickson deleted the t3/restrict-merge-cards-to-owned-prs branch November 30, 2026 02:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants