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

推荐订阅源

让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
The Blog of Author Tim Ferriss
博客园 - 司徒正美
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
有赞技术团队
有赞技术团队
量子位
S
SegmentFault 最新的问题
博客园 - 聂微东
博客园 - 【当耐特】
J
Java Code Geeks
美团技术团队
Hugging Face - Blog
Hugging Face - Blog
H
Help Net Security
V
V2EX
人人都是产品经理
人人都是产品经理
博客园 - Franky
罗磊的独立博客
Engineering at Meta
Engineering at Meta
A
About on SuperTechFans
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
酷 壳 – CoolShell
酷 壳 – CoolShell
云风的 BLOG
云风的 BLOG
Y
Y Combinator Blog
Apple Machine Learning Research
Apple Machine Learning Research

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(native-hook-relay): prune stale bridge files on regis...
clawsweeper · 2026-05-29 · via Recent Commits to openclaw:main
1-

import { statSync, writeFileSync } from "node:fs";

1+

import { randomUUID } from "node:crypto";

2+

import { rmSync, statSync, writeFileSync } from "node:fs";

23

import fs from "node:fs/promises";

34

import { createServer, request as httpRequest } from "node:http";

45

import { tmpdir } from "node:os";

@@ -24,6 +25,7 @@ import {

24252526

afterEach(() => {

2627

vi.useRealTimers();

28+

vi.restoreAllMocks();

2729

resetGlobalHookRunner();

2830

setActivePluginRegistry(createEmptyPluginRegistry());

2931

testing.clearNativeHookRelaysForTests();

@@ -80,6 +82,36 @@ async function waitForNativeHookRelayBridgeRecord(

8082

return record as Record<string, unknown>;

8183

}

828485+

async function writeForeignNativeHookRelayBridgeRecordForTests(

86+

relayId: string,

87+

record: {

88+

pid: number;

89+

expiresAtMs: number;

90+

},

91+

): Promise<string> {

92+

const bridgeDir = testing.getNativeHookRelayBridgeDirForTests();

93+

await fs.mkdir(bridgeDir, { recursive: true, mode: 0o700 });

94+

const registryPath = testing.getNativeHookRelayBridgeRegistryPathForTests(relayId);

95+

writeFileSync(

96+

registryPath,

97+

`${JSON.stringify({

98+

version: 1,

99+

relayId,

100+

pid: record.pid,

101+

hostname: "127.0.0.1",

102+

port: 9,

103+

token: `token-${relayId}`,

104+

expiresAtMs: record.expiresAtMs,

105+

})}\n`,

106+

{ mode: 0o600 },

107+

);

108+

return registryPath;

109+

}

110+111+

function uniqueNativeHookRelayIdForTests(prefix: string): string {

112+

return `${prefix}-${randomUUID()}`;

113+

}

114+83115

function openDeferredNativeHookRelayBridgeRequest(

84116

record: Record<string, unknown>,

85117

payload: Record<string, unknown>,

@@ -852,6 +884,122 @@ describe("native hook relay registry", () => {

852884

expect(response).toEqual({ stdout: "", stderr: "", exitCode: 0 });

853885

});

854886887+

it("prunes dead foreign direct bridge registry files during registration", async () => {

888+

const stalePath = await writeForeignNativeHookRelayBridgeRecordForTests(

889+

uniqueNativeHookRelayIdForTests("codex-dead-foreign-bridge"),

890+

{

891+

pid: 9_999_991,

892+

expiresAtMs: Date.now() + 60_000,

893+

},

894+

);

895+

const kill = vi.spyOn(process, "kill").mockImplementation((pid) => {

896+

if (pid === 9_999_991) {

897+

throw Object.assign(new Error("missing process"), { code: "ESRCH" });

898+

}

899+

return true;

900+

});

901+902+

registerNativeHookRelay({

903+

provider: "codex",

904+

relayId: "codex-prune-dead-foreign-bridge-session",

905+

sessionId: "session-1",

906+

runId: "run-1",

907+

allowedEvents: ["pre_tool_use"],

908+

});

909+910+

expect(kill).toHaveBeenCalledWith(9_999_991, 0);

911+

await expect(fs.stat(stalePath)).rejects.toMatchObject({ code: "ENOENT" });

912+

});

913+914+

it("prunes expired foreign direct bridge registry files even when their pid is alive", async () => {

915+

const stalePath = await writeForeignNativeHookRelayBridgeRecordForTests(

916+

uniqueNativeHookRelayIdForTests("codex-expired-foreign-bridge"),

917+

{

918+

pid: 9_999_992,

919+

expiresAtMs: Date.now() - 1,

920+

},

921+

);

922+

const kill = vi.spyOn(process, "kill").mockImplementation((pid) => {

923+

if (pid !== 9_999_992) {

924+

throw Object.assign(new Error("unexpected process"), { code: "ESRCH" });

925+

}

926+

return true;

927+

});

928+929+

registerNativeHookRelay({

930+

provider: "codex",

931+

relayId: "codex-prune-expired-foreign-bridge-session",

932+

sessionId: "session-1",

933+

runId: "run-1",

934+

allowedEvents: ["pre_tool_use"],

935+

});

936+937+

expect(kill).not.toHaveBeenCalled();

938+

await expect(fs.stat(stalePath)).rejects.toMatchObject({ code: "ENOENT" });

939+

});

940+941+

it("preserves live unexpired foreign direct bridge registry files during registration", async () => {

942+

const livePath = await writeForeignNativeHookRelayBridgeRecordForTests(

943+

uniqueNativeHookRelayIdForTests("codex-live-foreign-bridge"),

944+

{

945+

pid: 9_999_993,

946+

expiresAtMs: Date.now() + 60_000,

947+

},

948+

);

949+

const kill = vi.spyOn(process, "kill").mockImplementation((pid) => {

950+

if (pid !== 9_999_993) {

951+

throw Object.assign(new Error("unexpected process"), { code: "ESRCH" });

952+

}

953+

return true;

954+

});

955+956+

try {

957+

registerNativeHookRelay({

958+

provider: "codex",

959+

relayId: "codex-preserve-live-foreign-bridge-session",

960+

sessionId: "session-1",

961+

runId: "run-1",

962+

allowedEvents: ["pre_tool_use"],

963+

});

964+965+

expect(kill).toHaveBeenCalledWith(9_999_993, 0);

966+

await expect(fs.stat(livePath)).resolves.toBeDefined();

967+

} finally {

968+

rmSync(livePath, { force: true });

969+

}

970+

});

971+972+

it("preserves foreign direct bridge registry files when liveness is unknown", async () => {

973+

const livePath = await writeForeignNativeHookRelayBridgeRecordForTests(

974+

uniqueNativeHookRelayIdForTests("codex-unknown-liveness-foreign-bridge"),

975+

{

976+

pid: 9_999_994,

977+

expiresAtMs: Date.now() + 60_000,

978+

},

979+

);

980+

const kill = vi.spyOn(process, "kill").mockImplementation((pid) => {

981+

if (pid === 9_999_994) {

982+

throw Object.assign(new Error("permission denied"), { code: "EPERM" });

983+

}

984+

return true;

985+

});

986+987+

try {

988+

registerNativeHookRelay({

989+

provider: "codex",

990+

relayId: "codex-preserve-unknown-liveness-foreign-bridge-session",

991+

sessionId: "session-1",

992+

runId: "run-1",

993+

allowedEvents: ["pre_tool_use"],

994+

});

995+996+

expect(kill).toHaveBeenCalledWith(9_999_994, 0);

997+

await expect(fs.stat(livePath)).resolves.toBeDefined();

998+

} finally {

999+

rmSync(livePath, { force: true });

1000+

}

1001+

});

1002+8551003

it("keeps direct bridge registry files private and loopback-only", async () => {

8561004

const relay = registerNativeHookRelay({

8571005

provider: "codex",