fix(mobile): local-checkout threads record their branch so PR badges show #4986
main fromrefs/pull/4986/head·merged by juliusmarminge View on GitHubFixes #4951
Problem#
Creating a thread from the mobile composer with the untouched current-checkout default persisted branch: null: the local workspace mode never writes a workspaceSelection into the draft, and the automatic branch selection effect only runs for worktree mode. useThreadPr refuses to subscribe when thread.branch === null and matches on exact equality with the live status.refName, so an open PR for the work was never surfaced on the thread row — while threads with explicit branch metadata showed their badge fine.
Fix#
Online creation now resolves the branch through a small pure helper, resolveProjectThreadCreationBranch: an explicit picker choice always wins; an untouched local-checkout draft records the live checkout ref; worktree mode is unchanged. The current checkout comes from the project's vcsEnvironment.status stream (refName) — the exact value the PR matcher compares against, parsed fresh per publish — not from the ref list, whose current flag is served from a server-side cache with a 10-minute TTL. The subscription is deduped per (environmentId, cwd) with the ones thread rows already open and lives only while the composer sheet is mounted.
No branch is ever fabricated: a detached HEAD, a non-repository project, or a status that has not arrived yet all resolve to null, i.e. exactly the pre-fix behavior. Nothing is written back into the draft's workspaceSelection, so the untouched default stays distinguishable from an explicit choice.
Scope note: queued/offline tasks still record only explicit choices. A queued local task drains against whatever is checked out at drain time, so recording a queue-time guess would pin a stale branch to a thread that ran somewhere else; that trade is commented at the call site.
Visible side effects: mobile-created local threads now show a branch label on their rows and become eligible for web's informational local-checkout mismatch banner, the same treatment web gives its own local threads (web self-heals the branch on next send). Composer sessions open one deduped status subscription per project cwd.
Tests#
New projectThreadCreationValidation.test.ts with 5 cases: the regression (untouched local default records the checkout), explicit selection wins (local and worktree), no checked-out ref stays null, and worktree mode never borrows the checkout. Each behavior was mutation-checked (reverting it fails exactly its test). Scoped mobile typecheck, lint, and format checks are green, plus adjacent suites (thread-outbox, threadListV2, use-thread-pr — 45 tests). Verified via unit tests on Linux; no native iOS run was performed.
Implemented and reviewed with Claude Code (Fable 5).
Note
Low Risk Scoped mobile composer/thread-creation logic with a pure helper and deduped existing VCS status queries; no auth or server changes.
Overview Fixes #4951 by persisting a branch on mobile threads created from the default local-checkout composer, so PR badges and row branch labels can match live git status.
Adds resolveProjectThreadCreationBranch: explicit picker choice wins; otherwise local mode uses the live checkout ref from vcsEnvironment.status (refName), not the branch list’s cached current flag. Worktree mode and detached / missing status still resolve to null. NewTaskFlowProvider exposes currentCheckoutBranchName while the composer is open; NewTaskDraftScreen uses the helper for the displayed branch label and the createProjectThread payload.
Queued/offline tasks are unchanged: only explicit workspaceSelection.branch is stored, with a comment that a queue-time checkout guess would go stale at drain time. Five unit tests cover the resolver matrix.
Note
Record live checkout branch on local-checkout threads so PR badges display#
- Adds
resolveProjectThreadCreationBranchin projectThreadCreationValidation.ts to determine which branch to record: uses the explicit picker selection if provided, falls back to the live checked-out branch for local workspace mode, and returnsnullfor worktree mode without an explicit selection. - Exposes
currentCheckoutBranchNamefrom live VCS status in new-task-flow-provider.tsx by issuing avcsEnvironmentstatus query for the selected environment/cwd. - Updates NewTaskDraftScreen.tsx to pass the resolved branch to
createProjectThread, so threads created without an explicit branch selection still record the current checkout.
Screenshots (Android emulator, synthetic data)#
Verified end-to-end on a Linux-hosted Android emulator against a disposable local T3 environment with a synthetic git repo checked out on feature/checkout-demo. Threads created on pre-fix code persisted an empty branch; the thread created with this fix live recorded feature/checkout-demo (confirmed in projection_threads), and the row shows the branch label. iOS behavior is the same shared React Native code path.
| Before (pre-fix code) | After (fix active) |
|---|---|
![]() | ![]() |
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
Approvability#
Verdict: Approved ff916b0
Straightforward bug fix that adds a simple branch resolution function with unit tests. The change ensures local-checkout threads properly record their branch name so PR badges display correctly - limited scope with clear intent.
You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot).
Want fixes drafted automatically? Bugbot Autofix can create code changes for findings. A team admin can enable Autofix in the Cursor dashboard.
Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 0f5683d325b602db2d647c9dbf6a8fe90b090123. Configure [here](https://www.cursor.com/dashboard/bugbot).apps/mobile/src/features/threads/NewTaskDraftScreen.tsx line 723Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -713,3 +714,4 @@713714 threadTitle: deriveThreadTitleFromPrompt(initialMessageText),714715 projectTitle: selectedProject.title,715716 });717+ const creationBranch = resolveProjectThreadCreationBranch({Composer label ignores live checkout#
Low Severity
The draft screen still derives the visible branch label from
availableBranches(current/isDefault), while online submit now recordscurrentCheckoutBranchNamefrom the live status stream for untouched local drafts. When the refs cache lags an out-of-band checkout, the composer can show one branch and persist another, so the label the user confirms no longer matches the thread metadata used for PR badges.Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 0f5683d325b602db2d647c9dbf6a8fe90b090123. Configure [here](https://www.cursor.com/dashboard/bugbot).Additional Locations (1)
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
juliusmarminge merged thisf8bb92b
juliusmarminge closed this
Sign in to join this conversation.



Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
9e1bf817-3082-4363-b22d-eca74302640bYou can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share