@@ -13,6 +13,7 @@ import {
1313 OrchestratorMcpTarget ,
1414 type OrchestrationV2ThreadShell ,
1515 type ScheduledTask ,
16+ type ScheduledTaskUpsertInput ,
1617 ScheduledTaskId ,
1718 ProjectId ,
1819 ProviderDriverKind ,
@@ -2989,6 +2990,7 @@ describe("OrchestratorMcpService provider resolution", () => {
29892990 instanceId : codexInstanceId ,
29902991 driver : ProviderDriverKind . make ( "codex" ) ,
29912992 } ) ,
2993+ supportedRuntimeModes : [ "approval-required" , "auto-accept-edits" ] ,
29922994 models : [ "gpt-5" , "gpt-5-mini" ] . map ( ( slug ) => ( {
29932995 slug,
29942996 name : slug ,
@@ -3022,9 +3024,10 @@ describe("OrchestratorMcpService provider resolution", () => {
30223024 threadId : ThreadId . make ( "thread:scheduled-model-bound" ) ,
30233025 } ;
30243026 const service = (
3025- saved : Ref . Ref < ReadonlyArray < ScheduledTask [ "modelSelection" ] > > ,
3027+ saved : Ref . Ref < ReadonlyArray < ScheduledTaskUpsertInput > > ,
30263028 stored : ScheduledTask = existing ,
30273029 enabledForProject = true ,
3030+ defaultModelSelection : ScheduledTask [ "modelSelection" ] | null = existing . modelSelection ,
30283031 ) =>
30293032 OrchestratorMcpService . layer . pipe (
30303033 Layer . provide ( Layer . mock ( ThreadLaunchService . ThreadLaunchService ) ( { } ) ) ,
@@ -3051,15 +3054,15 @@ describe("OrchestratorMcpService provider resolution", () => {
30513054 Effect . succeedSome ( {
30523055 id : projectId ,
30533056 workspaceRoot : "/repo/scheduled-model" ,
3054- defaultModelSelection : existing . modelSelection ,
3057+ defaultModelSelection,
30553058 } as never ) ,
30563059 } ) ,
30573060 Layer . mock ( SecretRequests . SecretRequests ) ( { } ) ,
30583061 Layer . mock ( RemoteDelegation . RemoteDelegation ) ( { } ) ,
30593062 Layer . mock ( ScheduledTaskService . ScheduledTaskService ) ( {
30603063 list : ( ) => Effect . succeed ( { tasks : [ stored ] } ) ,
30613064 upsert : ( input ) =>
3062- Ref . update ( saved , ( selections ) => [ ...selections , input . modelSelection ] ) . pipe (
3065+ Ref . update ( saved , ( inputs ) => [ ...inputs , input ] ) . pipe (
30633066 Effect . as ( {
30643067 task : {
30653068 ...stored ,
@@ -3072,18 +3075,27 @@ describe("OrchestratorMcpService provider resolution", () => {
30723075 ) ,
30733076 ) ,
30743077 ) ;
3075- const savedSelections = < E > (
3078+ const savedInputs = < E > (
30763079 run : ( mcp : OrchestratorMcpService . OrchestratorMcpServiceShape ) => Effect . Effect < unknown , E > ,
30773080 stored : ScheduledTask = existing ,
3081+ defaultModelSelection ?: ScheduledTask [ "modelSelection" ] | null ,
30783082 ) =>
30793083 Effect . gen ( function * ( ) {
3080- const saved = yield * Ref . make < ReadonlyArray < ScheduledTask [ "modelSelection" ] > > ( [ ] ) ;
3084+ const saved = yield * Ref . make < ReadonlyArray < ScheduledTaskUpsertInput > > ( [ ] ) ;
30813085 const mcp = yield * OrchestratorMcpService . OrchestratorMcpService . pipe (
3082- Effect . provide ( service ( saved , stored ) ) ,
3086+ Effect . provide ( service ( saved , stored , true , defaultModelSelection ) ) ,
30833087 ) ;
30843088 yield * run ( mcp ) ;
30853089 return yield * Ref . get ( saved ) ;
30863090 } ) ;
3091+ const savedSelections = < E > (
3092+ run : ( mcp : OrchestratorMcpService . OrchestratorMcpServiceShape ) => Effect . Effect < unknown , E > ,
3093+ stored : ScheduledTask = existing ,
3094+ defaultModelSelection ?: ScheduledTask [ "modelSelection" ] | null ,
3095+ ) =>
3096+ savedInputs ( run , stored , defaultModelSelection ) . pipe (
3097+ Effect . map ( ( inputs ) => inputs . map ( ( input ) => input . modelSelection ) ) ,
3098+ ) ;
30873099
30883100 it . effect ( "saves a new task with the target's model and options" , ( ) =>
30893101 Effect . gen ( function * ( ) {
@@ -3109,6 +3121,52 @@ describe("OrchestratorMcpService provider resolution", () => {
31093121 } ) ,
31103122 ) ;
31113123
3124+ it . effect ( "takes a complete target when the project has no default model" , ( ) =>
3125+ Effect . gen ( function * ( ) {
3126+ const saved = yield * savedSelections (
3127+ ( mcp ) =>
3128+ mcp . scheduleTask ( client , {
3129+ projectId,
3130+ prompt : "Check the build" ,
3131+ schedule : { type : "interval" , everyMs : 3_600_000 } ,
3132+ target : { providerInstanceId : codexInstanceId , model : "gpt-5-mini" } ,
3133+ } ) ,
3134+ existing ,
3135+ null ,
3136+ ) ;
3137+ assert . deepEqual ( saved , [ { instanceId : codexInstanceId , model : "gpt-5-mini" } ] ) ;
3138+ } ) ,
3139+ ) ;
3140+
3141+ it . effect ( "steps the runtime mode down to one the target's provider offers" , ( ) =>
3142+ Effect . gen ( function * ( ) {
3143+ const fullAccess : McpInvocationScope = {
3144+ ...client ,
3145+ client : { sessionId : "scheduled-model" , label : "Claude Code" , access : "full-access" } ,
3146+ } ;
3147+ const stored : ScheduledTask = { ...existing , runtimeMode : "full-access" } ;
3148+ const target = { providerInstanceId : codexInstanceId } ;
3149+ const saved = yield * savedInputs (
3150+ ( mcp ) =>
3151+ Effect . all ( [
3152+ mcp . scheduleTask ( fullAccess , {
3153+ projectId,
3154+ prompt : "Check the build" ,
3155+ schedule : { type : "interval" , everyMs : 3_600_000 } ,
3156+ target,
3157+ } ) ,
3158+ mcp . updateScheduledTask ( fullAccess , { scheduledTaskId : stored . id , target } ) ,
3159+ mcp . updateScheduledTask ( fullAccess , { scheduledTaskId : stored . id , prompt : "Again" } ) ,
3160+ ] ) ,
3161+ stored ,
3162+ ) ;
3163+ assert . deepEqual (
3164+ saved . map ( ( input ) => input . runtimeMode ) ,
3165+ [ "auto-accept-edits" , "auto-accept-edits" , "full-access" ] ,
3166+ ) ;
3167+ } ) ,
3168+ ) ;
3169+
31123170 it . effect ( "merges an update's options into the stored selection" , ( ) =>
31133171 Effect . gen ( function * ( ) {
31143172 const saved = yield * savedSelections ( ( mcp ) =>
@@ -3141,7 +3199,7 @@ describe("OrchestratorMcpService provider resolution", () => {
31413199
31423200 it . effect ( "reports the saved model and options" , ( ) =>
31433201 Effect . gen ( function * ( ) {
3144- const saved = yield * Ref . make < ReadonlyArray < ScheduledTask [ "modelSelection" ] > > ( [ ] ) ;
3202+ const saved = yield * Ref . make < ReadonlyArray < ScheduledTaskUpsertInput > > ( [ ] ) ;
31453203 const mcp = yield * OrchestratorMcpService . OrchestratorMcpService . pipe (
31463204 Effect . provide ( service ( saved ) ) ,
31473205 ) ;
@@ -3156,7 +3214,7 @@ describe("OrchestratorMcpService provider resolution", () => {
31563214
31573215 it . effect ( "refuses a target for a bound task, whose runs use the thread's model" , ( ) =>
31583216 Effect . gen ( function * ( ) {
3159- const saved = yield * Ref . make < ReadonlyArray < ScheduledTask [ "modelSelection" ] > > ( [ ] ) ;
3217+ const saved = yield * Ref . make < ReadonlyArray < ScheduledTaskUpsertInput > > ( [ ] ) ;
31603218 const mcp = yield * OrchestratorMcpService . OrchestratorMcpService . pipe (
31613219 Effect . provide ( service ( saved , bound ) ) ,
31623220 ) ;
@@ -3190,7 +3248,7 @@ describe("OrchestratorMcpService provider resolution", () => {
31903248
31913249 it . effect ( "refuses a provider the project has disabled, which every run would fail on" , ( ) =>
31923250 Effect . gen ( function * ( ) {
3193- const saved = yield * Ref . make < ReadonlyArray < ScheduledTask [ "modelSelection" ] > > ( [ ] ) ;
3251+ const saved = yield * Ref . make < ReadonlyArray < ScheduledTaskUpsertInput > > ( [ ] ) ;
31943252 const mcp = yield * OrchestratorMcpService . OrchestratorMcpService . pipe (
31953253 Effect . provide ( service ( saved , existing , false ) ) ,
31963254 ) ;
@@ -3214,7 +3272,7 @@ describe("OrchestratorMcpService provider resolution", () => {
32143272 } ,
32153273 ] as const ) ( "refuses $name and saves nothing" , ( { target, code } ) =>
32163274 Effect . gen ( function * ( ) {
3217- const saved = yield * Ref . make < ReadonlyArray < ScheduledTask [ "modelSelection" ] > > ( [ ] ) ;
3275+ const saved = yield * Ref . make < ReadonlyArray < ScheduledTaskUpsertInput > > ( [ ] ) ;
32183276 const mcp = yield * OrchestratorMcpService . OrchestratorMcpService . pipe (
32193277 Effect . provide ( service ( saved ) ) ,
32203278 ) ;
0 commit comments