@@ -53,6 +53,7 @@ import * as ServerSettings from "../serverSettings.ts";
5353import * as ScheduledTasks from "../scheduledTasks/ScheduledTaskService.ts" ;
5454import * as SecretRequests from "../secrets/SecretRequests.ts" ;
5555import * as TextGeneration from "../textGeneration/TextGeneration.ts" ;
56+ import { ClaudeProviderCapabilitiesV2 } from "./Adapters/ClaudeAdapterV2.ts" ;
5657import { CodexProviderCapabilitiesV2 } from "./Adapters/CodexAdapterV2.ts" ;
5758import * as CommandReceiptStore from "./CommandReceiptStore.ts" ;
5859import * 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+
104117interface 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+
377441it . 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 * ( ) {
0 commit comments