Skip to content

fix(heartbeat): keep ack tokens and read-only tool failures out of owner chat - #5

Merged
tomorrowflow merged 2 commits into
mainfrom
fix/heartbeat-ack-tokens
Sep 12, 2026
Merged

tomorrowflow merged 2 commits into
mainfrom
fix/heartbeat-ack-tokens

Conversation

@tomorrowflow

@tomorrowflow tomorrowflow commented Sep 11, 2026 •

Copy link
Copy Markdown
Owner

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:

HEARTBEAT_OK — no proactive message needed.

NO_REPLY

The owner received the whole thing, tokens included. stripHeartbeatToken recognizes HEARTBEAT_OK only 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. normalizeHeartbeatReply treats a payload as silent only when the entire text is NO_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: stripTokenAtEdges also drops a closing line that opens with HEARTBEAT_OK followed 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 trailing NO_REPLY appended to prose is stripped and marks the reply silent; when no HEARTBEAT_OK was present, the remainder is judged by the same ack threshold (ackMaxChars), so a short status plus NO_REPLY is 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 with mutatingAction === false produces no warning payload. Unknown (undefined) or mutating failures keep the existing behavior, including heartbeatTerminalToolFailure.

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 + trailing NO_REPLY skipped, 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 (no mutatingAction field) is unchanged and still passes, which is why the suppression requires an explicit false.
  • Six of the new assertions fail on the original code. pnpm tsgo:core, oxlint, oxfmt --check, git diff --check clean. 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. from agent:main:main:heartbeat. The poll ran ls, 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 the write counted as a side effect, produced the warning. The silent-turn guard (shouldTreatEmptyAssistantReplyAsSilent) requires both allowEmptyAssistantReplyAsSilent and 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: resolveEmptyReplyPolicy in terminal-resolution.ts derives 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 offer NO_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.ts case reproducing the run (four settled tools incl. a non-replay-safe write, empty stop): heartbeat and cron complete as silent-empty with 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 except plugin boundaries, which fails because an upstream compatibility record passed its removal date (calendar-driven, fails on the unchanged branch, not addressed here).

tomorrowflow and others added 2 commits September 11, 2026 17:54
…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.
@tomorrowflow
tomorrowflow merged this pull request into main Sep 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant