GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(mobile): await branch refs before choosing an automatic feature branch by only21mil · Pull Request #22098 · pingdotgg/t3code

fix(mobile): await branch refs before choosing an automatic feature branch #22098

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
maria-rcks merged 5 commits into pingdotgg:main from only21mil:r7/s10-1
Oct 30, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

fix(mobile): await branch refs before choosing an automatic feature branch #22098

Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit Hold shift + click to select a range
76874f9
fix(mobile): await branch refs before choosing an automatic feature b…
only21mil Oct 20, 2026
54c1d52
fix(mobile): read branch refs with a finite action query
only21mil Oct 20, 2026
490bec0
fix(mobile): merge main and keep branch refresh regressions focused
maria-rcks Oct 26, 2026
9d5625b
fix(mobile): reuse the finite refs command for branch decisions
maria-rcks Oct 26, 2026
75c7b11
fix(mobile): merge main and preserve fresh branch lookup
maria-rcks Oct 30, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

1 change: 1 addition & 0 deletions 1 apps/mobile/src/features/threads/git/GitConfirmSheet.tsx
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export function GitConfirmSheet(props: GitConfirmSheetProps) {
gitState.selectedThreadBranches.length > 0
? gitState.selectedThreadBranches
: await gitActions.refreshSelectedThreadBranches();
if (branches === null) return;
const newBranchName = resolveAutoFeatureBranchName(
Arr.filterMap(branches, (branch) =>
branch.isRemote ? Result.failVoid : Result.succeed(branch.name),
Expand Down
125 changes: 119 additions & 6 deletions 125 apps/mobile/src/state/use-selected-thread-git-actions.test.tsx
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { act, useEffect, useReducer } from "react";
import { createRoot, type Root } from "react-dom/client";
import { AsyncResult } from "effect/reactivity";
import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
import type { VcsListRefsResult } from "@t3tools/contracts";
import { executeAtomQuery } from "@t3tools/client-runtime/state/runtime";
import { resolveAutoFeatureBranchName } from "@t3tools/shared/git";
import * as Effect from "effect/Effect";
import * as Stream from "effect/Stream";
import { AsyncResult, Atom } from "effect/reactivity";
import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";

const harness = vi.hoisted(() => ({
selection: {
Expand All @@ -13,6 +18,11 @@ const harness = vi.hoisted(() => ({
refreshStatusCalls: [] as Array<unknown>,
renderCount: 0,
onRefreshSettled: () => {},
branchAtom: null as Atom.Atom<AsyncResult.AsyncResult<VcsListRefsResult, unknown>> | null,
refsQueryAtom: null as Atom.Atom<AsyncResult.AsyncResult<VcsListRefsResult, unknown>> | null,
listRefs: vi.fn(),
refsQuery: vi.fn(),
showGitActionResult: vi.fn(),
}));

vi.mock("./use-atom-command", () => ({
Expand All @@ -26,19 +36,22 @@ vi.mock("./use-atom-command", () => ({
: async () => AsyncResult.success({}),
}));
vi.mock("./vcs", () => ({
vcsEnvironment: { refreshStatus: "refreshStatus" },
vcsEnvironment: { refreshStatus: "refreshStatus", listRefs: harness.listRefs },
vcsRefsQuery: harness.refsQuery,
vcsActionManager: { runStackedAction: () => "runStackedAction", track: vi.fn() },
}));
vi.mock("./threads", () => ({ threadEnvironment: { updateMetadata: "updateMetadata" } }));
vi.mock("./queries", () => ({ useBranches: () => ({ data: null, refresh: () => {} }) }));
vi.mock("../lib/uuid", () => ({ uuidv4: () => "uuid" }));
vi.mock("./atom-registry", () => ({ appAtomRegistry: {} }));
vi.mock("./atom-registry", async () => ({
appAtomRegistry: (await import("effect/reactivity")).AtomRegistry.make(),
}));
vi.mock("./session", () => ({
readEnvironmentScope: () => true,
useEnvironmentScope: () => true,
}));
vi.mock("./use-remote-environment-registry", () => ({ setPendingConnectionError: () => {} }));
vi.mock("./use-vcs-action-state", () => ({ showGitActionResult: () => {} }));
vi.mock("./use-vcs-action-state", () => ({ showGitActionResult: harness.showGitActionResult }));
vi.mock("./use-thread-selection", () => ({
useThreadSelection: () => {
harness.renderCount += 1;
Expand All @@ -53,16 +66,19 @@ vi.mock("./use-selected-thread-worktree", () => ({
}));

import { useSelectedThreadGitActions } from "./use-selected-thread-git-actions";
import { appAtomRegistry } from "./atom-registry";

let root: Root | null = null;
let rerender: () => void = () => {};
let actions: ReturnType<typeof useSelectedThreadGitActions>;

function Consumer() {
const [, bump] = useReducer((count: number) => count + 1, 0);
const gitActions = useSelectedThreadGitActions();
useEffect(() => {
rerender = bump;
actions = gitActions;
});
useSelectedThreadGitActions();
return null;
}

Expand All @@ -85,14 +101,111 @@ beforeEach(() => {
harness.refreshStatusCalls = [];
harness.renderCount = 0;
harness.onRefreshSettled = () => rerender();
harness.listRefs.mockReset().mockImplementation(() => harness.branchAtom);
harness.refsQuery.mockReset().mockImplementation(() => harness.refsQueryAtom);
harness.showGitActionResult.mockClear();
});

afterEach(() => {
act(() => root?.unmount());
root = null;
});

afterAll(() => appAtomRegistry.dispose());

describe("useSelectedThreadGitActions", () => {
it.each([false, true])(
"waits for fresh refs before naming a branch, cached: %s",
async (cached) => {
const request = Promise.withResolvers<VcsListRefsResult>();
const empty: VcsListRefsResult = {
refs: [],
isRepo: true,
hasPrimaryRemote: true,
nextCursor: null,
totalCount: 0,
};
let response = cached ? Promise.resolve(empty) : request.promise;
const fetchRefs = Effect.tryPromise(() => response);
harness.branchAtom = Atom.make(
Stream.concat(Stream.fromEffect(fetchRefs), Stream.never),
).pipe(Atom.keepAlive);
harness.refsQueryAtom = Atom.make(fetchRefs).pipe(Atom.keepAlive);
appAtomRegistry.get(harness.branchAtom);
if (cached) {
await vi.waitFor(() =>
expect(appAtomRegistry.get(harness.branchAtom)._tag).toBe("Success"),
);
expect(appAtomRegistry.get(harness.branchAtom).waiting).toBe(true);
await executeAtomQuery(appAtomRegistry, harness.refsQueryAtom);
response = request.promise;
}
root = createRoot(document.createElement("div"));
act(() => root!.render(<Consumer />));

let settled = false;
const refresh = actions.refreshSelectedThreadBranches().then((branches) => {
settled = true;
return branches;
});
await flush();
expect(settled).toBe(false);
const local = {
name: "feature/update",
isRemote: false,
current: false,
isDefault: false,
worktreePath: null,
};
request.resolve({
refs: [
local,
{ ...local, name: "origin/feature/update", isRemote: true, remoteName: "origin" },
],
nextCursor: null,
isRepo: true,
hasPrimaryRemote: true,
totalCount: 2,
});
await vi.waitFor(() => expect(settled).toBe(true));
expect(appAtomRegistry.get(harness.branchAtom)).toMatchObject({
_tag: "Success",
waiting: true,
});
const branches = await refresh;
expect(harness.refsQuery).toHaveBeenCalledWith({
environmentId: "environment-1",
input: { cwd: "/repo", limit: 100 },
});
expect(branches).toEqual([local]);
expect(resolveAutoFeatureBranchName(branches!.map((branch) => branch.name))).toBe(
"feature/update-2",
);
},
);

it("reports a failed ref refresh instead of returning an empty list for branch creation", async () => {
const request = Promise.withResolvers<VcsListRefsResult>();
void request.promise.catch(() => {});
harness.branchAtom = Atom.make(
Effect.tryPromise({
try: () => request.promise,
catch: (error) => error,
}),
);
harness.refsQueryAtom = harness.branchAtom;
root = createRoot(document.createElement("div"));
act(() => root!.render(<Consumer />));
const refresh = actions.refreshSelectedThreadBranches();
request.reject(new Error("Cannot list refs"));
expect(await refresh).toBeNull();
expect(harness.showGitActionResult).toHaveBeenCalledWith({
type: "error",
title: "Git action failed",
description: "Cannot list refs",
});
});

it("refreshes once on mount and does not loop when refreshes rerender the consumer", async () => {
root = createRoot(document.createElement("div"));
act(() => root!.render(<Consumer />));
Expand Down
33 changes: 25 additions & 8 deletions 33 apps/mobile/src/state/use-selected-thread-git-actions.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useCallback, useEffect, useEffectEvent, useMemo } from "react";

import { EnvironmentProject, EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
import type { AtomCommandResult } from "@t3tools/client-runtime/state/runtime";
import { executeAtomQuery, type AtomCommandResult } from "@t3tools/client-runtime/state/runtime";
import {
type GitActionRequestInput,
type VcsActionOperation,
Expand All @@ -22,7 +22,7 @@ import { AsyncResult } from "effect/reactivity";

import { useBranches } from "../state/queries";
import { threadEnvironment } from "../state/threads";
import { vcsActionManager, vcsEnvironment } from "../state/vcs";
import { vcsActionManager, vcsEnvironment, vcsRefsQuery } from "../state/vcs";
import { uuidv4 } from "../lib/uuid";
import { appAtomRegistry } from "./atom-registry";
import { readEnvironmentScope, useEnvironmentScope } from "./session";
Expand Down Expand Up @@ -218,12 +218,29 @@ export function useSelectedThreadGitActions() {
[selectedThread, selectedThreadCwd, selectedThreadProject],
);

const refreshSelectedThreadBranches = useCallback(async (): Promise<ReadonlyArray<VcsRef>> => {
branchState.refresh();
return dedupeRemoteBranchesWithLocalMatches(branchState.data?.refs ?? []).filter(
(branch) => !branch.isRemote,
);
}, [branchState]);
const refreshSelectedThreadBranches =
useCallback(async (): Promise<ReadonlyArray<VcsRef> | null> => {
if (branchTarget.environmentId === null || branchTarget.cwd === null) return null;
const result = await executeAtomQuery(
appAtomRegistry,
vcsRefsQuery({
environmentId: branchTarget.environmentId,
input: { cwd: branchTarget.cwd, limit: 100 },
}),
{ refresh: true, reportFailure: false },
);
if (AsyncResult.isFailure(result)) {
const error = Cause.squash(result.cause);
const message = error instanceof Error ? error.message : "Failed to refresh branches.";
setPendingConnectionError(message);
showGitActionResult({ type: "error", title: "Git action failed", description: message });
return null;
}
setPendingConnectionError(null);
return dedupeRemoteBranchesWithLocalMatches(result.value.refs).filter(
(branch) => !branch.isRemote,
);
}, [branchTarget]);

const syncSelectedThreadBranchState = useCallback(
async (input: {
Expand Down
8 changes: 8 additions & 0 deletions 8 apps/mobile/src/state/vcs.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@ import {
createVcsActionManager,
createVcsEnvironmentAtoms,
} from "@t3tools/client-runtime/state/vcs";
import { createEnvironmentRpcQueryAtomFamily } from "@t3tools/client-runtime/state/runtime";
import { WS_METHODS } from "@t3tools/contracts";

import { connectionAtomRuntime } from "../connection/runtime";

export const vcsEnvironment = createVcsEnvironmentAtoms(connectionAtomRuntime);
export const vcsActionManager = createVcsActionManager(connectionAtomRuntime);

// Action confirmations need a finite request; listRefs stays subscribed for cache updates.
export const vcsRefsQuery = createEnvironmentRpcQueryAtomFamily(connectionAtomRuntime, {
label: "mobile:vcs:refs-query",
tag: WS_METHODS.vcsListRefs,
});
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.