fix(FN-4393): stabilize heartbeat memory mode transition handling

Fusion-Task-Id: FN-4393
Fusion-Task-Lineage: 3615215d-9caa-4402-9258-a5a5de137dd6
This commit is contained in:
Fusion
2026-05-13 23:23:39 -07:00
committed by gsxdsm
parent fbec3e4d2d
commit 3a7a5f6e46

View File

@@ -41,7 +41,7 @@ import type { AgentReflectionService } from "./agent-reflection.js";
function adjustHeartbeatMemoryPrimer(basePrompt: string, mode: AgentMemoryInclusionMode): string {
if (mode === "full") return basePrompt;
const memoryPrimer = /\nYou may receive an Agent Memory section and a Project Memory section\.[\s\S]*?repository pitfalls\.\n/;
const memoryPrimer = /\nYou may receive an Agent Memory section and a Project Memory section\.[\s\S]*?- Project Memory examples:[^\n]*\n/;
if (mode === "off") return basePrompt.replace(memoryPrimer, "\n");
return basePrompt.replace(
memoryPrimer,
@@ -2058,6 +2058,16 @@ export class HeartbeatMonitor {
} catch (modeLogError) {
heartbeatLog.warn(`Failed to append memory-mode transition run log for ${agentId}: ${modeLogError instanceof Error ? modeLogError.message : String(modeLogError)}`);
}
try {
await this.store.updateAgent(agentId, {
runtimeConfig: {
...(agent.runtimeConfig ?? {}),
lastAgentMemoryInclusionMode: resolvedMemoryMode.mode,
},
});
} catch (modePersistError) {
heartbeatLog.warn(`Failed to persist memory-mode transition for ${agentId}: ${modePersistError instanceof Error ? modePersistError.message : String(modePersistError)}`);
}
}
// fn_heartbeat_done must be the last tool in the array (stable terminal signal)