@devries-cameron20 / t3code Mirror · read-only / commits / 0b4e83d7d0
Fork 0

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 21, 13:30 UTC

perf(server): the next turn no longer waits for the previous turn's git status refresh (#32349)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: shivam <91240327+shivamhwp@users.noreply.github.com>

Andrei committed Nov 15, 2026 at 03:07 UTC 0b4e83d7d03dfa331c8558797fbe066129e48851
2 files changed +54 -16
apps/server/src/orchestration-v2/RunFinalizationService.test.ts
+49 -15
@@ -36,18 +36,19 @@ const layerNoProject = Layer.mergeAll(
36 Layer.mock(ProjectEnrichment.ProjectEnrichmentService)({}),
37 );
38
39 -it.effect("completes finalization when the post-checkpoint workspace refresh fails", () => {
40 - const threadId = ThreadId.make("thread_refresh_failure");
41 - const runId = RunId.make("run_refresh_failure");
42 - const scopeId = CheckpointScopeId.make("scope_refresh_failure");
43 - const captured: string[] = [];
44 - const layer = RunFinalization.layer.pipe(
39 +const finalizationLayer = (
40 + scopeId: CheckpointScopeId,
41 + runId: RunId,
42 + steps: string[],
43 + refresh: (typeof RunFinalization.RunFinalizationObserver)["Service"]["refresh"],
44 +) =>
45 + RunFinalization.layer.pipe(
46 Layer.provide(
47 Layer.mergeAll(
48 Layer.mock(CheckpointCapture.CheckpointCaptureServiceV2)({
49 execute: () =>
50 Effect.sync(() => {
50 - captured.push("checkpoint");
51 + steps.push("checkpoint");
52 }),
53 }),
54 Layer.mock(ProjectionStore.ProjectionStoreV2)({
@@ -59,19 +60,27 @@ it.effect("completes finalization when the post-checkpoint workspace refresh fai
60 }),
61 }),
62 Layer.succeed(RunFinalization.RunFinalizationObserver, {
62 - refresh: () =>
63 - Effect.gen(function* () {
64 - captured.push("refresh");
65 - return yield* new RunFinalization.RunFinalizationRefreshError({
66 - cwd: "/repo",
67 - cause: new Error("Git command timed out"),
68 - });
69 - }),
63 + refresh,
64 refreshAfterTurn: () => Effect.void,
65 }),
66 ),
67 ),
68 );
69 +
70 +it.effect("completes finalization when the post-checkpoint workspace refresh fails", () => {
71 + const threadId = ThreadId.make("thread_refresh_failure");
72 + const runId = RunId.make("run_refresh_failure");
73 + const scopeId = CheckpointScopeId.make("scope_refresh_failure");
74 + const captured: string[] = [];
75 + const layer = finalizationLayer(scopeId, runId, captured, () =>
76 + Effect.gen(function* () {
77 + captured.push("refresh");
78 + return yield* new RunFinalization.RunFinalizationRefreshError({
79 + cwd: "/repo",
80 + cause: new Error("Git command timed out"),
81 + });
82 + }),
83 + );
84 return Effect.gen(function* () {
85 const service = yield* RunFinalization.RunFinalizationService;
86 yield* service.finalize({ threadId, runId, scopeId });
@@ -79,6 +88,31 @@ it.effect("completes finalization when the post-checkpoint workspace refresh fai
88 }).pipe(Effect.provide(layer));
89 });
90
91 +it.effect("completes finalization without waiting for the display refresh", () => {
92 + const threadId = ThreadId.make("thread_slow_refresh");
93 + const runId = RunId.make("run_slow_refresh");
94 + const scopeId = CheckpointScopeId.make("scope_slow_refresh");
95 + const steps: string[] = [];
96 + const release = Deferred.makeUnsafe<void>();
97 + const refreshed = Deferred.makeUnsafe<void>();
98 + const layer = finalizationLayer(scopeId, runId, steps, () =>
99 + Deferred.await(release).pipe(Effect.andThen(Deferred.succeed(refreshed, undefined))),
100 + );
101 + return Effect.gen(function* () {
102 + const service = yield* RunFinalization.RunFinalizationService;
103 + const finalize = yield* service
104 + .finalize({ threadId, runId, scopeId })
105 + .pipe(Effect.timeoutOption("1 minute"), Effect.forkChild({ startImmediately: true }));
106 + yield* TestClock.adjust("1 minute");
107 + assert.isTrue(
108 + Option.isSome(yield* Fiber.join(finalize)),
109 + "finalization waited on the display refresh, blocking the thread's next turn",
110 + );
111 + yield* Deferred.succeed(release, undefined);
112 + yield* Deferred.await(refreshed);
113 + }).pipe(Effect.provide(layer));
114 +});
115 +
116 it.effect.each(
117 (
118 [
apps/server/src/orchestration-v2/RunFinalizationService.ts
+5 -1
@@ -2,6 +2,7 @@ import { CheckpointScopeId, ProjectId, RunId, ThreadId } from "@t3tools/contract
2 import * as Context from "effect/Context";
3 import * as Effect from "effect/Effect";
4 import * as FiberMap from "effect/FiberMap";
5 +import * as FiberSet from "effect/FiberSet";
6 import * as Layer from "effect/Layer";
7 import * as Option from "effect/Option";
8 import * as Schema from "effect/Schema";
@@ -56,6 +57,7 @@ const make = Effect.gen(function* () {
57 const checkpointCapture = yield* CheckpointCapture.CheckpointCaptureServiceV2;
58 const projections = yield* ProjectionStore.ProjectionStoreV2;
59 const observer = yield* RunFinalizationObserver;
60 + const refreshes = yield* FiberSet.make<void>();
61
62 const finalize: RunFinalizationService["Service"]["finalize"] = Effect.fn(
63 "RunFinalizationService.finalize",
@@ -76,7 +78,8 @@ const make = Effect.gen(function* () {
78 );
79 const cwd = projection.checkpointScopes.find((scope) => scope.id === input.scopeId)?.cwd;
80 if (cwd !== undefined) {
79 - // Retrying a display refresh after the checkpoint is durable blocks the next turn.
81 + // The refresh only updates the display, so the thread's next turn must not wait for it.
82 + // Never replaced by a newer one: back-to-back turns would interrupt each before it publishes.
83 yield* observer.refresh({ cwd, threadId: input.threadId, runId: input.runId }).pipe(
84 Effect.catchTags({
85 RunFinalizationRefreshError: (cause) =>
@@ -85,6 +88,7 @@ const make = Effect.gen(function* () {
88 cause,
89 }),
90 }),
91 + FiberSet.run(refreshes),
92 );
93 }
94 });