Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): settle on merge no longer cancels a wake queued behind a finished turn #29934

Mergedjuliusmarmingemerged 12 commits intomain fromrefs/pull/29934/headmerged by juliusmarminge View on GitHub

Showing 3 changed files with 132 additions and 2 deletions.

x
0 of 3 viewed, 3 left
18 additions and 0 deletionsapps/server/src/orchestration-v2/Orchestrator.tsModified
View file
@@ -785,6 +785,8 @@
​
const WORKSPACE_PREPARATION_INPUT = "Preparing workspace";
+/** How long automatic settlement waits for a queued turn to start. */
+export const QUEUED_TURN_START_GRACE_MS = 2 * 60 * 1_000;
const RUNTIME_REQUEST_DELIVERY_FAILED_MESSAGE =
"T3 Code could not confirm that your answer reached the agent. If the run stays stuck, stop it and try again.";
​
@@ -16009,6 +16011,22 @@
cause: `Thread ${command.threadId} changed before automatic settlement.`,
+ // The completion reaction starts or holds the queue just after a run ends; settling
+ // first would cancel an automatic wake it was about to start.
+ const { runs } = yield* loadProjectionForCommand(command, ["runs"]);
+ const endedAt = latestExecutedRun(runs)?.completedAt;
+ if (
+ endedAt != null &&
+ runs.some((run) => run.status === "queued") &&
+ Math.abs(DateTime.toEpochMillis(yield* DateTime.now) - DateTime.toEpochMillis(endedAt)) <
+ QUEUED_TURN_START_GRACE_MS
+ ) {
+ return yield* new OrchestratorDispatchError({
+ commandId: command.commandId,
+ commandType: command.type,
+ cause: `Thread ${command.threadId} has a queued run that may still start.`,
+ });