fix: don't bleed top-level interval/prompt into heartbeat task parsing (#64488)

Merged via squash.

Prepared head SHA: c0cd0fc823
Co-authored-by: Rahulkumar070 <151990777+Rahulkumar070@users.noreply.github.com>
Co-authored-by: jalehman <550978+jalehman@users.noreply.github.com>
Reviewed-by: @jalehman
This commit is contained in:
Rahul kumar Pal
2026-04-11 04:35:09 +05:30
committed by GitHub
parent 5f089b6c2c
commit 3b57af0388
3 changed files with 28 additions and 10 deletions

View File

@@ -148,7 +148,7 @@ Docs: https://docs.openclaw.ai
- Daemon/launchd: keep `openclaw gateway stop` persistent without uninstalling the macOS LaunchAgent, re-enable it on explicit restart or repair, and harden launchd label handling. (#64447) Thanks @ngutman.
- Agents/Slack: preserve threaded announce delivery when `sessions.list` rows lack stored thread metadata by falling back to the thread id encoded in the session key. (#63143) Thanks @mariosousa-finn.
- Plugins/context engines: preserve `plugins.slots.contextEngine` through normalization and keep explicitly selected workspace context-engine plugins enabled, so loader diagnostics and plugin activation stop dropping that slot selection. (#64192) Thanks @hclsys.
- Heartbeat: stop top-level `interval:` and `prompt:` fields outside the `tasks:` block from bleeding into the last parsed heartbeat task. (#64488) Thanks @Rahulkumar070.
## 2026.4.9
### Changes

View File

@@ -2,6 +2,7 @@ import { describe, expect, it } from "vitest";
import {
DEFAULT_HEARTBEAT_ACK_MAX_CHARS,
isHeartbeatContentEffectivelyEmpty,
parseHeartbeatTasks,
stripHeartbeatToken,
} from "./heartbeat.js";
import { HEARTBEAT_TOKEN } from "./tokens.js";
@@ -109,7 +110,6 @@ describe("stripHeartbeatToken", () => {
});
it("strips trailing punctuation only when directly after the token", () => {
// Token with trailing dot/exclamation/dashes → should still strip
expect(stripHeartbeatToken(`${HEARTBEAT_TOKEN}.`, { mode: "heartbeat" })).toEqual({
shouldSkip: true,
text: "",
@@ -128,7 +128,6 @@ describe("stripHeartbeatToken", () => {
});
it("strips a sentence-ending token and keeps trailing punctuation", () => {
// Token appears at sentence end with trailing punctuation.
expect(
stripHeartbeatToken(`I should not respond ${HEARTBEAT_TOKEN}.`, {
mode: "message",
@@ -156,7 +155,6 @@ describe("stripHeartbeatToken", () => {
});
it("preserves trailing punctuation on text before the token", () => {
// Token at end, preceding text has its own punctuation — only the token is stripped
expect(stripHeartbeatToken(`All clear. ${HEARTBEAT_TOKEN}`, { mode: "message" })).toEqual({
shouldSkip: false,
text: "All clear.",
@@ -194,10 +192,6 @@ describe("isHeartbeatContentEffectivelyEmpty", () => {
});
it("returns false when a template includes plain instructional prose", () => {
// Regression: this test used to be named "returns true for default template
// content" while asserting `false`, which obscured the real behavior. The
// heuristic does NOT skip plain-text instructional sentences because they
// are indistinguishable from actionable content.
const defaultTemplate = `# HEARTBEAT.md
Keep this file empty unless you want a tiny checklist. Keep it small.
@@ -270,3 +264,21 @@ Check the server logs
expect(isHeartbeatContentEffectivelyEmpty(content)).toBe(true);
});
});
describe("parseHeartbeatTasks", () => {
it("does not bleed top-level interval/prompt fields into task parsing", () => {
const content = `tasks:
- name: email-check
interval: 30m
prompt: Check for urgent emails
interval: should-not-bleed
`;
expect(parseHeartbeatTasks(content)).toEqual([
{
name: "email-check",
interval: "30m",
prompt: "Check for urgent emails",
},
]);
});
});

View File

@@ -249,12 +249,18 @@ export function parseHeartbeatTasks(content: string): HeartbeatTask[] {
}
// Check for task fields BEFORE checking for end of block
if (nextTrimmed.startsWith("interval:")) {
if (
nextTrimmed.startsWith("interval:") &&
(nextLine.startsWith(" ") || nextLine.startsWith("\t"))
) {
interval = nextTrimmed
.replace("interval:", "")
.trim()
.replace(/^["']|["']$/g, "");
} else if (nextTrimmed.startsWith("prompt:")) {
} else if (
nextTrimmed.startsWith("prompt:") &&
(nextLine.startsWith(" ") || nextLine.startsWith("\t"))
) {
prompt = nextTrimmed
.replace("prompt:", "")
.trim()