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

推荐订阅源

Stack Overflow Blog
Stack Overflow Blog
量子位
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
美团技术团队
小众软件
小众软件
aimingoo的专栏
aimingoo的专栏
Recent Announcements
Recent Announcements
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Microsoft Security Blog
Microsoft Security Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
酷 壳 – CoolShell
酷 壳 – CoolShell
J
Java Code Geeks
V
V2EX
大猫的无限游戏
大猫的无限游戏
D
DataBreaches.Net
博客园 - Franky
爱范儿
爱范儿
T
Tailwind CSS Blog
A
About on SuperTechFans
Google DeepMind News
Google DeepMind News
博客园_首页
B
Blog RSS Feed
博客园 - 司徒正美
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知

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(plugins): add default timeout for before_compaction/a...
100yenadmin · 2026-05-20 · via Recent Commits to openclaw:main

@@ -0,0 +1,121 @@

1+

/**

2+

* Test: before_compaction & after_compaction void-hook default timeouts.

3+

*

4+

* Without a default budget these hooks run fully unbounded. In the codex

5+

* agent harness they fire on the serialized notification queue, so a hung

6+

* handler freezes every later codex notification — including turn/completed —

7+

* and the whole turn hangs. The runner seeds DEFAULT_VOID_HOOK_TIMEOUT_MS_BY_HOOK

8+

* with a defensive budget for both hooks; these tests assert a never-settling

9+

* handler is bounded by that default rather than hanging.

10+

*/

11+

import { beforeEach, describe, expect, it, vi } from "vitest";

12+

import { createHookRunner } from "./hooks.js";

13+

import { addTestHook, TEST_PLUGIN_AGENT_CTX } from "./hooks.test-helpers.js";

14+

import { createEmptyPluginRegistry, type PluginRegistry } from "./registry.js";

15+

import type { PluginHookRegistration } from "./types.js";

16+17+

// The defensive default applied to before_compaction / after_compaction in

18+

// DEFAULT_VOID_HOOK_TIMEOUT_MS_BY_HOOK. Kept in sync with hooks.ts.

19+

const DEFAULT_COMPACTION_HOOK_TIMEOUT_MS = 30_000;

20+21+

describe("compaction hook default timeouts", () => {

22+

let registry: PluginRegistry;

23+24+

beforeEach(() => {

25+

registry = createEmptyPluginRegistry();

26+

});

27+28+

it("bounds a never-settling before_compaction handler with the default timeout", async () => {

29+

vi.useFakeTimers();

30+

try {

31+

const handler = vi.fn(() => new Promise<void>(() => {}));

32+

addTestHook({

33+

registry,

34+

pluginId: "plugin-a",

35+

hookName: "before_compaction",

36+

handler: handler as PluginHookRegistration["handler"],

37+

});

38+

const logger = {

39+

error: vi.fn(),

40+

warn: vi.fn(),

41+

};

42+43+

// No voidHookTimeoutMsByHook override — relies on the built-in default.

44+

const runner = createHookRunner(registry, { logger });

45+

const run = runner.runBeforeCompaction({ messageCount: 3 }, TEST_PLUGIN_AGENT_CTX);

46+47+

await vi.advanceTimersByTimeAsync(DEFAULT_COMPACTION_HOOK_TIMEOUT_MS);

48+49+

await expect(run).resolves.toBeUndefined();

50+

expect(logger.error).toHaveBeenCalledWith(

51+

`[hooks] before_compaction handler from plugin-a failed: timed out after ${DEFAULT_COMPACTION_HOOK_TIMEOUT_MS}ms`,

52+

);

53+

} finally {

54+

vi.useRealTimers();

55+

}

56+

});

57+58+

it("bounds a never-settling after_compaction handler with the default timeout", async () => {

59+

vi.useFakeTimers();

60+

try {

61+

const handler = vi.fn(() => new Promise<void>(() => {}));

62+

addTestHook({

63+

registry,

64+

pluginId: "plugin-a",

65+

hookName: "after_compaction",

66+

handler: handler as PluginHookRegistration["handler"],

67+

});

68+

const logger = {

69+

error: vi.fn(),

70+

warn: vi.fn(),

71+

};

72+73+

const runner = createHookRunner(registry, { logger });

74+

const run = runner.runAfterCompaction(

75+

{ messageCount: 2, compactedCount: 1 },

76+

TEST_PLUGIN_AGENT_CTX,

77+

);

78+79+

await vi.advanceTimersByTimeAsync(DEFAULT_COMPACTION_HOOK_TIMEOUT_MS);

80+81+

await expect(run).resolves.toBeUndefined();

82+

expect(logger.error).toHaveBeenCalledWith(

83+

`[hooks] after_compaction handler from plugin-a failed: timed out after ${DEFAULT_COMPACTION_HOOK_TIMEOUT_MS}ms`,

84+

);

85+

} finally {

86+

vi.useRealTimers();

87+

}

88+

});

89+90+

it("lets a fast before_compaction handler complete without timing out", async () => {

91+

vi.useFakeTimers();

92+

try {

93+

const handler = vi.fn(

94+

async () =>

95+

await new Promise<void>((resolve) => {

96+

setTimeout(resolve, 20);

97+

}),

98+

);

99+

addTestHook({

100+

registry,

101+

pluginId: "plugin-a",

102+

hookName: "before_compaction",

103+

handler: handler as PluginHookRegistration["handler"],

104+

});

105+

const logger = {

106+

error: vi.fn(),

107+

warn: vi.fn(),

108+

};

109+110+

const runner = createHookRunner(registry, { logger });

111+

const run = runner.runBeforeCompaction({ messageCount: 3 }, TEST_PLUGIN_AGENT_CTX);

112+113+

await vi.advanceTimersByTimeAsync(20);

114+115+

await expect(run).resolves.toBeUndefined();

116+

expect(logger.error).not.toHaveBeenCalled();

117+

} finally {

118+

vi.useRealTimers();

119+

}

120+

});

121+

});