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

推荐订阅源

Engineering at Meta
Engineering at Meta
Microsoft Azure Blog
Microsoft Azure Blog
I
InfoQ
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
人人都是产品经理
人人都是产品经理
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
Tailwind CSS Blog
MongoDB | Blog
MongoDB | Blog
Google DeepMind News
Google DeepMind News
WordPress大学
WordPress大学
量子位
美团技术团队
大猫的无限游戏
大猫的无限游戏
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Last Week in AI
Last Week in AI
博客园 - 司徒正美
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
小众软件
小众软件
C
Check Point Blog
博客园 - 三生石上(FineUI控件)
N
Netflix TechBlog - Medium
Recent Announcements
Recent Announcements
有赞技术团队
有赞技术团队
月光博客
月光博客

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(heartbeat): route outbound mirror to isolated session...
openclaw-clo · 2026-06-14 · via Recent Commits to openclaw:main
1+

// Covers isolated heartbeat outbound session routing and base-session bookkeeping.

2+

import fs from "node:fs/promises";

3+

import path from "node:path";

4+

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

5+

import type { OpenClawConfig } from "../config/config.js";

6+

import { resolveMainSessionKey } from "../config/sessions.js";

7+

import { runHeartbeatOnce } from "./heartbeat-runner.js";

8+

import { installHeartbeatRunnerTestRuntime } from "./heartbeat-runner.test-harness.js";

9+

import { seedSessionStore, withTempHeartbeatSandbox } from "./heartbeat-runner.test-utils.js";

10+11+

const deliverOutboundPayloadsInternal = vi.hoisted(() =>

12+

vi.fn().mockResolvedValue([{ channel: "whatsapp", messageId: "msg-1" }]),

13+

);

14+15+

vi.mock("./outbound/deliver.js", () => ({

16+

deliverOutboundPayloads: deliverOutboundPayloadsInternal,

17+

deliverOutboundPayloadsInternal,

18+

}));

19+20+

installHeartbeatRunnerTestRuntime();

21+22+

afterEach(() => {

23+

deliverOutboundPayloadsInternal.mockClear();

24+

});

25+26+

type DeliveryRequest = {

27+

channel?: string;

28+

to?: string;

29+

session?: {

30+

key?: string;

31+

policyKey?: string;

32+

};

33+

};

34+35+

function latestDeliveryRequest(): DeliveryRequest {

36+

const [request] = deliverOutboundPayloadsInternal.mock.calls.at(-1) ?? [];

37+

if (!request || typeof request !== "object") {

38+

throw new Error("expected heartbeat delivery request");

39+

}

40+

return request as DeliveryRequest;

41+

}

42+43+

function makeIsolatedLastTargetConfig(tmpDir: string, storePath: string): OpenClawConfig {

44+

return {

45+

agents: {

46+

list: [{ id: "main", default: true }],

47+

defaults: {

48+

workspace: tmpDir,

49+

heartbeat: {

50+

every: "5m",

51+

target: "last",

52+

isolatedSession: true,

53+

},

54+

},

55+

},

56+

channels: { whatsapp: { allowFrom: ["*"] } },

57+

session: { store: storePath },

58+

};

59+

}

60+61+

describe("runHeartbeatOnce - isolated heartbeat outbound session mirror", () => {

62+

it("uses the isolated run key for outbound delivery while base session owns target and state", async () => {

63+

await withTempHeartbeatSandbox(async ({ tmpDir, storePath, replySpy }) => {

64+

const cfg = makeIsolatedLastTargetConfig(tmpDir, storePath);

65+

const baseSessionKey = resolveMainSessionKey(cfg);

66+

const isolatedSessionKey = `${baseSessionKey}:heartbeat`;

67+

const nowMs = Date.now();

68+

await fs.writeFile(

69+

path.join(tmpDir, "HEARTBEAT.md"),

70+

`tasks:

71+

- name: check-in

72+

interval: 5m

73+

prompt: "Check whether the user needs a status update."

74+

`,

75+

"utf-8",

76+

);

77+

await seedSessionStore(storePath, baseSessionKey, {

78+

sessionId: "base-session",

79+

updatedAt: nowMs - 1_000,

80+

lastChannel: "whatsapp",

81+

lastProvider: "whatsapp",

82+

lastTo: "+15551234567",

83+

});

84+

replySpy.mockResolvedValueOnce({ text: "Status needs attention." });

85+86+

const result = await runHeartbeatOnce({

87+

cfg,

88+

deps: {

89+

getReplyFromConfig: replySpy,

90+

getQueueSize: () => 0,

91+

nowMs: () => nowMs,

92+

},

93+

});

94+95+

expect(result.status).toBe("ran");

96+

expect(replySpy.mock.calls[0]?.[0]).toMatchObject({

97+

SessionKey: isolatedSessionKey,

98+

});

99+

const deliveryRequest = latestDeliveryRequest();

100+

expect(deliveryRequest).toMatchObject({

101+

channel: "whatsapp",

102+

to: "+15551234567",

103+

session: {

104+

key: isolatedSessionKey,

105+

policyKey: baseSessionKey,

106+

},

107+

});

108+109+

const store = JSON.parse(await fs.readFile(storePath, "utf-8")) as Record<

110+

string,

111+

{

112+

heartbeatTaskState?: Record<string, number>;

113+

lastHeartbeatText?: string;

114+

lastHeartbeatSentAt?: number;

115+

heartbeatIsolatedBaseSessionKey?: string;

116+

}

117+

>;

118+

expect(store[baseSessionKey]).toMatchObject({

119+

heartbeatTaskState: { "check-in": nowMs },

120+

lastHeartbeatText: "Status needs attention.",

121+

lastHeartbeatSentAt: nowMs,

122+

});

123+

expect(store[isolatedSessionKey]).toMatchObject({

124+

heartbeatIsolatedBaseSessionKey: baseSessionKey,

125+

});

126+

expect(store[isolatedSessionKey]?.heartbeatTaskState).toBeUndefined();

127+

expect(store[isolatedSessionKey]?.lastHeartbeatText).toBeUndefined();

128+

});

129+

});

130+131+

it("keeps the base policy key when wake re-entry starts from the isolated key", async () => {

132+

await withTempHeartbeatSandbox(async ({ tmpDir, storePath, replySpy }) => {

133+

const cfg = makeIsolatedLastTargetConfig(tmpDir, storePath);

134+

const baseSessionKey = resolveMainSessionKey(cfg);

135+

const isolatedSessionKey = `${baseSessionKey}:heartbeat`;

136+

const nowMs = Date.now();

137+138+

await fs.writeFile(

139+

storePath,

140+

JSON.stringify({

141+

[isolatedSessionKey]: {

142+

sessionId: "isolated-session",

143+

updatedAt: nowMs - 1_000,

144+

lastChannel: "whatsapp",

145+

lastProvider: "whatsapp",

146+

lastTo: "+15551234567",

147+

heartbeatIsolatedBaseSessionKey: baseSessionKey,

148+

},

149+

}),

150+

"utf-8",

151+

);

152+

replySpy.mockResolvedValueOnce({ text: "Wake result needs attention." });

153+154+

const result = await runHeartbeatOnce({

155+

cfg,

156+

sessionKey: isolatedSessionKey,

157+

deps: {

158+

getReplyFromConfig: replySpy,

159+

getQueueSize: () => 0,

160+

nowMs: () => nowMs,

161+

},

162+

});

163+164+

expect(result.status).toBe("ran");

165+

expect(replySpy.mock.calls[0]?.[0]).toMatchObject({

166+

SessionKey: isolatedSessionKey,

167+

});

168+

expect(latestDeliveryRequest()).toMatchObject({

169+

channel: "whatsapp",

170+

to: "+15551234567",

171+

session: {

172+

key: isolatedSessionKey,

173+

policyKey: baseSessionKey,

174+

},

175+

});

176+

});

177+

});

178+

});