refactor: address review feedback on exec event matching and target guard

- Anchor isExecCompletionEvent patterns to maybeNotifyOnExit format
  ("exec completed/failed/killed (") to avoid false positives in
  free-form cron reminder text
- Collapse redundant double-check on target === "none" into single
  if/else block

Co-authored-by: eviaaaaa <2278596667@qq.com>
This commit is contained in:
Kaspre 2026-03-20 00:15:46 -04:00
parent c21582983d
commit ca9df70e07
2 changed files with 14 additions and 16 deletions

View File

@ -86,12 +86,11 @@ function isHeartbeatNoiseEvent(evt: string): boolean {
export function isExecCompletionEvent(evt: string): boolean {
const lower = evt.toLowerCase();
// "exec finished" — emitExecSystemEvent (gateway/node approval path)
// "exec completed/failed/killed" — maybeNotifyOnExit (backgrounded allowlisted commands)
// "Exec completed/failed/killed (" — maybeNotifyOnExit (backgrounded allowlisted commands)
// Anchored to the parenthesised format to avoid false positives in free-form cron text
return (
lower.includes("exec finished") ||
lower.includes("exec completed") ||
lower.includes("exec failed") ||
lower.includes("exec killed")
/exec (?:completed|failed|killed) \(/.test(lower)
);
}

View File

@ -270,18 +270,17 @@ export function resolveHeartbeatDeliveryTarget(params: {
}
}
if (target === "none" && !forceLastTargetWhenNone) {
const base = resolveSessionDeliveryTarget({ entry });
return buildNoHeartbeatDeliveryTarget({
reason: "target-none",
lastChannel: base.lastChannel,
lastAccountId: base.lastAccountId,
});
}
// For async exec completion events, always fall back to the session's last
// delivery target even when heartbeat target is explicitly set to "none".
if (target === "none" && forceLastTargetWhenNone) {
if (target === "none") {
if (!forceLastTargetWhenNone) {
const base = resolveSessionDeliveryTarget({ entry });
return buildNoHeartbeatDeliveryTarget({
reason: "target-none",
lastChannel: base.lastChannel,
lastAccountId: base.lastAccountId,
});
}
// For async exec completion events, always fall back to the session's last
// delivery target even when heartbeat target is explicitly set to "none".
target = "last";
}