@@ -172,6 +172,7 @@ interface FakePi {
172172 readonly vetoNextNewSession : ( ) => void ;
173173 readonly allRequests : ( ) => ReadonlyArray < PiRpcRecord > ;
174174 readonly promptThinkingLevels : ReadonlyArray < string > ;
175+ readonly promptModels : ReadonlyArray < string > ;
175176 readonly queueStats : ( data : unknown ) => void ;
176177 /** Pi before 0.84.4 answers clear_queue as an unknown command. */
177178 readonly setClearQueue : (
@@ -228,6 +229,8 @@ const makeFakePi: Effect.Effect<FakePi> = Effect.gen(function* () {
228229 let stdinBuffer = "" ;
229230 let thinkingLevel = "high" ;
230231 const promptThinkingLevels : Array < string > = [ ] ;
232+ const promptModels : Array < string > = [ ] ;
233+ let currentModel = "default" ;
231234
232235 const emit = ( record : PiRpcRecord , chunkBytes ?: number ) =>
233236 Effect . gen ( function * ( ) {
@@ -267,6 +270,7 @@ const makeFakePi: Effect.Effect<FakePi> = Effect.gen(function* () {
267270 case "set_model" :
268271 // Pi reapplies the target model's configured thinking default.
269272 thinkingLevel = "low" ;
273+ currentModel = `${ String ( record [ "provider" ] ) } /${ String ( record [ "modelId" ] ) } ` ;
270274 return base ;
271275 case "set_thinking_level" :
272276 if ( failThinking ) {
@@ -328,7 +332,10 @@ const makeFakePi: Effect.Effect<FakePi> = Effect.gen(function* () {
328332 stdinBuffer = stdinBuffer . slice ( newline + 1 ) ;
329333 if ( line . length === 0 ) continue ;
330334 const record = decodeJsonLine ( line ) as PiRpcRecord ;
331- if ( record [ "type" ] === "prompt" ) promptThinkingLevels . push ( thinkingLevel ) ;
335+ if ( record [ "type" ] === "prompt" ) {
336+ promptThinkingLevels . push ( thinkingLevel ) ;
337+ promptModels . push ( currentModel ) ;
338+ }
332339 allRequests . push ( record ) ;
333340 yield * Queue . offer ( requests , record ) ;
334341 if ( record [ "type" ] === "get_state" && deferState ) {
@@ -387,6 +394,7 @@ const makeFakePi: Effect.Effect<FakePi> = Effect.gen(function* () {
387394 failThinking = true ;
388395 } ,
389396 promptThinkingLevels,
397+ promptModels,
390398 emit,
391399 takeRequest,
392400 queueEntries : ( data ) => entriesQueue . push ( data ) ,
@@ -2285,7 +2293,7 @@ describe("PiAdapterV2", () => {
22852293 } ) . pipe ( Effect . scoped , Effect . provide ( layerTest ) ) ,
22862294 ) ;
22872295
2288- it . effect . each ( [ false , true ] ) (
2296+ it . effect . each ( [ false , true , "previous" ] as const ) (
22892297 "resets applied thinking when returning to Pi default (failed first restore: %s)" ,
22902298 ( failFirstRestore ) =>
22912299 Effect . gen ( function * ( ) {
@@ -2305,12 +2313,12 @@ describe("PiAdapterV2", () => {
23052313
23062314 yield * startTurn ( runtime , providerThread , "default" , [ ] , "Hello pi" , {
23072315 instanceId : PI_INSTANCE_ID ,
2308- model : "xai/grok-4.6 " ,
2316+ model : "anthropic/model-a " ,
23092317 options : [ { id : "thinking" , value : "high" } ] ,
23102318 } ) ;
23112319 const modelRequest = yield * fake . takeRequest ( "set_model" ) ;
2312- assert . equal ( modelRequest [ "provider" ] , "xai " ) ;
2313- assert . equal ( modelRequest [ "modelId" ] , "grok-4.6 " ) ;
2320+ assert . equal ( modelRequest [ "provider" ] , "anthropic " ) ;
2321+ assert . equal ( modelRequest [ "modelId" ] , "model-a " ) ;
23142322 const levelRequest = yield * fake . takeRequest ( "set_thinking_level" ) ;
23152323 assert . equal ( levelRequest [ "level" ] , "high" ) ;
23162324 yield * fake . takeRequest ( "prompt" ) ;
@@ -2346,17 +2354,37 @@ describe("PiAdapterV2", () => {
23462354 "Hello pi" ,
23472355 {
23482356 instanceId : PI_INSTANCE_ID ,
2349- model : "default" ,
2357+ model : failFirstRestore === "previous" ? "anthropic/model-a" : "default" ,
2358+ ...( failFirstRestore === "previous"
2359+ ? { options : [ { id : "thinking" , value : "high" } ] }
2360+ : { } ) ,
23502361 } ,
23512362 2 ,
23522363 ) ;
2353- const replayModel = yield * fake . takeRequest ( "set_model" ) ;
2354- assert . equal ( replayModel [ "provider" ] , "xai" ) ;
2355- assert . equal ( replayModel [ "modelId" ] , "grok-4.6" ) ;
2356- const resetLevel = yield * fake . takeRequest ( "set_thinking_level" ) ;
2357- assert . equal ( resetLevel [ "level" ] , "medium" ) ;
23582364 yield * fake . takeRequest ( "prompt" ) ;
2359- assert . deepEqual ( fake . promptThinkingLevels , [ "high" , "medium" ] ) ;
2365+ assert . deepEqual ( fake . promptThinkingLevels , [
2366+ "high" ,
2367+ failFirstRestore === "previous" ? "high" : "medium" ,
2368+ ] ) ;
2369+ assert . deepEqual ( fake . promptModels , [
2370+ "anthropic/model-a" ,
2371+ failFirstRestore === "previous" ? "anthropic/model-a" : "xai/grok-4.6" ,
2372+ ] ) ;
2373+ const replayModel = fake
2374+ . allRequests ( )
2375+ . findLast ( ( request ) => request [ "type" ] === "set_model" ) ! ;
2376+ assert . equal (
2377+ replayModel [ "provider" ] ,
2378+ failFirstRestore === "previous" ? "anthropic" : "xai" ,
2379+ ) ;
2380+ assert . equal (
2381+ replayModel [ "modelId" ] ,
2382+ failFirstRestore === "previous" ? "model-a" : "grok-4.6" ,
2383+ ) ;
2384+ const resetLevel = fake
2385+ . allRequests ( )
2386+ . findLast ( ( request ) => request [ "type" ] === "set_thinking_level" ) ! ;
2387+ assert . equal ( resetLevel [ "level" ] , failFirstRestore === "previous" ? "high" : "medium" ) ;
23602388 } ) . pipe ( Effect . scoped , Effect . provide ( layerTest ) ) ,
23612389 ) ;
23622390
0 commit comments