Skip to content

Commit d3d11c2

Browse files
committed
fix(server): a limit reset read before a later recovery choice is refused
1 parent 7b838d7 commit d3d11c2

3 files changed

Lines changed: 18 additions & 2 deletions

File tree

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4791,6 +4791,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
47914791
if (
47924792
recovery?.runId !== command.runId ||
47934793
recovery.resetAt !== command.resetAt ||
4794+
recovery.requestId !== command.requestId ||
47944795
recovery.resetEarly === true ||
47954796
!(recovery.autoResume || recovery.snooze) ||
47964797
Date.parse(recovery.resetAt) <= DateTime.toEpochMillis(now) ||
@@ -14719,13 +14720,14 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
1471914720
const reset = DateTime.toEpochMillis(input.failedBefore);
1472014721
yield* Effect.forEach(
1472114722
waiting,
14722-
({ threadId, limitRecovery: { runId, resetAt } }) =>
14723+
({ threadId, limitRecovery: { runId, resetAt, requestId } }) =>
1472314724
dispatchWithReceipt({
1472414725
type: "thread.limit-recovery.reset",
1472514726
commandId: CommandId.make(`limit-reset:${threadId}:${runId}:${reset}`),
1472614727
threadId,
1472714728
runId,
1472814729
resetAt,
14730+
...(requestId === undefined ? {} : { requestId }),
1472914731
}).pipe(
1473014732
// A thread that moved on since the read is refused and keeps its own schedule.
1473114733
Effect.catchCause((cause) =>

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9000,14 +9000,26 @@ it.layer(layerTest)("usage-limit recovery", (it) => {
90009000
failedBefore: now,
90019001
resetBefore: DateTime.makeUnsafe(resetAt),
90029002
});
9003-
// So does a reset of a limit this thread does not wait on.
9003+
// So does a reset of a limit this thread does not wait on, or one read before a later
9004+
// recovery choice.
90049005
yield* orchestrator
90059006
.dispatch({
90069007
type: "thread.limit-recovery.reset",
90079008
commandId: CommandId.make(`recovery:other-limit:${scenario}`),
90089009
threadId,
90099010
runId: run.id,
90109011
resetAt: DateTime.formatIso(DateTime.add(DateTime.makeUnsafe(resetAt), { hours: 1 })),
9012+
requestId: armCommand.commandId,
9013+
})
9014+
.pipe(Effect.flip);
9015+
yield* orchestrator
9016+
.dispatch({
9017+
type: "thread.limit-recovery.reset",
9018+
commandId: CommandId.make(`recovery:stale-choice:${scenario}`),
9019+
threadId,
9020+
runId: run.id,
9021+
resetAt,
9022+
requestId: CommandId.make(`recovery:earlier-choice:${scenario}`),
90119023
})
90129024
.pipe(Effect.flip);
90139025
assert.deepEqual(

‎packages/contracts/src/orchestrationV2.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3450,6 +3450,8 @@ const OrchestrationV2InternalCommand = Schema.Union([
34503450
threadId: ThreadId,
34513451
runId: RunId,
34523452
resetAt: IsoDateTime,
3453+
/** The recovery choice the reset was read from; a later choice refuses it. */
3454+
requestId: Schema.optional(CommandId),
34533455
}),
34543456
/** Moves a thread to a project rooted at the folder it already works in, so its cwd never changes. */
34553457
Schema.Struct({

0 commit comments

Comments
 (0)