Skip to content

Commit bbc4a50

Browse files
committed
fix(codex): share harness task scope registry
1 parent fcdd184 commit bbc4a50

2 files changed

Lines changed: 24 additions & 6 deletions

File tree

extensions/codex/src/app-server/native-subagent-monitor.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import fs from "node:fs/promises";
22
import os from "node:os";
33
import path from "node:path";
4-
import type { AgentHarnessTaskRecord } from "openclaw/plugin-sdk/agent-harness-task-runtime";
4+
import type {
5+
AgentHarnessTaskRecord,
6+
AgentHarnessTaskRuntimeScope,
7+
} from "openclaw/plugin-sdk/agent-harness-task-runtime";
58
import { describe, expect, it, vi } from "vitest";
6-
import { createAgentHarnessTaskRuntimeScope } from "../../../../src/tasks/agent-harness-task-runtime-scope.js";
79
import {
810
CodexNativeSubagentMonitor,
911
registerCodexNativeSubagentMonitor,
@@ -70,7 +72,7 @@ function createRuntime() {
7072
}
7173

7274
function createTaskScope(requesterSessionKey = "agent:main:discord:channel:C123") {
73-
return createAgentHarnessTaskRuntimeScope({ requesterSessionKey });
75+
return { requesterSessionKey } as AgentHarnessTaskRuntimeScope;
7476
}
7577

7678
async function notifyChildStarted(

src/tasks/agent-harness-task-runtime-scope.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
11
import { normalizeDeliveryContext } from "../utils/delivery-context.shared.js";
22
import 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

622
export 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

2844
export 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

Comments
 (0)