Skip to content

fix(cron): preserve UTF-16 boundaries in exec tails - #104385

Merged
steipete merged 1 commit into
openclaw:mainfrom
mushuiyu886:fix/followup-103740
Jul 11, 2026
Merged

steipete merged 1 commit into
openclaw:mainfrom
mushuiyu886:fix/followup-103740

Conversation

@mushuiyu886

Copy link
Copy Markdown
Contributor

Summary

  • preserve UTF-16 boundaries when retaining the tail of failed exec output
  • add a regression test through createCronRunDiagnosticsFromAgentResult
  • reuse the shared sliceUtf16Safe helper

What Problem This Solves

Cron failed-exec diagnostics retain the final 2,000 UTF-16 code units because the actionable error is usually at the end. The previous tail slice could begin between an emoji's surrogate halves, leaving a lone low surrogate in the persisted diagnostic summary and message.

User Impact

Long exec failures containing emoji or other astral characters at the truncation boundary can no longer produce malformed cron diagnostics in run logs and control surfaces.

Origin / follow-up

  • Follows: fix(codex): preserve Unicode diagnostics boundaries #103740, which made Codex diagnostic truncation UTF-16 safe.
  • Gap this fills: cron diagnostics had already adopted safe prefix truncation, but the failed-exec tail helper still used raw String.prototype.slice.
  • Consistency: this change reuses the same shared UTF-16-safe slicing utility used by other bounded text paths.

Competition / linked PR analysis

A fresh competition scan of related open PR changed files and exact tailText references found no PR covering src/cron/run-diagnostics.ts. The author's open PRs also do not overlap this path.

Merge risk

  • Why it matters / User impact: malformed UTF-16 can be rendered as replacement characters or rejected by downstream serializers.
  • Risk labels considered: availability.
  • Risk explanation: the change can retain one fewer UTF-16 code unit when the old boundary landed inside a surrogate pair.
  • Why acceptable: dropping the incomplete half preserves valid text and keeps the existing tail-first diagnostic policy.
  • Maintainer-ready confidence: High; the production entry is directly reproducible and the patch uses an existing shared helper.
  • Patch quality notes: focused two-file patch with no type escape, fallback, public contract change, or unrelated refactor.
  • Target test file: src/cron/run-diagnostics.test.ts
  • Root cause: the normalization invariant was violated because tailText used a raw UTF-16 code-unit slice whose start could land on a low surrogate.
  • Why this is root-cause fix: the source boundary is corrected where the retained tail is created, before the malformed substring can enter normalization, the runtime diagnostics object, or persistence.
  • What did NOT change: only surrogate-boundary handling changed; diagnostic limits, redaction, severity, entry ordering, fallback messages, schemas, and public APIs remain unchanged.
  • Architecture / source-of-truth check: tailText in the canonical cron diagnostic construction path is the source of truth for failed-exec tail retention; no downstream renderer, storage schema, or delivery path was changed.
  • Scenario locked in: a 2,002-code-unit failed exec output whose 2,000-unit tail starts inside an emoji.
  • Why this is the smallest reliable guardrail: one shared-helper substitution plus one production-entry regression test.

Real behavior proof

  • Behavior or issue addressed: failed-exec tail truncation no longer emits a lone low surrogate.
  • Canonical reachability path: input source payloads[].details.aggregated from the shipped exec tool result → ingestion/type checks in createCronRunDiagnosticsFromAgentResult and createCronRunDiagnosticsFromExecDetails → string normalization by normalizeOptionalString → runtime failed-exec message → tailText effect → normalized CronRunDiagnostics summary and entry.
  • Boundary crossed: the production entry ingests the canonical exec-result payload and returns the runtime diagnostic object consumed by cron persistence and control surfaces; the proof terminates at that returned production object.
  • Shared helper / provider constraint check: reused the repository's existing shared sliceUtf16Safe helper; provider-specific constraints are not applicable.
  • Real environment tested: Linux worktree on Node 22 with the repository pnpm toolchain.
  • Exact steps or command run after this patch: direct production-function execution with a 2,002-code-unit boundary fixture, plus pnpm test src/cron/run-diagnostics.test.ts.
  • Evidence after fix:
BEFORE: summary started with lone low surrogate U+DE00
AFTER:  summary length=1999, first code unit=0x79 ('y')
        entry length=1000, first code unit=0x79 ('y')
CONTROL: short ASCII failed-exec diagnostic remained unchanged
TESTS:   1 file passed, 14 tests passed
  • Observed result after fix: both summary and entry begin on a complete character boundary while preserving the actionable tail.
  • What was not tested: rendering and storage consumers were not exercised; this defect and proof terminate at the returned production diagnostic object.
  • Fix classification: Root cause fix

Review findings addressed

N/A — new focused follow-up with no existing review findings.

Regression Test Plan

  • run pnpm test src/cron/run-diagnostics.test.ts
  • verify the surrogate-boundary failed-exec fixture remains valid
  • verify short successful and failed exec controls remain unchanged

Risk / Compatibility

No API or schema changes. At a split surrogate boundary, the retained tail can be one code unit shorter than before so the output remains valid UTF-16.

What was not changed

No changes to cron scheduling, exec execution, diagnostic severity, redaction, storage schema, UI rendering, or delivery behavior.

Root Cause

The tail helper bounded text with a raw UTF-16 code-unit slice. When its start index pointed at the low half of a surrogate pair, the returned string began with an unpaired surrogate.

@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. P2 Normal backlog priority with limited blast radius. labels Jul 11, 2026
@clawsweeper

clawsweeper Bot commented Jul 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 11, 2026, 6:15 AM ET / 10:15 UTC.

Summary
The PR replaces raw cron failed-exec tail slicing with sliceUtf16Safe and adds a boundary regression test through createCronRunDiagnosticsFromAgentResult.

PR surface: Source 0, Tests +21. Total +21 across 2 files.

Reproducibility: yes. from source with high confidence. On current main, x😀 followed by 1,999 ASCII code units makes the retained 2,000-unit tail begin on the emoji’s low surrogate.

Review metrics: none identified.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🐚 platinum hermit
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • none.

Next step before merge

  • This active PR appears correct as submitted and needs normal maintainer review rather than a separate ClawSweeper repair job.

Security
Cleared: The focused internal string-slicing and regression-test change introduces no concrete security or supply-chain concern.

Review details

Best possible solution:

Land the shared-helper substitution and production-entry regression test while preserving the existing tail-first policy, diagnostic limits, redaction, schemas, and downstream consumers.

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

Yes, from source with high confidence. On current main, x😀 followed by 1,999 ASCII code units makes the retained 2,000-unit tail begin on the emoji’s low surrogate.

Is this the best way to solve the issue?

Yes. Reusing the repository’s surrogate-safe slicer at the canonical tail-construction boundary is the narrowest maintainable root-cause fix and avoids duplicating Unicode logic downstream.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 5e8a534fadb9.

Label changes

Label justifications:

  • P2: The PR fixes malformed cron diagnostic text at a rare truncation boundary with limited blast radius and no public contract change.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body provides after-fix output from the production constructor, an unchanged ASCII control, and a passing focused test result that directly demonstrate the corrected boundary.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides after-fix output from the production constructor, an unchanged ASCII control, and a passing focused test result that directly demonstrate the corrected boundary.
Evidence reviewed

PR surface:

Source 0, Tests +21. Total +21 across 2 files.

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

What I checked:

Likely related people:

  • vincentkoc: Git history attributes the current cron diagnostics module, its tests, and the shared UTF-16 slicing helper to this contributor’s merged work. (role: feature introducer and recent area contributor; confidence: high; commits: 64a76d18eee5; files: src/cron/run-diagnostics.ts, src/cron/run-diagnostics.test.ts, packages/normalization-core/src/utf16-slice.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.

@steipete steipete self-assigned this Jul 11, 2026
@steipete
steipete merged commit 1c576a2 into openclaw:main Jul 11, 2026
135 of 140 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary 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