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

@@ -59,7 +59,7 @@ import {
resolveHeartbeatDeliveryTarget,
resolveHeartbeatSenderContext,
} from "./outbound/targets.js";
import { peekSystemEvents } from "./system-events.js";
import { peekSystemEventEntries } from "./system-events.js";
type HeartbeatDeps = OutboundSendDeps &
ChannelHeartbeatDeps & {
@@ -487,11 +487,23 @@ export async function runHeartbeatOnce(opts: {
// If so, use a specialized prompt that instructs the model to relay the result
// instead of the standard heartbeat prompt with "reply HEARTBEAT_OK".
const isExecEvent = opts.reason === "exec-event";
const isCronEvent = Boolean(opts.reason?.startsWith("cron:"));
const pendingEvents = isExecEvent || isCronEvent ? peekSystemEvents(sessionKey) : [];
const cronEvents = pendingEvents.filter((evt) => isCronSystemEvent(evt));
const pendingEventEntries = peekSystemEventEntries(sessionKey);
const hasTaggedCronEvents = pendingEventEntries.some((event) =>
event.contextKey?.startsWith("cron:"),
);
const shouldInspectPendingEvents = isExecEvent || isCronEventReason || hasTaggedCronEvents;
const pendingEvents = shouldInspectPendingEvents
? pendingEventEntries.map((event) => event.text)
: [];
const cronEvents = pendingEventEntries
.filter(
(event) =>
(isCronEventReason || event.contextKey?.startsWith("cron:")) &&
isCronSystemEvent(event.text),
)
.map((event) => event.text);
const hasExecCompletion = pendingEvents.some(isExecCompletionEvent);
const hasCronEvents = isCronEvent && cronEvents.length > 0;
const hasCronEvents = cronEvents.length > 0;
const prompt = hasExecCompletion
? EXEC_EVENT_PROMPT
: hasCronEvents