Skip to content

Commit 1b564bc

Browse files
committed
fix(server): reject model changes in archived threads
1 parent 3140dcd commit 1b564bc

4 files changed

Lines changed: 45 additions & 7 deletions

File tree

‎apps/server/src/mcp/toolkits/core.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,12 @@ it("bounds public command rejections and redacts internal dispatch causes", () =
263263
});
264264

265265
it.effect.each([
266+
{
267+
name: "reports an archived thread",
268+
error: new ThreadManagement.ThreadManagementThreadArchivedError({ threadId }),
269+
code: "thread_not_sendable",
270+
message: `Thread ${threadId} is archived and cannot receive messages.`,
271+
},
266272
{
267273
name: "reports a disabled provider instance",
268274
error: new ThreadManagement.ThreadManagementProviderInstanceDisabledError({

‎apps/server/src/mcp/toolkits/thread/handlers.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ export const layer = McpToolAccess.toLayer(ThreadToolkit, {
199199
.pipe(
200200
Effect.mapError((error) => {
201201
switch (error._tag) {
202+
case "ThreadManagementThreadArchivedError":
202203
case "ThreadManagementNoSteerableRunError":
203204
return new OrchestratorMcpFailure({
204205
code: "thread_not_sendable",

‎apps/server/src/orchestration-v2/SelectionRestart.integration.test.ts‎

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ it.live.each([
401401
"unsupported",
402402
"preparing",
403403
"disabled",
404+
"archived",
404405
] as const)("configures the calling thread without losing work: %s", (scenario) =>
405406
Effect.scoped(
406407
Effect.gen(function* () {
@@ -526,8 +527,26 @@ it.live.each([
526527
});
527528
yield* worker.drain();
528529
}
530+
if (scenario === "archived") {
531+
yield* orchestrator.dispatch({
532+
type: "thread.archive",
533+
commandId: CommandId.make(`${name}:archive`),
534+
threadId,
535+
});
536+
}
529537
const before = yield* orchestrator.getThreadProjection(threadId);
530538
const sequence = yield* orchestrator.getThreadEventSequence(threadId);
539+
if (scenario === "archived") {
540+
assert.isNotNull(before.thread.archivedAt);
541+
const run = before.runs[0]!;
542+
assert.equal(run.status, "running");
543+
assert.isTrue(
544+
before.providerTurns.some(
545+
(turn) => turn.runAttemptId === run.activeAttemptId && turn.status === "running",
546+
),
547+
);
548+
assert.lengthOf(starts, 1);
549+
}
531550
const configure = threads.configureModelSelection({
532551
projectId,
533552
threadId,
@@ -536,15 +555,22 @@ it.live.each([
536555
createdBy: "agent",
537556
creationSource: "mcp",
538557
});
539-
if (scenario === "unsupported" || scenario === "preparing" || scenario === "disabled") {
558+
if (
559+
scenario === "unsupported" ||
560+
scenario === "preparing" ||
561+
scenario === "disabled" ||
562+
scenario === "archived"
563+
) {
540564
const error = yield* Effect.flip(configure);
541565
assert.equal(
542566
error._tag,
543-
scenario === "disabled"
544-
? "ThreadManagementProviderInstanceDisabledError"
545-
: scenario === "preparing"
546-
? "ThreadManagementNoSteerableRunError"
547-
: "OrchestratorDispatchError",
567+
scenario === "archived"
568+
? "ThreadManagementThreadArchivedError"
569+
: scenario === "disabled"
570+
? "ThreadManagementProviderInstanceDisabledError"
571+
: scenario === "preparing"
572+
? "ThreadManagementNoSteerableRunError"
573+
: "OrchestratorDispatchError",
548574
);
549575
if (scenario === "disabled") {
550576
assert.deepEqual(before.runs[0]?.modelSelection, selection);
@@ -617,7 +643,7 @@ it.live.each([
617643
CommandReceiptStore.layer.pipe(Layer.provide(layerDatabase)),
618644
ProviderReplayHarness.layerWithRegistry({ name }, registry, {
619645
databaseLayer: layerDatabase,
620-
runEffectWorker: scenario !== "preparing",
646+
runEffectWorker: scenario !== "preparing" && scenario !== "archived",
621647
}),
622648
),
623649
),

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,11 @@ const make = Effect.gen(function* () {
743743
"orchestrationV2.threadManagement.configureModelSelection",
744744
)(function* (input: Parameters<ThreadManagementServiceShape["configureModelSelection"]>[0]) {
745745
const target = yield* getProjectThreadRecords(input, ["runs", "providerTurns"]);
746+
if (target.thread.archivedAt !== null) {
747+
return yield* new ThreadManagementThreadArchivedError({
748+
threadId: input.threadId,
749+
});
750+
}
746751
const activeRun = latestActiveRun(target);
747752
if (
748753
modelSelectionsEqual(

0 commit comments

Comments
 (0)