11import { normalizeDeliveryContext } from "../utils/delivery-context.shared.js" ;
22import type { DeliveryContext } from "../utils/delivery-context.types.js" ;
33
4- const hostIssuedScopes = new WeakSet < object > ( ) ;
4+ const scopeRegistryKey = Symbol . for ( "openclaw.agentHarnessTaskRuntimeScope.registry" ) ;
5+
6+ type ScopeRegistry = {
7+ hostIssuedScopes : WeakSet < object > ;
8+ } ;
9+
10+ type GlobalWithScopeRegistry = typeof globalThis & {
11+ [ scopeRegistryKey ] ?: ScopeRegistry ;
12+ } ;
13+
14+ function getScopeRegistry ( ) : ScopeRegistry {
15+ const globalState = globalThis as GlobalWithScopeRegistry ;
16+ globalState [ scopeRegistryKey ] ??= {
17+ hostIssuedScopes : new WeakSet < object > ( ) ,
18+ } ;
19+ return globalState [ scopeRegistryKey ] ;
20+ }
521
622export type AgentHarnessTaskRuntimeScope = {
723 readonly requesterSessionKey : string ;
@@ -21,14 +37,14 @@ export function createAgentHarnessTaskRuntimeScope(params: {
2137 requesterSessionKey,
2238 ...( requesterOrigin ? { requesterOrigin } : { } ) ,
2339 } ;
24- hostIssuedScopes . add ( scope ) ;
40+ getScopeRegistry ( ) . hostIssuedScopes . add ( scope ) ;
2541 return scope ;
2642}
2743
2844export function assertAgentHarnessTaskRuntimeScope (
2945 scope : AgentHarnessTaskRuntimeScope ,
3046) : AgentHarnessTaskRuntimeScope {
31- if ( ! hostIssuedScopes . has ( scope ) ) {
47+ if ( ! getScopeRegistry ( ) . hostIssuedScopes . has ( scope ) ) {
3248 throw new Error ( "Agent harness task runtime requires a host-issued scope" ) ;
3349 }
3450 return scope ;
0 commit comments