@@ -42,31 +42,16 @@ export type PreparedAgentRunAdmission = Readonly<{
4242type DelegatedAuthorityLease = {
4343 authority : AgentRunDelegatedAuthority ;
4444 foregroundClosed : boolean ;
45- nativeHookRecoveryRetained : boolean ;
4645} ;
4746
4847const delegatedAuthorityLeases = new WeakMap < AdmittedRunContext , DelegatedAuthorityLease > ( ) ;
4948const activeNativeHookRecoveryLeases = new Map < string , DelegatedAuthorityLease > ( ) ;
5049
51- function bindAdmittedRunDelegatedAuthority (
52- context : AdmittedRunContext ,
53- ) : AgentRunDelegatedAuthority {
50+ function bindAdmittedRunDelegatedAuthority ( context : AdmittedRunContext ) : void {
51+ activeNativeHookRecoveryLeases . delete ( context . operationalRunInstance . runId ) ;
5452 const authority = claimAgentRunDelegatedAuthority ( context . operationalRunInstance ) ;
55- const lease = {
56- authority,
57- foregroundClosed : false ,
58- nativeHookRecoveryRetained : false ,
59- } ;
60- activeNativeHookRecoveryLeases . set ( context . operationalRunInstance . runId , lease ) ;
53+ const lease = { authority, foregroundClosed : false } ;
6154 delegatedAuthorityLeases . set ( context , lease ) ;
62- return authority ;
63- }
64-
65- function releaseNativeHookRecoveryLease ( lease : DelegatedAuthorityLease ) : void {
66- const runId = lease . authority . operationalRunInstance . runId ;
67- if ( activeNativeHookRecoveryLeases . get ( runId ) === lease ) {
68- activeNativeHookRecoveryLeases . delete ( runId ) ;
69- }
7055}
7156
7257/** Reads the immutable outer-run authority without reviving a closed claim. */
@@ -87,9 +72,6 @@ export function closeAdmittedRunDelegatedAuthority(context: AdmittedRunContext):
8772 }
8873 lease . foregroundClosed = true ;
8974 releaseAgentRunDelegatedAuthority ( lease . authority ) ;
90- if ( ! lease . nativeHookRecoveryRetained ) {
91- releaseNativeHookRecoveryLease ( lease ) ;
92- }
9375 return true ;
9476}
9577
@@ -107,18 +89,14 @@ export function retainAdmittedRunBeforeToolCallRecovery(
10789 if (
10890 ! lease ||
10991 lease . foregroundClosed ||
110- lease . nativeHookRecoveryRetained ||
111- activeNativeHookRecoveryLeases . get ( runId ) !== lease ||
92+ activeNativeHookRecoveryLeases . has ( runId ) ||
11293 ! validateAgentRunDelegatedAuthority ( lease . authority )
11394 ) {
11495 return undefined ;
11596 }
116- lease . nativeHookRecoveryRetained = true ;
117- let released = false ;
97+ activeNativeHookRecoveryLeases . set ( runId , lease ) ;
11898 const assertActive = ( ) => {
11999 if (
120- released ||
121- ! lease . nativeHookRecoveryRetained ||
122100 getAgentRunLifecycleGeneration ( ) !== lease . authority . lifecycleGeneration ||
123101 activeNativeHookRecoveryLeases . get ( runId ) !== lease
124102 ) {
@@ -128,13 +106,8 @@ export function retainAdmittedRunBeforeToolCallRecovery(
128106 return Object . freeze ( {
129107 assertActive,
130108 release : ( ) => {
131- if ( released ) {
132- return ;
133- }
134- released = true ;
135- lease . nativeHookRecoveryRetained = false ;
136- if ( lease . foregroundClosed ) {
137- releaseNativeHookRecoveryLease ( lease ) ;
109+ if ( activeNativeHookRecoveryLeases . get ( runId ) === lease ) {
110+ activeNativeHookRecoveryLeases . delete ( runId ) ;
138111 }
139112 } ,
140113 } ) ;
0 commit comments