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

推荐订阅源

L
LINUX DO - 热门话题
T
The Blog of Author Tim Ferriss
WordPress大学
WordPress大学
酷 壳 – CoolShell
酷 壳 – CoolShell
美团技术团队
博客园 - 叶小钗
李成银的技术随笔
V
Visual Studio Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Apple Machine Learning Research
Apple Machine Learning Research
Hugging Face - Blog
Hugging Face - Blog
V
V2EX
博客园 - 司徒正美
Blog — PlanetScale
Blog — PlanetScale
大猫的无限游戏
大猫的无限游戏
T
Tailwind CSS Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
aimingoo的专栏
aimingoo的专栏
人人都是产品经理
人人都是产品经理
GbyAI
GbyAI
A
About on SuperTechFans
罗磊的独立博客
W
WeLiveSecurity
L
LINUX DO - 最新话题
M
MIT News - Artificial intelligence
Hacker News: Ask HN
Hacker News: Ask HN
Application and Cybersecurity Blog
Application and Cybersecurity Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
P
Proofpoint News Feed
Microsoft Security Blog
Microsoft Security Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
H
Help Net Security
Martin Fowler
Martin Fowler
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
www.infosecurity-magazine.com
www.infosecurity-magazine.com
The Register - Security
The Register - Security
M
Microsoft Research Blog - Microsoft Research
Hacker News - Newest:
Hacker News - Newest: "LLM"
博客园 - Franky
The Cloudflare Blog
C
Cisco Blogs
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Google Online Security Blog
Google Online Security Blog
有赞技术团队
有赞技术团队
AWS News Blog
AWS News Blog
C
Cybersecurity and Infrastructure Security Agency CISA
小众软件
小众软件
I
Intezer
N
Netflix TechBlog - Medium
N
News and Events Feed by Topic

Recent Commits to openclaw:main

docs(channels): document ackReactionScope for Slack & Telegram (DM go… · openclaw/openclaw@bbbed26 build(pnpm): use packageManager as pnpm source ci: export Crabbox hydrate pnpm layout · openclaw/openclaw@f6840ac fix(gateway): attribute agent wait timeouts ci: keep Crabbox hydrate runs reusable · openclaw/openclaw@489ea84 Speed up /models browse replies (#84735) · openclaw/openclaw@936dfaa docs: update changelog for plugin binding command escape (#85188) · openclaw/openclaw@9fc5346 Let binding commands escape plugin routes · openclaw/openclaw@af12082 ci: fix Crabbox hydrate pnpm modules dir · openclaw/openclaw@c9b17c5 Restore Control UI gateway token pairing [AI] (#85459) · openclaw/openclaw@10cb0a5 fix(docker): accept single-object pnpm list output · openclaw/openclaw@5e97045 fix: apply docs sweep updates · openclaw/openclaw@59aef2f fix(update): roll back failed git updates · openclaw/openclaw@769fd0b test(docker): expect prod store seed command fix(agents): bound embedded compaction write locks · openclaw/openclaw@46de078 fix(update): repair managed npm plugin peers · openclaw/openclaw@571f364 fix(update): repair managed npm plugin peers (#83794) (thanks @fuller… · openclaw/openclaw@de8a82a fix(telegram): honor table mode in outbound chunks (#85455) · openclaw/openclaw@7fc691a fix(docker): precreate owned named volume targets (#85454) · openclaw/openclaw@d8b9736 fix(ui): strip ANSI from displayed gateway logs (#85453) · openclaw/openclaw@664611c fix(skills): accept macos os requirement on darwin (#85451) fix(gateway): preserve message-tool replies in chat history test: track Docker prod store seed command · openclaw/openclaw@9a816f4 fix: satisfy prod store package list lint · openclaw/openclaw@d5247d0 test(plugins): clear lookup metadata memo fix(docker): seed prod store before offline prune · openclaw/openclaw@6788aa1 fix(memory): expand home paths in extra memory paths (#85449) · openclaw/openclaw@48bf037 docs: add security FAQ guidance chore(deps): refresh npm shrinkwraps docs: clarify OpenAI HTTP client guidance docs: remove stale showcase intro videos · openclaw/openclaw@00d3dca fix(gateway): point model override error to config docs docs: document secrets provider plan fields docs: clarify media directive formatting · openclaw/openclaw@c876fec docs: align memory search cache default refactor(ios): centralize setup auth parsing test(release): wait for config reload log proof refactor(ios): consolidate manual auth override inputs · openclaw/openclaw@d93c597 fix(ui): hide thinking options for non-reasoning models (#85406) · openclaw/openclaw@bb4d88e fix(ui): attach pasted data image text (#85392) · openclaw/openclaw@a03a8d9 fix(gateway): preserve OpenAI usage aliases in chat history (#85383) · openclaw/openclaw@d9c6c5f feat(ios): add realtime talk relay mode · openclaw/openclaw@e730e9b fix(browser): hint WSL portproxy CDP empty replies (#85379) · openclaw/openclaw@933f01c fix(installer): persist portable Git on Windows · openclaw/openclaw@5b90a48 fix(opencode-go): strip Kimi reasoning replay fields (#85377) · openclaw/openclaw@d22bcfc fix(build): normalize cache paths on Windows (#85437) · openclaw/openclaw@81d22c8 fix(update): detect nested macOS gateway ancestry (#85391) · openclaw/openclaw@adc6adc fix(docker): seed offline prune store in runtime stage · openclaw/openclaw@faf2a6c fix(ci): stabilize npm shrinkwrap metadata · openclaw/openclaw@21bedd3 fix(codex): route node exec through OpenClaw tools · openclaw/openclaw@5cc0dbc test(installer): track portable node root helper · openclaw/openclaw@9364b21 fix(ui): sync talk transcript translations fix(ui): localize talk transcript labels · openclaw/openclaw@8fc48af fix(release): stabilize config restart QA · openclaw/openclaw@cc91ff0 fix(installer): extract portable Node directly test(qa-lab): report scenario pack coverage · openclaw/openclaw@dcd98bf fix(plugins): drop stale tlon tool contract · openclaw/openclaw@d70dc4b fix(installer): prefer tar for portable Node extraction · openclaw/openclaw@a54a881 fix(codex): deliver native subagent completions feat: add context-engine host capability requirements (#84994) · openclaw/openclaw@cff5244 fix(release): keep shrinkwrap pinned to pnpm lock · openclaw/openclaw@9d24fde fix: surface plan updates as status notices · openclaw/openclaw@dc04503 test(google): narrow web search fake timers · openclaw/openclaw@fe7d13c fix(installer): extract portable Node with ZipFile · openclaw/openclaw@ffa6cd8 fix(gateway): defer provider auth prewarm after startup (#85369) · openclaw/openclaw@69255f8 fix(talk): stabilize realtime voice consults · openclaw/openclaw@683ad75 test(qa): tolerate slow gateway rpc startup · openclaw/openclaw@29118a0 chore(diagnostics): refresh plugin sdk baseline · openclaw/openclaw@ab684f5 fix(diagnostics): surface async queue drops fix(diagnostics): bound diagnostic buffers · openclaw/openclaw@bdcaac0 fix(installer): copy portable Node into place · openclaw/openclaw@c21ca88 fix(cli): recover replaced device approvals (#85342) · openclaw/openclaw@6ea907c test(release): align prerelease validation · openclaw/openclaw@0def3e2 fix(installer): install portable Node directory atomically · openclaw/openclaw@2890b1a fix(runtime-llm): avoid duplicate provider prefix in allowlist diagno… · openclaw/openclaw@937a756 fix(gateway): include openclaw bin in service PATH (#84475) · openclaw/openclaw@66d1d13 fix(gateway): handle concurrent launchd bootstrap restart race (#84722) · openclaw/openclaw@ba86716 feat: support pi and opencode autoreview engines · openclaw/openclaw@31a189d ci(package): gate acceptance on package integrity · openclaw/openclaw@5275929 ci(release): bypass pnpm for tsdown package build · openclaw/openclaw@fea89cd test(release): align prerelease validation baselines · openclaw/openclaw@04ebdc6 ci(release): harden docker package build · openclaw/openclaw@7b1fbe1 fix(codex): skip native web search transcript mirroring (#85346) · openclaw/openclaw@c3531fc fix(gateway): harden launchd reload handoff race recovery (#84641) · openclaw/openclaw@fc7a531 fix: honor per-model provider transport overrides (#80488) fix(skills): type watcher mock calls in dedupe regression tests · openclaw/openclaw@bb73f0a fix(skills): dedupe shared-directory watchers across agent workspaces… · openclaw/openclaw@3e94290 fix(skills): document watcher edge cases, add teardown/rebuild tests,… · openclaw/openclaw@19ff77e fix(infra): allow macos browser open over ssh env (#85340) · openclaw/openclaw@47d66fe fix(update): preserve package service state during cutover (#83026) · openclaw/openclaw@a15797a fix(gateway): broadcast agent-run error payloads (#85355) · openclaw/openclaw@07e61fc test(e2e): avoid synthetic channel config in plugin smoke fix(cli): suppress systemd hints for live gateway (#85336) · openclaw/openclaw@a00c583 fix(cli): honor agent for model auth logout (#85326) · openclaw/openclaw@fc47c1f fix(gateway): eager-load lifecycle runtime to survive in-place upgrad… · openclaw/openclaw@4a91385 fix(doctor): point codex asset warning at migrate plan (#85324) fix(update): harden managed handoff cwd (#83875) · openclaw/openclaw@1bafc23 docs(release): prepare 2026.5.21 notes ci(crabbox): harden docker hydration refactor(crabbox): parse provider list from binary help instead of ha…
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>;