Skip to content

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.

fetch in background

Julius Marminge98c4b7c724da
diff --git a/apps/server/src/git.test.ts b/apps/server/src/git.test.ts
index 323b385ed..515a763cf 100644
--- a/apps/server/src/git.test.ts
+++ b/apps/server/src/git.test.ts
@@ -272,11 +272,12 @@ describe("git integration", () => {
await checkoutGitBranch({ cwd: source.path, branch: featureBranch });
const core = new GitCoreService();
- const details = await core.statusDetails(source.path);
-
- expect(details.branch).toBe(featureBranch);
- expect(details.aheadCount).toBe(0);
- expect(details.behindCount).toBe(1);
+ await vi.waitFor(async () => {
+ const details = await core.statusDetails(source.path);
+ expect(details.branch).toBe(featureBranch);
+ expect(details.aheadCount).toBe(0);
+ expect(details.behindCount).toBe(1);
+ });
});
it("keeps checkout successful when upstream refresh fails", async () => {
@@ -320,7 +321,9 @@ describe("git integration", () => {
await expect(core.checkoutBranch({ cwd: source.path, branch: featureBranch })).resolves.toBe(
undefined,
);
- expect(core.refreshFetchAttempts).toBe(1);
+ await vi.waitFor(() => {
+ expect(core.refreshFetchAttempts).toBe(1);
+ });
expect(await git(source.path, "branch --show-current")).toBe(featureBranch);
});
@@ -362,6 +365,9 @@ describe("git integration", () => {
const core = new FetchRecordingGitCoreService();
await core.checkoutBranch({ cwd: source.path, branch: featureBranch });
+ await vi.waitFor(() => {
+ expect(core.fetchArgs).not.toBeNull();
+ });
expect(await git(source.path, "branch --show-current")).toBe(featureBranch);
expect(core.fetchArgs).toEqual([
@@ -373,6 +379,67 @@ describe("git integration", () => {
]);
});
+ it("returns checkout result before background upstream refresh completes", async () => {
+ await using remote = await makeTmpDir();
+ await using source = await makeTmpDir();
+ await git(remote.path, "init --bare");
+
+ await initRepoWithCommit(source.path);
+ const defaultBranch = (await listGitBranches({ cwd: source.path })).branches.find(
+ (branch) => branch.current,
+ )!.name;
+ await git(source.path, `remote add origin ${JSON.stringify(remote.path)}`);
+ await git(source.path, `push -u origin ${defaultBranch}`);
+
+ const featureBranch = "feature/background-refresh";
+ await git(source.path, `checkout -b ${featureBranch}`);
+ await writeFile(path.join(source.path, "feature.txt"), "feature base\n");
+ await git(source.path, "add feature.txt");
+ await git(source.path, "commit -m 'feature base'");
+ await git(source.path, `push -u origin ${featureBranch}`);
+ await git(source.path, `checkout ${defaultBranch}`);
+
+ class SlowRefreshGitCoreService extends GitCoreService {
+ fetchStarted = false;
+ private readonly waitForReleasePromise: Promise<void>;
+ private releaseWait: () => void = () => undefined;
+
+ constructor() {
+ super();
+ this.waitForReleasePromise = new Promise<void>((resolve) => {
+ this.releaseWait = resolve;
+ });
+ }
+
+ releaseFetch(): void {
+ this.releaseWait();
+ }
+
+ override async git(
+ cwd: string,
+ args: readonly string[],
+ allowNonZeroExit = false,
+ ): Promise<void> {
+ if (args[0] === "fetch") {
+ this.fetchStarted = true;
+ await this.waitForReleasePromise;
+ return;
+ }
+ await super.git(cwd, args, allowNonZeroExit);
+ }
+ }
+
+ const core = new SlowRefreshGitCoreService();
+ await expect(core.checkoutBranch({ cwd: source.path, branch: featureBranch })).resolves.toBe(
+ undefined,
+ );
+ await vi.waitFor(() => {
+ expect(core.fetchStarted).toBe(true);
+ });
+ expect(await git(source.path, "branch --show-current")).toBe(featureBranch);
+ core.releaseFetch();
+ });
+
it("throws when branch does not exist", async () => {
await using tmp = await makeTmpDir();
await initRepoWithCommit(tmp.path);
diff --git a/apps/server/src/git.ts b/apps/server/src/git.ts
index ea035d988..1fbd86c7b 100644
--- a/apps/server/src/git.ts
+++ b/apps/server/src/git.ts
@@ -587,11 +587,8 @@ export class GitCoreService {
timeoutMs: 10_000,
fallbackErrorMessage: "git checkout failed",
});
- try {
- await this.refreshCheckedOutBranchUpstream(input.cwd);
- } catch {
- // Best effort: checkout already succeeded, so avoid surfacing refresh failures.
- }
+ // Refresh upstream refs in the background so checkout remains responsive.
+ void this.refreshCheckedOutBranchUpstream(input.cwd).catch(() => undefined);
}
async initRepo(input: GitInitInput): Promise<void> {