The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 25, 06:15 UTC
Refresh local git status on turn completion (#1821)
Co-authored-by: codex <codex@users.noreply.github.com>
Julius Marminge committed
Apr 9, 2026 at 11:02 UTC
2aa73985ea8d13d401ef9063ead4fbb9eaeeab38
6 files changed
+131
-4
apps/server/integration/OrchestrationEngineHarness.integration.ts
+17
@@ -26,6 +26,7 @@ import { CheckpointStoreLive } from "../src/checkpointing/Layers/CheckpointStore
26
import { CheckpointStore } from "../src/checkpointing/Services/CheckpointStore.ts";
27
import { GitCoreLive } from "../src/git/Layers/GitCore.ts";
28
import { GitCore, type GitCoreShape } from "../src/git/Services/GitCore.ts";
29
+import { GitStatusBroadcaster } from "../src/git/Services/GitStatusBroadcaster.ts";
30
import { TextGeneration, type TextGenerationShape } from "../src/git/Services/TextGeneration.ts";
31
import { OrchestrationCommandReceiptRepositoryLive } from "../src/persistence/Layers/OrchestrationCommandReceipts.ts";
32
import { OrchestrationEventStoreLive } from "../src/persistence/Layers/OrchestrationEventStore.ts";
@@ -321,6 +322,22 @@ export const makeOrchestrationIntegrationHarness = (
322
);
323
const checkpointReactorLayer = CheckpointReactorLive.pipe(
324
Layer.provideMerge(runtimeServicesLayer),
325
+ Layer.provideMerge(
326
+ Layer.succeed(GitStatusBroadcaster, {
327
+ getStatus: () => Effect.die("getStatus should not be called in this test"),
328
+ refreshLocalStatus: () =>
329
+ Effect.succeed({
330
+ isRepo: true,
331
+ hasOriginRemote: false,
332
+ isDefaultBranch: true,
333
+ branch: "main",
334
+ hasWorkingTreeChanges: false,
335
+ workingTree: { files: [], insertions: 0, deletions: 0 },
336
+ }),
337
+ refreshStatus: () => Effect.die("refreshStatus should not be called in this test"),
338
+ streamStatus: () => Stream.empty,
339
+ }),
340
+ ),
341
Layer.provideMerge(
342
WorkspaceEntriesLive.pipe(
343
Layer.provide(WorkspacePathsLive),
apps/server/src/git/Layers/GitStatusBroadcaster.test.ts
+36
@@ -143,6 +143,42 @@ describe("GitStatusBroadcasterLive", () => {
143
}).pipe(Effect.provide(makeTestLayer(state)));
144
});
145
146
+ it.effect("refreshes only the cached local snapshot when requested", () => {
147
+ const state = {
148
+ currentLocalStatus: baseLocalStatus,
149
+ currentRemoteStatus: baseRemoteStatus,
150
+ localStatusCalls: 0,
151
+ remoteStatusCalls: 0,
152
+ localInvalidationCalls: 0,
153
+ remoteInvalidationCalls: 0,
154
+ };
155
+
156
+ return Effect.gen(function* () {
157
+ const broadcaster = yield* GitStatusBroadcaster;
158
+ const initial = yield* broadcaster.getStatus({ cwd: "/repo" });
159
+
160
+ state.currentLocalStatus = {
161
+ ...baseLocalStatus,
162
+ branch: "feature/local-only-refresh",
163
+ hasWorkingTreeChanges: true,
164
+ };
165
+
166
+ const refreshedLocal = yield* broadcaster.refreshLocalStatus("/repo");
167
+ const cached = yield* broadcaster.getStatus({ cwd: "/repo" });
168
+
169
+ assert.deepStrictEqual(initial, baseStatus);
170
+ assert.deepStrictEqual(refreshedLocal, state.currentLocalStatus);
171
+ assert.deepStrictEqual(cached, {
172
+ ...state.currentLocalStatus,
173
+ ...baseRemoteStatus,
174
+ });
175
+ assert.equal(state.localStatusCalls, 2);
176
+ assert.equal(state.remoteStatusCalls, 1);
177
+ assert.equal(state.localInvalidationCalls, 1);
178
+ assert.equal(state.remoteInvalidationCalls, 0);
179
+ }).pipe(Effect.provide(makeTestLayer(state)));
180
+ });
181
+
182
it.effect("streams a local snapshot first and remote updates later", () => {
183
const state = {
184
currentLocalStatus: baseLocalStatus,
apps/server/src/git/Layers/GitStatusBroadcaster.ts
+8
-4
@@ -179,10 +179,13 @@ export const GitStatusBroadcasterLive = Layer.effect(
179
return mergeGitStatusParts(local, remote);
180
});
181
182
- const refreshLocalStatus = Effect.fn("refreshLocalStatus")(function* (cwd: string) {
183
- yield* gitManager.invalidateLocalStatus(cwd);
184
- const local = yield* gitManager.localStatus({ cwd });
185
- return yield* updateCachedLocalStatus(cwd, local, { publish: true });
182
+ const refreshLocalStatus: GitStatusBroadcasterShape["refreshLocalStatus"] = Effect.fn(
183
+ "refreshLocalStatus",
184
+ )(function* (cwd) {
185
+ const normalizedCwd = normalizeCwd(cwd);
186
+ yield* gitManager.invalidateLocalStatus(normalizedCwd);
187
+ const local = yield* gitManager.localStatus({ cwd: normalizedCwd });
188
+ return yield* updateCachedLocalStatus(normalizedCwd, local, { publish: true });
189
});
190
191
const refreshRemoteStatus = Effect.fn("refreshRemoteStatus")(function* (cwd: string) {
@@ -300,6 +303,7 @@ export const GitStatusBroadcasterLive = Layer.effect(
303
304
return {
305
getStatus,
306
+ refreshLocalStatus,
307
refreshStatus,
308
streamStatus,
309
} satisfies GitStatusBroadcasterShape;
apps/server/src/git/Services/GitStatusBroadcaster.ts
+4
@@ -3,6 +3,7 @@ import type { Effect, Stream } from "effect";
3
import type {
4
GitManagerServiceError,
5
GitStatusInput,
6
+ GitStatusLocalResult,
7
GitStatusResult,
8
GitStatusStreamEvent,
9
} from "@t3tools/contracts";
@@ -11,6 +12,9 @@ export interface GitStatusBroadcasterShape {
12
readonly getStatus: (
13
input: GitStatusInput,
14
) => Effect.Effect<GitStatusResult, GitManagerServiceError>;
15
+ readonly refreshLocalStatus: (
16
+ cwd: string,
17
+ ) => Effect.Effect<GitStatusLocalResult, GitManagerServiceError>;
18
readonly refreshStatus: (cwd: string) => Effect.Effect<GitStatusResult, GitManagerServiceError>;
19
readonly streamStatus: (
20
input: GitStatusInput,
apps/server/src/orchestration/Layers/CheckpointReactor.test.ts
+43
@@ -20,6 +20,7 @@ import { afterEach, describe, expect, it, vi } from "vitest";
20
import { CheckpointStoreLive } from "../../checkpointing/Layers/CheckpointStore.ts";
21
import { CheckpointStore } from "../../checkpointing/Services/CheckpointStore.ts";
22
import { GitCoreLive } from "../../git/Layers/GitCore.ts";
23
+import { GitStatusBroadcaster } from "../../git/Services/GitStatusBroadcaster.ts";
24
import { RepositoryIdentityResolverLive } from "../../project/Layers/RepositoryIdentityResolver.ts";
25
import { CheckpointReactorLive } from "./CheckpointReactor.ts";
26
import { OrchestrationEngineLive } from "./OrchestrationEngine.ts";
@@ -243,6 +244,7 @@ describe("CheckpointReactor", () => {
244
readonly threadWorktreePath?: string | null;
245
readonly providerSessionCwd?: string;
246
readonly providerName?: ProviderKind;
247
+ readonly gitStatusRefreshCalls?: Array<string>;
248
}) {
249
const cwd = createGitRepository();
250
tempDirs.push(cwd);
@@ -264,11 +266,30 @@ describe("CheckpointReactor", () => {
266
const ServerConfigLayer = ServerConfig.layerTest(process.cwd(), {
267
prefix: "t3-checkpoint-reactor-test-",
268
});
269
+ const gitStatusBroadcasterLayer = Layer.succeed(GitStatusBroadcaster, {
270
+ getStatus: () => Effect.die("getStatus should not be called in this test"),
271
+ refreshLocalStatus: (cwd: string) =>
272
+ Effect.sync(() => {
273
+ options?.gitStatusRefreshCalls?.push(cwd);
274
+ }).pipe(
275
+ Effect.as({
276
+ isRepo: true,
277
+ hasOriginRemote: false,
278
+ isDefaultBranch: true,
279
+ branch: "main",
280
+ hasWorkingTreeChanges: false,
281
+ workingTree: { files: [], insertions: 0, deletions: 0 },
282
+ }),
283
+ ),
284
+ refreshStatus: () => Effect.die("refreshStatus should not be called in this test"),
285
+ streamStatus: () => Stream.empty,
286
+ });
287
288
const layer = CheckpointReactorLive.pipe(
289
Layer.provideMerge(orchestrationLayer),
290
Layer.provideMerge(RuntimeReceiptBusLive),
291
Layer.provideMerge(Layer.succeed(ProviderService, provider.service)),
292
+ Layer.provideMerge(gitStatusBroadcasterLayer),
293
Layer.provideMerge(CheckpointStoreLive),
294
Layer.provideMerge(WorkspaceEntriesLive.pipe(Layer.provide(WorkspacePathsLive))),
295
Layer.provideMerge(WorkspacePathsLive),
@@ -426,6 +447,28 @@ describe("CheckpointReactor", () => {
447
).toBe("v2\n");
448
});
449
450
+ it("refreshes local git status state on turn completion using the session cwd", async () => {
451
+ const gitStatusRefreshCalls: string[] = [];
452
+ const harness = await createHarness({
453
+ seedFilesystemCheckpoints: false,
454
+ gitStatusRefreshCalls,
455
+ });
456
+
457
+ harness.provider.emit({
458
+ type: "turn.completed",
459
+ eventId: EventId.makeUnsafe("evt-turn-completed-refresh-local-status"),
460
+ provider: "codex",
461
+ createdAt: new Date().toISOString(),
462
+ threadId: ThreadId.makeUnsafe("thread-1"),
463
+ turnId: asTurnId("turn-refresh-local-status"),
464
+ payload: { state: "completed" },
465
+ });
466
+
467
+ await harness.drain();
468
+
469
+ expect(gitStatusRefreshCalls).toEqual([harness.cwd]);
470
+ });
471
+
472
it("ignores auxiliary thread turn completion while primary turn is active", async () => {
473
const harness = await createHarness({ seedFilesystemCheckpoints: false });
474
const createdAt = new Date().toISOString();
apps/server/src/orchestration/Layers/CheckpointReactor.ts
+23
@@ -24,6 +24,7 @@ import { RuntimeReceiptBus } from "../Services/RuntimeReceiptBus.ts";
24
import { CheckpointStoreError } from "../../checkpointing/Errors.ts";
25
import { OrchestrationDispatchError } from "../Errors.ts";
26
import { isGitRepository } from "../../git/Utils.ts";
27
+import { GitStatusBroadcaster } from "../../git/Services/GitStatusBroadcaster.ts";
28
import { WorkspaceEntries } from "../../workspace/Services/WorkspaceEntries.ts";
29
30
type ReactorInput =
@@ -69,6 +70,7 @@ const make = Effect.gen(function* () {
70
const checkpointStore = yield* CheckpointStore;
71
const receiptBus = yield* RuntimeReceiptBus;
72
const workspaceEntries = yield* WorkspaceEntries;
73
+ const gitStatusBroadcaster = yield* GitStatusBroadcaster;
74
75
const appendRevertFailureActivity = (input: {
76
readonly threadId: ThreadId;
@@ -498,6 +500,26 @@ const make = Effect.gen(function* () {
500
},
501
);
502
503
+ const refreshLocalGitStatusFromTurnCompletion = Effect.fn(
504
+ "refreshLocalGitStatusFromTurnCompletion",
505
+ )(function* (event: Extract<ProviderRuntimeEvent, { type: "turn.completed" }>) {
506
+ const sessionRuntime = yield* resolveSessionRuntimeForThread(event.threadId);
507
+ if (Option.isNone(sessionRuntime)) {
508
+ return;
509
+ }
510
+
511
+ yield* gitStatusBroadcaster.refreshLocalStatus(sessionRuntime.value.cwd).pipe(
512
+ Effect.catch((error) =>
513
+ Effect.logWarning("failed to refresh local git status after turn completion", {
514
+ threadId: event.threadId,
515
+ turnId: event.turnId ?? null,
516
+ cwd: sessionRuntime.value.cwd,
517
+ detail: error.message,
518
+ }),
519
+ ),
520
+ );
521
+ });
522
+
523
const ensurePreTurnBaselineFromDomainTurnStart = Effect.fn(
524
"ensurePreTurnBaselineFromDomainTurnStart",
525
)(function* (
@@ -736,6 +758,7 @@ const make = Effect.gen(function* () {
758
759
if (event.type === "turn.completed") {
760
const turnId = toTurnId(event.turnId);
761
+ yield* refreshLocalGitStatusFromTurnCompletion(event);
762
yield* captureCheckpointFromTurnCompletion(event).pipe(
763
Effect.catch((error) =>
764
appendCaptureFailureActivity({