Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.
fix(mobile): local-checkout threads record their branch so PR badges show (#4986)
Zeus-Deusf8bb92b51b72
diff --git a/apps/mobile/src/features/threads/NewTaskDraftScreen.tsx b/apps/mobile/src/features/threads/NewTaskDraftScreen.tsxindex baa28d7b4..6084d8e15 100644--- a/apps/mobile/src/features/threads/NewTaskDraftScreen.tsx+++ b/apps/mobile/src/features/threads/NewTaskDraftScreen.tsx@@ -56,6 +56,7 @@ import { armAgentAwarenessLiveActivityForLocalWork } from "../agent-awareness/reimport { enqueueThreadOutboxMessage, removeThreadOutboxMessage } from "../../state/thread-outbox";import { useRemoteConnectionStatus } from "../../state/use-remote-environment-registry";import { useNewTaskFlow } from "./new-task-flow-provider";+import { resolveProjectThreadCreationBranch } from "./projectThreadCreationValidation";import { useCreateProjectThread } from "./use-project-actions";import { resolveDraftProjectSelection } from "./new-task-project-selection";import {@@ -583,11 +584,17 @@ export function NewTaskDraftScreen(props: {flow.environments.find((environment) => environment.environmentId === flow.selectedEnvironmentId,)?.environmentLabel ?? "Environment";- const currentBranchName =+ const availableCurrentBranchName =flow.availableBranches.find((branch) => branch.current)?.name ??flow.availableBranches.find((branch) => branch.isDefault)?.name ??null;- const selectedBranchName = flow.selectedBranchName ?? currentBranchName;+ const selectedBranchName = resolveProjectThreadCreationBranch({+ workspaceMode: flow.workspaceMode,+ selectedBranch:+ flow.selectedBranchName ??+ (flow.workspaceMode === "worktree" ? availableCurrentBranchName : null),+ currentCheckoutBranch: flow.currentCheckoutBranchName,+ });const selectedBranchLabel = resolveNewTaskBranchLabel({branchName: selectedBranchName,startFromOrigin: flow.startFromOrigin,@@ -713,11 +720,16 @@ export function NewTaskDraftScreen(props: {threadTitle: deriveThreadTitleFromPrompt(initialMessageText),projectTitle: selectedProject.title,});+ const creationBranch = resolveProjectThreadCreationBranch({+ workspaceMode,+ selectedBranch: selectedBranchName,+ currentCheckoutBranch: flow.currentCheckoutBranchName,+ });const result = await createProjectThread({project: selectedProject,modelSelection,envMode: workspaceMode,- branch: selectedBranchName,+ branch: creationBranch,worktreePath: workspaceMode === "worktree" ? null : selectedWorktreePath,startFromOrigin,runtimeMode,diff --git a/apps/mobile/src/features/threads/new-task-flow-provider.tsx b/apps/mobile/src/features/threads/new-task-flow-provider.tsxindex 44056ead3..14f0fcc95 100644--- a/apps/mobile/src/features/threads/new-task-flow-provider.tsx+++ b/apps/mobile/src/features/threads/new-task-flow-provider.tsx@@ -52,6 +52,7 @@ import {useComposerDraft,} from "../../state/use-composer-drafts";import { useDebouncedValue, usePaginatedBranches } from "../../state/queries";+import { vcsEnvironment } from "../../state/vcs";import {flattenQueuedThreadMessages,threadOutboxManager,@@ -139,6 +140,7 @@ type NewTaskFlowContextValue = {readonly branchesFetchingNextPage: boolean;readonly hasMoreBranches: boolean;readonly availableBranches: ReadonlyArray<VcsRef>;+ readonly currentCheckoutBranchName: string | null;readonly runtimeMode: RuntimeMode;readonly interactionMode: ProviderInteractionMode;readonly planModeEnabled: boolean;@@ -553,6 +555,22 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {),[allBranchRefs],);+ // The ref actually checked out in the project root, serialized onto new+ // local threads. It comes from the live status stream rather than listRefs'+ // `current` flag, which is served from a cache that can lag an out-of-band+ // `git switch` by minutes — and from the same value the PR badge compares+ // against. Detached HEAD and non-repository projects report no ref, so this+ // stays null instead of fabricating a branch. The status family is+ // deduplicated per (environmentId, cwd) with the thread rows.+ const projectGitStatus = useEnvironmentQuery(+ branchTarget.environmentId !== null && branchTarget.cwd !== null+ ? vcsEnvironment.status({+ environmentId: branchTarget.environmentId,+ input: { cwd: branchTarget.cwd },+ })+ : null,+ );+ const currentCheckoutBranchName = projectGitStatus.data?.refName ?? null;const filteredBranches = useMemo(() => {const query = branchQuery.trim().toLowerCase();@@ -859,6 +877,10 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {...(projectTitle !== undefined ? { projectTitle } : {}),...(projectCwd !== undefined ? { projectCwd } : {}),workspaceMode: mode,+ // Only an explicit picker choice, never the current checkout: a+ // queued local task drains days later against whatever is checked+ // out then, so recording a queue-time guess would pin a stale label+ // to a thread that ran somewhere else.branch: workspaceSelection?.branch ?? null,worktreePath: mode === "worktree" ? null : (workspaceSelection?.worktreePath ?? null),// The draft only carries the flag when the user touched it; fall@@ -996,6 +1018,7 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {branchesFetchingNextPage,hasMoreBranches,availableBranches,+ currentCheckoutBranchName,runtimeMode,interactionMode,planModeEnabled,@@ -1043,6 +1066,7 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {branchesFetchingNextPage,buildPendingTaskMessage,cancelEditingPendingTask,+ currentCheckoutBranchName,editingPendingTask,environments,expandedProvider,diff --git a/apps/mobile/src/features/threads/projectThreadCreationValidation.test.ts b/apps/mobile/src/features/threads/projectThreadCreationValidation.test.tsnew file mode 100644index 000000000..5c4980e6e--- /dev/null+++ b/apps/mobile/src/features/threads/projectThreadCreationValidation.test.ts@@ -0,0 +1,55 @@+import { describe, expect, it } from "vite-plus/test";++import { resolveProjectThreadCreationBranch } from "./projectThreadCreationValidation";++describe("resolveProjectThreadCreationBranch", () => {+ it("uses the live checkout for an untouched local draft label and recorded branch", () => {+ expect(+ resolveProjectThreadCreationBranch({+ workspaceMode: "local",+ selectedBranch: null,+ currentCheckoutBranch: "feature/x",+ }),+ ).toBe("feature/x");+ });++ it("prefers an explicit picker choice over the current checkout", () => {+ expect(+ resolveProjectThreadCreationBranch({+ workspaceMode: "local",+ selectedBranch: "main",+ currentCheckoutBranch: "feature/x",+ }),+ ).toBe("main");+ });++ it("stays null when no ref is checked out (detached HEAD, non-repository, status not loaded)", () => {+ expect(+ resolveProjectThreadCreationBranch({+ workspaceMode: "local",+ selectedBranch: null,+ currentCheckoutBranch: null,+ }),+ ).toBeNull();+ });++ it("never borrows the current checkout for a worktree draft", () => {+ expect(+ resolveProjectThreadCreationBranch({+ workspaceMode: "worktree",+ selectedBranch: null,+ currentCheckoutBranch: "feature/x",+ }),+ ).toBeNull();+ });++ it("keeps the explicit base branch for a worktree draft", () => {+ expect(+ resolveProjectThreadCreationBranch({+ workspaceMode: "worktree",+ selectedBranch: "main",+ currentCheckoutBranch: "feature/x",+ }),+ ).toBe("main");+ });+});diff --git a/apps/mobile/src/features/threads/projectThreadCreationValidation.ts b/apps/mobile/src/features/threads/projectThreadCreationValidation.tsindex e4ad776e2..f2c98bdfb 100644--- a/apps/mobile/src/features/threads/projectThreadCreationValidation.ts+++ b/apps/mobile/src/features/threads/projectThreadCreationValidation.ts@@ -32,6 +32,26 @@ export const ProjectThreadCreationValidationError = Schema.Union([]);export type ProjectThreadCreationValidationError = typeof ProjectThreadCreationValidationError.Type;+/**+ * Branch recorded on a thread created from the new-task composer. An explicit+ * picker choice always wins. An untouched current-checkout draft records the+ * ref that is actually checked out, so the thread's PR badge and branch label+ * match the live git status instead of staying blank. A detached HEAD, a+ * non-repository project, or a status that has not arrived stays null rather+ * than fabricating a branch. Only the online creation path resolves a+ * checkout; a queued task cannot know the checkout it will drain against.+ */+export function resolveProjectThreadCreationBranch(input: {+ readonly workspaceMode: "local" | "worktree";+ readonly selectedBranch: string | null;+ readonly currentCheckoutBranch: string | null;+}): string | null {+ if (input.selectedBranch !== null) {+ return input.selectedBranch;+ }+ return input.workspaceMode === "local" ? input.currentCheckoutBranch : null;+}+export function validateProjectThreadCreation(input: {readonly environmentId: EnvironmentId;readonly projectId: ProjectId;