Skip to content

fix(heartbeat): Control UI completion replies leak to an explicit heartbeat channel - #161006

Merged
Patrick-Erichsen merged 7 commits into
openclaw:mainfrom
Marvinthebored:fix/exec-completion-webchat-route
Oct 2, 2026
Merged

Patrick-Erichsen merged 7 commits into
openclaw:mainfrom
Marvinthebored:fix/exec-completion-webchat-route

Conversation

@Marvinthebored

@Marvinthebored Marvinthebored commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Related: #147387

What Problem This Solves

Fixes: background-command completions and post-restart continuations from Control UI/WebChat sessions leak to an explicitly configured heartbeat channel.

User Impact

User impact: eligible session-owned replies stay in the session that started the work, rather than also appearing in the heartbeat channel.

This intentionally changes existing explicit-target configurations. Maintainer acceptance of that destination change is still required. Ordinary heartbeat alerts, mixed event batches, external-route sessions, untagged restart wakes, and target:none retain their existing behavior. No config or stored-data migration is introduced.

Why This Change Was Made

Use the existing internal-session publisher for session-owned completions. Restart continuations use the sentinel's existing task:restart-sentinel: key, only on restart-sentinel wakes.

The review's P1 queue-loss defect is repaired: prompt admission formats captured restart occurrences without consuming them. The canonical queue owner still checks current membership and preserves selection order. Delivery settlement consumes those exact occurrences only after accepted session publication; a rejected write, thrown write, or failed model turn leaves them available for retry. Late arrivals are not consumed, and an occurrence already handled by another turn is not re-admitted.

Eligibility remains the existing internal-projection gate: an internal-delivery, client-owned session, excluding internally created/internal-effects sessions. A failed session write does not fall back to the channel.

Evidence

Review repair

  • Reproduced the P1 on the previous PR head: after real generic-event formatting and a forced publication rejection, the captured occurrence was missing from the queue.
  • Patched: 155/155 tests across seven queue/heartbeat suites pass. Includes rejected-write, thrown-write and failed-model retry, exactly one successful session publication, and no channel send on either attempt.
  • A separate production runPreparedReply admission regression passes patched and fails on clean PR base 2a0a65c: the unpatched queue is empty instead of retaining the captured occurrence. This guards the actual deferred-ID option handoff, not just the formatter helper.
  • Live-membership, captured-order and late-arrival regressions pass. Existing target-suppression, genuine-heartbeat, mixed-batch and untagged-wake coverage passes.
  • Core typecheck passes; scoped lint on all ten repair files reports 0 errors, 0 warnings. Independent Codex re-review found no remaining findings in the repaired scope.

Gateway proof

Existing real-Gateway exec-completion observations remain valid (Discord transport): before the first commit, the same replies appeared in the session and heartbeat channel; after it, tested completions appeared only in the session. The restart leak was observed with the first commit but without restart handling.

After-fix isolated public Gateway restart proof: PASS on head 9b3b46cad9c. Redacted terminal trace, selected public-history/outbound evidence, and reproducible harness.

  • Authenticated public sessions.create created a non-main session; initial public chat.send naturally established internal delivery (no session-row mutation).
  • The Gateway was stopped and started with the same explicit heartbeat-target configuration. Real startup recovery executed heartbeat_respond with notify:true; public chat.history contained exactly one recovery marker.
  • A later public same-session turn completed; a subsequent history read still contained exactly one recovery marker. Main and sibling histories contained none.
  • The outbound recorder contained no recovery marker. A positive public explicit-send control reached that configured destination exactly once, establishing that the recorder could detect delivery.
  • Gateway children and temporary state were removed; production was untouched.

Limits: restart-sentinel input is manually seeded through its canonical writer; inference and channel transport are synthetic loopback fixtures. The rest of the public Gateway/recovery/publication path is real. This does not establish production deployment, lifecycle-produced sentinel creation, or external Discord/Telegram API behavior. This harness was not run against stock; earlier fixture failures are not stock results. Ordinary-heartbeat and mixed-batch retention are established by the focused regressions, not by the explicit-send control.

Existing-configuration impact: the isolated proof reuses the unchanged explicit destination across both Gateway starts; no migration or new option is needed. The destination exception is deliberate, with no channel fallback after rejected publication. Maintainer acceptance remains outstanding.

Previously captured real-Gateway observations (UTC; text and identifiers omitted)
Case Build Session reply Same reply in heartbeat channel
Exec completion Before 00:35:28.859 00:35:29.678
Exec completion Before 00:53:02.294 00:53:03.136
Exec completion First commit 05:50:51.461 None
Exec completion First commit 05:51:50.874 None
Exec completion First commit 05:56:46.622 None
Restart continuation First commit only 10:09:07.565 10:09:15.788

Source: originating-session transcript timestamps and Gateway channel-history reads. Configuration: disabled periodic cadence and an explicit Discord heartbeat destination.

CI test-typecheck repair

The fresh CI run on 9b3b46cad9c passed runtime, production-typecheck and lint checks but failed infra test typecheck: two newly added expectDefined calls omitted the required diagnostic argument (TS2554). Test-only follow-up 85f3fcd83bc supplies those contexts. The CI-equivalent infra test-typecheck config now exits 0 locally; all 80 queue tests and scoped lint pass. Production source is unchanged from the head used for the Gateway proof. Fresh CI is pending.

Existing CI failures

The previous CI run failed in five files outside the changed routing path. Eight failures in service.failure-alert-notifications, service.heartbeat-busy-poll and update-candidate-canary reproduce with matching signatures on clean PR base 2a0a65c as well as the patched checkout. The other two restart/private-completion cases pass when isolated on both. Relevant upstream fixes have since landed, including #161455; this push requests fresh merged-base CI. No unrelated test fixes were added.

AI-assisted implementation and verification using OpenClaw and Codex. The intentional destination change still needs a maintainer decision; code checks cannot supply that acceptance.

@clawsweeper

clawsweeper Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. size: S labels Sep 29, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 29, 2026
@clawsweeper

clawsweeper Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 2, 2026, 5:58 PM ET / 21:58 UTC (Revision 9).

ClawSweeper review

What this changes

Keeps eligible internal-session command completions and restart continuations in their originating conversation, retaining restart events until successful publication.

Merge readiness

✅ Ready for maintainer review

This PR remains necessary: current main still routes eligible completion replies to an explicit heartbeat destination. The prior queue-loss defect and conflict blocker are resolved, the destination change has explicit acceptance, and no actionable patch defects remain.

Likely related people: Peter Steinberger (area-history routing candidate, medium confidence) and Patrick-Erichsen (verified repository writer and current reviewer, high confidence).

Priority: P1
Reviewed head: 30086eb0cc76b2e137e5b909a180148ca0d3ef91

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-boundary repair with convincing scoped Gateway proof, meaningful regressions, and no remaining actionable findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): Supplied real-Gateway completion observations and the inspected public restart trace exercise heartbeat routing and session publication: one owning-session recovery reply persists after a later turn, with none in sibling/main histories or the functioning channel recorder. The fresh candidate run is reported on production-identical e600999. Synthetic inference, synthetic channel transport, and writer-seeded sentinel input are explicit boundaries permitted by scoped Gateway policy; no external API behavior is claimed. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): Supplied real-Gateway completion observations and the inspected public restart trace exercise heartbeat routing and session publication: one owning-session recovery reply persists after a later turn, with none in sibling/main histories or the functioning channel recorder. The fresh candidate run is reported on production-identical e600999. Synthetic inference, synthetic channel transport, and writer-seeded sentinel input are explicit boundaries permitted by scoped Gateway policy; no external API behavior is claimed. No stored-data contract changes.
Evidence reviewed 11 items Pinned introduced routing change: The introduced delta overrides an explicit channel only for wholly session-owned batches eligible for the existing internal projection. Target suppression, externally routed sessions, and mixed batches retain their existing routing.
Prior queue-loss finding resolved: Reply admission now carries deferred occurrence IDs into the canonical queue owner. Dispatch includes retained restart occurrences in publication identity and consumes them only after successful delivery settlement. Rejected writes, thrown writes, and failed-model retries have focused regression coverage.
Current main still needs the fix: Current main creates an internal projection for exec completions but preserves the explicit channel destination; it lacks the session-owned destination override and deferred restart settlement.
Findings None None.
Security None None.

How this fits together

OpenClaw’s heartbeat runner processes queued background events and periodic alerts. It chooses between publishing a reply into the originating session and delivering it to a configured channel.

flowchart TD
  A[Command completion or restart event] --> B[Session event queue]
  B --> C[Heartbeat routing]
  D[Session ownership and destination settings] --> C
  C --> E[Originating session publication]
  C --> F[Configured channel delivery]
  E --> G[Settle accepted occurrences]
  E --> H[Retain failed occurrences for retry]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +53, Tests +473, Docs +1, Other -1. Total +526 across 15 files.

View PR surface stats
Area Files Added Removed Net
Source 9 67 14 +53
Tests 4 520 47 +473
Docs 1 2 1 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 1 0 1 -1
Total 15 589 63 +526

Review metrics

Metric Value Why it matters
Production and regression coverage growth production +67/-14 (net +53); tests/support +520/-47 (net +473) The stated production growth preserves occurrence identity and custody through admission and accepted publication using existing owners.

Technical review

Best possible solution:

Use the existing session publisher for eligible completion replies and preserve queue custody until publication succeeds, while retaining ordinary heartbeat routing.

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

Yes: an eligible internal session with an explicit heartbeat channel exposes the routing failure in current source, and the supplied validation reports failing current-main regressions. This read-only review did not rerun them.

Is this the best way to solve the issue?

Yes: the patch repairs routing and settlement in their existing owners, with no competing publisher or queue; the intentional destination exception is explicitly accepted.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 0356bacb8c66.

Labels

Label changes:

No label changes.

Label justifications:

  • P1: The reported failure misroutes background-command and restart replies from active Control UI conversations.
  • merge-risk: 🚨 compatibility: Existing explicit heartbeat destinations intentionally stop receiving eligible session-owned replies; this exact tradeoff has been accepted.
  • merge-risk: 🚨 message-delivery: Completion delivery changes destination and retains failed publication for retry without channel fallback; acceptance and scoped proof cover this contract.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): Supplied real-Gateway completion observations and the inspected public restart trace exercise heartbeat routing and session publication: one owning-session recovery reply persists after a later turn, with none in sibling/main histories or the functioning channel recorder. The fresh candidate run is reported on production-identical e600999. Synthetic inference, synthetic channel transport, and writer-seeded sentinel input are explicit boundaries permitted by scoped Gateway policy; no external API behavior is claimed. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. Supplied real-Gateway completion observations and the inspected public restart trace exercise heartbeat routing and session publication: one owning-session recovery reply persists after a later turn, with none in sibling/main histories or the functioning channel recorder. The fresh candidate run is reported on production-identical e600999. Synthetic inference, synthetic channel transport, and writer-seeded sentinel input are explicit boundaries permitted by scoped Gateway policy; no external API behavior is claimed. No stored-data contract changes.

Evidence

What I checked:

  • Pinned introduced routing change: The introduced delta overrides an explicit channel only for wholly session-owned batches eligible for the existing internal projection. Target suppression, externally routed sessions, and mixed batches retain their existing routing. (src/infra/heartbeat-runner-execution.ts:419, 30086eb0cc76)
  • Prior queue-loss finding resolved: Reply admission now carries deferred occurrence IDs into the canonical queue owner. Dispatch includes retained restart occurrences in publication identity and consumes them only after successful delivery settlement. Rejected writes, thrown writes, and failed-model retries have focused regression coverage. (src/auto-reply/reply/get-reply-run-admission.ts:173, 30086eb0cc76)
  • Current main still needs the fix: Current main creates an internal projection for exec completions but preserves the explicit channel destination; it lacks the session-owned destination override and deferred restart settlement. (src/infra/heartbeat-runner-execution.ts:406, 0356bacb8c66)
  • Latest release lacks the destination override: REST inspection of v2026.9.7 shows the existing projection and resolved-channel routing, with no sessionOwnedCompletion override. No shipped fixing release was established. (src/infra/heartbeat-runner-execution.ts:406, c074824a27c9)
  • Destination tradeoff explicitly accepted: fix(heartbeat): Control UI completion replies leak to an explicit heartbeat channel #161006 (comment) accepts originating-session delivery despite an existing explicit heartbeat destination, retry retention after rejected publication, and no channel fallback. GitHub permission inspection confirms Patrick-Erichsen has repository write permission, so the CONTRIBUTOR association does not invalidate this acceptance.
  • Inspected public Gateway proof: Read the trace, selected observations, and complete unexecuted harness at https://gist.github.com/Marvinthebored/f564c24c6c16e5ffb8c841ec21208bf6. Captured source head is 9b3b46cad9c8b3c7d5636c772bf045f924704500. Public session creation and chat establish internal delivery; real Gateway restart produces exactly one recovery reply, still one after a subsequent turn, zero in sibling/main histories, and zero in the outbound recorder. An explicit-send positive control delivers once. Sentinel input is seeded through its writer; inference and channel transport are synthetic.

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Patrick-Erichsen: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (8 earlier review cycles)
  • reviewed 2026-09-29T06:03:41.695Z sha 3a26efb9a7c6c165af52ddd17db609bee1bcaa83 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-29T07:36:28.436Z sha 3a26efb9a7c6c165af52ddd17db609bee1bcaa83 :: blocked before merge. :: none
  • reviewed 2026-09-29T08:41:40.418Z sha 83bcbd3a24de144982281b788c4db42129ede808 :: blocked before merge. :: none
  • reviewed 2026-09-30T00:41:02.341Z sha 3ce9441dcf4d27f1767ee040d454a5d6925f661b :: needs real behavior proof before merge. :: [P1] Keep restart events queued until the session reply commits
  • reviewed 2026-09-30T00:51:40.998Z sha bfe6ed3bb9c8a3087b40d3cd3e1c855ce2390ba4 :: needs real behavior proof before merge. :: [P1] Retain restart events until the session reply commits
  • reviewed 2026-10-01T15:13:50.928Z sha 9b3b46cad9c8b3c7d5636c772bf045f924704500 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-01T15:36:57.165Z sha 85f3fcd83bc2b88939bcfe34adf0dc9d9122ab15 :: blocked before merge. :: none
  • reviewed 2026-10-02T21:38:18.064Z sha 85f3fcd83bc2b88939bcfe34adf0dc9d9122ab15 :: needs changes before merge. :: none

@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Sep 29, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 29, 2026
@Marvinthebored Marvinthebored changed the title fix(heartbeat): keep WebChat exec completions out of an explicit heartbeat target fix(heartbeat): Control UI exec completion replies post to an explicit heartbeat channel Sep 29, 2026
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: M and removed size: S labels Sep 29, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 30, 2026
@Marvinthebored
Marvinthebored force-pushed the fix/exec-completion-webchat-route branch from 3ce9441 to bfe6ed3 Compare September 30, 2026 00:43
@Marvinthebored Marvinthebored changed the title fix(heartbeat): Control UI exec completion replies post to an explicit heartbeat channel fix(heartbeat): Control UI exec completion and restart continuation replies post to an explicit heartbeat channel Sep 30, 2026
@Marvinthebored Marvinthebored changed the title fix(heartbeat): Control UI exec completion and restart continuation replies post to an explicit heartbeat channel fix(heartbeat): Control UI completion replies leak to an explicit heartbeat channel Oct 1, 2026
@Marvinthebored

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

The PR description now links the completed isolated public Gateway restart proof: authenticated public non-main session creation, initial chat establishing internal delivery, actual Gateway stop/start and startup recovery, structured heartbeat_respond notification, exactly one public-history marker after a later same-session turn, no marker in sibling/main histories or outbound recorder, and a positive channel-send control. The trace, selected evidence, and reproducible harness state the fixture boundaries explicitly (seeded restart sentinel; synthetic inference/channel transport, not production or external Discord/Telegram proof). Maintainer acceptance of the destination exception remains required.

@clawsweeper

clawsweeper Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 1, 2026
Marvin added 2 commits October 2, 2026 14:28
…rget

A background command finishing in a WebChat session wakes a heartbeat turn.
With an explicit heartbeat target (e.g. discord #heartbeat, cadence 0m), the
reply was sent to that channel instead of publishing into the session that
ran the command. When the pending queue is only exec completions and a
WebChat projection exists, deliver by projection only; target:none is still
respected and ordinary heartbeat output keeps its configured target.
…ver mixed batches

Address review: the override uses the existing internal-projection eligibility
(not WebChat only), so say so in code and docs; document that a failed session
write retries on a later wake with no channel fallback; assert a genuine poll
writes nothing into the session; add a mixed-batch test that keeps the explicit
target.
@Patrick-Erichsen

Copy link
Copy Markdown
Contributor

Maintainer decision: accepted. Patrick explicitly requested landing this PR, including its documented destination change: eligible internal-session exec completions and restart continuations belong in the originating conversation, even with an existing explicit heartbeat destination. Rejected session publication retains the occurrence for retry; there is no channel fallback. Ordinary heartbeat alerts, mixed batches, external-route sessions, untagged restart wakes, and target suppression keep their existing routing.

This resolves the remaining maintainer decision and the latest review's rank-up request. Landing work is in progress: reconcile the branch with current main, rerun the focused regression/owner-boundary checks and isolated public-Gateway fixture, complete fresh autoreview, and require green CI on the final head before the native merge workflow.

I directly inspected the publication and queue settlement owners, the supplied public Gateway evidence/harness, and sibling Codex completion provenance (codex-rs/core/src/unified_exec/async_watcher.rs:163-237,331-378). The source-level routing repair stays in OpenClaw's existing heartbeat/session publisher; no Codex protocol change is introduced.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

Marvinthebored and others added 5 commits October 2, 2026 14:34
…t of the heartbeat target

A turn interrupted by a Gateway restart resumes through a restart-sentinel
heartbeat wake. With an explicit heartbeat target, that continuation reply was
sent to the heartbeat channel. On a restart-sentinel wake, events carrying the
sentinel's task:restart-sentinel: context key now count as session-owned
alongside exec completions: they publish into the owning session through the
internal projection and join the publication idempotency key. The sentinel reads
the prefix from the shared constant.
@Patrick-Erichsen Patrick-Erichsen self-assigned this Oct 2, 2026
@Patrick-Erichsen
Patrick-Erichsen force-pushed the fix/exec-completion-webchat-route branch from 85f3fcd to 30086eb Compare October 2, 2026 21:51
@Patrick-Erichsen

Patrick-Erichsen commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Landing validation for the rebased candidate 30086eb0cc76.

The heartbeat runner previously let an explicit heartbeat destination capture work owned by an internal session; reply admission also consumed restart occurrences before session publication committed. The fix keeps routing and event custody with their existing owners: internal session-owned batches publish to that session, and restart occurrences settle only after accepted publication. There is no channel fallback after a failed session write. Ordinary heartbeat polls, mixed batches, untagged wakes, target-none suppression, and externally routed sessions retain their routes.

Before/after evidence:

  • Current-main production with the PR regression fails because the completion reaches the heartbeat channel. The production-admission regression also fails because its queued restart occurrence disappears. Both pass on the candidate.
  • 181 routing/publication/system-event tests and 93 reply-admission tests passed. The 93 admission tests passed again after extracting the two related cases into a smaller test-support module, in the same execution order.
  • A fresh isolated Gateway run passed on e60099922f61; all production files are identical in the final candidate. Public session creation and chat established internal delivery. After a real Gateway restart, recovery appeared once in the owning transcript, remained once after another public chat turn, and appeared zero times in the main session, sibling session, and channel recorder. An explicit channel-send positive control delivered once. Gateway children stopped and temporary state was removed.
  • That Gateway proof uses a synthetic loopback Responses model and channel recorder. The restart sentinel is seeded through its canonical writer; Gateway startup, public session APIs, recovery, heartbeat handling, and publication are real. The older proof fixture needed current-main configuration only: an explicit model allowlist and removal of a retired default-agent marker.
  • Fresh AutoReview completed with no findings at its default P0 threshold. Manual owner/caller/sibling review found no blocking defects. Direct Codex contract inspection: codex-rs/core/src/unified_exec/async_watcher.rs:163-237,331-378 in sibling openai/codex, confirming completion remains bound to the original session/turn.

Production LOC: +67/-14 (net +53). Tests/test support: +520/-47 (net +473, including an existing-case move). Docs: +2/-1. Tooling: -1 obsolete max-lines baseline entry. Production growth preserves occurrence identity and custody across admission/publication using the existing queue and publisher. Merely suppressing channel sends would omit transcript delivery; consuming at admission would still lose retries after publication failure. No new queue, storage, configuration, or fallback path is introduced.

The rebase preserves upstream heartbeat failure-copy behavior. The only maintainer additions split oversized test coverage and remove an inherited stale baseline entry for the already-shortened Discord native-command module. ClawSweeper's policy/rank-up decision is accepted in the earlier maintainer comment; the new Gateway evidence independently covers its recovery boundary.

Full local changed-file validation passed. Exact-head CI and the required aggregate gate are green on the published candidate. Native review/prepare/merge verification is the remaining landing step.

@Patrick-Erichsen
Patrick-Erichsen merged commit f0308b7 into openclaw:main Oct 2, 2026
133 checks passed
@Patrick-Erichsen

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 3, 2026
…rtbeat channel (openclaw#161006)

* fix(heartbeat): keep WebChat exec completions out of the heartbeat target

A background command finishing in a WebChat session wakes a heartbeat turn.
With an explicit heartbeat target (e.g. discord #heartbeat, cadence 0m), the
reply was sent to that channel instead of publishing into the session that
ran the command. When the pending queue is only exec completions and a
WebChat projection exists, deliver by projection only; target:none is still
respected and ordinary heartbeat output keeps its configured target.

* fix(heartbeat): document session-owned exec completion routing and cover mixed batches

Address review: the override uses the existing internal-projection eligibility
(not WebChat only), so say so in code and docs; document that a failed session
write retries on a later wake with no channel fallback; assert a genuine poll
writes nothing into the session; add a mixed-batch test that keeps the explicit
target.

* fix(heartbeat): keep restart continuations for Control UI sessions out of the heartbeat target

A turn interrupted by a Gateway restart resumes through a restart-sentinel
heartbeat wake. With an explicit heartbeat target, that continuation reply was
sent to the heartbeat channel. On a restart-sentinel wake, events carrying the
sentinel's task:restart-sentinel: context key now count as session-owned
alongside exec completions: they publish into the owning session through the
internal projection and join the publication idempotency key. The sentinel reads
the prefix from the shared constant.

* fix(heartbeat): retain restart occurrences until session publication commits

* test(heartbeat): name captured occurrence invariants

* test(heartbeat): split system-event admission coverage

* chore: remove stale Discord max-lines baseline entry

---------

Co-authored-by: Marvin <marvin@local>
Co-authored-by: Patrick Erichsen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants