Skip to content

Commit 972c8a9

Browse files
test(server): one regression case for thread-bound scheduled runs
Co-Authored-By: Claude Fable 5.1 <[email protected]>
1 parent 0bb509d commit 972c8a9

2 files changed

Lines changed: 7 additions & 28 deletions

File tree

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

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,6 @@ const claudeAdapter = {
113113
planSelectionTransition: () => Effect.succeed({ type: "apply_on_next_turn" as const }),
114114
openSession: () => Effect.die("provider execution is disabled in launch tests"),
115115
} as ProviderAdapter.ProviderAdapterV2["Service"];
116-
// A second account of the same provider, configured as its own instance.
117-
const otherCodexModelSelection = {
118-
instanceId: ProviderInstanceId.make("codex_work"),
119-
model: modelSelection.model,
120-
} as const;
121-
const otherCodexAdapter = {
122-
...adapter,
123-
instanceId: otherCodexModelSelection.instanceId,
124-
} as ProviderAdapter.ProviderAdapterV2["Service"];
125116

126117
interface HarnessOptions {
127118
readonly closeTerminal?: TerminalManager.TerminalManager["Service"]["close"];
@@ -396,18 +387,8 @@ it.effect.each(
396387
},
397388
);
398389

399-
it.effect.each([
400-
{ switchedTo: "another provider", selection: claudeModelSelection },
401-
{ switchedTo: "another account of the same provider", selection: otherCodexModelSelection },
402-
])("runs a thread-bound automation on $switchedTo the thread uses now", ({ selection }) => {
403-
const harness = makeHarness({
404-
adapters: [adapter, claudeAdapter, otherCodexAdapter],
405-
serverSettings: {
406-
providerInstances: {
407-
[otherCodexModelSelection.instanceId]: { driver: adapter.driver, config: {} },
408-
},
409-
},
410-
});
390+
it.effect("runs a thread-bound automation on the provider the thread uses now", () => {
391+
const harness = makeHarness({ adapters: [adapter, claudeAdapter] });
411392
const layerScheduledTasks = ScheduledTasks.layer.pipe(
412393
Layer.provide(
413394
Layer.mergeAll(
@@ -425,7 +406,6 @@ it.effect.each([
425406
const launched = yield* launches.launch(
426407
launchInput({ command: "command:switched", thread: "thread:switched" }),
427408
);
428-
// The task is created while the thread is on Codex...
429409
const { task } = yield* tasks.upsert({
430410
id: ScheduledTaskId.make("scheduled-task:switched"),
431411
title: "Hourly check",
@@ -441,21 +421,20 @@ it.effect.each([
441421
createdBy: "agent",
442422
creationSource: "mcp",
443423
});
444-
// ...and the user then switches the thread away from that instance.
445424
yield* threads.dispatch({
446425
type: "thread.model-selection.set",
447426
commandId: CommandId.make("command:switch-selection"),
448427
threadId: launched.threadId,
449-
modelSelection: selection,
428+
modelSelection: claudeModelSelection,
450429
});
451430

452431
const result = yield* tasks.runNow({ id: task.id });
453432
assert.equal(result.task.lastRunStatus, "succeeded");
454433
const projection = yield* threads.getThreadProjection(launched.threadId);
455434
const message = projection.messages.find((item) => item.scheduledTaskId === task.id);
456435
const run = projection.runs.find((item) => item.id === message?.runId);
457-
assert.deepStrictEqual(run?.modelSelection, selection);
458-
assert.deepStrictEqual(projection.thread.modelSelection, selection);
436+
assert.deepStrictEqual(run?.modelSelection, claudeModelSelection);
437+
assert.deepStrictEqual(projection.thread.modelSelection, claudeModelSelection);
459438
}).pipe(Effect.provide(Layer.mergeAll(harness.layer, layerScheduledTasks)));
460439
});
461440

‎apps/server/src/scheduledTasks/ScheduledTaskService.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -761,8 +761,8 @@ export const layer = Layer.effect(
761761
}),
762762
)
763763
: yield* Effect.exit(
764-
// No modelSelection: the run follows the thread's current
765-
// provider and model, not the one the task was created with.
764+
// The stored selection only seeds fresh threads. A bound run
765+
// follows the thread's current provider, so it passes none.
766766
threadManagement.sendToThread({
767767
projectId: active.projectId,
768768
commandId,

0 commit comments

Comments
 (0)