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

推荐订阅源

D
DataBreaches.Net
N
Netflix TechBlog - Medium
P
Proofpoint News Feed
D
Docker
J
Java Code Geeks
L
LangChain Blog
Microsoft Security Blog
Microsoft Security Blog
The GitHub Blog
The GitHub Blog
I
InfoQ
Stack Overflow Blog
Stack Overflow Blog
云风的 BLOG
云风的 BLOG
Engineering at Meta
Engineering at Meta
MongoDB | Blog
MongoDB | Blog
月光博客
月光博客
T
Tailwind CSS Blog
M
MIT News - Artificial intelligence
Blog — PlanetScale
Blog — PlanetScale
Google DeepMind News
Google DeepMind News
腾讯CDC
罗磊的独立博客
U
Unit 42
爱范儿
爱范儿
Vercel News
Vercel News
MyScale Blog
MyScale 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(agents): preserve code mode hook context (#83481) · o...
steipete · 2026-05-18 · via Recent Commits to openclaw:main
Original file line numberDiff line numberDiff line change

@@ -35,6 +35,7 @@ Docs: https://docs.openclaw.ai

3535
3636

### Fixes

3737
38+

- Agents/code mode: preserve agent, session, run, and channel context in `before_tool_call` hooks for top-level `exec`/`wait` dispatches. Fixes #83387.

3839

- Replies: keep final payload delivery after live preview updates so channels can finalize or send the completed answer instead of losing preview-only drafts. (#83468)

3940

- Providers/Xiaomi: replay MiMo Anthropic-compatible `reasoning_content` as provider-required thinking blocks even when OpenClaw thinking is disabled, fixing follow-up tool turns for `mimo-v2-flash`. Fixes #83407. Thanks @Xgenious7.

4041

- Agents/exec approvals: forward approval-runtime credentials on agent-owned Gateway approval calls so approved async commands complete through the existing runtime path instead of stalling on unauthenticated follow-up calls. Thanks @IWhatsskill, @Patrick-Erichsen, and @jesse-merhi.

Original file line numberDiff line numberDiff line change

@@ -1061,6 +1061,15 @@ async function compactEmbeddedPiSessionDirectOnce(

10611061

const { customTools } = splitSdkTools({

10621062

tools: effectiveTools,

10631063

sandboxEnabled: !!sandbox?.enabled,

1064+

toolHookContext: {

1065+

agentId: sessionAgentId,

1066+

config: params.config,

1067+

cwd: effectiveWorkspace,

1068+

sessionKey: sandboxSessionKey,

1069+

sessionId: params.sessionId,

1070+

runId: params.runId,

1071+

channelId: params.currentChannelId,

1072+

},

10641073

});

10651074

// Pi treats `tools` as a name allowlist during session creation. Pass the

10661075

// exact OpenClaw-managed registrations so custom tools survive startup.

Original file line numberDiff line numberDiff line change

@@ -2179,6 +2179,7 @@ export async function runEmbeddedAttempt(

21792179

const { customTools } = splitSdkTools({

21802180

tools: effectiveTools,

21812181

sandboxEnabled: !!sandbox?.enabled,

2182+

toolHookContext: catalogToolHookContext,

21822183

});

21832184
21842185

// Add client tools (OpenResponses hosted tools) to customTools.

Original file line numberDiff line numberDiff line change

@@ -1,15 +1,20 @@

11

import type { AgentTool } from "@earendil-works/pi-agent-core";

22

import { toToolDefinitions } from "../pi-tool-definition-adapter.js";

3+

import type { HookContext } from "../pi-tools.before-tool-call.js";

34
45

// We always pass tools via `customTools` so our policy filtering, sandbox integration,

56

// and extended toolset remain consistent across providers.

67

type AnyAgentTool = AgentTool;

78
8-

export function splitSdkTools(options: { tools: AnyAgentTool[]; sandboxEnabled: boolean }): {

9+

export function splitSdkTools(options: {

10+

tools: AnyAgentTool[];

11+

sandboxEnabled: boolean;

12+

toolHookContext?: HookContext;

13+

}): {

914

customTools: ReturnType<typeof toToolDefinitions>;

1015

} {

11-

const { tools } = options;

16+

const { tools, toolHookContext } = options;

1217

return {

13-

customTools: toToolDefinitions(tools),

18+

customTools: toToolDefinitions(tools, toolHookContext),

1419

};

1520

}

Original file line numberDiff line numberDiff line change

@@ -223,7 +223,10 @@ export function isClientToolNameConflictError(err: unknown): err is Error {

223223

return err instanceof Error && err.message.startsWith(CLIENT_TOOL_NAME_CONFLICT_PREFIX);

224224

}

225225
226-

export function toToolDefinitions(tools: AnyAgentTool[]): ToolDefinition[] {

226+

export function toToolDefinitions(

227+

tools: AnyAgentTool[],

228+

hookContext?: HookContext,

229+

): ToolDefinition[] {

227230

return tools.map((tool) => {

228231

const name = tool.name || "tool";

229232

const normalizedName = normalizeToolName(name);

@@ -242,6 +245,7 @@ export function toToolDefinitions(tools: AnyAgentTool[]): ToolDefinition[] {

242245

toolName: name,

243246

params,

244247

toolCallId,

248+

ctx: hookContext,

245249

});

246250

if (hookOutcome.blocked) {

247251

if (hookOutcome.kind === "veto") {

Original file line numberDiff line numberDiff line change

@@ -313,6 +313,46 @@ describe("before_tool_call hook deduplication (#15502)", () => {

313313

expect(beforeToolCallHook).toHaveBeenCalledTimes(1);

314314

});

315315
316+

it("passes hook context for unwrapped tool definitions", async () => {

317+

const execute = vi.fn().mockResolvedValue({ content: [], details: { ok: true } });

318+

const baseTool = { name: "exec", execute, description: "exec", parameters: {} } as any;

319+

const [def] = toToolDefinitions([baseTool], {

320+

agentId: "code-agent",

321+

sessionKey: "agent:code-agent:main",

322+

sessionId: "session-code",

323+

runId: "run-code",

324+

channelId: "channel-code",

325+

});

326+

const extensionContext = {} as Parameters<typeof def.execute>[4];

327+
328+

await def.execute(

329+

"call-code-exec",

330+

{ code: "echo hi" },

331+

undefined,

332+

undefined,

333+

extensionContext,

334+

);

335+
336+

expect(beforeToolCallHook).toHaveBeenCalledTimes(1);

337+

expect(beforeToolCallHook).toHaveBeenCalledWith(

338+

{

339+

toolName: "exec",

340+

params: { code: "echo hi" },

341+

runId: "run-code",

342+

toolCallId: "call-code-exec",

343+

},

344+

{

345+

toolName: "exec",

346+

agentId: "code-agent",

347+

sessionKey: "agent:code-agent:main",

348+

sessionId: "session-code",

349+

runId: "run-code",

350+

toolCallId: "call-code-exec",

351+

channelId: "channel-code",

352+

},

353+

);

354+

});

355+
316356

it("preserves the hook marker when abort wrapping a hooked tool", () => {

317357

const execute = vi.fn().mockResolvedValue({ content: [], details: { ok: true } });

318358

const baseTool = { name: "Bash", execute, description: "bash", parameters: {} } as any;