@@ -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 * ( ) {
@@ -1751,8 +1815,38 @@ it.effect.each(["failed", "interrupted"] as const)(
17511815 } ) ;
17521816 assert . equal ( queued . delivery , "queued" ) ;
17531817 const projection = yield * threads . getThreadProjection ( launched . threadId ) ;
1754- assert . equal ( projection . runs . at ( - 1 ) ?. status , "queued" ) ;
1755- assert . equal ( projection . runs . at ( - 1 ) ?. queueHeld , true ) ;
1818+ const held = projection . runs . at ( - 1 ) ! ;
1819+ assert . equal ( held . status , "queued" ) ;
1820+ assert . equal ( held . queueHeld , true ) ;
1821+
1822+ // A message the user starts does not release it: the held message would
1823+ // run after it in the project checkout.
1824+ yield * threads . sendToThread ( {
1825+ projectId,
1826+ commandId : CommandId . make ( `command:launch:late-queued-follow-up-${ ending } :start` ) ,
1827+ threadId : launched . threadId ,
1828+ messageId : MessageId . make ( `message:launch:late-queued-follow-up-${ ending } :start` ) ,
1829+ text : "Sent after setup" ,
1830+ attachments : [ ] ,
1831+ mode : "auto" ,
1832+ createdBy : "user" ,
1833+ creationSource : "web" ,
1834+ } ) ;
1835+ // Nor does the next one, though the run that message started is now the
1836+ // latest and carries no workspace preparation.
1837+ yield * threads . sendToThread ( {
1838+ projectId,
1839+ commandId : CommandId . make ( `command:launch:late-queued-follow-up-${ ending } :again` ) ,
1840+ threadId : launched . threadId ,
1841+ messageId : MessageId . make ( `message:launch:late-queued-follow-up-${ ending } :again` ) ,
1842+ text : "Sent after that" ,
1843+ attachments : [ ] ,
1844+ mode : "auto" ,
1845+ createdBy : "user" ,
1846+ creationSource : "web" ,
1847+ } ) ;
1848+ const after = yield * threads . getThreadProjection ( launched . threadId ) ;
1849+ assert . isTrue ( after . runs . find ( ( run ) => run . id === held . id ) ?. queueHeld ) ;
17561850 } ) . pipe ( Effect . provide ( harness . layer ) ) ;
17571851 } ,
17581852) ;
0 commit comments