Skip to content

[ENG-22434] fix(heartbeat): background result sent with the message tool is lost in Boon Web chats - #344

Merged
orswn merged 1 commit into
boonfrom
okka/ENG-22434/completion-reply-delivery
Nov 24, 2026
Merged

orswn merged 1 commit into
boonfrom
okka/ENG-22434/completion-reply-delivery

Conversation

@orswn

@orswn orswn commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Related: ENG-22434 (Linear). Follow-up to #342.

What Problem This Solves

Fixes an issue where a user in a Boon Web chat who asked the agent to run a background command saw only "Done." (or nothing) when the command finished. The agent got its turn right after the exit (since #342), read the output and sent it with the message tool, but that message never reached the chat. A second background result in the same chat could disappear entirely.

Seen on a production test org running 2026.7.35-boon.4: the completion turn started 0.8 s after the exit, sent the output with the message tool, ended with "Done.", and the chat received only "Done.".

Why This Change Was Made

Boon Web does not post a message send to the current conversation itself. It stages it as an internal source reply, and the reply pipeline delivers it. On a normal inbound turn the dispatcher sends every final payload, so the staged reply shows. The heartbeat runner sends one payload, the last one with content. So a staged reply was lost whenever the turn ended with other text, a HEARTBEAT_OK ack, or a final that matched the previous heartbeat text (duplicate suppression).

Changes:

  • Staged replies are sent on their own. Right after the heartbeat turn's reply is resolved, before the ack and duplicate skip branches, the runner sends the turn's staged message replies, in order, to the run's own delivery target. Then the existing final-text path runs unchanged.
  • Bounded to chat completions. Only replies staged for the run's session. Only from a chat session: not the heartbeat session, not an isolated heartbeat run. Only to a real channel target. Only when the channel shows heartbeat alerts (showAlerts). Not on the heartbeat-response-tool path.
  • No transcript duplicate. The send has no transcript mirror: the message tool already wrote the text to the transcript.
  • No literal ack next to the result. After staged replies went out, a token-only final (HEARTBEAT_OK) is treated as an ack and skipped, instead of being relayed as the exec result.
  • Repeated results still show. The duplicate-final check no longer drops a final that is itself a staged reply.
  • After a staged send, the run's own pending-final record is cleared, and one info line is logged: heartbeat: delivered staged source replies.

Not changed: heartbeat turns without staged replies, the normal inbound reply path, and channels whose message tool sends directly (Slack, Microsoft Teams). Upstream retired this heartbeat runner, so there is no upstream change to port.

Known limits, not changed here:

  • Staged replies carry only text and media on this path. Cards and suggested replies in a staged payload are not sent, same as the heartbeat final today.
  • Staged media goes out without the inbound turn's media access rules, same as the heartbeat final today. A failed staged send fails the run like a failed final send.
  • If the staged send succeeds and the final send then fails, the completion event stays queued, so a later turn can report the output again.
  • When the final is only an ack, the heartbeat event still reports ok-token.

User Impact

In a Boon Web chat, when the agent reports a background command's result with the message tool, the user now sees that result, followed by the agent's closing text if any. A second result in the same chat also shows. Slack, Microsoft Teams and turns without a message send behave as before.

Evidence

Tests written first. The new behavior tests fail on boon and pass with this change:

  • src/infra/heartbeat-runner.source-reply-delivery.test.ts (new, 16 tests):
    • [staged output, "Done."] sends the output, then Done.. On boon: expected [ 'Done.' ].
    • [staged output, HEARTBEAT_OK] sends the output and no literal token. On boon: expected [ 'HEARTBEAT_OK' ].
    • Two completions in one chat that both end with Done. both deliver their output. On boon: expected [ 'Done.' ].
    • A repeated staged-only result that is itself the final is sent again. On boon: expected ['same output'] to equal ['same output','same output'].
    • The staged send has no transcript mirror.
    • Guards: a different session, target: none, showAlerts: false, an isolated run, a scheduled heartbeat in the heartbeat session, a channel that is not ready, and a suppressed staged send. Each sends nothing new, and each guard test fails when its gate is removed.
    • A failed staged send keeps the event queued.
  • src/auto-reply/heartbeat-reply-payload.source-replies.test.ts (new, 5 tests): selection order, exclusion of the final, other sessions, reasoning and failure notices skipped.

Local runs (Node 22.23.5): all heartbeat suites (src/infra/heartbeat-*.test.ts, src/auto-reply/heartbeat-reply-payload*.test.ts): 395 passed, existing tests unchanged. tsgo core and core test, oxlint, oxfmt --check, git diff --check: clean. pnpm build: ok.

Local smoke (before vs after)

Local gateway with the fleet heartbeat and session settings (heartbeat.every: "1h", session.dmScope: "per-channel-peer", messages.queue.mode: "collect", empty HEARTBEAT.md), Boon Web chat through the same anychat plugin release as production, Claude Sonnet 5.5 on Bedrock, current fleet persona. Before = boon at e654143e4c7 (2026.7.35-boon.4). After = this branch. A heartbeat had run before each scenario.

Scenario Before After
Agent sends the output with the message tool, then replies "Done." only "Done." output, then "Done." (2 of 2 runs), 5.6 to 6.4 s after the completion turn starts
Second background command in the same chat, same shape nothing after the exit output shows (the repeated "Done." is still suppressed as a duplicate)
Natural request ("tell me the output when it finishes") not run (the production failure above) output shows
Same output twice in one chat, agent sends only the message not run both show
Completion answered in plain text not run output once, no duplicate
Normal question, no tool not run one answer

No chat row in any after run contains HEARTBEAT_OK or NO_REPLY. Each staged delivery logged {"count": 1, "channel": "anychat-boon-web"} heartbeat: delivered staged source replies.

Before and after: first and second background result in a Boon Web chat

Not covered locally: Slack, Microsoft Teams and Google Chat delivery (no local channel; their message sends do not stage), a staged reply with media, and the out-of-turn reply in Boon Web still carries no suggested-reply chips (the heartbeat delivery path; not changed here).


Summary by cubic

Fixes background command results being lost in Boon Web chats when the agent sent them with the message tool, with only "Done." or nothing appearing in the chat.

Boon Web doesn't post message tool sends directly; it stages them as source replies that a later pipeline delivers. Normal inbound turns deliver these staged replies, but the heartbeat runner didn't, so a staged result was dropped whenever the turn ended with other text, a HEARTBEAT_OK ack, or a repeated final.

  • The heartbeat runner now sends a turn's staged message replies on their own, in order, before the ack and duplicate-skip branches.
  • This is bounded to chat completions: only replies staged for the run's session, from a chat session, to a real channel target that shows heartbeat alerts.
  • After staged replies go out, a token-only final (HEARTBEAT_OK) is treated as an ack and not relayed as literal text.
  • The duplicate-final check no longer drops a final that is itself a staged reply, so repeated results still show.
  • Slack, Microsoft Teams, turns without staged replies, and the normal inbound path are unchanged.

Known limits, unchanged here: staged payloads carry only text and media (no cards or suggested replies), staged media lacks the inbound turn's media access rules, and if the staged send succeeds but the final send fails, the completion event stays queued for a later turn.

Written for commit b2232ec. Summary will update on new commits.

View guided diff Turn on auto-fix

…in Boon Web chats

When a background command exits in a chat, the exec-event wake now
starts a heartbeat turn in that chat. If the agent sends the output
with the message tool, Boon Web does not post it directly: it stages
the send as an internal source reply, and the reply pipeline is
expected to deliver it. On a normal inbound turn the dispatcher
delivers every final payload, so the staged reply shows. The heartbeat
runner instead sends a single payload, the last one with content. When
the turn ends with any text after the message send (for example
"Done."), the staged output is dropped and the chat shows only that
text. A token-only final (HEARTBEAT_OK) or a duplicate final also
dropped it, because those branches return before any send.

Send the staged message-tool replies of a heartbeat turn on their own,
right after the turn's reply is resolved and before the skip branches,
to the run's own delivery target. Only replies staged for the run's
session are sent, only from a chat session (not the heartbeat session
or an isolated heartbeat run), only to a real channel target, and only
when the channel shows heartbeat alerts. The send has no transcript
mirror, because the message tool already wrote the text to the
transcript. After staged replies went out, a token-only final is
treated as an ack and is not posted as literal text, and the owned
pending-final record is cleared. The duplicate-final check no longer
drops a final that is itself a staged reply, so a repeated identical
result still shows.

Turns without staged replies, the normal inbound path, and channels
that send message-tool replies directly (Slack, Microsoft Teams) are
unchanged.

Related: ENG-22434

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 4 files

Heads up: you’re close to your included review allowance. Set a flex budget so reviews don’t pause.

Tip: Get a Slack DM when cubic finishes reviewing your PRs. Connect Slack

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread src/infra/heartbeat-runner.ts Resolved
Comment thread src/infra/heartbeat-runner.ts Resolved

@boon-hermes-bot boon-hermes-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Verified test coverage, CI status, and triaged cubic review items. Clean fix for ENG-22434.

@orswn
orswn merged commit 8fb4811 into boon Nov 24, 2026
158 of 163 checks passed
@orswn
orswn deleted the okka/ENG-22434/completion-reply-delivery branch November 24, 2026 11:04
orswn added a commit that referenced this pull request Nov 24, 2026
Cuts the fork release carrying #344 (ENG-22434), merged to boon after
the v2026.7.35-boon.4 tag. Without a tagged release the fix cannot be
pinned in the fleet, so Boon Web chats on running hosts still lose a
background command's result that the agent sent with the message tool.

Version-only bump, same pattern as #343: upstream base stays 2026.7.35;
fork increment moves boon.4 -> boon.5. Bumps root
package.json/npm-shrinkwrap.json, packages/ai, all 142 bundled plugin
manifests (pnpm plugins:sync, which also adds the matrix changelog
entry), and every extension npm-shrinkwrap.json, version strings only.
Adds the 2026.7.35-boon.5 CHANGELOG.md section.

Refs: ENG-22434
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