@@ -35,6 +35,7 @@ import { describe } from "vite-plus/test";
3535
3636import type * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter" ;
3737import * as McpProviderSessions from "@t3tools/provider-core/server/McpProviderSessions" ;
38+ import { buildRuntimeInstructions } from "@t3tools/provider-core/server/runtimeInstructions" ;
3839import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator" ;
3940import * as ProviderContinuationRequests from "@t3tools/provider-core/server/ProviderContinuationRequests" ;
4041import {
@@ -3243,6 +3244,60 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => {
32433244 } ) . pipe ( Effect . scoped ) ,
32443245 ) ;
32453246
3247+ it . effect ( "re-registers T3 MCP each turn and drops its instructions when adding fails" , ( ) =>
3248+ Effect . gen ( function * ( ) {
3249+ const mcpSessions = yield * McpProviderSessions . McpProviderSessions ;
3250+ yield * mcpSessions . set ( {
3251+ environmentId : EnvironmentId . make ( "environment:opencode2-adapter" ) ,
3252+ threadId,
3253+ providerSessionId : "mcp:opencode2-adapter" ,
3254+ providerInstanceId : instanceId ,
3255+ endpoint : "http://127.0.0.1:3773/mcp" ,
3256+ authorizationHeader : "Bearer thread-credential" ,
3257+ browserToolsAvailable : false ,
3258+ } ) ;
3259+ yield * Effect . addFinalizer ( ( ) => mcpSessions . clear ( threadId ) ) ;
3260+ const server = "t3-code-thread_opencode2-adapter" ;
3261+ const add = out ( "mcp.add" , {
3262+ server,
3263+ "location[directory]" : WORK ,
3264+ config : {
3265+ type : "remote" ,
3266+ url : "http://127.0.0.1:3773/mcp" ,
3267+ headers : { Authorization : "Bearer thread-credential" } ,
3268+ oauth : false ,
3269+ } ,
3270+ } ) ;
3271+ const turn = [
3272+ out ( "session.prompt" , { sessionID : SESSION , text : "<any>" } ) ,
3273+ promptAccepted ,
3274+ event ( "session.execution.succeeded" , { sessionID : SESSION } ) ,
3275+ ] ;
3276+ // Idle Location eviction drops OpenCode's runtime MCP servers without a reconnect.
3277+ const { runtime, thread } = yield * resumed ( [
3278+ add ,
3279+ reply ( "mcp.add" , null ) ,
3280+ ...turn ,
3281+ add ,
3282+ reply ( "mcp.add" , { status : 500 , body : { message : "MCP unavailable" } } ) ,
3283+ out ( "session.instructions.entry.put" , {
3284+ sessionID : SESSION ,
3285+ key : "t3-code" ,
3286+ value : buildRuntimeInstructions ( { harness : "OpenCode" , model : bigPickle . model } ) ,
3287+ } ) ,
3288+ reply ( "session.instructions.entry.put" , null ) ,
3289+ ...turn ,
3290+ out ( "mcp.remove" , { server, "location[directory]" : WORK } ) ,
3291+ reply ( "mcp.remove" , null ) ,
3292+ ] ) ;
3293+ for ( let index = 0 ; index < 2 ; index ++ ) {
3294+ const terminal = yield * terminalOf ( runtime ) . pipe ( Effect . forkScoped ) ;
3295+ yield * runtime . startTurn ( turnInput ( thread ) ) ;
3296+ assert . equal ( ( yield * Fiber . join ( terminal ) ) ?. status , "completed" ) ;
3297+ }
3298+ } ) . pipe ( Effect . scoped ) ,
3299+ ) ;
3300+
32463301 it . effect ( "registers a long thread id's MCP server under a name OpenCode accepts" , ( ) =>
32473302 Effect . gen ( function * ( ) {
32483303 const child = ThreadId . make (
0 commit comments