Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(hooks): heartbeat writes core_chars, core_revision, pressure_pct and superseded (#6794)

time-attack95cecbcc8954
diff --git a/src/core/context/hook-heartbeat.ts b/src/core/context/hook-heartbeat.ts
index 1c26d92cda..e0898e5e5d 100644
--- a/src/core/context/hook-heartbeat.ts
+++ b/src/core/context/hook-heartbeat.ts
@@ -169,11 +169,15 @@ export async function writeHeartbeat(
...(entry.segment !== undefined ? { segment: entry.segment } : {}),
...(entry.inserted !== undefined ? { inserted: entry.inserted } : {}),
...(entry.duplicate !== undefined ? { duplicate: entry.duplicate } : {}),
+ ...(entry.superseded !== undefined ? { superseded: entry.superseded } : {}),
...(entry.near_duplicate !== undefined ? { near_duplicate: entry.near_duplicate } : {}),
...(entry.links !== undefined ? { links: entry.links } : {}),
...(entry.flush !== undefined ? { flush: entry.flush } : {}),
...(entry.pattern !== undefined ? { pattern: entry.pattern } : {}),
...(entry.fingerprint !== undefined ? { fingerprint: entry.fingerprint } : {}),
+ ...(entry.core_chars !== undefined ? { core_chars: entry.core_chars } : {}),
+ ...(entry.core_revision !== undefined ? { core_revision: entry.core_revision } : {}),
+ ...(entry.pressure_pct !== undefined ? { pressure_pct: entry.pressure_pct } : {}),
// A seat reason carries its fixed recovery hint even when the writer did not attach one.
...((entry.hint ?? seatReasonHint(entry.reason)) !== undefined ? { hint: entry.hint ?? seatReasonHint(entry.reason) } : {}),
});
diff --git a/test/hook-command.serial.test.ts b/test/hook-command.serial.test.ts
index fa788634a9..a67ae80d43 100644
--- a/test/hook-command.serial.test.ts
+++ b/test/hook-command.serial.test.ts
@@ -27,6 +27,7 @@ import {
HOOK_EVENTS,
type HookHeartbeatEntry,
} from '../src/commands/hook.ts';
+import { writeHeartbeat } from '../src/core/context/hook-heartbeat.ts';
import { pushStatusPathForRoot } from '../src/core/workspace-push.ts';
import {
ensureIpcSecret,
@@ -1103,6 +1104,17 @@ describe('heartbeat', () => {
expect(JSON.parse(lines[lines.length - 1]).event).toBe('stop');
});
+ test('#6794: every allowlisted key round-trips through writeHeartbeat', async () => {
+ const entry: Record<string, string | number> = {};
+ HEARTBEAT_ALLOWED_KEYS.forEach((key, i) => {
+ entry[key] = key === 'outcome' ? 'ok' : key === 'duration_ms' ? i : `v-${key}`;
+ });
+ await writeHeartbeat(entry as unknown as HookHeartbeatEntry);
+ const [written] = await readHeartbeatTail(1);
+ expect(Object.keys(written).sort()).toEqual([...HEARTBEAT_ALLOWED_KEYS].sort());
+ expect(written).toEqual(entry as unknown as HookHeartbeatEntry);
+ });
+
test('readHeartbeatTail returns the last n entries oldest→newest', async () => {
const p = await heartbeatPath();
const mk = (i: number) => JSON.stringify({ ts: `t${i}`, event: 'stop', outcome: 'ok', duration_ms: i });