@@ -7104,6 +7104,20 @@ async function sendMessage(extraChatParams = {}) {
71047104 return false ;
71057105 }
71067106
7107+ let renewedContextMenuClaim = false ;
7108+ const releaseRenewedContextMenuClaim = async ( ) => {
7109+ if ( ! renewedContextMenuClaim ) return ;
7110+ renewedContextMenuClaim = false ;
7111+ try {
7112+ await sendToBackground ( 'release_context_menu_prompt_claim' , {
7113+ tabId,
7114+ promptId : contextMenuClaim . promptId ,
7115+ claimantId : contextMenuClaim . claimantId ,
7116+ } ) ;
7117+ } catch { /* the durable lease still expires if release fails */ }
7118+ onContextMenuClaimRejected ?. ( { reason : 'panel-hidden' , retryAfterMs : 250 } ) ;
7119+ } ;
7120+
71077121 if ( contextMenuClaim ?. promptId && contextMenuClaim ?. claimantId ) {
71087122 let renewedClaim = null ;
71097123 try {
@@ -7115,18 +7129,12 @@ async function sendMessage(extraChatParams = {}) {
71157129 } catch {
71167130 renewedClaim = { claimed : false , reason : 'connection' , retryAfterMs : 1_000 } ;
71177131 }
7132+ renewedContextMenuClaim = renewedClaim ?. claimed === true ;
71187133 const claimStillVisible = document . visibilityState !== 'hidden'
71197134 && sameTabId ( currentTabId , tabId )
71207135 && sameTabId ( renderedTabId , tabId ) ;
7121- if ( renewedClaim ?. claimed && ! claimStillVisible ) {
7122- try {
7123- await sendToBackground ( 'release_context_menu_prompt_claim' , {
7124- tabId,
7125- promptId : contextMenuClaim . promptId ,
7126- claimantId : contextMenuClaim . claimantId ,
7127- } ) ;
7128- } catch { /* the durable lease still expires if release fails */ }
7129- onContextMenuClaimRejected ?. ( { reason : 'panel-hidden' , retryAfterMs : 250 } ) ;
7136+ if ( renewedContextMenuClaim && ! claimStillVisible ) {
7137+ await releaseRenewedContextMenuClaim ( ) ;
71307138 setTabProcessing ( tabId , false ) ;
71317139 setTabAbortRequested ( tabId , false ) ;
71327140 if ( sameTabId ( currentTabId , tabId ) ) syncSendButtonState ( ) ;
@@ -7148,6 +7156,7 @@ async function sendMessage(extraChatParams = {}) {
71487156 && sameTabId ( currentTabId , tabId )
71497157 && sameTabId ( renderedTabId , tabId ) ;
71507158 if ( ! renderToCurrentTab ) {
7159+ await releaseRenewedContextMenuClaim ( ) ;
71517160 if ( text ) saveInputDraftForTab ( tabId , text ) ;
71527161 setTabProcessing ( tabId , false ) ;
71537162 setTabAbortRequested ( tabId , false ) ;
0 commit comments