@@ -12,6 +12,7 @@ import {
1212 type AuthProfileStore ,
1313} from "openclaw/plugin-sdk/agent-runtime" ;
1414import { type FileLockOptions , withFileLock } from "openclaw/plugin-sdk/file-lock" ;
15+ import { KeyedAsyncQueue } from "openclaw/plugin-sdk/keyed-async-queue" ;
1516import {
1617 CODEX_PLUGINS_MARKETPLACE_NAME ,
1718 normalizeCodexServiceTier ,
@@ -40,7 +41,7 @@ const CODEX_APP_SERVER_BINDING_LOCK_OPTIONS: FileLockOptions = {
4041 } ,
4142 stale : CODEX_APP_SERVER_BINDING_GUARDED_REQUEST_TIMEOUT_MS * 2 ,
4243} ;
43- const bindingMutationQueues = new Map < string , Promise < void > > ( ) ;
44+ const bindingMutationQueue = new KeyedAsyncQueue ( ) ;
4445const bindingMutationContext = new AsyncLocalStorage < Set < string > > ( ) ;
4546
4647type ProviderAuthAliasLookupParams = Parameters < typeof resolveProviderIdForAuth > [ 1 ] ;
@@ -118,30 +119,13 @@ export async function withCodexAppServerBindingLock<T>(
118119 // The SDK file lock is process-reentrant, so pair it with a local queue.
119120 // Nested writes from the same guarded mutation can proceed, but unrelated
120121 // same-process tasks cannot slip between compare/clear/start.
121- const previous = bindingMutationQueues . get ( bindingPath ) ?? Promise . resolve ( ) ;
122- let releaseCurrent ! : ( ) => void ;
123- const current = new Promise < void > ( ( resolve ) => {
124- releaseCurrent = resolve ;
125- } ) ;
126- const queued = previous . then (
127- ( ) => current ,
128- ( ) => current ,
129- ) ;
130- bindingMutationQueues . set ( bindingPath , queued ) ;
131- await previous . catch ( ( ) => undefined ) ;
132-
133122 const nestedOwnedBindings = new Set ( ownedBindings ) ;
134123 nestedOwnedBindings . add ( bindingPath ) ;
135- try {
136- return await bindingMutationContext . run ( nestedOwnedBindings , ( ) =>
124+ return await bindingMutationQueue . enqueue ( bindingPath , ( ) =>
125+ bindingMutationContext . run ( nestedOwnedBindings , ( ) =>
137126 withFileLock ( bindingPath , CODEX_APP_SERVER_BINDING_LOCK_OPTIONS , run ) ,
138- ) ;
139- } finally {
140- releaseCurrent ( ) ;
141- if ( bindingMutationQueues . get ( bindingPath ) === queued ) {
142- bindingMutationQueues . delete ( bindingPath ) ;
143- }
144- }
127+ ) ,
128+ ) ;
145129}
146130
147131/** Reads and normalizes a Codex app-server binding sidecar, returning undefined on stale data. */
0 commit comments