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

推荐订阅源

博客园 - 叶小钗
Last Week in AI
Last Week in AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
雷峰网
雷峰网
GbyAI
GbyAI
Hugging Face - Blog
Hugging Face - Blog
N
Netflix TechBlog - Medium
博客园 - 聂微东
Y
Y Combinator Blog
罗磊的独立博客
博客园_首页
小众软件
小众软件
有赞技术团队
有赞技术团队
爱范儿
爱范儿
F
Fortinet All Blogs
C
Check Point Blog
Google DeepMind News
Google DeepMind News
云风的 BLOG
云风的 BLOG
Apple Machine Learning Research
Apple Machine Learning Research
M
MIT News - Artificial intelligence
月光博客
月光博客
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 司徒正美
aimingoo的专栏
aimingoo的专栏

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: clear embedded runs before lifecycle end (#70187) · ...
amknight · 2026-04-23 · via Recent Commits to openclaw:main

@@ -11,6 +11,7 @@ function createContext(

1111

lastAssistant: unknown,

1212

overrides?: {

1313

onAgentEvent?: (event: unknown) => void;

14+

onBeforeLifecycleTerminal?: () => void | Promise<void>;

1415

onBlockReplyFlush?: () => void | Promise<void>;

1516

},

1617

): EmbeddedPiSubscribeContext {

@@ -21,6 +22,7 @@ function createContext(

2122

config: {},

2223

sessionKey: "agent:main:main",

2324

onAgentEvent: overrides?.onAgentEvent,

25+

onBeforeLifecycleTerminal: overrides?.onBeforeLifecycleTerminal,

2426

onBlockReply,

2527

onBlockReplyFlush: overrides?.onBlockReplyFlush,

2628

},

@@ -380,6 +382,90 @@ describe("handleAgentEnd", () => {

380382

await endPromise;

381383

});

382384385+

it("runs the before-lifecycle callback before the lifecycle end event", async () => {

386+

const order: string[] = [];

387+

const onAgentEvent = vi.fn(() => {

388+

order.push("event");

389+

});

390+

const onBeforeLifecycleTerminal = vi.fn(() => {

391+

order.push("before");

392+

});

393+

const ctx = createContext(undefined, {

394+

onAgentEvent,

395+

onBeforeLifecycleTerminal,

396+

});

397+398+

await handleAgentEnd(ctx);

399+400+

expect(order).toEqual(["before", "event"]);

401+

expect(onBeforeLifecycleTerminal).toHaveBeenCalledTimes(1);

402+

expect(onAgentEvent).toHaveBeenCalledWith({

403+

stream: "lifecycle",

404+

data: { phase: "end" },

405+

});

406+

});

407+408+

it("runs an async before-lifecycle callback before the lifecycle end event", async () => {

409+

const order: string[] = [];

410+

const onAgentEvent = vi.fn(() => {

411+

order.push("event");

412+

});

413+

const onBeforeLifecycleTerminal = vi.fn(() =>

414+

Promise.resolve().then(() => {

415+

order.push("before");

416+

}),

417+

);

418+

const ctx = createContext(undefined, {

419+

onAgentEvent,

420+

onBeforeLifecycleTerminal,

421+

});

422+423+

await handleAgentEnd(ctx);

424+425+

expect(order).toEqual(["before", "event"]);

426+

expect(onBeforeLifecycleTerminal).toHaveBeenCalledTimes(1);

427+

expect(onAgentEvent).toHaveBeenCalledWith({

428+

stream: "lifecycle",

429+

data: { phase: "end" },

430+

});

431+

});

432+433+

it("still emits lifecycle terminal when sync before-lifecycle callback throws", async () => {

434+

const onAgentEvent = vi.fn();

435+

const onBeforeLifecycleTerminal = vi.fn(() => {

436+

throw new Error("hook exploded");

437+

});

438+

const ctx = createContext(undefined, {

439+

onAgentEvent,

440+

onBeforeLifecycleTerminal,

441+

});

442+443+

await handleAgentEnd(ctx);

444+445+

expect(onBeforeLifecycleTerminal).toHaveBeenCalledTimes(1);

446+

expect(onAgentEvent).toHaveBeenCalledWith({

447+

stream: "lifecycle",

448+

data: { phase: "end" },

449+

});

450+

});

451+452+

it("still emits lifecycle terminal when async before-lifecycle callback rejects", async () => {

453+

const onAgentEvent = vi.fn();

454+

const onBeforeLifecycleTerminal = vi.fn(() => Promise.reject(new Error("hook failed")));

455+

const ctx = createContext(undefined, {

456+

onAgentEvent,

457+

onBeforeLifecycleTerminal,

458+

});

459+460+

await handleAgentEnd(ctx);

461+462+

expect(onBeforeLifecycleTerminal).toHaveBeenCalledTimes(1);

463+

expect(onAgentEvent).toHaveBeenCalledWith({

464+

stream: "lifecycle",

465+

data: { phase: "end" },

466+

});

467+

});

468+383469

it("emits lifecycle end after async channel flush completes", async () => {

384470

let resolveChannelFlush: (() => void) | undefined;

385471

const onAgentEvent = vi.fn();