Repository navigation
fix(heartbeat): keep ack tokens and read-only tool failures out of owner chat - #5
Merged
Merged
Conversation
…ner chat Two heartbeat deliveries reached the owner on Signal that should not have: - A status summary that closed with "HEARTBEAT_OK — no proactive message needed." and "NO_REPLY" on their own lines was delivered verbatim, tokens included. stripHeartbeatToken only recognized HEARTBEAT_OK at the very start or end of the text, and normalizeHeartbeatReply only treated an entire payload equal to NO_REPLY as silent. Strip a closing line that opens with HEARTBEAT_OK (the ack plus the model's commentary on it) and a trailing NO_REPLY appended to prose; both count as acknowledgements, so the usual heartbeat ack threshold decides whether the remaining status is delivered. A token inside a sentence stays untouched. - "⚠️ Ls failed": a heartbeat poll listed a missing directory, carried on with a successful tool call, and ended with NO_REPLY; the runner still surfaced the earlier failure as the owner-visible reply. A proven read-only failure (mutatingAction === false) on a quiet heartbeat has nothing the owner can act on and remains in the log; unknown or mutating failures keep surfacing through the existing heartbeatTerminalToolFailure path. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Heartbeat polls that ran their checks (ls, calendar query, read, write of the state file) and then stopped with an empty assistant message were reported to the owner as "Agent couldn't generate a response. Note: some tool actions may have already been executed" (2026-09-12 11:06 and 13:06). PR #3 correctly stopped finalizing that turn into prose, so it fell through to the incomplete-turn classifier, which saw an empty stop with side effects. The silent-turn guard needs both allowEmptyAssistantReplyAsSilent and an optional reply expectation. Heartbeats deliberately leave the expectation to the trigger, and only group chats set the allowance, so a heartbeat could never qualify. Resolve the effective policy from the trigger when the caller leaves it open: a run that owes no visible reply (heartbeat, cron, whose prompts already offer NO_REPLY) accepts a clean empty stop after settled tools as silence. User and manual runs, and callers that set an explicit expectation, are unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #3 and #4, from two heartbeat messages the owner received on Signal after those landed.
Problem
1. Ack tokens delivered verbatim (16:06 local). The heartbeat's reply was a status summary that ended with two lines:
The owner received the whole thing, tokens included.
stripHeartbeatTokenrecognizesHEARTBEAT_OKonly at the very start or end of the text (optionally followed by up to four punctuation characters), so a closing line with commentary after the token is not an acknowledgement to it.normalizeHeartbeatReplytreats a payload as silent only when the entire text isNO_REPLY; a trailing token appended to prose is left in place and delivered.2. "⚠️ Ls failed" (15:41 local). A heartbeat listed a directory that does not exist in its sandbox, continued with a successful tool call, and ended the turn with
NO_REPLY. The runner keeps the last tool error across a run and, because the turn was otherwise silent, emitted the failure warning as the owner-visible reply. The owner cannot act on a read-only listing failure during a background poll; it belongs in the log.Solution
auto-reply/heartbeat.ts:stripTokenAtEdgesalso drops a closing line that opens withHEARTBEAT_OKfollowed by a non-word character (the ack plus the model's commentary). A token inside a sentence is still untouched.infra/heartbeat-delivery-normalization.ts: a trailingNO_REPLYappended to prose is stripped and marks the reply silent; when noHEARTBEAT_OKwas present, the remainder is judged by the same ack threshold (ackMaxChars), so a short status plusNO_REPLYis skipped and a long one is delivered without the token. Media still delivers.embedded-agent-runner/run/payloads.ts: on a heartbeat trigger with no user-facing reply, a failure withmutatingAction === falseproduces no warning payload. Unknown (undefined) or mutating failures keep the existing behavior, includingheartbeatTerminalToolFailure.Impact
Heartbeat acknowledgements never leak as text. A heartbeat that says something and then acknowledges still delivers the something, minus the tokens, subject to the existing threshold. Read-only tool hiccups during a quiet poll stop paging the owner. No change for user turns, cron delivery, or mutating failures.
Not changed: the model still writes status prose when nothing is due; that is prompt guidance (
HEARTBEAT.md), not runtime.Evidence
auto-reply/heartbeat.test.ts: new case for a closing ack line with commentary (long remainder delivered without the line, short remainder skipped, token glued to a word untouched).infra/heartbeat-delivery-normalization.test.ts(new): bare token, short status + trailingNO_REPLYskipped, the observed 16:06 message delivered without any token, long status + trailing token kept minus the token, media not skipped.embedded-agent-runner/run/payloads.test.ts: read-only heartbeat failure on a quiet turn yields no payload; a mutating one still yields the warning. The existing heartbeat exec-privacy test (nomutatingActionfield) is unchanged and still passes, which is why the suppression requires an explicitfalse.pnpm tsgo:core,oxlint,oxfmt --check,git diff --checkclean. Heartbeat runner and auto-reply heartbeat suites: 13 files, 284 tests passed.🤖 Generated with Claude Code
Also in this PR: empty stop after settled tools reported as an error (e338484)
2026-09-12 11:06 and 13:06 the owner received
⚠️ Agent couldn't generate a response. Note: some tool actions may have already been executed — please verify before retrying.fromagent:main:main:heartbeat. The poll ranls,dav__calendar_query,read,write(state file), then stopped with an assistant message carrying no content. Journal:incomplete turn detected … payloads=0 tools=4 replaySafe=no … surfacing error to user.Cause: #3 correctly stopped finalizing that turn into prose, so it fell through to
resolveIncompleteTurnPayloadText, which classified the empty stop as an incomplete turn and, because thewritecounted as a side effect, produced the warning. The silent-turn guard (shouldTreatEmptyAssistantReplyAsSilent) requires bothallowEmptyAssistantReplyAsSilentand an optional reply expectation; heartbeats deliberately leave the expectation to the trigger (undefined) and only group chats set the allowance, so a heartbeat could never qualify.Fix:
resolveEmptyReplyPolicyinterminal-resolution.tsderives the effective policy from the trigger when the caller leaves the expectation open. A run that owes no visible reply (heartbeat, cron; their prompts already offerNO_REPLY) treats a clean empty stop after settled tools as silence. User/manual runs and callers with an explicit expectation are unchanged.Evidence: new
terminal-resolution.test.tscase reproducing the run (four settled tools incl. a non-replay-safewrite, emptystop): heartbeat and cron complete assilent-emptywith no retry, a user run still receives the side-effect warning. The heartbeat/cron cases fail on the previous commit with the exact warning text. Suites: terminal-resolution (51), incomplete-turn recovery/resolution/settled-finalization/payloads (80 + 6),run.incomplete-turn.*(76) pass.check:changed: every lane ok exceptplugin boundaries, which fails because an upstream compatibility record passed its removal date (calendar-driven, fails on the unchanged branch, not addressed here).