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, 21:00 UTC
fix(server): a slow baseline checkpoint no longer holds every prompt for 30 seconds (#34849)
Julius Marminge committed
Nov 11, 2026 at 23:39 UTC
c085a0aa5d26ce3a1eff7ab10b5dd7ad0421c937
2 files changed
+81
apps/server/src/orchestration-v2/CheckpointService.test.ts
+77
@@ -12,8 +12,12 @@ import {
12
VcsUnsupportedOperationError,
13
} from "@t3tools/contracts";
14
import * as DateTime from "effect/DateTime";
15
+import * as Deferred from "effect/Deferred";
16
import * as Effect from "effect/Effect";
17
+import * as Fiber from "effect/Fiber";
18
import * as Layer from "effect/Layer";
19
+import * as Ref from "effect/Ref";
20
+import * as TestClock from "effect/testing/TestClock";
21
22
import * as CheckpointStore from "../checkpointing/CheckpointStore.ts";
23
import * as CheckpointService from "./CheckpointService.ts";
@@ -98,6 +102,79 @@ it.effect(
102
}),
103
);
104
105
+it.effect(
106
+ "bounds a slow baseline snapshot but waits for an in-flight capture of the same ref",
107
+ () =>
108
+ Effect.gen(function* () {
109
+ const scope: OrchestrationV2CheckpointScope = {
110
+ id: CheckpointScopeId.make("checkpoint-scope:slow-baseline"),
111
+ threadId: ThreadId.make("thread:slow-baseline"),
112
+ runId: RunId.make("run:slow-baseline:1"),
113
+ nodeId: NodeId.make("node:slow-baseline:1"),
114
+ parentScopeId: null,
115
+ providerThreadId: ProviderThreadId.make("provider-thread:slow-baseline"),
116
+ kind: "root_run",
117
+ ordinalWithinParent: 0,
118
+ advancesAppRunCount: true,
119
+ cwd: "/repo/slow",
120
+ createdAt: DateTime.makeUnsafe("2026-07-28T00:00:00.000Z"),
121
+ };
122
+ const refs = yield* Ref.make<ReadonlySet<string>>(new Set());
123
+ const snapshots = yield* Ref.make(0);
124
+ const firstSnapshotStarted = yield* Deferred.make<void>();
125
+ const layerTest = CheckpointService.layer.pipe(
126
+ Layer.provide(
127
+ Layer.mergeAll(
128
+ IdAllocator.layer,
129
+ Layer.mock(CheckpointStore.CheckpointStore)({
130
+ isGitRepository: () => Effect.succeed(true),
131
+ hasCheckpointRef: ({ checkpointRef }) =>
132
+ Ref.get(refs).pipe(Effect.map((current) => current.has(checkpointRef))),
133
+ captureCheckpoint: ({ checkpointRef }) =>
134
+ Effect.gen(function* () {
135
+ yield* Ref.update(snapshots, (count) => count + 1);
136
+ yield* Deferred.succeed(firstSnapshotStarted, undefined);
137
+ yield* Effect.sleep("10 seconds");
138
+ yield* Ref.update(refs, (current) => new Set([...current, checkpointRef]));
139
+ }),
140
+ }),
141
+ ),
142
+ ),
143
+ Layer.provideMerge(NodeCrypto.layer),
144
+ );
145
+
146
+ yield* Effect.gen(function* () {
147
+ const checkpoints = yield* CheckpointService.CheckpointServiceV2;
148
+ // A stopped run's post-turn capture writes the next run's baseline ref while holding the lock.
149
+ const postTurn = yield* checkpoints
150
+ .capture({
151
+ scope,
152
+ ordinalWithinScope: 1,
153
+ runId: scope.runId!,
154
+ nodeId: scope.nodeId!,
155
+ appRunOrdinal: 1,
156
+ capturedAt: scope.createdAt,
157
+ })
158
+ .pipe(Effect.forkChild);
159
+ yield* Deferred.await(firstSnapshotStarted);
160
+ const waitingBaseline = yield* checkpoints
161
+ .captureBaseline({ scope, ordinalWithinScope: 1 })
162
+ .pipe(Effect.result, Effect.forkChild);
163
+ yield* TestClock.adjust("10 seconds");
164
+ assert.strictEqual((yield* Fiber.join(postTurn)).status, "ready");
165
+ assert.strictEqual((yield* Fiber.join(waitingBaseline))._tag, "Success");
166
+
167
+ const slowBaseline = yield* checkpoints
168
+ .captureBaseline({ scope, ordinalWithinScope: 2 })
169
+ .pipe(Effect.result, Effect.forkChild);
170
+ yield* TestClock.adjust("5 seconds");
171
+ assert.strictEqual((yield* Fiber.join(slowBaseline))._tag, "Failure");
172
+ assert.strictEqual(yield* Ref.get(snapshots), 2);
173
+ assert.strictEqual((yield* Ref.get(refs)).size, 1);
174
+ }).pipe(Effect.provide(layerTest));
175
+ }),
176
+);
177
+
178
it.effect("records a repository probe failure as an error checkpoint, not a missing one", () =>
179
Effect.gen(function* () {
180
const scope: OrchestrationV2CheckpointScope = {
apps/server/src/orchestration-v2/CheckpointService.ts
+4
@@ -25,6 +25,9 @@ import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
25
26
const CHECKPOINT_REFS_PREFIX = "refs/t3/orchestration-v2/checkpoints";
27
const ROOT_CHECKPOINT_SCOPE_NAME = "root";
28
+// The provider turn waits on the baseline, so a workspace too slow for this starts without one.
29
+// It bounds only the snapshot: waiting on the lock lets an in-flight capture finish the same ref.
30
+const BASELINE_CAPTURE_BUDGET = "5 seconds";
31
32
export class CheckpointRootScopePrepareError extends Schema.TaggedError<CheckpointRootScopePrepareError>()(
33
"CheckpointRootScopePrepareError",
@@ -287,6 +290,7 @@ export const layer: Layer.Layer<
290
checkpointRef,
291
})
292
.pipe(
293
+ Effect.timeout(BASELINE_CAPTURE_BUDGET),
294
Effect.catchTags({
295
VcsUnsupportedOperationError: () => Effect.void,
296
}),