Skip to content

fix(infra): keep astral automation summaries whole at the heartbeat preview cap - #182776

Merged
steipete merged 2 commits into
openclaw:mainfrom
wangmiao0668000666:fix/infra-heartbeat-preview-astral
Oct 26, 2026
Merged

steipete merged 2 commits into
openclaw:mainfrom
wangmiao0668000666:fix/infra-heartbeat-preview-astral

Conversation

@wangmiao0668000666

@wangmiao0668000666 wangmiao0668000666 commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Related: #181741, #181742

What Problem This Solves

Converted command automations can leave a replacement character in heartbeat diagnostics when their summary crosses the 2,000 UTF-16-unit preview cap.

User Impact

Heartbeat previews keep astral characters whole while preserving the existing cap, ordinary text, and absent-summary behavior.

Why This Change Was Made

Use the existing surrogate-safe truncation helper at the diagnostic projection that owns the cap. Agent-turn summaries are already capped safely; converted command output can reach this projection without that earlier cap. No new configuration, state, or truncation policy is added.

Thanks to @wangmiao0668000666 for the fix and the isolated shipped-CLI reproduction. Contributor commits are preserved. Production +1 line (the existing helper import), tests +25 lines; there is no redundant nearby path to remove without broadening this two-line fix.

Evidence

  • Regression red on unchanged current-main owner: one failure (a trailing lone surrogate), 10 passes; 5.00 seconds including the runner.
  • With the fix: all 11 tests pass; 5.61 seconds including the runner, 0.46 seconds of tests.
  • Targeted oxlint/oxfmt and diff checks pass. Independent Codex autoreview is scoped-clean, with no actionable P0–P2 finding. All selected type graphs and ownership checks pass; the broad script/full-tree unused-export scans report untouched test helpers, including a Telegram helper that is byte-identical on current main. The production unused-export scan passes with zero entries.

Which completions reach the cut

The projection is fed only by receipt-owned converted/default automations: refreshLegacyMonitorProjection() seeds its map from readHeartbeatSummarySnapshot() → readDefaultProactiveJobsAsync (src/infra/heartbeat-summary-snapshot.ts:36, src/gateway/server-cron.ts:350-370), and emitLegacyHeartbeatCronOutcome is called only for those jobs on action === "finished" (src/gateway/server-cron.ts:601-610). A plain user-created cron job never enters that path.

Two producers can hand it a summary:

  • Agent-turn completions: pickSummaryFromOutput already caps the text at 2,000 units with truncateUtf16Safe (src/cron/isolated-agent/helpers.ts:67-74), so an agent summary can never straddle the boundary. (My first attempt at an end-to-end run used the migrated agent-turn automation and produced a well-formed 1,999-unit preview on both base and head — a real control, but not a reproducer.)
  • Command completions: the same converted automation can be pointed at a command payload through the shipped CLI (openclaw automations edit <id> --command …; command payloads are legal on the migrated session: target per src/cron/service/jobs-validation.ts:113). runCronCommandJob returns the command output as the run summary (src/gateway/server-cron.ts:443-464, src/cron/command-output-summary.ts), which is not pre-capped at 2,000. That summary is the input that reaches the cut.

Evidence: shipped run against the same tree, one variable

Proof host, Node v24.22.1, built dist/entry.js, isolated HOME/OPENCLAW_STATE_DIR, loopback Gateway on 127.0.0.1:18961, no network, no model credentials, no installs.

Setup, all through the shipped CLI: a config carrying legacy agents.defaults.heartbeat is migrated by openclaw doctor --fix into the receipt-owned automation (automation-default:/tmp/hbstate/cron/jobs.json:main → {"phase":"complete","heartbeatEnabled":true}), the same automation is pointed at a command payload whose output is "s" * 1999 + U+1F600 + "tail" (2,005 UTF-16 units), the run is triggered with openclaw automations run <id>, and the result is read back with openclaw system heartbeat last --json.

The changed production file is byte-identical to the PR base b2754d0da28 on the tree used for both builds (src/infra/heartbeat-events.ts md5 98268327e415dec50be48e24a810db27), so the only difference on this projection's code path is this PR's patch. (The post-change build also carries an unrelated plugins uninstall preview patch from a separate worktree; it does not touch last-heartbeat.)

Before (dist built from that tree, i.e. the base content of the changed file):

$ openclaw system heartbeat last --json
{"status":"ok-empty","units":2000,"loneSurrogates":1,"wellFormed":false,
 "tail":["U+73","U+73","U+73","U+73","U+73","U+73","U+73","U+D83D"]}

After (same tree, this PR's production change applied, rebuilt dist):

$ openclaw system heartbeat last --json
{"status":"ok-empty","units":1999,"loneSurrogates":0,"wellFormed":true,
 "tail":["U+73","U+73","U+73","U+73","U+73","U+73","U+73","U+73"]}

The boundary-crossing emoji is dropped whole rather than half-written; the receipt row for that run shows payload_kind: "command" for the same jobId the receipt names.

Legal control (fixed build, same projection): a command output of "s" * 1999 + "tail" (2,003 units, no astral character) still yields units: 2000, loneSurrogates: 0, wellFormed: true, ending … s, t. The 2,000-unit cap itself is unchanged; only the pair boundary moves.

Owning-boundary vitest against upstream main b2754d0da28:

  • Base tree (upstream + this PR's test only): Test Files 1 failed (1), Tests 1 failed | 10 passed (11); the only failure is keeps an astral automation summary whole at the preview cap, and the reporter shows the received value ending in U+FFFD.
  • Head tree (same tree + this fix): Test Files 1 passed (1), Tests 11 passed (11).
  • Second new test (control): a summary that fits the cap with the astral character fully inside it ("s" * 1998 + U+1F600) is unchanged on base and head.

Formatting: node scripts/run-format.mts --check src/infra/heartbeat-events.ts src/infra/heartbeat-events.test.ts → All matched files use the correct format.

Exact head SHA: a015d7f89645fd66158711318982628097953295

Not tested

The Control UI Debug page and status --json were not separately exercised; they consume the same last-heartbeat RPC field that the shipped run above read. No other producer of this projection was found: agent-turn summaries are pre-capped safely, and the skip/defer summaries are short static strings.

The shipped Gateway/CLI proof above is contributor evidence from the original patch. This lane reran the owning-boundary regression on the unchanged main owner and the exact repair. A new Gateway/Doctor migration run was not attempted because rebuilding and provisioning that path exceeds the targeted live-proof budget; the UI Debug page and status command were not separately live-tested.

Integrated current main (b307533754a13be26e3d1b1cb78ae4956531ded0) with contributor commits intact. Both reviewed files are unchanged by integration. On final head 2ea850617dcae85acc893a2c4d79808b3edc771e, node scripts/run-vitest.mjs src/infra/heartbeat-events.test.ts --maxWorkers=1 passes all 11 cases in 3.85 seconds including the runner.

Exact-head CI: run 40250393670 passed on 2ea850617dcae85acc893a2c4d79808b3edc771e; the CI watcher reports GREEN, with superseded cancelled checks excluded. ClawSweeper reviewed this exact head with no findings and sufficient live-output proof.

@clawsweeper

clawsweeper Bot commented Oct 24, 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.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 24, 2026
@clawsweeper

clawsweeper Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR prevents the heartbeat preview’s 2,000-unit cap from splitting a UTF-16 surrogate pair.

Example: A converted command automation outputs 1,999 copies of s followed by 😀tail.

  • Before: The preview contains 2,000 UTF-16 units and ends with a lone high surrogate.
  • After: The preview contains 1,999 copies of s, dropping the boundary-crossing emoji whole.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Focused repair with shipped-entry-point before/after evidence, meaningful boundary tests, and no identified defect; broad CI is still pending.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Contributor live output exercises the changed heartbeat projection through an isolated built Gateway and shipped automation and heartbeat CLI commands, showing the malformed 2,000-unit preview become a well-formed 1,999-unit preview; an ordinary-text control preserves the cap, and integration leaves the exercised owner unchanged.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Heartbeat diagnostics can display a broken character when converted command output crosses the preview boundary.
Reason: The repair restores valid surrogate boundaries with existing machinery and no new configuration, storage, or behavior policy.

Merge readiness

✅ Ready for maintainer review

This PR fixes a reachable diagnostic-text defect still present on current main with a minimal, correct change; no actionable findings remain.

Priority: P3
Reviewed head: 2ea850617dcae85acc893a2c4d79808b3edc771e

Before merge

None.

Findings

None.

Agent review details

How this fits together

Receipt-owned automation completions enter the legacy heartbeat diagnostic projection; its bounded preview is stored in memory and exposed through the last-heartbeat RPC and system heartbeat last CLI.

flowchart LR
  A[Converted command automation] --> B[Cron completion]
  B --> C[Heartbeat diagnostic projection]
  C --> D[UTF16 safe truncation]
  D --> E[Last heartbeat state]
  E --> F[Gateway RPC and CLI]
Loading

Technical review

Best possible solution:

Merge the focused repair through the normal CI gates, retaining the existing preview owner and truncation helper.

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

Source confirms the reachable unsafe cut, and the contributor’s shipped-CLI before/after trace demonstrates it; this read-only review executed no target code.

Is this the best way to solve the issue?

Reusing the existing helper at the projection that owns the cap is the smallest complete fix and preserves ordinary text, intact pairs, and absent summaries.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Legacy heartbeat completion preview keeps the original intent (ec5d369: Expose settled receipt-owned automation outcomes through retained heartbeat diagnostics during the Automations migration.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +1, Tests +25. Total +26 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 2 1 +1
Tests 1 25 0 +25
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 27 1 +26

Labels

Label changes:

No label changes.

Label justifications:

  • P3: The defect affects a diagnostic preview at a specific Unicode boundary without changing automation execution or delivered output.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-24T18:46:10.939Z sha a015d7f :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-25T01:48:27.347Z sha a015d7f :: needs maintainer review before merge. :: none

Reviewed October 25, 2026, 8:44 PM ET / October 26, 2026, 00:44 UTC (Revision 3).

@wangmiao0668000666

Copy link
Copy Markdown
Contributor Author

Evidence boundary correction in the PR body: this projection is only fed by default-proactive automation completions (readHeartbeatSummarySnapshot → readDefaultProactiveJobsAsync seeds legacyMonitorJobs), so a user-created cron job never reaches emitLegacyHeartbeatCronOutcome. On the offline proof host the seeded Memory Dreaming Promotion agentTurn short-circuits with NO_REPLY before any model call, so a shipped last-heartbeat preview carrying astral text could not be produced without model credentials. The owning-boundary red/green suite and the legal control in the body stand as the deepest reachable proof; I have not requested a re-review because the requested end-to-end artifact is not obtainable here.

@wangmiao0668000666

Copy link
Copy Markdown
Contributor Author

Shipped-run evidence added to the body.

The input is the receipt-owned automation produced by the shipped migration, not a synthetic event: openclaw doctor --fix converts the legacy heartbeat config into automation-default:/tmp/hbstate/cron/jobs.json:main → {"phase":"complete"}, the same job is pointed at a command payload with openclaw automations edit <id> --command …, run with openclaw automations run <id>, and read back with openclaw system heartbeat last --json from a built dist Gateway.

  • Base content of src/infra/heartbeat-events.ts (md5 98268327e415dec50be48e24a810db27, byte-identical to b2754d0da28): units: 2000, loneSurrogates: 1, wellFormed: false, last unit U+D83D.
  • Same tree with this PR's change: units: 1999, loneSurrogates: 0, wellFormed: true, emoji dropped whole.
  • Control on the fixed build ("s" * 1999 + "tail", no astral character): still units: 2000 — the cap is unchanged.

One boundary I now state explicitly in the body: agent-turn summaries cannot reproduce this because pickSummaryFromOutput already caps them at 2,000 with truncateUtf16Safe (src/cron/isolated-agent/helpers.ts:67-74); the command completion is the remaining producer that reaches the cut.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed 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. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 25, 2026
@steipete

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added the clawsweeper:intake:bug Preliminary submission classification; full source review pending. label Oct 26, 2026
@clawsweeper clawsweeper Bot removed the clawsweeper:intake:bug Preliminary submission classification; full source review pending. label Oct 26, 2026
@steipete
steipete merged commit 5f71bbf into openclaw:main Oct 26, 2026
134 of 135 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 27, 2026
…review cap (openclaw#182776)

Use UTF-16-safe truncation for receipt-owned automation heartbeat previews. Preserve the existing cap without splitting astral characters in command summaries.

Co-authored-by: wangmiao0668000666 <[email protected]>
@wangmiao0668000666
wangmiao0668000666 deleted the fix/infra-heartbeat-preview-astral branch October 28, 2026 06:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: XS 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