惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

L
LangChain Blog
S
SegmentFault 最新的问题
V
Visual Studio Blog
J
Java Code Geeks
宝玉的分享
宝玉的分享
美团技术团队
博客园 - Franky
酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hackread – Cybersecurity News, Data Breaches, AI and More
有赞技术团队
有赞技术团队
量子位
Martin Fowler
Martin Fowler
MyScale Blog
MyScale Blog
Google DeepMind News
Google DeepMind News
Jina AI
Jina AI
博客园 - 叶小钗
月光博客
月光博客
P
Proofpoint News Feed
D
DataBreaches.Net
Blog — PlanetScale
Blog — PlanetScale
博客园_首页
腾讯CDC
Microsoft Azure Blog
Microsoft Azure Blog
Stack Overflow Blog
Stack Overflow Blog

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(codex): honor node exec policy for native surfaces (#...
joshavant · 2026-05-23 · via Recent Commits to openclaw:main

@@ -0,0 +1,196 @@

1+

import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";

2+

import { resolveSandboxRuntimeStatus } from "openclaw/plugin-sdk/sandbox";

3+

import { getSessionEntry, type SessionEntry } from "openclaw/plugin-sdk/session-store-runtime";

4+5+

type ExecHost = "sandbox" | "gateway" | "node";

6+

type ExecTarget = "auto" | ExecHost;

7+8+

type ExecHostOverride = {

9+

host?: string;

10+

node?: string;

11+

};

12+13+

type AgentEntry = NonNullable<NonNullable<OpenClawConfig["agents"]>["list"]>[number];

14+15+

const DEFAULT_AGENT_ID = "main";

16+

const VALID_AGENT_ID_PATTERN = /^[a-z0-9][a-z0-9_-]{0,63}$/i;

17+

const INVALID_AGENT_ID_CHARS_PATTERN = /[^a-z0-9_-]+/g;

18+

const LEADING_DASH_PATTERN = /^-+/;

19+

const TRAILING_DASH_PATTERN = /-+$/;

20+21+

export type CodexNativeExecutionPolicy = {

22+

nativeToolSurfaceAllowed: boolean;

23+

requestedExecHost: ExecTarget;

24+

effectiveExecHost: ExecHost;

25+

node?: string;

26+

blockReason?: string;

27+

};

28+29+

export function resolveCodexNativeExecutionPolicy(params: {

30+

config?: OpenClawConfig;

31+

sessionEntry?: SessionEntry;

32+

sessionKey?: string;

33+

sessionId?: string;

34+

agentId?: string;

35+

execOverrides?: ExecHostOverride;

36+

sandboxAvailable?: boolean;

37+

readRuntimeSessionEntry?: boolean;

38+

}): CodexNativeExecutionPolicy {

39+

const config = params.config ?? {};

40+

const sessionKey = params.sessionKey?.trim() || params.sessionId?.trim() || undefined;

41+

const sessionEntry =

42+

params.sessionEntry ??

43+

(params.readRuntimeSessionEntry && sessionKey

44+

? readRuntimeSessionEntryBestEffort(sessionKey)

45+

: undefined);

46+

const sandboxAvailable =

47+

params.sandboxAvailable ??

48+

(sessionKey

49+

? resolveSandboxRuntimeStatus({

50+

cfg: config,

51+

sessionKey,

52+

}).sandboxed

53+

: false);

54+

const agentId = resolvePolicyAgentId({ config, sessionKey, agentId: params.agentId });

55+

const agentExec = resolvePolicyAgentExec({ config, agentId });

56+

const globalExec = config.tools?.exec;

57+

const requestedExecHost =

58+

normalizeExecTarget(params.execOverrides?.host) ??

59+

normalizeExecTarget(sessionEntry?.execHost) ??

60+

normalizeExecTarget(agentExec?.host) ??

61+

normalizeExecTarget(globalExec?.host) ??

62+

"auto";

63+

const effectiveExecHost = resolveEffectiveExecHost({

64+

requestedExecHost,

65+

sandboxAvailable,

66+

});

67+

const node =

68+

params.execOverrides?.node ?? sessionEntry?.execNode ?? agentExec?.node ?? globalExec?.node;

69+

if (effectiveExecHost !== "node") {

70+

return {

71+

nativeToolSurfaceAllowed: true,

72+

requestedExecHost,

73+

effectiveExecHost,

74+

node,

75+

};

76+

}

77+

return {

78+

nativeToolSurfaceAllowed: false,

79+

requestedExecHost,

80+

effectiveExecHost,

81+

node,

82+

blockReason:

83+

"OpenClaw exec host=node is active for this session. Codex app-server native execution cannot route shell, filesystem, MCP, or app-backed work through the selected OpenClaw node.",

84+

};

85+

}

86+87+

export function formatCodexNativeNodeExecBlock(params: {

88+

surface: string;

89+

reason?: string;

90+

}): string {

91+

return [

92+

`Codex-native ${params.surface} is unavailable because OpenClaw exec host=node is active for this session.`,

93+

params.reason ??

94+

"Codex app-server native execution cannot route execution through the selected OpenClaw node.",

95+

"Use a normal Codex harness turn so OpenClaw exec/process tools run on the node, or switch exec host to gateway for native Codex app-server execution.",

96+

].join(" ");

97+

}

98+99+

function resolvePolicyAgentId(params: {

100+

config: OpenClawConfig;

101+

sessionKey?: string;

102+

agentId?: string;

103+

}): string {

104+

const explicitAgentId = normalizeAgentIdOrDefault(params.agentId);

105+

if (explicitAgentId) {

106+

return explicitAgentId;

107+

}

108+

const sessionAgentId = parseAgentIdFromSessionKey(params.sessionKey);

109+

if (sessionAgentId) {

110+

return sessionAgentId;

111+

}

112+

const agents = listAgentEntries(params.config);

113+

const defaultEntry = agents.find((entry) => entry?.default) ?? agents[0];

114+

return normalizeAgentId(defaultEntry?.id);

115+

}

116+117+

function resolvePolicyAgentExec(params: {

118+

config: OpenClawConfig;

119+

agentId: string;

120+

}): ExecHostOverride | undefined {

121+

return listAgentEntries(params.config).find(

122+

(entry) => normalizeAgentId(entry?.id) === params.agentId,

123+

)?.tools?.exec;

124+

}

125+126+

function listAgentEntries(config: OpenClawConfig): AgentEntry[] {

127+

return (config.agents?.list ?? []).filter(

128+

(entry): entry is AgentEntry => entry !== null && typeof entry === "object",

129+

);

130+

}

131+132+

function parseAgentIdFromSessionKey(sessionKey?: string): string | undefined {

133+

const raw = sessionKey?.trim();

134+

if (!raw) {

135+

return undefined;

136+

}

137+

const parts = raw.toLowerCase().split(":").filter(Boolean);

138+

if (parts.length < 3 || parts[0] !== "agent" || !parts[2]) {

139+

return undefined;

140+

}

141+

return normalizeAgentIdOrDefault(parts[1]);

142+

}

143+144+

function normalizeAgentIdOrDefault(value?: string | null): string | undefined {

145+

const normalized = normalizeAgentId(value);

146+

return normalized === DEFAULT_AGENT_ID && !(value ?? "").trim() ? undefined : normalized;

147+

}

148+149+

function normalizeAgentId(value?: string | null): string {

150+

const trimmed = (value ?? "").trim();

151+

if (!trimmed) {

152+

return DEFAULT_AGENT_ID;

153+

}

154+

const normalized = trimmed.toLowerCase();

155+

if (VALID_AGENT_ID_PATTERN.test(trimmed)) {

156+

return normalized;

157+

}

158+

return (

159+

normalized

160+

.replace(INVALID_AGENT_ID_CHARS_PATTERN, "-")

161+

.replace(LEADING_DASH_PATTERN, "")

162+

.replace(TRAILING_DASH_PATTERN, "")

163+

.slice(0, 64) || DEFAULT_AGENT_ID

164+

);

165+

}

166+167+

function normalizeExecTarget(value?: string | null): ExecTarget | undefined {

168+

const normalized = value?.trim().toLowerCase();

169+

if (

170+

normalized === "auto" ||

171+

normalized === "sandbox" ||

172+

normalized === "gateway" ||

173+

normalized === "node"

174+

) {

175+

return normalized;

176+

}

177+

return undefined;

178+

}

179+180+

function resolveEffectiveExecHost(params: {

181+

requestedExecHost: ExecTarget;

182+

sandboxAvailable: boolean;

183+

}): ExecHost {

184+

if (params.requestedExecHost === "auto") {

185+

return params.sandboxAvailable ? "sandbox" : "gateway";

186+

}

187+

return params.requestedExecHost;

188+

}

189+190+

function readRuntimeSessionEntryBestEffort(sessionKey: string): SessionEntry | undefined {

191+

try {

192+

return getSessionEntry({ sessionKey });

193+

} catch {

194+

return undefined;

195+

}

196+

}