Skip to content

fix(scripts): keep format-generated-module output tails UTF-8 safe - #110826

Closed
wings1029 wants to merge 1 commit into
openclaw:mainfrom
wings1029:fix/format-generated-module-utf8-tail-safe
Closed

wings1029 wants to merge 1 commit into
openclaw:mainfrom
wings1029:fix/format-generated-module-utf8-tail-safe

Conversation

@wings1029

@wings1029 wings1029 commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where scripts/lib/format-generated-module.mjs could render a
replacement character (�) in failure diagnostics when a formatter
(oxfmt) error output on a generated TypeScript/JavaScript module exceeded the
16 KiB tail cap and the retained byte window started inside a multibyte UTF-8
character. For example, a code-generated module containing CJK string
literals or comments that tripped the formatter would produce a corrupted
first character in the diagnostic tail.

Why This Change Was Made

outputTail took a byte-bounded suffix with
bytes.subarray(-N).toString("utf8") before decoding, matching the same
pattern already addressed in the sibling script
scripts/run-additional-boundary-checks.mjs (#109167). A new
decodeUtf8Tail helper now skips any leading UTF-8 continuation bytes,
keeping the existing 16 KiB cap unchanged.

User Impact

Generated-module formatting failure diagnostics stay readable when the capped
formatter output contains multibyte text at the retention boundary. There is
no behaviour change for ASCII-only output or output that stays within the
16 KiB budget.

Evidence

  • Before the fix, node -e confirmed:

    const bytes = Buffer.from("你好", "utf8");
    // Boundary at continuation byte 0xA0 of "你" (E4 BD A0).
    const tail = bytes.subarray(bytes.byteLength - 4);
    console.log(tail.toString("utf8"));  // "��好" – corrupted
  • After the fix, the same input produces "好" — the single continuation
    byte is skipped and the intact character follows.

  • node scripts/run-vitest.mjs test/scripts/format-generated-module.test.ts -- -t decodeUtf8
    passed with 3 tests (continuation-byte boundary skip, ASCII passthrough,
    empty buffer).

  • oxfmt --check passed on both changed files.

@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts size: XS labels Jul 18, 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. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. labels Jul 18, 2026
@clawsweeper

clawsweeper Bot commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 19, 2026, 12:32 PM ET / 16:32 UTC.

Summary
The branch makes format-generated-module discard leading UTF-8 continuation bytes from oversized formatter-output tails, exports outputTail, and adds regression coverage.

PR surface: Tests +18, Other +32. Total +50 across 6 files.

Reproducibility: yes. from source: current outputTail byte-truncates and directly decodes the suffix, so a formatter error string whose 16 KiB boundary lands inside a UTF-8 sequence produces a replacement character. I did not execute that path in the read-only checkout.

Review metrics: 1 noteworthy metric.

  • Dead-code audit exemption: 1 added exemption. The branch adds a Knip exclusion for a new module that is not imported by the changed runtime, reducing audit coverage without supporting the fix.

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🦪 silver shellfish
Patch quality: 🦐 gold shrimp
Result: blocked until stronger real behavior proof is added.

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

Rank-up moves:

  • Remove the unused decoder module, Knip ignore, and matching Knip test expectation.
  • [P1] Add redacted terminal or live output from a real oversized multibyte formatter failure after the fix; updating the PR body should trigger review, or a maintainer can comment @clawsweeper re-review.

Proof guidance:

  • [P1] Needs stronger real behavior proof before merge: The body shows helper-level terminal output and focused test claims, but not an after-fix run through an actual oversized multibyte formatter failure; add redacted terminal/live output showing the formatter diagnostic tail without U+FFFD. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Risk before merge

  • [P1] The added Knip exemption weakens the dead-code audit for a file that the branch does not use; leaving it would preserve duplicate implementation drift.
  • [P1] The body does not yet prove the full formatter-failure path after the fix, so the readable-diagnostic claim remains unverified in the affected runtime.

Maintainer options:

  1. Remove the dead-code exemption before merge (recommended)
    Delete the unused decoder module, its Knip ignore, and the matching Knip expectation while retaining the in-use helper and UTF-8 regression test.
  2. Pause for a narrower refresh
    If the contributor cannot provide a real formatter-failure transcript, pause this diagnostic-only fix until the behavior can be demonstrated on the affected path.

Next step before merge

  • [P1] A mechanical repair can remove the unused decoder and audit exemption, but the contributor must still supply full-path real behavior proof before merge.

Security
Cleared: The scripts-only diff adds no dependency, credential, permission, workflow, or external execution surface beyond the existing formatter path.

Review findings

  • [P2] Remove the unused decoder module and its Knip exemption — config/knip.all-exports.config.ts:118-120
Review details

Best possible solution:

Keep one decoder implementation in scripts/lib/format-generated-module.mjs, remove the unused module and its audit exemption, then add redacted terminal or live output from an oversized multibyte formatter failure showing the corrected tail.

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

Yes, from source: current outputTail byte-truncates and directly decodes the suffix, so a formatter error string whose 16 KiB boundary lands inside a UTF-8 sequence produces a replacement character. I did not execute that path in the read-only checkout.

Is this the best way to solve the issue?

No, not as submitted: the inline decoder is a narrow fix, but the separate unused module and its Knip suppression are unnecessary duplicate machinery. The implementation should retain one owner and provide full-path runtime proof.

Full review comments:

  • [P2] Remove the unused decoder module and its Knip exemption — config/knip.all-exports.config.ts:118-120
    format-generated-module.mjs defines the decoder locally and never imports scripts/lib/decode-utf8-tail.mjs; the new Knip ignore therefore masks a dead file introduced by this PR. Delete the unused module, its ignore entry, and the matching assertion, or import one canonical helper instead.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.95

AGENTS.md: found and applied where relevant.

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

Label changes

Label justifications:

  • P3: This is a low-blast-radius diagnostic readability fix in a scripts-only failure path.
  • merge-risk: 🚨 automation: The PR adds a Knip exclusion that can conceal dead exports in a file the production code does not use.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The body shows helper-level terminal output and focused test claims, but not an after-fix run through an actual oversized multibyte formatter failure; add redacted terminal/live output showing the formatter diagnostic tail without U+FFFD. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed

PR surface:

Tests +18, Other +32. Total +50 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 2 18 0 +18
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 4 35 3 +32
Total 6 53 3 +50

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs test/scripts/format-generated-module.test.ts.
  • [P1] node scripts/run-vitest.mjs test/scripts/check-deadcode-exports.test.ts.
  • [P1] git diff --check.

What I checked:

Likely related people:

  • vincentkoc: Authored the commit that introduced bounded generated-module formatter execution and subsequent formatter-path maintenance reflected in the test history. (role: introduced formatter execution path and recent area contributor; confidence: high; commits: 88c1af0a2cb4, 43bbde483046, 0a985594402a; files: scripts/lib/format-generated-module.mjs, test/scripts/format-generated-module.test.ts)
  • qingminglong: Authored the merged sibling UTF-8 output-tail repair, which establishes the closest existing implementation pattern but in a different script owner. (role: adjacent invariant contributor; confidence: medium; commits: f3e8164e7c0b; files: scripts/run-additional-boundary-checks.mjs)
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.
Review history (9 earlier review cycles; latest 8 shown)
  • reviewed 2026-07-18T17:25:46.918Z sha 2d43f35dc295fab7be13e933c08051a283a54729 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-18T17:32:15.176Z sha 6eb67a9629a012880f74cea983a7590dfd794864 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-18T17:43:36.280Z sha 9836dabb71e3cc90e611a32c5959ca31812e7e7c :: needs real behavior proof before merge. :: [P2] Keep the declared input type aligned with UTF-8 decoding
  • reviewed 2026-07-19T04:49:15.893Z sha ae8b0847089b4fdcf9a647f045fa28d2f87f5de4 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-19T04:57:04.468Z sha 505e162bb754f82d0dc013c4e2bc8fdea764c84f :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-19T05:24:52.047Z sha b352e6ed1431dff11d02a07e666cb71ee2b50334 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-19T06:07:45.765Z sha b352e6ed1431dff11d02a07e666cb71ee2b50334 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-19T14:44:16.319Z sha dd5acb6 :: needs real behavior proof before merge. :: [P2] Remove the unused decoder module and its Knip exemption

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Jul 18, 2026
@wings1029
wings1029 force-pushed the fix/format-generated-module-utf8-tail-safe branch 6 times, most recently from 2b2acbf to 01e4277 Compare July 19, 2026 14:35
When formatter (oxfmt) error output on a generated TypeScript/JavaScript
module exceeds the 16 KiB tail cap and the retained byte window starts
inside a multibyte UTF-8 character, the diagnostic tail would begin with
a replacement character (�).

Add a decodeUtf8Tail helper that skips leading UTF-8 continuation bytes
before decoding the byte suffix, matching the same pattern already
addressed in scripts/run-additional-boundary-checks.mjs (openclaw#109167).

Keep the existing 16 KiB cap and ASCII behavior unchanged.
@wings1029
wings1029 force-pushed the fix/format-generated-module-utf8-tail-safe branch from 01e4277 to dd5acb6 Compare July 19, 2026 14:40
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. label Jul 19, 2026
@steipete

Copy link
Copy Markdown
Contributor

Thank you for working on UTF-8-safe formatter diagnostics and for identifying the split-character boundary. Your broader original #110825 is now merged as 796ee27 and fixes this generated-module formatter through one shared helper, while also fixing the docs formatter and adding an end-to-end regression that runs an actual failing child process. Closing this narrower sibling as superseded keeps your original contribution and its stronger regression intact, without introducing an unused decoder or weakening the Knip dead-code audit. Thank you again for both contributions.

@steipete steipete closed this Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. scripts Repository scripts size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants