Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

openclaw: seat heartbeat hints come from the heartbeat writer

garrytan807801ee5fbe
diff --git a/src/core/context-engine.ts b/src/core/context-engine.ts
index 7ede53c4ec..7c2e87a845 100644
--- a/src/core/context-engine.ts
+++ b/src/core/context-engine.ts
@@ -790,7 +790,7 @@ export function sanitizeEngineSessionId(raw: unknown): string | null {
*/
async function recordOpenclawSeat(dir: string, sessionId: string, sessionFile: string): Promise<void> {
try {
- const { resolveSeat, seatReasonHint, writeSeatSidecar } = await import('./context/seat.ts');
+ const { resolveSeat, writeSeatSidecar } = await import('./context/seat.ts');
let reasons: string[];
try {
const seat = resolveSeat({ env: process.env, harness: 'openclaw', transcriptPath: sessionFile });
@@ -800,11 +800,9 @@ async function recordOpenclawSeat(dir: string, sessionId: string, sessionFile: s
}
const reason = reasons[0];
if (!reason) return;
- const hint = seatReasonHint(reason);
const { writeHeartbeat } = await import('./context/hook-heartbeat.ts');
- // trim:false: the gateway process is long-lived; only short-lived hooks trim the heartbeat file.
- await writeHeartbeat({ ts: new Date().toISOString(), event: 'compact', outcome: 'degraded', reason, duration_ms: 0, ...(hint ? { hint } : {}) },
- { trim: false });
+ // trim:false: the gateway process is long-lived; only short-lived hooks trim the heartbeat file. The entry gets the reason's hint.
+ await writeHeartbeat({ ts: new Date().toISOString(), event: 'compact', outcome: 'degraded', reason, duration_ms: 0 }, { trim: false });
} catch { /* provenance and telemetry never fail the checkpoint */ }
}
diff --git a/src/core/context/hook-heartbeat.ts b/src/core/context/hook-heartbeat.ts
index ec04efbbe7..1fb0e39bdd 100644
--- a/src/core/context/hook-heartbeat.ts
+++ b/src/core/context/hook-heartbeat.ts
@@ -18,6 +18,7 @@ import { homedir } from 'node:os';
import { delimiter, join } from 'node:path';
import type { ToolCallRecord } from '../transcripts/claude-code-jsonl.ts';
import { ensureGbrainHome, resolveGbrainHome } from '../gbrain-home.ts';
+import { seatReasonHint } from './seat.ts';
/** Heartbeat file line cap [S3#7]. */
export const HEARTBEAT_MAX_LINES = 5000;
@@ -165,7 +166,8 @@ export async function writeHeartbeat(
...(entry.flush !== undefined ? { flush: entry.flush } : {}),
...(entry.pattern !== undefined ? { pattern: entry.pattern } : {}),
...(entry.fingerprint !== undefined ? { fingerprint: entry.fingerprint } : {}),
- ...(entry.hint !== undefined ? { hint: entry.hint } : {}),
+ // 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) } : {}),
});
appendFileSync(p, line + '\n', { mode: 0o600 });
if (opts?.trim === false) return;