The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 23, 01:45 UTC
fix(server): thread-bound scheduled tasks run on the thread's current provider (#18467)
Co-authored-by: Julius Marminge <julius0216@outlook.com> Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Otavio Salvador committed
Oct 19, 2026 at 02:58 UTC
a27e32fba7a7a8368a6a106c691ec0cc6af147d4
2 files changed
+66
-1
apps/server/src/orchestration-v2/ThreadLaunchService.test.ts
+64
@@ -53,6 +53,7 @@ import * as ServerSettings from "../serverSettings.ts";
53
import * as ScheduledTasks from "../scheduledTasks/ScheduledTaskService.ts";
54
import * as SecretRequests from "../secrets/SecretRequests.ts";
55
import * as TextGeneration from "../textGeneration/TextGeneration.ts";
56
+import { ClaudeProviderCapabilitiesV2 } from "./Adapters/ClaudeAdapterV2.ts";
57
import { CodexProviderCapabilitiesV2 } from "./Adapters/CodexAdapterV2.ts";
58
import * as CommandReceiptStore from "./CommandReceiptStore.ts";
59
import * as EffectOutbox from "./EffectOutbox.ts";
@@ -101,6 +102,18 @@ const adapter = {
102
openSession: () => Effect.die("provider execution is disabled in launch tests"),
103
} as ProviderAdapter.ProviderAdapterV2["Service"];
104
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
+
117
interface HarnessOptions {
118
readonly closeTerminal?: TerminalManager.TerminalManager["Service"]["close"];
119
readonly adapters?: ReadonlyArray<ProviderAdapter.ProviderAdapterV2["Service"]>;
@@ -374,6 +387,57 @@ it.effect.each(
387
},
388
);
389
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
+
441
it.effect("retains automation and sender attribution while a message waits in the queue", () => {
442
const harness = makeHarness({ runSetup: () => Effect.never });
443
return Effect.gen(function* () {
apps/server/src/scheduledTasks/ScheduledTaskService.ts
+2
-1
@@ -761,6 +761,8 @@ export const layer = Layer.effect(
761
}),
762
)
763
: 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.
766
threadManagement.sendToThread({
767
projectId: active.projectId,
768
commandId,
@@ -769,7 +771,6 @@ export const layer = Layer.effect(
771
scheduledTaskId: active.id,
772
text: prompt,
773
attachments: [],
772
- modelSelection: active.modelSelection,
774
mode: "queue",
775
createdBy: active.createdBy,
776
creationSource: active.creationSource,