@@ -1884,6 +1884,188 @@ describe("orchestration v2 provider switching", () => {
18841884 ) ,
18851885 ) ;
18861886
1887+ it . live ( "queues an unpicked follow-up on the newest queued pick" , ( ) =>
1888+ Effect . scoped (
1889+ Effect . gen ( function * ( ) {
1890+ const cwd = yield * checkpointWorkspace ( "queued-unpicked-follow-up" ) ;
1891+ const capturedTurns = yield * Ref . make < ReadonlyArray < CapturedTurn > > ( [ ] ) ;
1892+ const started = yield * Deferred . make < void > ( ) ;
1893+ const threadId = ThreadId . make ( "thread:queued-unpicked-follow-up" ) ;
1894+ const layerRegistry = ProviderAdapterRegistry . layerFromAdapters ( [
1895+ makeTestAdapter ( {
1896+ instanceId : CODEX_MODEL_SELECTION . instanceId ,
1897+ driver : CODEX_DRIVER ,
1898+ capabilities : CodexProviderCapabilitiesV2 ,
1899+ modelSelection : CODEX_MODEL_SELECTION ,
1900+ responseByRunOrdinal : { } ,
1901+ capturedTurns,
1902+ holdFirstTurn : started ,
1903+ } ) ,
1904+ makeTestAdapter ( {
1905+ instanceId : CLAUDE_MODEL_SELECTION . instanceId ,
1906+ driver : CLAUDE_DRIVER ,
1907+ capabilities : ClaudeProviderCapabilitiesV2 ,
1908+ modelSelection : CLAUDE_MODEL_SELECTION ,
1909+ responseByRunOrdinal : { } ,
1910+ capturedTurns,
1911+ } ) ,
1912+ ] ) ;
1913+ yield * Effect . gen ( function * ( ) {
1914+ const orchestrator = yield * Orchestrator . OrchestratorV2 ;
1915+ const worker = yield * EffectWorker . OrchestrationEffectWorkerV2 ;
1916+ yield * orchestrator . dispatch ( {
1917+ type : "thread.create" ,
1918+ createdBy : "user" ,
1919+ creationSource : "web" ,
1920+ commandId : CommandId . make ( "command:queued-unpicked-follow-up:create" ) ,
1921+ threadId,
1922+ projectId : ProjectId . make ( "project:queued-unpicked-follow-up" ) ,
1923+ title : "Queued unpicked follow-up" ,
1924+ modelSelection : CODEX_MODEL_SELECTION ,
1925+ runtimeMode : "full-access" ,
1926+ interactionMode : "default" ,
1927+ branch : null ,
1928+ worktreePath : cwd ,
1929+ } ) ;
1930+ yield * orchestrator . dispatch ( {
1931+ type : "message.dispatch" ,
1932+ createdBy : "user" ,
1933+ creationSource : "web" ,
1934+ commandId : CommandId . make ( "command:queued-unpicked-follow-up:first" ) ,
1935+ threadId,
1936+ messageId : MessageId . make ( "message:queued-unpicked-follow-up:first" ) ,
1937+ text : "Current Codex turn" ,
1938+ attachments : [ ] ,
1939+ modelSelection : CODEX_MODEL_SELECTION ,
1940+ dispatchMode : { type : "start_immediately" } ,
1941+ } ) ;
1942+ yield * Deferred . await ( started ) ;
1943+ yield * worker . drain ( ) ;
1944+ yield * orchestrator . dispatch ( {
1945+ type : "message.dispatch" ,
1946+ createdBy : "user" ,
1947+ creationSource : "mobile" ,
1948+ commandId : CommandId . make ( "command:queued-unpicked-follow-up:pick" ) ,
1949+ threadId,
1950+ messageId : MessageId . make ( "message:queued-unpicked-follow-up:pick" ) ,
1951+ text : "Picked Claude" ,
1952+ attachments : [ ] ,
1953+ modelSelection : CLAUDE_MODEL_SELECTION ,
1954+ dispatchMode : { type : "queue_after_active" } ,
1955+ } ) ;
1956+ yield * orchestrator . dispatch ( {
1957+ type : "message.dispatch" ,
1958+ createdBy : "user" ,
1959+ creationSource : "mobile" ,
1960+ commandId : CommandId . make ( "command:queued-unpicked-follow-up:follow-up" ) ,
1961+ threadId,
1962+ messageId : MessageId . make ( "message:queued-unpicked-follow-up:follow-up" ) ,
1963+ text : "Follow-up without a pick" ,
1964+ attachments : [ ] ,
1965+ dispatchMode : { type : "queue_after_active" } ,
1966+ } ) ;
1967+ const projection = yield * orchestrator . getThreadProjection ( threadId ) ;
1968+ assert . deepEqual (
1969+ projection . runs . map ( ( run ) => [ run . status , run . modelSelection . instanceId ] ) ,
1970+ [
1971+ [ "running" , CODEX_MODEL_SELECTION . instanceId ] ,
1972+ [ "queued" , CLAUDE_MODEL_SELECTION . instanceId ] ,
1973+ [ "queued" , CLAUDE_MODEL_SELECTION . instanceId ] ,
1974+ ] ,
1975+ ) ;
1976+ yield * orchestrator . dispatch ( {
1977+ type : "message.dispatch" ,
1978+ createdBy : "agent" ,
1979+ creationSource : "server" ,
1980+ commandId : CommandId . make ( "command:queued-unpicked-follow-up:monitor" ) ,
1981+ threadId,
1982+ messageId : MessageId . make ( "message:queued-unpicked-follow-up:monitor" ) ,
1983+ text : "Monitor update" ,
1984+ attachments : [ ] ,
1985+ dispatchMode : { type : "queue_after_active" } ,
1986+ notification : { source : { kind : "monitor" } , outcome : "updated" , summary : "Update" } ,
1987+ } ) ;
1988+ yield * orchestrator . dispatch ( {
1989+ type : "message.dispatch" ,
1990+ createdBy : "user" ,
1991+ creationSource : "mobile" ,
1992+ commandId : CommandId . make ( "command:queued-unpicked-follow-up:after-monitor" ) ,
1993+ threadId,
1994+ messageId : MessageId . make ( "message:queued-unpicked-follow-up:after-monitor" ) ,
1995+ text : "Follow-up after a monitor update" ,
1996+ attachments : [ ] ,
1997+ dispatchMode : { type : "queue_after_active" } ,
1998+ } ) ;
1999+ const afterMonitor = yield * orchestrator . getThreadProjection ( threadId ) ;
2000+ assert . equal (
2001+ afterMonitor . runs . find (
2002+ ( run ) => run . userMessageId === "message:queued-unpicked-follow-up:after-monitor" ,
2003+ ) ?. modelSelection . instanceId ,
2004+ CLAUDE_MODEL_SELECTION . instanceId ,
2005+ ) ;
2006+ yield * orchestrator . dispatch ( {
2007+ type : "message.dispatch" ,
2008+ createdBy : "user" ,
2009+ creationSource : "server" ,
2010+ commandId : CommandId . make ( "command:queued-unpicked-follow-up:server" ) ,
2011+ threadId,
2012+ messageId : MessageId . make ( "message:queued-unpicked-follow-up:server" ) ,
2013+ text : "Server-created answer" ,
2014+ attachments : [ ] ,
2015+ dispatchMode : { type : "queue_after_active" } ,
2016+ } ) ;
2017+ const withServerMessage = yield * orchestrator . getThreadProjection ( threadId ) ;
2018+ assert . equal (
2019+ withServerMessage . runs . find (
2020+ ( run ) => run . userMessageId === "message:queued-unpicked-follow-up:server" ,
2021+ ) ?. modelSelection . instanceId ,
2022+ CODEX_MODEL_SELECTION . instanceId ,
2023+ ) ;
2024+ yield * orchestrator . dispatch ( {
2025+ type : "thread.stop" ,
2026+ commandId : CommandId . make ( "command:queued-unpicked-follow-up:stop" ) ,
2027+ threadId,
2028+ } ) ;
2029+ yield * worker . drain ( ) ;
2030+ yield * orchestrator . dispatch ( {
2031+ type : "message.dispatch" ,
2032+ createdBy : "user" ,
2033+ creationSource : "mobile" ,
2034+ commandId : CommandId . make ( "command:queued-unpicked-follow-up:continue" ) ,
2035+ threadId,
2036+ messageId : MessageId . make ( "message:queued-unpicked-follow-up:continue" ) ,
2037+ text : "Continue without a pick" ,
2038+ attachments : [ ] ,
2039+ dispatchMode : { type : "start_immediately" } ,
2040+ } ) ;
2041+ const continued = yield * orchestrator . getThreadProjection ( threadId ) ;
2042+ const continuation = continued . runs . find (
2043+ ( run ) => run . userMessageId === "message:queued-unpicked-follow-up:continue" ,
2044+ ) ;
2045+ assert . equal ( continuation ?. modelSelection . instanceId , CODEX_MODEL_SELECTION . instanceId ) ;
2046+ } ) . pipe (
2047+ Effect . provide (
2048+ ProviderReplayHarness . layerWithRegistry (
2049+ {
2050+ name : "queued-unpicked-follow-up" ,
2051+ runtimePolicyOverride : {
2052+ cwd,
2053+ approvalPolicy : "never" ,
2054+ sandboxPolicy : {
2055+ type : "readOnly" ,
2056+ access : { type : "fullAccess" } ,
2057+ networkAccess : false ,
2058+ } ,
2059+ } ,
2060+ } ,
2061+ layerRegistry ,
2062+ ) ,
2063+ ) ,
2064+ ) ;
2065+ } ) ,
2066+ ) ,
2067+ ) ;
2068+
18872069 it . live ( "hands completed Grok steering context to earlier queued Codex and later Claude" , ( ) =>
18882070 Effect . scoped (
18892071 Effect . gen ( function * ( ) {
0 commit comments