Skip to content

[Bug]: Reused long-lived branch remains associated with a historical merged PR #4970

Description

@Ionmi

Before submitting

  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.

Area

apps/web

Steps to reproduce

  1. Use a long-lived integration branch in a local checkout, for example dev.
  2. Open a PR from dev to main and merge it.
  3. Continue using the same dev branch after the merge for new work.
  4. Create a new T3 Code thread on the local checkout while dev is checked out.
  5. Complete a turn and inspect the branch/PR indicator and Sidebar V2 thread state.

Concrete observed case: GitHub PR rebel-tickets/NewWeb#182 was merged from dev into main. New unrelated threads created later on the still-active dev branch display #182 as their PR.

Expected behavior

A new thread on a reused long-lived branch should not inherit a historical merged PR merely because its head branch name matches.

T3 Code should associate a terminal PR only while it still describes the current branch state. If the branch HEAD has advanced beyond the PR head after merge, the historical PR badge/state should be ignored. Consequently, unrelated new threads should remain active.

Actual behavior

T3 Code displays the historical merged PR on every new thread using the reused dev branch. The merged PR state is then fed into automatic settlement, so each new unrelated thread settles when its turn finishes even when Auto-settle inactive threads is disabled.

The settle behavior is secondary damage. The root problem is stale PR association for a reused branch.

This appears adjacent to #4460, which prevents PR state from a different branch affecting settlement, but exact branch-name equality is insufficient for a long-lived branch reused after a merge. It is also related to #4752/#4755, which retain terminal PR state for local checkouts.

Suggested minimal fix: for merged/closed PRs, verify that the current branch HEAD still corresponds to the PR head commit before displaying or applying its terminal state. If the branch has advanced, discard the historical association. Open PR selection can continue using the existing branch match.

Impact

Major degradation or frequent failure

Version or commit

Current T3 Code desktop build as of 2026-07-30

Environment

macOS desktop app, local checkout, Sidebar V2, GitHub repository, Codex provider

Logs or stack traces

No runtime error. GitHub reports the historical PR as:
baseRefName=main
headRefName=dev
state=MERGED

Workaround

Disable Sidebar V2 or create threads on a new uniquely named branch/worktree. Disabling Auto-settle inactive threads does not help because merged/closed PR settlement is unconditional.

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