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

推荐订阅源

Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
The Last Watchdog
The Last Watchdog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
T
Troy Hunt's Blog
L
LINUX DO - 最新话题
C
Check Point Blog
T
Threat Research - Cisco Blogs
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
罗磊的独立博客
V
Vulnerabilities – Threatpost
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
J
Java Code Geeks
Apple Machine Learning Research
Apple Machine Learning Research
大猫的无限游戏
大猫的无限游戏
S
Security @ Cisco Blogs
IT之家
IT之家
T
The Exploit Database - CXSecurity.com
The GitHub Blog
The GitHub Blog
D
Docker
Engineering at Meta
Engineering at Meta
AWS News Blog
AWS News Blog
S
Security Affairs
U
Unit 42
P
Palo Alto Networks Blog
V
Visual Studio Blog
Y
Y Combinator Blog
D
DataBreaches.Net
Forbes - Security
Forbes - Security
阮一峰的网络日志
阮一峰的网络日志
美团技术团队
Security Latest
Security Latest
aimingoo的专栏
aimingoo的专栏
Simon Willison's Weblog
Simon Willison's Weblog
A
Arctic Wolf
博客园_首页
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
H
Hacker News: Front Page
博客园 - 司徒正美
博客园 - Franky
宝玉的分享
宝玉的分享
TaoSecurity Blog
TaoSecurity Blog
Latest news
Latest news
Scott Helme
Scott Helme
MongoDB | Blog
MongoDB | Blog
量子位
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
C
Cisco Blogs
P
Privacy International News Feed
Application and Cybersecurity Blog
Application and Cybersecurity 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 test: trim doctor command hotspots · openclaw/openclaw@c66f16a test: isolate agent auth and spawn hotspots · openclaw/openclaw@9285935 test: stabilize MCP startup disposal race · openclaw/openclaw@dd9d2eb test: merge browser contract server suites · openclaw/openclaw@5817a76 test: narrow ollama provider discovery setup · openclaw/openclaw@a0d9598 build: declare qa-lab aimock runtime dependency · openclaw/openclaw@24431e5 test: speed up safe-bins exec harness · openclaw/openclaw@ee856ab test: preserve tool helpers in embedded runner mocks · openclaw/openclaw@acd86a0 refactor: move memory embeddings into provider plugins · openclaw/openclaw@77e6e4c test: reuse system-run temp fixtures · openclaw/openclaw@7e9ff0f test: trim hotspot wait overhead · openclaw/openclaw@12a59b0 Check: avoid duplicate boundary prep · openclaw/openclaw@baf11b8 test: reduce hotspot fixture overhead · openclaw/openclaw@3a59edd feat(ui): overhaul settings and slash command UX (#67819) thanks @Bun… · openclaw/openclaw@2cfb660 QA Matrix: exit cleanly on failure · openclaw/openclaw@42805d2 QA Matrix: isolate scenario coverage · openclaw/openclaw@7e659e1 Matrix: refresh crypto bootstrap state · openclaw/openclaw@94081d8 QA Lab: add provider registry · openclaw/openclaw@bb7e982 Matrix: add plugin changelog · openclaw/openclaw@4acab55 test: trim more hotspot overhead · openclaw/openclaw@f485311 test: trim remaining hotspot tests · openclaw/openclaw@6ba8626 test: narrow hotspot mocks · openclaw/openclaw@dbc8179 test: isolate gemini embedding request helpers · openclaw/openclaw@cd330f5 test: trim memory and mcp hotspots · openclaw/openclaw@fd48dfa test: slim provider registry mocks · openclaw/openclaw@2e08c77 test: harden Parallels update smoke · openclaw/openclaw@1a98090 feat: default Anthropic to Opus 4.7 · openclaw/openclaw@628b454 fix: harden node-host shell payload mutability checks · openclaw/openclaw@75c551e fix: land node-host approval binding for native binaries (#66731) (th… · openclaw/openclaw@29919bb CI: add daily schedule to CodeQL workflow (#67645) · openclaw/openclaw@69d25f5 fix(gateway): capture config hash after plugin auto-enable to prevent… · openclaw/openclaw@8c11210 fix: repair sanitized replay tool results before send (#67620) (thank… · openclaw/openclaw@c3c7a99 fix: restrict HTML timeout short-circuit to transient statuses · openclaw/openclaw@de129a6 fix: keep TUI watchdog bound to active run (#67401) (thanks @xantorres) · openclaw/openclaw@3525273 Gateway/skills: dedupe skills prefix-match + drop dead fallback on log · openclaw/openclaw@d7f489f Extensions/lmstudio: back off inference preload after consecutive fai… · openclaw/openclaw@b555214 TUI/streaming: add watchdog that resets the activity indicator after … · openclaw/openclaw@f44ab20 Agents/tool-loop: enable unknown-tool stream guard by default · openclaw/openclaw@36ed367 Gateway/skills: invalidate session skills snapshot on config write · openclaw/openclaw@b23d59a fix: classify HTML provider error pages correctly (#67642) (thanks @s… · openclaw/openclaw@e588e90 fix(skills): remove unused model-usage import (#67641) · openclaw/openclaw@55f05df docs(changelog): credit codex fix superseded PRs · openclaw/openclaw@e485f24 fix(openai-codex): normalize stale transport metadata in resolution a… · openclaw/openclaw@90801ba CI: pin Docker-related GitHub Actions (#67632) · openclaw/openclaw@f697b01 Android: modernize WebView and discovery API usage (#67627) · openclaw/openclaw@44a6e50 fix(deps): bump hono to 4.12.14 and @hono/node-server to 1.19.14 (GHS… · openclaw/openclaw@fbccc18 fix(deps): bump dompurify to 3.4.0 (#67614) · openclaw/openclaw@2c2dc00 CI: add explicit permissions to all workflow jobs (fixes code-scannin… · openclaw/openclaw@01b7516 fix: register bundled TTS providers and route overrides correctly (#6… · openclaw/openclaw@6ea3cdd fix: align host tilde paths with OS home (#62804) (thanks @stainlu) · openclaw/openclaw@ecfaf64 fix: flush creds queue before reconnect socket open (#67464) (thanks … · openclaw/openclaw@405c63f fix: strip standalone <function> tool call tags from visible text (#6… · openclaw/openclaw@78df859 fix(agents): preserve cli session metadata before transcript persist … · openclaw/openclaw@898fd04 docs(changelog): move cli transcript entry · openclaw/openclaw@c1817c6 fix(agents): normalize cli transcript api field · openclaw/openclaw@3a3fae0 docs(changelog): note cli transcript persistence · openclaw/openclaw@6c343f1 fix(agents): persist cli transcript turns · openclaw/openclaw@b8ef507 fix(msteams): harden security-sensitive flows (#65841) · openclaw/openclaw@c56b56e [Dashboard] Fix exec approval modal overflow for long command content… · openclaw/openclaw@053c5b0 Docs: remove QA changelog entry · openclaw/openclaw@7fd5771 QA: fix private runtime source loading (#67428) · openclaw/openclaw@d5933af docs(gateway): correct protocol.md schema path, hello-ok example, aut… · openclaw/openclaw@489404d CI: pin Node 22 runners to 22.18.0 · openclaw/openclaw@4ffa621 models.authStatus: normalize provider ids + tighten env-backed escape… · openclaw/openclaw@f2fdb9d Update CHANGELOG.md · openclaw/openclaw@7694a92 test(parallels): clean up npm update guard jobs · openclaw/openclaw@045ea7b Plugins: prefer scanDir override paths · openclaw/openclaw@b2974da fix(dreaming): default storage.mode to "separate" so phase blocks sto… · openclaw/openclaw@8c392f0 fix(memory-core): skip dreaming transcript ingestion via session stor… · openclaw/openclaw@a1b01f0 fix: dedupe replayed exec.finished node events (#67281) · openclaw/openclaw@5dcf526
fix(gateway): preserve fresh agent session state · openclaw/openclaw@6f41653
CodeReclaime · 2026-05-23 · via Recent Commits to openclaw:main

@@ -40,7 +40,13 @@ const mocks = vi.hoisted(() => ({

4040

loadConfigReturn: {} as Record<string, unknown>,

4141

loadVoiceWakeRoutingConfig: vi.fn(),

4242

resolveVoiceWakeRouteByTrigger: vi.fn(),

43-

resolveSendPolicy: vi.fn(() => "allow"),

43+

resolveSendPolicy: vi.fn((_args?: { entry?: { sendPolicy?: string } }) => "allow"),

44+

resolveSessionLifecycleTimestamps: vi.fn(

45+

({ entry }: { entry?: { sessionStartedAt?: number; lastInteractionAt?: number } }) => ({

46+

sessionStartedAt: entry?.sessionStartedAt,

47+

lastInteractionAt: entry?.lastInteractionAt,

48+

}),

49+

),

4450

}));

45514652

vi.mock("../session-utils.js", async () => {

@@ -59,6 +65,7 @@ vi.mock("../../config/sessions.js", async () => {

5965

return {

6066

...actual,

6167

updateSessionStore: mocks.updateSessionStore,

68+

resolveSessionLifecycleTimestamps: mocks.resolveSessionLifecycleTimestamps,

6269

resolveAgentIdFromSessionKey: (sessionKey: string) => {

6370

const m = /^agent:([^:]+):/.exec(sessionKey.trim());

6471

return m?.[1] ?? "main";

@@ -497,6 +504,14 @@ describe("gateway agent handler", () => {

497504

mocks.resolveBareResetBootstrapFileAccess.mockReset().mockReturnValue(true);

498505

mocks.listAgentIds.mockReset().mockReturnValue(["main"]);

499506

mocks.resolveSendPolicy.mockReset().mockReturnValue("allow");

507+

mocks.resolveSessionLifecycleTimestamps

508+

.mockReset()

509+

.mockImplementation(

510+

({ entry }: { entry?: { sessionStartedAt?: number; lastInteractionAt?: number } }) => ({

511+

sessionStartedAt: entry?.sessionStartedAt,

512+

lastInteractionAt: entry?.lastInteractionAt,

513+

}),

514+

);

500515

dateOnlyFakeClockActive = false;

501516

vi.useRealTimers();

502517

resetExecApprovalFollowupRuntimeHandoffsForTests();

@@ -1021,6 +1036,344 @@ describe("gateway agent handler", () => {

10211036

expect(capturedEntry.cliSessionIds).toEqual(existingCliSessionIds);

10221037

expect(capturedEntry.claudeCliSessionId).toBe(existingClaudeCliSessionId);

10231038

});

1039+

// #5369: sessions.patch can write modelOverride to the session store between

1040+

// when the agent handler reads its cached entry and when updateSessionStore

1041+

// runs. The handler's loadSessionEntry may return the stale pre-patch entry

1042+

// (no modelOverride), while the store-load inside updateSessionStore has the

1043+

// fresh value. If the patch built from the stale entry carries modelOverride:

1044+

// undefined, the merge {...fresh, ...patch} clobbers the fresh value.

1045+

it("preserves fresh modelOverride when cached entry is stale (#5369)", async () => {

1046+

mocks.loadSessionEntry.mockReturnValue({

1047+

cfg: {},

1048+

storePath: "/tmp/sessions.json",

1049+

entry: {

1050+

sessionId: "subagent-session-id",

1051+

updatedAt: Date.now() - 1000,

1052+

// modelOverride absent — stale pre-patch view

1053+

},

1054+

canonicalKey: "agent:main:subagent:test-uuid",

1055+

});

1056+

let capturedEntry: Record<string, unknown> | undefined;

1057+

mocks.updateSessionStore.mockImplementation(async (_path, updater) => {

1058+

const freshStore: Record<string, Record<string, unknown>> = {

1059+

"agent:main:subagent:test-uuid": {

1060+

sessionId: "subagent-session-id",

1061+

updatedAt: Date.now(),

1062+

modelOverride: "qwen3-coder:30b",

1063+

providerOverride: "ollama",

1064+

},

1065+

};

1066+

const result = await updater(freshStore);

1067+

capturedEntry = freshStore["agent:main:subagent:test-uuid"];

1068+

return result;

1069+

});

1070+

mocks.agentCommand.mockResolvedValue({

1071+

payloads: [{ text: "ok" }],

1072+

meta: { durationMs: 100 },

1073+

});

1074+

await invokeAgent(

1075+

{

1076+

message: "hi",

1077+

agentId: "main",

1078+

sessionKey: "agent:main:subagent:test-uuid",

1079+

idempotencyKey: "test-5369-race",

1080+

},

1081+

{ reqId: "race-1" },

1082+

);

1083+

expect(capturedEntry?.modelOverride).toBe("qwen3-coder:30b");

1084+

expect(capturedEntry?.providerOverride).toBe("ollama");

1085+

});

1086+

// Broader regression guard for the #5369 stale-writeback class: any field

1087+

// that the patch blindly carries from the cached entry will clobber a fresh

1088+

// concurrent write. The fix dropped all such fields from the patch; this

1089+

// test ensures none get silently re-added. If a future change puts e.g.

1090+

// `sendPolicy: entry?.sendPolicy` back into the patch, this test fails.

1091+

it("preserves all fresh session fields when cached entry is stale (#5369 broader)", async () => {

1092+

mocks.loadSessionEntry.mockReturnValue({

1093+

cfg: {},

1094+

storePath: "/tmp/sessions.json",

1095+

entry: {

1096+

sessionId: "subagent-session-id",

1097+

updatedAt: Date.now() - 1000,

1098+

// All fields below absent — stale pre-patch view

1099+

},

1100+

canonicalKey: "agent:main:subagent:test-broader",

1101+

});

1102+

const freshFields = {

1103+

sendPolicy: "allow",

1104+

skillsSnapshot: { tools: ["bash"] },

1105+

thinkingLevel: "high",

1106+

fastMode: true,

1107+

verboseLevel: "detailed",

1108+

traceLevel: "info",

1109+

reasoningLevel: "on",

1110+

systemSent: true,

1111+

spawnedWorkspaceDir: "/work/fresh",

1112+

spawnDepth: 2,

1113+

label: "fresh-label",

1114+

spawnedBy: "agent:main:main",

1115+

channel: "telegram",

1116+

deliveryContext: {

1117+

channel: "telegram",

1118+

to: "12345",

1119+

accountId: "acct-1",

1120+

threadId: 42,

1121+

},

1122+

lastChannel: "telegram",

1123+

lastTo: "12345",

1124+

lastAccountId: "acct-1",

1125+

lastThreadId: 42,

1126+

cliSessionIds: { "claude-cli": "fresh-cli-id" },

1127+

cliSessionBindings: { "claude-cli": { sessionId: "fresh-binding" } },

1128+

claudeCliSessionId: "fresh-cli-id",

1129+

};

1130+

let capturedEntry: Record<string, unknown> | undefined;

1131+

mocks.updateSessionStore.mockImplementation(async (_path, updater) => {

1132+

const freshStore: Record<string, Record<string, unknown>> = {

1133+

"agent:main:subagent:test-broader": {

1134+

sessionId: "subagent-session-id",

1135+

updatedAt: Date.now(),

1136+

...freshFields,

1137+

},

1138+

};

1139+

const result = await updater(freshStore);

1140+

capturedEntry = freshStore["agent:main:subagent:test-broader"];

1141+

return result;

1142+

});

1143+

mocks.agentCommand.mockResolvedValue({

1144+

payloads: [{ text: "ok" }],

1145+

meta: { durationMs: 100 },

1146+

});

1147+

await invokeAgent(

1148+

{

1149+

message: "hi",

1150+

agentId: "main",

1151+

sessionKey: "agent:main:subagent:test-broader",

1152+

idempotencyKey: "test-5369-broader",

1153+

},

1154+

{ reqId: "broader-1" },

1155+

);

1156+

for (const [field, expected] of Object.entries(freshFields)) {

1157+

expect(capturedEntry?.[field]).toEqual(expected);

1158+

}

1159+

});

1160+

it("checks delivery sendPolicy against the fresh store entry (#5369)", async () => {

1161+

mocks.loadSessionEntry.mockReturnValue({

1162+

cfg: {},

1163+

storePath: "/tmp/sessions.json",

1164+

entry: {

1165+

sessionId: "subagent-session-id",

1166+

updatedAt: Date.now() - 1000,

1167+

// sendPolicy absent — stale pre-patch view

1168+

},

1169+

canonicalKey: "agent:main:subagent:test-policy",

1170+

});

1171+

const freshUpdatedAt = Date.now();

1172+

let capturedEntry: Record<string, unknown> | undefined;

1173+

mocks.updateSessionStore.mockImplementation(async (_path, updater) => {

1174+

const freshStore: Record<string, Record<string, unknown>> = {

1175+

"agent:main:subagent:test-policy": {

1176+

sessionId: "subagent-session-id",

1177+

updatedAt: freshUpdatedAt,

1178+

sendPolicy: "deny",

1179+

channel: "telegram",

1180+

},

1181+

};

1182+

const result = await updater(freshStore);

1183+

capturedEntry = freshStore["agent:main:subagent:test-policy"];

1184+

return result;

1185+

});

1186+

mocks.resolveSendPolicy.mockImplementation((args?: { entry?: { sendPolicy?: string } }) =>

1187+

args?.entry?.sendPolicy === "deny" ? "deny" : "allow",

1188+

);

1189+

mocks.agentCommand.mockClear();

1190+

mocks.agentCommand.mockResolvedValue({

1191+

payloads: [{ text: "ok" }],

1192+

meta: { durationMs: 100 },

1193+

});

1194+

const respond = vi.fn();

1195+

await invokeAgent(

1196+

{

1197+

message: "hi",

1198+

agentId: "main",

1199+

sessionKey: "agent:main:subagent:test-policy",

1200+

channel: "telegram",

1201+

to: "99999",

1202+

deliver: true,

1203+

idempotencyKey: "test-5369-policy",

1204+

},

1205+

{ reqId: "policy-1", respond },

1206+

);

1207+

expectRespondError(respond, { message: "send blocked by session policy" });

1208+

const sendPolicyArgs = expectRecordFields(mockCallArg(mocks.resolveSendPolicy), {

1209+

sessionKey: "agent:main:subagent:test-policy",

1210+

});

1211+

expectRecordFields(sendPolicyArgs.entry, { sendPolicy: "deny" });

1212+

expectRecordFields(capturedEntry, {

1213+

sessionId: "subagent-session-id",

1214+

updatedAt: freshUpdatedAt,

1215+

sendPolicy: "deny",

1216+

channel: "telegram",

1217+

deliveryContext: undefined,

1218+

lastTo: undefined,

1219+

});

1220+

expect(mocks.agentCommand).not.toHaveBeenCalled();

1221+

});

1222+

it("does not restore a stale session id over a fresh store rotation (#5369)", async () => {

1223+

mocks.resolveSessionLifecycleTimestamps.mockImplementation(

1224+

({ entry }: { entry?: { sessionId?: string; sessionStartedAt?: number } }) => ({

1225+

sessionStartedAt: entry?.sessionId === "old-session-id" ? 123 : entry?.sessionStartedAt,

1226+

lastInteractionAt: undefined,

1227+

}),

1228+

);

1229+

mocks.loadSessionEntry.mockReturnValue({

1230+

cfg: {},

1231+

storePath: "/tmp/sessions.json",

1232+

entry: {

1233+

sessionId: "old-session-id",

1234+

updatedAt: Date.now() - 1000,

1235+

},

1236+

canonicalKey: "agent:main:subagent:test-rotation",

1237+

});

1238+

let capturedEntry: Record<string, unknown> | undefined;

1239+

mocks.updateSessionStore.mockImplementation(async (_path, updater) => {

1240+

const freshStore: Record<string, Record<string, unknown>> = {

1241+

"agent:main:subagent:test-rotation": {

1242+

sessionId: "fresh-session-id",

1243+

updatedAt: Date.now(),

1244+

status: "running",

1245+

startedAt: 111,

1246+

sessionFile: "/tmp/fresh-session.jsonl",

1247+

},

1248+

};

1249+

const result = await updater(freshStore);

1250+

capturedEntry = freshStore["agent:main:subagent:test-rotation"];

1251+

return result;

1252+

});

1253+

mocks.agentCommand.mockResolvedValue({

1254+

payloads: [{ text: "ok" }],

1255+

meta: { durationMs: 100 },

1256+

});

1257+1258+

await invokeAgent(

1259+

{

1260+

message: "hi",

1261+

agentId: "main",

1262+

sessionKey: "agent:main:subagent:test-rotation",

1263+

idempotencyKey: "test-5369-rotation",

1264+

},

1265+

{ reqId: "rotation-1" },

1266+

);

1267+1268+

expectRecordFields(capturedEntry, {

1269+

sessionId: "fresh-session-id",

1270+

status: "running",

1271+

startedAt: 111,

1272+

sessionStartedAt: undefined,

1273+

sessionFile: "/tmp/fresh-session.jsonl",

1274+

});

1275+

});

1276+

// Upgrade-path self-heal: a legacy session entry may lack sessionStartedAt

1277+

// because the field was added after the entry was first persisted. The

1278+

// handler recovers it from the transcript JSONL header and writes it back,

1279+

// but only when the fresh store still lacks the field — so a concurrent

1280+

// writer that sets it cannot be clobbered (the #5369 stale-writeback class).

1281+

it("self-heals missing sessionStartedAt from JSONL when fresh store also lacks it", async () => {

1282+

// Use a value distinct from `now` but recent enough that

1283+

// evaluateSessionFreshness — which also calls the mocked

1284+

// resolveSessionLifecycleTimestamps — keeps this session fresh.

1285+

const recoveredStartedAt = Date.now() - 5_000;

1286+

mocks.loadSessionEntry.mockReturnValue({

1287+

cfg: {},

1288+

storePath: "/tmp/sessions.json",

1289+

entry: {

1290+

sessionId: "legacy-session-id",

1291+

updatedAt: Date.now() - 1000,

1292+

// sessionStartedAt absent — legacy schema

1293+

},

1294+

canonicalKey: "agent:main:subagent:legacy",

1295+

});

1296+

mocks.resolveSessionLifecycleTimestamps.mockReturnValue({

1297+

sessionStartedAt: recoveredStartedAt,

1298+

lastInteractionAt: undefined,

1299+

});

1300+

let capturedEntry: Record<string, unknown> | undefined;

1301+

mocks.updateSessionStore.mockImplementation(async (_path, updater) => {

1302+

const freshStore: Record<string, Record<string, unknown>> = {

1303+

"agent:main:subagent:legacy": {

1304+

sessionId: "legacy-session-id",

1305+

updatedAt: Date.now(),

1306+

// sessionStartedAt absent on disk too — self-heal should fire

1307+

},

1308+

};

1309+

const result = await updater(freshStore);

1310+

capturedEntry = freshStore["agent:main:subagent:legacy"];

1311+

return result;

1312+

});

1313+

mocks.agentCommand.mockResolvedValue({

1314+

payloads: [{ text: "ok" }],

1315+

meta: { durationMs: 100 },

1316+

});

1317+

await invokeAgent(

1318+

{

1319+

message: "hi",

1320+

agentId: "main",

1321+

sessionKey: "agent:main:subagent:legacy",

1322+

idempotencyKey: "test-selfheal-write",

1323+

},

1324+

{ reqId: "selfheal-1" },

1325+

);

1326+

expect(capturedEntry?.sessionStartedAt).toBe(recoveredStartedAt);

1327+

});

1328+

it("does not clobber fresh sessionStartedAt with the recovered candidate", async () => {

1329+

// See note in the prior test: keep both values recent so freshness

1330+

// evaluation (which also reads the lifecycle mock) doesn't trip the

1331+

// idle-reset path and turn this into an isNewSession path.

1332+

const recoveredStartedAt = Date.now() - 5_000;

1333+

const freshStartedAt = Date.now() - 2_500;

1334+

mocks.loadSessionEntry.mockReturnValue({

1335+

cfg: {},

1336+

storePath: "/tmp/sessions.json",

1337+

entry: {

1338+

sessionId: "legacy-session-id",

1339+

updatedAt: Date.now() - 1000,

1340+

// sessionStartedAt absent in cached entry — would trigger recovery

1341+

},

1342+

canonicalKey: "agent:main:subagent:concurrent",

1343+

});

1344+

mocks.resolveSessionLifecycleTimestamps.mockReturnValue({

1345+

sessionStartedAt: recoveredStartedAt,

1346+

lastInteractionAt: undefined,

1347+

});

1348+

let capturedEntry: Record<string, unknown> | undefined;

1349+

mocks.updateSessionStore.mockImplementation(async (_path, updater) => {

1350+

const freshStore: Record<string, Record<string, unknown>> = {

1351+

"agent:main:subagent:concurrent": {

1352+

sessionId: "legacy-session-id",

1353+

updatedAt: Date.now(),

1354+

// Concurrent writer set sessionStartedAt between cache load and lock

1355+

sessionStartedAt: freshStartedAt,

1356+

},

1357+

};

1358+

const result = await updater(freshStore);

1359+

capturedEntry = freshStore["agent:main:subagent:concurrent"];

1360+

return result;

1361+

});

1362+

mocks.agentCommand.mockResolvedValue({

1363+

payloads: [{ text: "ok" }],

1364+

meta: { durationMs: 100 },

1365+

});

1366+

await invokeAgent(

1367+

{

1368+

message: "hi",

1369+

agentId: "main",

1370+

sessionKey: "agent:main:subagent:concurrent",

1371+

idempotencyKey: "test-selfheal-noclobber",

1372+

},

1373+

{ reqId: "selfheal-2" },

1374+

);

1375+

expect(capturedEntry?.sessionStartedAt).toBe(freshStartedAt);

1376+

});

10241377

it("reactivates completed subagent sessions and broadcasts send updates", async () => {

10251378

const childSessionKey = "agent:main:subagent:followup";

10261379

const completedRun = {

@@ -3471,7 +3824,7 @@ describe("gateway agent handler", () => {

34713824

let capturedEntry: Record<string, unknown> | undefined;

34723825

mocks.updateSessionStore.mockImplementation(async (_path, updater) => {

34733826

const store: Record<string, unknown> = {

3474-

[sessionKey]: { sessionId: "existing-session-id" },

3827+

[sessionKey]: { sessionId: "existing-session-id", ...entry },

34753828

};

34763829

await updater(store);

34773830

capturedEntry = store[sessionKey] as Record<string, unknown>;