Skip to content

fix(claws): refuse malformed UTF-8 before adding agents - #180741

Merged
steipete merged 3 commits into
openclaw:mainfrom
Leon-SK668:leon/fix-claw-source-utf8-20261022
Oct 25, 2026
Merged

steipete merged 3 commits into
openclaw:mainfrom
Leon-SK668:leon/fix-claw-source-utf8-20261022

Conversation

@Leon-SK668

@Leon-SK668 Leon-SK668 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes Claw inspection and Add accepting malformed JSON or YAML bytes as altered names, manifest paths, or policy text.

User Impact

Malformed UTF-8 is rejected with the existing source diagnostic before Add plans or creates an agent. Valid Unicode, JSON BOM rejection, YAML BOM support, legacy profile pointers, and byte-based integrity checks retain their behavior.

Why This Change Was Made

Both text intake owners use the existing decodeUtf8Input before parsing, while retaining the original bytes for integrity hashing. The profile reader also reuses its existing filesystem root instead of creating it twice.

Thanks to @Leon-SK668 for the original fix and Linux CLI reproduction.

Evidence

  • Four regressions fail against the unchanged current-main readers: package metadata can select a replacement-character filename, JSON manifests accept altered names, and conventional/legacy YAML profiles accept altered policy text. All four pass with strict decoding, including repaired Unicode controls.
  • node scripts/run-vitest.mjs src/claws/reader.test.ts src/claws/openclaw-profile.test.ts --maxWorkers=1: all 40 tests pass, including BOM, bounds, integrity, link admission, and legacy-profile controls. After merging current main, all 40 tests passed again (277.22 s wrapper / 225.79 s Vitest). The earlier green run took 251.83 s / 201.81 s; the base red run took 241.81 s / 209.15 s. Most time was module compilation (98% of the green Vitest duration), not test execution.
  • Targeted oxlint, oxfmt, and diff checks pass.
  • Production +6/-4 (net +2), tests +55/-1 (net +54), docs +3. The small production increase validates text once while preserving raw-byte integrity; redundant root creation and comments were removed.

The contributor's original PR includes compiled Linux CLI proof pinned to c52cfbb5ce46d8dc4142d3152b663aff148018bc. This revision exercises the real filesystem and inspection owner; the built CLI and live Gateway were not rerun because a separate full build was not proportionate. The Add caller returns on a failed source read before planning or creating resources.

Independent P0–P2 autoreview completed with no actionable findings.

The previous head passed all 68 CI jobs (run 40139956445), but the separate security-review workflow failed on inconsistent GitHub diff metadata (13,906 reported files versus the five-file local diff). A normal merge of current main preserves the reviewed five-file patch byte-for-byte and refreshes that required check.

Prior-head compiled CLI trace (contributor evidence)

The following captured Linux output predates this revision. The contributor ran node ../claw-source-utf8-proof-20261022.mjs against base ce54bc879ad922006023cf889f1f38df9efd689d and candidate c52cfbb5ce46d8dc4142d3152b663aff148018bc on October 22, using Node 24.22.1 and isolated synthetic state. It is retained for inspection, not claimed as runtime proof of the current head.

Captured native output and independent readback

The malformed manifest contains byte sequence c3 28 inside the agent name. These are captured output excerpts; only temporary roots are redacted as <proof-root> and unrelated fields are omitted.

Base claws add ... --json exits 0 and reports:

{
  "status": "complete",
  "agent": {
    "requestedId": "utf8-import",
    "finalId": "utf8-import",
    "workspace": "<proof-root>/manifest/rejected-workspace",
    "config": {
      "id": "utf8-import",
      "name": "Caf�(",
      "workspace": "<proof-root>/manifest/rejected-workspace"
    }
  },
  "workspaceCreated": true,
  "configCommitted": true
}

A subsequent agents list --json process reads the stored agent back with "id": "utf8-import", "name": "Caf�(". For the profile variant, a subsequent config get agents.entries.utf8-import.groupChat.mentionPatterns --json exits 0 and reads:

[
  "@caf�("
]

At the candidate head, the identical malformed manifest Add exits 1 with this complete stdout:

{
  "schemaVersion": "openclaw.clawAddPlan.v1",
  "stability": "experimental",
  "valid": false,
  "diagnostics": [
    {
      "level": "error",
      "code": "invalid_json",
      "phase": "parse",
      "path": "$",
      "message": "Could not parse <proof-root>/manifest/source/openclaw.claw.json: <proof-root>/manifest/source/openclaw.claw.json must be valid UTF-8."
    }
  ]
}

Fresh agent-list readback contains only main; the rejected workspace is absent and config/source bytes match their pre-Add hashes. The profile variant reports openclaw_profile_read_failed at $.profiles.openclaw with profiles/openclaw.yml must be valid UTF-8. The package variant refuses before a replacement-decoded manifest path can select a different file.

Re-encoding the sources and retrying Add exits 0, creates exactly one agent per isolated case, and fresh agents list --json reads "name": "Café �( 😺". The repaired BOM-prefixed profile's fresh config readback is:

[
  "@café �( 😺"
]

This distinguishes legitimate U+FFFD from invalid input bytes rather than rejecting a character in the decoded string.

@clawsweeper

clawsweeper Bot commented Oct 22, 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 docs Improvements or additions to documentation size: S labels Oct 22, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. 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 clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 22, 2026
@clawsweeper

clawsweeper Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

Reject malformed UTF-8 in Claw JSON manifests, package metadata, and OpenClaw YAML profiles before agent creation.

Example: A JSON manifest encodes the agent name Café using a lone Latin-1 byte E9.

  • Before: Inspection accepts the replacement-decoded name Caf�.
  • After: Inspection rejects the source with a valid-UTF-8 diagnostic.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The patch is focused and appears correct, but the underlying CLI evidence referenced by the current body is unavailable for inspection.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A damaged Claw package can be accepted with altered agent names, manifest filenames, or profile text.
Reason: Rejecting invalid source encoding restores validated-import behavior with minimal production complexity and preserves valid Unicode.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep this PR open: it fixes a concrete import-corruption path still present on current main, and no actionable patch defects were found.

Priority: P2
Reviewed head: 4213890af6b0fc1a5b4141f0a34640f542ccc594

Before merge

  • Add real behavior proof - The current body references Linux CLI proof at c52cfbb, and the previous review describes malformed Add exiting 1, unchanged source/config hashes, absent rejected agents, and successful repaired Unicode. However, neither the complete current body nor its comments retains the terminal output or an artifact link, so that evidence cannot be inspected. Restore the existing redacted trace or a working link; redact IPs, API keys, phone numbers, and non-public endpoints. The current filesystem-test report supports the patch but does not replace shipped-entry-point evidence. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.

Findings

None.

Tests

  • Missing end-to-end proof: Restore the existing compiled Linux CLI trace showing malformed-source refusal before agent creation and successful repaired-Unicode input; the body reports four base failures and 40 passing candidate tests.
Agent review details

How this fits together

Claw readers turn bounded package files into validated manifests, profiles, and raw-byte snapshots consumed by inspection, package validation, registry intake, and Add.

flowchart LR
  Files[Claw source files] --> Readers[Bounded file readers]
  Readers --> Decoder[Strict UTF-8 decoding]
  Decoder --> Parser[JSON and YAML parsing]
  Parser --> Validation[Schema validation]
  Validation --> Consumers[Inspect and Add]
  Decoder --> Errors[Encoding diagnostics]
Loading

Technical review

Best possible solution:

Use the existing strict decoder at both intake owners while preserving raw-byte integrity, supported Unicode, and format-specific BOM behavior.

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

Current-main readers visibly replacement-decode malformed bytes before parsing, and the added filesystem regressions exercise concrete accepted corruption cases; no target code was run during this review.

Is this the best way to solve the issue?

This is the smallest complete fix: reject malformed bytes before parsing through the existing owners, without new state, wrappers, or caller-specific policy.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • JSON manifest and package metadata decoding keeps the original intent (67384b4: The bounded-reader consolidation preserved existing JSON behavior while removing a duplicate parser; replacement decoding was carried forward, not justified as a compatibility requirement.)
  • OpenClaw YAML profile decoding keeps the original intent (e9b3252: Profiles were designed as bounded, validated package-local policy bound to exact source bytes; the shared-YAML refactor retained reader-owned BOM handling and diagnostics.)
  • Profile filesystem root reuse keeps the original intent (5046876: The earlier runtime refactor preserved subsystem contracts; reusing the already-created package root retains the same read bounds and link-admission options.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Verified introduced patch: The pinned introduction adds strict decoding at the existing JSON and profile readers, preserves original buffers, reuses the profile filesystem root, and adds focused regressions and recovery documentation. (src/claws/reader.ts:139, 4213890af6b0)
  • Current-main defect: Current main still calls JSON.parse on raw.toString("utf8"); its profile reader also replacement-decodes raw bytes before YAML parsing. (src/claws/reader.ts:138, c8dfebcfaee8)
  • Decoder and BOM contract: The existing decoder uses fatal UTF-8 decoding and preserves the BOM character, retaining JSON BOM rejection and the profile reader's explicit YAML BOM removal. (src/infra/utf8-input.ts:4, 4213890af6b0)
  • Add rejects before planning: The CLI returns immediately when the shared source reader fails, before building the Add plan or creating its resources. (src/cli/claws-cli.runtime.ts:204, 4213890af6b0)
  • Reader provenance: The consolidation in refactor(claws): share bounded document reading #157436 established one bounded-document owner while preserving limits, diagnostics, and raw-byte integrity; strict decoding retains that ownership. (src/claws/reader.ts, 67384b481adb)
  • Proof source inspected: The complete current body references compiled Linux CLI evidence at c52cfbb but contains neither that output nor an artifact link; current comments contain no underlying trace. The prior review describes the earlier evidence but does not retain it. (4213890af6b0)

Likely related people:

  • Patrick Erichsen: Raw commit f469f6d adds docs/cli/claws.md:14 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: f469f6da5636; files: docs/cli/claws.md)

PR surface

Source +2, Tests +54, Docs +3. Total +59 across 5 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 6 4 +2
Tests 2 55 1 +54
Docs 1 3 0 +3
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 64 5 +59

Review metrics

Metric Value Why it matters
Production versus regression coverage Production +6/-4; tests +55/-1 The small production increase reuses the canonical decoder; the regressions cover corrupted names, replacement-decoded package paths, and distinct profile locations.

Labels

Label changes:

  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.
  • remove proof: sufficient: Current real behavior proof status is insufficient, not sufficient.
  • remove rating: 🦞 diamond lobster: Current PR rating is rating: 🧂 unranked krab, so this older rating label is no longer current.
  • remove status: 👀 ready for maintainer look: Current PR status label is status: 📣 needs proof.

Label justifications:

  • P2: Malformed Claw imports can silently alter agent names, selected manifests, or policy text, with impact limited to affected source packages.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Restore the previously captured Linux CLI output or its artifact link so the existing behavior proof can be inspected.

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 (1 earlier review cycle)
  • reviewed 2026-10-22T16:02:04.515Z sha c52cfbb :: needs maintainer review before merge. :: none

Reviewed October 24, 2026, 7:43 PM ET / 23:43 UTC (Revision 2).

@steipete
steipete requested a review from a team as a code owner October 24, 2026 22:45
@steipete

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot added channel: discord Channel integration: discord channel: googlechat Channel integration: googlechat channel: imessage Channel integration: imessage channel: line Channel integration: line channel: matrix Channel integration: matrix channel: mattermost Channel integration: mattermost channel: msteams Channel integration: msteams channel: nextcloud-talk Channel integration: nextcloud-talk channel: nostr Channel integration: nostr channel: signal Channel integration: signal channel: slack Channel integration: slack channel: telegram Channel integration: telegram channel: tlon Channel integration: tlon channel: voice-call Channel integration: voice-call channel: whatsapp-web Channel integration: whatsapp-web labels Oct 24, 2026
@steipete

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@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

docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. 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