@@ -17,35 +17,101 @@ const session = (providerSessionId: string) => ({
1717 browserToolsAvailable : false ,
1818} ) ;
1919
20- it . effect ( "a call waiting on its caller never resolves through the next credential" , ( ) =>
21- Effect . gen ( function * ( ) {
22- const sessions = yield * McpProviderSessions . McpProviderSessions ;
23- yield * sessions . set ( session ( "credential:old" ) ) ;
24- const pending = yield * Effect . forkChild (
25- sessions . resolveNativeCaller ( {
20+ it . effect . each ( [ "codex-thread:native" , "claude-tool:native" ] ) (
21+ "a call waiting on its caller never resolves through the next credential: %s" ,
22+ ( callId ) =>
23+ Effect . gen ( function * ( ) {
24+ const sessions = yield * McpProviderSessions . McpProviderSessions ;
25+ yield * sessions . set ( session ( "credential:old" ) ) ;
26+ const pending = yield * Effect . forkChild (
27+ sessions . resolveNativeCaller ( {
28+ threadId,
29+ providerSessionId : "credential:old" ,
30+ callId,
31+ } ) ,
32+ { startImmediately : true } ,
33+ ) ;
34+ yield * sessions . set ( session ( "credential:new" ) ) ;
35+ yield * sessions . bindNativeCaller ( {
2636 threadId,
27- providerSessionId : "credential:old" ,
28- callId : "codex-thread:native" ,
29- } ) ,
30- { startImmediately : true } ,
31- ) ;
32- // A resumed Codex session binds the same native thread id under its new credential.
33- yield * sessions . set ( session ( "credential:new" ) ) ;
34- yield * sessions . bindNativeCaller ( {
35- threadId,
36- callId : "codex-thread:native" ,
37- callerThreadId : ThreadId . make ( "thread:native-child" ) ,
38- } ) ;
39- assert . isUndefined ( yield * Fiber . join ( pending ) ) ;
40- assert . equal (
41- yield * sessions . resolveNativeCaller ( {
37+ callId,
38+ callerThreadId : ThreadId . make ( "thread:native-child" ) ,
39+ } ) ;
40+ assert . isUndefined ( yield * Fiber . join ( pending ) ) ;
41+ assert . equal (
42+ yield * sessions . resolveNativeCaller ( {
43+ threadId,
44+ providerSessionId : "credential:new" ,
45+ callId,
46+ } ) ,
47+ ThreadId . make ( "thread:native-child" ) ,
48+ ) ;
49+ for ( const reset of [ "replace" , "clear" ] as const ) {
50+ if ( reset === "clear" ) yield * sessions . clear ( threadId ) ;
51+ yield * sessions . set ( session ( `credential:${ reset } ` ) ) ;
52+ const missing = yield * Effect . forkChild (
53+ sessions . resolveNativeCaller ( {
54+ threadId,
55+ providerSessionId : `credential:${ reset } ` ,
56+ callId,
57+ } ) ,
58+ { startImmediately : true } ,
59+ ) ;
60+ yield * TestClock . adjust ( "5 seconds" ) ;
61+ assert . isUndefined ( yield * Fiber . join ( missing ) ) ;
62+ yield * sessions . bindNativeCaller ( {
63+ threadId,
64+ callId,
65+ callerThreadId : ThreadId . make ( "thread:native-child" ) ,
66+ } ) ;
67+ }
68+ } ) . pipe ( Effect . provide ( McpProviderSessions . layer ) ) ,
69+ ) ;
70+
71+ it . effect . each ( [ "codex-thread:" , "claude-tool:" ] ) (
72+ "keeps active Codex callers after many %s bindings" ,
73+ ( prefix ) =>
74+ Effect . gen ( function * ( ) {
75+ const sessions = yield * McpProviderSessions . McpProviderSessions ;
76+ yield * sessions . set ( session ( "credential:current" ) ) ;
77+ const callerThreadId = ThreadId . make ( "thread:native-child" ) ;
78+ yield * sessions . bindNativeCaller ( {
4279 threadId,
43- providerSessionId : "credential:new" ,
44- callId : "codex-thread:native" ,
45- } ) ,
46- ThreadId . make ( "thread:native-child" ) ,
47- ) ;
48- } ) . pipe ( Effect . provide ( McpProviderSessions . layer ) ) ,
80+ callId : "codex-thread:root" ,
81+ callerThreadId : threadId ,
82+ } ) ;
83+ yield * sessions . bindNativeCaller ( { threadId, callId : "codex-thread:active" , callerThreadId } ) ;
84+ for ( let index = 0 ; index < 1_025 ; index += 1 ) {
85+ yield * sessions . bindNativeCaller ( { threadId, callId : `${ prefix } ${ index } ` , callerThreadId } ) ;
86+ }
87+ for ( const [ callId , expected ] of [
88+ [ "codex-thread:root" , threadId ] ,
89+ [ "codex-thread:active" , callerThreadId ] ,
90+ ] as const ) {
91+ const resolved = yield * Effect . forkChild (
92+ sessions . resolveNativeCaller ( {
93+ threadId,
94+ providerSessionId : "credential:current" ,
95+ callId,
96+ } ) ,
97+ { startImmediately : true } ,
98+ ) ;
99+ yield * TestClock . adjust ( "5 seconds" ) ;
100+ assert . equal ( yield * Fiber . join ( resolved ) , expected ) ;
101+ }
102+ if ( prefix === "claude-tool:" ) {
103+ const expired = yield * Effect . forkChild (
104+ sessions . resolveNativeCaller ( {
105+ threadId,
106+ providerSessionId : "credential:current" ,
107+ callId : "claude-tool:0" ,
108+ } ) ,
109+ { startImmediately : true } ,
110+ ) ;
111+ yield * TestClock . adjust ( "5 seconds" ) ;
112+ assert . isUndefined ( yield * Fiber . join ( expired ) ) ;
113+ }
114+ } ) . pipe ( Effect . provide ( McpProviderSessions . layer ) ) ,
49115) ;
50116
51117it . effect . each ( [ "interrupted" , "timed out" ] as const ) (
0 commit comments