Skip to content

fix: heartbeat filter ignores reasoning/thinking blocks in HEARTBEAT_OK detection - #96021

Closed
pengxuewu-lab wants to merge 1 commit into
openclaw:mainfrom
pengxuewu-lab:fix/issue-95796-heartbeat-reasoning-filter
Closed

pengxuewu-lab wants to merge 1 commit into
openclaw:mainfrom
pengxuewu-lab:fix/issue-95796-heartbeat-reasoning-filter

Conversation

@pengxuewu-lab

@pengxuewu-lab pengxuewu-lab commented Jun 23, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Heartbeat filtering in isHeartbeatOkResponse() incorrectly rejected HEARTBEAT_OK responses whenever the assistant message contained reasoning or thinking blocks alongside the heartbeat token. The resolveMessageText() helper returns hasNonTextContent: true for any content block that is not plain text (including reasoning and thinking blocks), and the pre-existing code used this flag as an early return false gate.

Impact: Agents that emit reasoning/thinking blocks (e.g. Claude with extended thinking, Codex with reasoning_effort) could never pass the heartbeat OK check. Heartbeat acknowledgements were silently ignored, causing unnecessary re-scheduling of heartbeat turns.

Root cause: src/auto-reply/heartbeat-filter.ts — isHeartbeatOkResponse() checked hasNonTextContent from resolveMessageText() and returned false before reaching stripHeartbeatToken(), even when the text content contained a valid HEARTBEAT_OK token.

Evidence

Targeted tests (heartbeat-filter.test.ts)

Three new test cases added, all passing:

Test case Input Expected
Reasoning block + HEARTBEAT_OK [{type:"reasoning",...}, {type:"text",text:"HEARTBEAT_OK"}] true
Thinking block + HEARTBEAT_OK [{type:"thinking",...}, {type:"text",text:"HEARTBEAT_OK"}] true
Reasoning + long text exceeding maxAckChars Reasoning block + long text with HEARTBEAT_OK totalling over limit false (respects length cap)

Fix (heartbeat-filter.ts)

Removed two lines — the hasNonTextContent early return gate. The stripHeartbeatToken() call on line 340 already handles text extraction correctly regardless of non-text blocks:

-  const { text, hasNonTextContent } = resolveMessageText(message.content);
-  if (hasNonTextContent) {
-    return false;
-  }
+  const { text } = resolveMessageText(message.content);
   return stripHeartbeatToken(text, { mode: "heartbeat", maxAckChars: ackMaxChars }).shouldSkip;

Why this is safe

  • tool_call blocks are still explicitly rejected by the preceding hasAssistantToolCall() check
  • stripHeartbeatToken() still enforces the ackMaxChars limit — long responses with reasoning are correctly rejected when text exceeds the cap (proven by the third test case)
  • Non-text blocks without any HEARTBEAT_OK token continue to return false since stripHeartbeatToken() finds no match

🤖 Generated with Claude Code

@clawsweeper

clawsweeper Bot commented Jun 23, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Close as superseded: the same heartbeat reasoning/thinking ACK bug is already owned by a proof-positive, mergeable candidate, and this branch fixes it by removing a broader safety guard that should be preserved.

Canonical path: Land one canonical narrow heartbeat-filter fix, preferably #95798, then close the duplicate candidate PRs for the linked bug.

So I’m closing this here and keeping the remaining discussion on #95798.

Review details

Best possible solution:

Land one canonical narrow heartbeat-filter fix, preferably #95798, then close the duplicate candidate PRs for the linked bug.

Do we have a high-confidence way to reproduce the issue?

Yes. Source inspection gives a high-confidence path: an assistant content array with a reasoning/thinking block plus { type: "text", text: "HEARTBEAT_OK" } sets hasNonTextContent on current main and makes isHeartbeatOkResponse return false before token stripping.

Is this the best way to solve the issue?

No. The branch is a plausible fix for the reported shape, but the best fix is the narrower classifier carve-out used by the canonical candidate so other non-text content remains protected.

Security review:

Security review cleared: The diff only changes deterministic heartbeat message classification and colocated tests, with no dependency, workflow, secret, or code-execution surface changes.

AGENTS.md: found and applied where relevant.

What I checked:

  • Repository policy read: Root AGENTS.md was read fully; no scoped AGENTS.md applies under src/auto-reply, and the relevant policy requires whole-path PR review plus best-fix assessment before verdict. (AGENTS.md:1, d1b917120a47)
  • Current-main bug path: Current main still marks any block outside text/input_text/output_text as non-text and then returns false before stripHeartbeatToken, which proves the reported reasoning/thinking ACK failure remains unfixed on main. (src/auto-reply/heartbeat-filter.ts:257, d1b917120a47)
  • Runtime caller: The embedded runner calls filterHeartbeatTranscriptArtifacts before constructing prompt history, so a too-broad heartbeat ACK match can remove assistant content from future model context. (src/agents/embedded-agent-runner/run/attempt.ts:4171, d1b917120a47)
  • Display caller: Gateway chat projection also hides messages when isHeartbeatOkResponse returns true, so broadening the predicate affects visible chat history in addition to prompt history. (src/gateway/chat-display-projection.ts:1460, d1b917120a47)
  • PR broadens safety boundary: The submitted branch drops hasNonTextContent entirely after the tool-call check; media or unknown structured blocks plus short HEARTBEAT_OK text would now be classified as a silent heartbeat ack. (src/auto-reply/heartbeat-filter.ts:339, e4eafaf7685d)
  • Existing non-text invariant: Adjacent heartbeat code already treats media/rich payloads plus HEARTBEAT_OK as not heartbeat-only, matching the guard this PR removes for transcript blocks. (src/cron/isolated-agent/helpers.test.ts:185, d1b917120a47)

Likely related people:

  • nxmxbbd: PR metadata for the merged heartbeat transcript-pruning replacement shows this contributor authored the original heartbeat-filter implementation and tests. (role: introduced heartbeat filter behavior; confidence: high; commits: 57f9f0a08dd7; files: src/auto-reply/heartbeat-filter.ts, src/auto-reply/heartbeat-filter.test.ts)
  • obviyus: GitHub metadata shows this account merged the heartbeat transcript-pruning replacement and authored adjacent cleanup commits in that PR branch. (role: merger and adjacent contributor; confidence: medium; commits: 57f9f0a08dd7, a0625a9831fb, 80ac5d4ae2de; files: src/auto-reply/heartbeat-filter.ts, src/auto-reply/heartbeat-filter.test.ts)
  • lin-hongkuan: Current-main blame on the heartbeat filter points to a recent repository-wide trajectory preservation commit that carried the present implementation forward. (role: recent area contributor; confidence: low; commits: 67118d5ab912; files: src/auto-reply/heartbeat-filter.ts, src/auto-reply/heartbeat-filter.test.ts)
  • hanZeng-08: This contributor opened the proof-positive, mergeable related PR that keeps the narrow reasoning-block carve-out and is the safest current landing candidate. (role: active canonical fix candidate author; confidence: medium; commits: 034787c9a890; files: src/auto-reply/heartbeat-filter.ts, src/auto-reply/heartbeat-filter.test.ts)

Codex review notes: model internal, reasoning high; reviewed against d1b917120a47.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Jun 23, 2026
@steipete steipete closed this Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XS status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants