Skip to content

Commit c085a0a

Browse files
fix(server): a slow baseline checkpoint no longer holds every prompt for 30 seconds (pingdotgg#34849)
1 parent 9f1e97d commit c085a0a

2 files changed

Lines changed: 81 additions & 0 deletions

File tree

‎apps/server/src/orchestration-v2/CheckpointService.test.ts‎

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ import {
1212
VcsUnsupportedOperationError,
1313
} from "@t3tools/contracts";
1414
import * as DateTime from "effect/DateTime";
15+
import * as Deferred from "effect/Deferred";
1516
import * as Effect from "effect/Effect";
17+
import * as Fiber from "effect/Fiber";
1618
import * as Layer from "effect/Layer";
19+
import * as Ref from "effect/Ref";
20+
import * as TestClock from "effect/testing/TestClock";
1721

1822
import * as CheckpointStore from "../checkpointing/CheckpointStore.ts";
1923
import * as CheckpointService from "./CheckpointService.ts";
@@ -98,6 +102,79 @@ it.effect(
98102
}),
99103
);
100104

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+
101178
it.effect("records a repository probe failure as an error checkpoint, not a missing one", () =>
102179
Effect.gen(function* () {
103180
const scope: OrchestrationV2CheckpointScope = {

‎apps/server/src/orchestration-v2/CheckpointService.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
2525

2626
const CHECKPOINT_REFS_PREFIX = "refs/t3/orchestration-v2/checkpoints";
2727
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";
2831

2932
export class CheckpointRootScopePrepareError extends Schema.TaggedError<CheckpointRootScopePrepareError>()(
3033
"CheckpointRootScopePrepareError",
@@ -287,6 +290,7 @@ export const layer: Layer.Layer<
287290
checkpointRef,
288291
})
289292
.pipe(
293+
Effect.timeout(BASELINE_CAPTURE_BUDGET),
290294
Effect.catchTags({
291295
VcsUnsupportedOperationError: () => Effect.void,
292296
}),

0 commit comments

Comments
 (0)