Skip to content

Commit a27e32f

Browse files
otaviojuliusmarmingeclaude
authored
fix(server): thread-bound scheduled tasks run on the thread's current provider (pingdotgg#18467)
Co-authored-by: Julius Marminge <[email protected]> Co-authored-by: Claude Fable 5.1 <[email protected]>
1 parent 18f26cf commit a27e32f

2 files changed

Lines changed: 66 additions & 1 deletion

File tree

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

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import * as ServerSettings from "../serverSettings.ts";
5353
import * as ScheduledTasks from "../scheduledTasks/ScheduledTaskService.ts";
5454
import * as SecretRequests from "../secrets/SecretRequests.ts";
5555
import * as TextGeneration from "../textGeneration/TextGeneration.ts";
56+
import { ClaudeProviderCapabilitiesV2 } from "./Adapters/ClaudeAdapterV2.ts";
5657
import { CodexProviderCapabilitiesV2 } from "./Adapters/CodexAdapterV2.ts";
5758
import * as CommandReceiptStore from "./CommandReceiptStore.ts";
5859
import * as EffectOutbox from "./EffectOutbox.ts";
@@ -101,6 +102,18 @@ const adapter = {
101102
openSession: () => Effect.die("provider execution is disabled in launch tests"),
102103
} as ProviderAdapter.ProviderAdapterV2["Service"];
103104

105+
const claudeModelSelection = {
106+
instanceId: ProviderInstanceId.make("claudeAgent"),
107+
model: "claude-opus-5-5",
108+
} as const;
109+
const claudeAdapter = {
110+
instanceId: claudeModelSelection.instanceId,
111+
driver: ProviderDriverKind.make("claudeAgent"),
112+
getCapabilities: () => Effect.succeed(ClaudeProviderCapabilitiesV2),
113+
planSelectionTransition: () => Effect.succeed({ type: "apply_on_next_turn" as const }),
114+
openSession: () => Effect.die("provider execution is disabled in launch tests"),
115+
} as ProviderAdapter.ProviderAdapterV2["Service"];
116+
104117
interface HarnessOptions {
105118
readonly closeTerminal?: TerminalManager.TerminalManager["Service"]["close"];
106119
readonly adapters?: ReadonlyArray<ProviderAdapter.ProviderAdapterV2["Service"]>;
@@ -374,6 +387,57 @@ it.effect.each(
374387
},
375388
);
376389

390+
it.effect("runs a thread-bound automation on the provider the thread uses now", () => {
391+
const harness = makeHarness({ adapters: [adapter, claudeAdapter] });
392+
const layerScheduledTasks = ScheduledTasks.layer.pipe(
393+
Layer.provide(
394+
Layer.mergeAll(
395+
harness.layer,
396+
NodeCrypto.layer,
397+
Scheduler.layer,
398+
Layer.mock(SecretRequests.SecretRequests)({}),
399+
),
400+
),
401+
);
402+
return Effect.gen(function* () {
403+
const tasks = yield* ScheduledTasks.ScheduledTaskService;
404+
const launches = yield* ThreadLaunch.ThreadLaunchService;
405+
const threads = yield* ThreadManagement.ThreadManagementService;
406+
const launched = yield* launches.launch(
407+
launchInput({ command: "command:switched", thread: "thread:switched" }),
408+
);
409+
const { task } = yield* tasks.upsert({
410+
id: ScheduledTaskId.make("scheduled-task:switched"),
411+
title: "Hourly check",
412+
prompt: "Check on the delegated workers.",
413+
enabled: false,
414+
schedule: { type: "interval", everyMs: 3_600_000 },
415+
projectId,
416+
threadId: launched.threadId,
417+
workspaceStrategy: { type: "root" },
418+
modelSelection,
419+
runtimeMode: "full-access",
420+
interactionMode: "default",
421+
createdBy: "agent",
422+
creationSource: "mcp",
423+
});
424+
yield* threads.dispatch({
425+
type: "thread.model-selection.set",
426+
commandId: CommandId.make("command:switch-selection"),
427+
threadId: launched.threadId,
428+
modelSelection: claudeModelSelection,
429+
});
430+
431+
const result = yield* tasks.runNow({ id: task.id });
432+
assert.equal(result.task.lastRunStatus, "succeeded");
433+
const projection = yield* threads.getThreadProjection(launched.threadId);
434+
const message = projection.messages.find((item) => item.scheduledTaskId === task.id);
435+
const run = projection.runs.find((item) => item.id === message?.runId);
436+
assert.deepStrictEqual(run?.modelSelection, claudeModelSelection);
437+
assert.deepStrictEqual(projection.thread.modelSelection, claudeModelSelection);
438+
}).pipe(Effect.provide(Layer.mergeAll(harness.layer, layerScheduledTasks)));
439+
});
440+
377441
it.effect("retains automation and sender attribution while a message waits in the queue", () => {
378442
const harness = makeHarness({ runSetup: () => Effect.never });
379443
return Effect.gen(function* () {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,8 @@ export const layer = Layer.effect(
761761
}),
762762
)
763763
: yield* Effect.exit(
764+
// The stored selection only seeds fresh threads. A bound run
765+
// follows the thread's current provider, so it passes none.
764766
threadManagement.sendToThread({
765767
projectId: active.projectId,
766768
commandId,
@@ -769,7 +771,6 @@ export const layer = Layer.effect(
769771
scheduledTaskId: active.id,
770772
text: prompt,
771773
attachments: [],
772-
modelSelection: active.modelSelection,
773774
mode: "queue",
774775
createdBy: active.createdBy,
775776
creationSource: active.creationSource,

0 commit comments

Comments
 (0)