fix (heartbeat/cron): preserve cron prompts for tagged interval events

This commit is contained in:
Vignesh Natarajan
2026-02-14 19:46:07 -08:00
parent 1712a71a39
commit 4c4d2558e3
5 changed files with 41 additions and 14 deletions

View File

@@ -35,7 +35,7 @@ export type CronServiceDeps = {
resolveSessionStorePath?: (agentId?: string) => string;
/** Path to the session store (sessions.json) for reaper use. */
sessionStorePath?: string;
enqueueSystemEvent: (text: string, opts?: { agentId?: string }) => void;
enqueueSystemEvent: (text: string, opts?: { agentId?: string; contextKey?: string }) => void;
requestHeartbeatNow: (opts?: { reason?: string }) => void;
runHeartbeatOnce?: (opts?: { reason?: string; agentId?: string }) => Promise<HeartbeatRunResult>;
/**

View File

@@ -445,7 +445,10 @@ async function executeJobCore(
: 'main job requires payload.kind="systemEvent"',
};
}
state.deps.enqueueSystemEvent(text, { agentId: job.agentId });
state.deps.enqueueSystemEvent(text, {
agentId: job.agentId,
contextKey: `cron:${job.id}`,
});
if (job.wakeMode === "now" && state.deps.runHeartbeatOnce) {
const reason = `cron:${job.id}`;
const delay = (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms));
@@ -503,7 +506,10 @@ async function executeJobCore(
const prefix = "Cron";
const label =
res.status === "error" ? `${prefix} (error): ${summaryText}` : `${prefix}: ${summaryText}`;
state.deps.enqueueSystemEvent(label, { agentId: job.agentId });
state.deps.enqueueSystemEvent(label, {
agentId: job.agentId,
contextKey: `cron:${job.id}`,
});
if (job.wakeMode === "now") {
state.deps.requestHeartbeatNow({ reason: `cron:${job.id}` });
}