fix(server): reject archiving threads with active turns #23451
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
juliusmarminge added labelsbugfix
juliusmarminge added labelspr:needs-julius
- @@ -2764,3 +2764,15 @@27642764 cause: `Thread ${command.threadId} is already archived.`,27652765 });27662766 }2767+ // Archive detaches the provider session, which would kill a live turn2768+ // mid-flight. Queued and preparing runs have no turn yet and are cancelled2769+ // by the archive below.2770+ if (command.type === "thread.archive") {2771+ const records = yield* projectionStore2772+ .getThreadRecords(command.threadId, ["runs"])2773+ .pipe(mapDispatchError(command));2774+ if (records.runs.some((run) => ["starting", "running", "waiting"].includes(run.status))) {2775+ return yield* new OrchestratorDispatchError({2776+ commandId: command.commandId,2777+ commandType: command.type,2778+ cause: `Thread ${command.threadId} is still running. Stop it before archiving.`,
juliusmarminge reviewed
@@ -2764,3 +2764,15 @@27642764 cause: `Thread ${command.threadId} is already archived.`,27652765 });27662766 }2767+ // Archive detaches the provider session, which would kill a live turn2768+ // mid-flight. Queued and preparing runs have no turn yet and are cancelled2769+ // by the archive below.2770+ if (command.type === "thread.archive") {2771+ const records = yield* projectionStore2772+ .getThreadRecords(command.threadId, ["runs"])2773+ .pipe(mapDispatchError(command));2774+ if (records.runs.some((run) => ["starting", "running", "waiting"].includes(run.status))) {2775+ return yield* new OrchestratorDispatchError({2776+ commandId: command.commandId,2777+ commandType: command.type,2778+ cause: `Thread ${command.threadId} is still running. Stop it before archiving.`,macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
- @@ -3593,3 +3593,15 @@35933593 cause: `Thread ${command.threadId} is already archived.`,35943594 });35953595 }3596+ // Archive detaches the provider session, which would kill a live turn3597+ // mid-flight. Queued and preparing runs have no turn yet and are cancelled3598+ // by the archive below.3599+ if (command.type === "thread.archive") {3600+ const records = yield* projectionStore3601+ .getThreadRecords(command.threadId, ["runs"])3602+ .pipe(mapDispatchError(command));3603+ if (records.runs.some((run) => ["starting", "running", "waiting"].includes(run.status))) {3604+ return yield* new OrchestratorDispatchError({3605+ commandId: command.commandId,3606+ commandType: command.type,3607+ cause: `Thread ${command.threadId} is still running. Stop it before archiving.`,
tanstack-source added labelsbug
Pushed376a576
Sign in to join this conversation.




macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed