Skip to content

Commit cb2cd39

Browse files
test(server): drop the lock-timing #29898 test, keep the grace test
AI-assisted; verified with the tests and tools listed above.
1 parent 8aced92 commit cb2cd39

1 file changed

Lines changed: 0 additions & 93 deletions

File tree

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

Lines changed: 0 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -3291,100 +3291,7 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
32913291
return { threadId, activeRun, wakeRun };
32923292
});
32933293

3294-
// Completes `run`, then dispatches automatic settlement while the completion reaction waits
3295-
// before releasing and starting the queue: the window the settlement sweep races.
3296-
const autoSettleBeforeCompletionReaction = (run: OrchestrationV2Run, commandId: CommandId) =>
3297-
Effect.gen(function* () {
3298-
const orchestrator = yield* Orchestrator.OrchestratorV2;
3299-
const eventSink = yield* EventSink.EventSinkV2;
3300-
const executor = yield* ThreadCommandExecutor.ThreadCommandExecutor;
3301-
const threadId = run.threadId;
3302-
const reactionReached = yield* Deferred.make<void>();
3303-
const releaseReaction = yield* Deferred.make<void>();
3304-
const promotionDone = yield* Deferred.make<void>();
3305-
const withLock = executor.withLock;
3306-
let reactionFiber: number | undefined;
3307-
// Relies on the reaction taking the thread lock twice: finalizeDelegatedCompletionDelivery,
3308-
// then releaseUnattendedHolds with startNextQueuedRun.
3309-
const holdReaction: ThreadCommandExecutor.ThreadCommandExecutor["Service"]["withLock"] = (
3310-
lockKey,
3311-
effect,
3312-
) =>
3313-
Effect.flatMap(Effect.fiberId, (fiber) => {
3314-
if (lockKey !== threadId) return withLock(lockKey, effect);
3315-
if (reactionFiber === undefined) {
3316-
reactionFiber = fiber;
3317-
return Deferred.succeed(reactionReached, undefined).pipe(
3318-
Effect.andThen(Deferred.await(releaseReaction)),
3319-
Effect.andThen(withLock(lockKey, effect)),
3320-
);
3321-
}
3322-
return fiber === reactionFiber
3323-
? withLock(lockKey, effect).pipe(
3324-
Effect.ensuring(Deferred.succeed(promotionDone, undefined)),
3325-
)
3326-
: withLock(lockKey, effect);
3327-
});
3328-
const lockSpy = vi.spyOn(executor, "withLock").mockImplementation(holdReaction);
3329-
return yield* Effect.gen(function* () {
3330-
const completedAt = yield* DateTime.now;
3331-
yield* eventSink.write({
3332-
events: [
3333-
{
3334-
id: EventId.make(`${run.id}:completed`),
3335-
type: "run.updated",
3336-
threadId,
3337-
runId: run.id,
3338-
...(run.rootNodeId === null ? {} : { nodeId: run.rootNodeId }),
3339-
providerInstanceId: run.providerInstanceId,
3340-
occurredAt: completedAt,
3341-
payload: { ...run, status: "completed", completedAt },
3342-
},
3343-
],
3344-
});
3345-
yield* Deferred.await(reactionReached);
3346-
3347-
const window = yield* orchestrator.getThreadProjection(threadId);
3348-
yield* orchestrator
3349-
.dispatch({
3350-
type: "thread.auto-settle",
3351-
commandId,
3352-
threadId,
3353-
snapshotAt: window.thread.updatedAt,
3354-
})
3355-
.pipe(Effect.exit);
3356-
const afterSettle = yield* orchestrator.getThreadProjection(threadId);
3357-
3358-
yield* Deferred.succeed(releaseReaction, undefined);
3359-
yield* Deferred.await(promotionDone);
3360-
return { window, afterSettle, after: yield* orchestrator.getThreadProjection(threadId) };
3361-
}).pipe(
3362-
Effect.ensuring(
3363-
Effect.sync(() => lockSpy.mockRestore()).pipe(
3364-
// The held reaction runs on the shared run-update stream; later tests need it back.
3365-
Effect.andThen(Deferred.succeed(releaseReaction, undefined)),
3366-
),
3367-
),
3368-
);
3369-
});
3370-
33713294
// regression: #29898 settle on merge cancelled a watch wake queued behind the finished run
3372-
it.effect("automatic settlement leaves a queued pull request watch wake to run", () =>
3373-
Effect.gen(function* () {
3374-
const { activeRun, wakeRun } = yield* queuedWatchWake("pr-watch-queued-wake");
3375-
const { window, afterSettle, after } = yield* autoSettleBeforeCompletionReaction(
3376-
activeRun,
3377-
CommandId.make("pr-watch-queued-wake-auto-settle"),
3378-
);
3379-
assert.equal(window.runs.find((run) => run.id === wakeRun.id)?.status, "queued");
3380-
assert.isNull(
3381-
afterSettle.thread.settledAt,
3382-
"automatic settlement must wait for the queued pull request watch wake",
3383-
);
3384-
assert.equal(after.runs.find((run) => run.id === wakeRun.id)?.status, "starting");
3385-
}),
3386-
);
3387-
33883295
it.effect("automatic settlement refuses a held wake only within the queued-turn grace", () =>
33893296
Effect.gen(function* () {
33903297
const orchestrator = yield* Orchestrator.OrchestratorV2;

0 commit comments

Comments
 (0)