Skip to content

fix: preserve .wslconfig encoding - #1224

Merged
shanselman merged 2 commits into
openclaw:mainfrom
joelagnel:fix/1193-wslconfig-surgical
Aug 26, 2026
Merged

shanselman merged 2 commits into
openclaw:mainfrom
joelagnel:fix/1193-wslconfig-surgical

Conversation

@joelagnel

@joelagnel joelagnel commented Aug 25, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Detect UTF-8, UTF-8 BOM, UTF-16 LE BOM, and UTF-16 BE BOM before parsing .wslconfig.
  • Decode strictly and reject malformed, UTF-32, NUL-bearing, and BOM-less UTF-16 input before creating backup or rollback files.
  • Preserve valid decoded control characters, unknown content, the original encoding/BOM, newline convention, and byte-exact rollback behavior.

Validation

  • .\build.ps1 (passed on AMD64; Shared, CLI, WinNode CLI, SetupEngine, and WinUI built)
  • dotnet test .\tests\OpenClaw.SetupEngine.Tests\OpenClaw.SetupEngine.Tests.csproj --filter FullyQualifiedName~WslGlobalConfigManagerTests --no-restore (30 passed, 0 failed)
  • dotnet test .\tests\OpenClaw.SetupEngine.Tests\OpenClaw.SetupEngine.Tests.csproj --no-restore (967 passed, 0 failed)
  • dotnet test .\tests\OpenClaw.Shared.Tests\OpenClaw.Shared.Tests.csproj --no-restore (3,812 passed, 32 skipped, 0 failed)
  • dotnet test .\tests\OpenClaw.Tray.Tests\OpenClaw.Tray.Tests.csproj --no-restore (2,703 passed, 0 failed)
  • Hanselman adversarial review: no remaining correctness defects; Opus 97% and Codex 98% merge confidence.

Real behavior proof

Current-head proof loaded the built OpenClaw.SetupEngine.dll and invoked WslGlobalConfigManager against an isolated CRLF UTF-16 LE BOM file containing unrelated [experimental] content.

{
  "encoding": "UTF-16 LE with BOM",
  "applyChanged": true,
  "bomPreserved": true,
  "mirroredSettingPresent": true,
  "unknownContentPreserved": true,
  "rollbackResult": "Restored",
  "originalSha256": "3a95220877974453a6475a51cdb8944aae960bd010c6148d44c96bec1bc98c4f",
  "restoredSha256": "3a95220877974453a6475a51cdb8944aae960bd010c6148d44c96bec1bc98c4f",
  "rollbackByteIdentical": true
}

Malformed UTF-8/UTF-16, UTF-32 BOM, and BOM-less UTF-16 cases also assert that the original bytes remain unchanged and the backup directory is never created.

Closes #1193

@clawsweeper

clawsweeper Bot commented Aug 25, 2026

Copy link
Copy Markdown

🦞👀
ClawSweeper picked this up.

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

@clawsweeper clawsweeper Bot added P2 Normal priority bug or improvement with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 25, 2026
@clawsweeper

clawsweeper Bot commented Aug 25, 2026 •

Copy link
Copy Markdown

Codex review: needs maintainer review before merge. Reviewed August 25, 2026, 9:10 PM ET / August 26, 2026, 01:10 UTC.

ClawSweeper review

What this changes

The PR adds strict .wslconfig decoding, preserves supported encoding/BOM/newlines on mirrored-networking updates, and adds rollback and invalid-input regression coverage.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep this active PR open. Current main still uses permissive UTF-8-only handling, while this focused repair safely preserves supported encodings and its updated body includes direct after-fix rollback output.

Priority: P2
Reviewed head: 5f7138acf1601d86a5875ec50649e1d2c90fc292

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The focused patch, regression coverage, and direct file-operation proof provide normal merge-ready evidence.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The PR body includes current-head live output showing a UTF-16 LE BOM update, unrelated-content preservation, and byte-identical rollback.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body includes current-head live output showing a UTF-16 LE BOM update, unrelated-content preservation, and byte-identical rollback.
Evidence reviewed 4 items Current-main behavior: Current main still parses through ReadUtf8Document and writes through EncodeUtf8, so it does not preserve UTF-16 files or reject malformed bytes strictly.
Implementation and tests: The PR detects BOM-marked UTF-8/UTF-16, rejects UTF-32, malformed sequences, and NUL-bearing data before backup creation, then writes using the detected representation; tests cover both UTF-16 byte orders, line endings, byte-identical rollback, and no-write rejection.
Current-head provenance: Current decoding lines blame to the maintainer follow-up commit that narrowed rejection to NUL-bearing ambiguous input while retaining other valid controls.
Findings None None.
Security None None.

Live Verification

Command: dotnet test ./tests/OpenClaw.SetupEngine.Tests/OpenClaw.SetupEngine.Tests.csproj --filter FullyQualifiedName~WslGlobalConfigManagerTests --no-restore

Result: FAIL (failed) — execution before step 1 run: sh -lc pnpm install --ignore-scripts --frozen-lockfile failed: ! Corepack is about to download https://registry.npmjs.org/pnpm/-/pnpm-11.24.0.tgz

sh -lc pnpm install --ignore-scripts --frozen-lockfile failed: ! Corepack is about to download https://registry.npmjs.org/pnpm/-/pnpm-11.24.0.tgz

Assertions:

  • FAIL expect_output: Passed!

How this fits together

The Setup Engine reads a user-owned .wslconfig before enabling local-AI mirrored networking, updates its wsl2 section, and keeps original bytes for rollback. WSL later consumes the edited configuration.

flowchart LR
A[User .wslconfig bytes] --> B[Setup Engine]
B --> C[Strict encoding validation]
C --> D[Mirrored networking edit]
D --> E[WSL networking]
D --> F[Original-byte backup]
F --> G[Rollback restore]
Loading

Before merge

  • Resolve merge risk (P1) - BOM-less UTF-16 and UTF-32 files will now safely make local-AI networking unavailable rather than being rewritten, so affected users need a clear re-save-and-retry recovery path.
  • Complete next step (P2) - No mechanical repair is identified; the active, maintainer-engaged PR should proceed through normal checks with the safe-rejection compatibility tradeoff visible.
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Focused scope 2 PR files, production +55/-13, tests +167 The submitted change is narrowly confined to the configuration manager and its regression tests.

Merge-risk options

Maintainer options:

  1. Accept the safe rejection boundary (recommended)
    Land the intentional fail-closed behavior because it prevents corruption of unsupported configuration files.
  2. Improve recovery guidance first
    Add a specific supported-encoding re-save instruction before landing, while retaining strict decoding and no-write rejection.

Technical review

Best possible solution:

Keep strict pre-write rejection and representation-preserving writes, while making the recovery text actionable for users whose existing file is unsupported.

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

Yes. Current main’s UTF-8-only path is source-reproducible for BOM-marked UTF-16 input, and the PR body supplies current-head update-and-rollback output.

Is this the best way to solve the issue?

Yes. Strict detection before backup or write, preservation of recognized representations, and rejection of ambiguous input are the narrowest safe repair.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add merge-risk: 🚨 compatibility: Unsupported existing files now fail closed instead of being rewritten during setup.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes current-head live output showing a UTF-16 LE BOM update, unrelated-content preservation, and byte-identical rollback.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body includes current-head live output showing a UTF-16 LE BOM update, unrelated-content preservation, and byte-identical rollback.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.

Label justifications:

  • P2: This is a bounded setup configuration safety repair.
  • merge-risk: 🚨 compatibility: Unsupported existing files now fail closed instead of being rewritten during setup.
  • 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 includes current-head live output showing a UTF-16 LE BOM update, unrelated-content preservation, and byte-identical rollback.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes current-head live output showing a UTF-16 LE BOM update, unrelated-content preservation, and byte-identical rollback.

Evidence

What I checked:

  • Current-main behavior: Current main still parses through ReadUtf8Document and writes through EncodeUtf8, so it does not preserve UTF-16 files or reject malformed bytes strictly. (src/OpenClaw.SetupEngine/WslGlobalConfigManager.cs:53, c446f34882af)
  • Implementation and tests: The PR detects BOM-marked UTF-8/UTF-16, rejects UTF-32, malformed sequences, and NUL-bearing data before backup creation, then writes using the detected representation; tests cover both UTF-16 byte orders, line endings, byte-identical rollback, and no-write rejection. (src/OpenClaw.SetupEngine/WslGlobalConfigManager.cs:137, 5f7138acf160)
  • Current-head provenance: Current decoding lines blame to the maintainer follow-up commit that narrowed rejection to NUL-bearing ambiguous input while retaining other valid controls. (src/OpenClaw.SetupEngine/WslGlobalConfigManager.cs:137, 5f7138acf160)
  • Active implementation context: The PR body provides current-head output for a CRLF UTF-16 LE BOM update, preserved unrelated content, and byte-identical rollback; its timeline also records maintainer follow-up and active-landing status. (5f7138acf160)

Likely related people:

  • shanselman: Authored the current-head encoding-rejection refinement and appears in current-line blame for the decoding path. (role: recent area contributor; confidence: high; commits: 5f7138acf160; files: src/OpenClaw.SetupEngine/WslGlobalConfigManager.cs, tests/OpenClaw.SetupEngine.Tests/WslGlobalConfigManagerTests.cs)
  • joelagnel: History identifies the managed-local-AI feature that introduced the configuration-manager surface. (role: feature introducer; confidence: medium; commits: ccd64bbb7d68; files: src/OpenClaw.SetupEngine/WslGlobalConfigManager.cs)
  • Barbara Kudiess: Earlier setup-engine refactor history is adjacent to the configuration manager’s ownership boundary. (role: adjacent setup contributor; confidence: medium; commits: b37307cbd51f; files: src/OpenClaw.SetupEngine/ConfigureWslInstanceStep.cs)

Rank-up moves

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

  • Confirm that recovery text tells users of rejected BOM-less UTF-16 or UTF-32 files how to re-save and retry.

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 (1 earlier review cycle)
  • reviewed 2026-08-25T18:50:19.692Z sha cfd4f27 :: needs real behavior proof before merge. :: none

@shanselman shanselman added the status: 🚢 actively landing A maintainer or agent is actively driving this item through implementation, validation, or merge. label Aug 26, 2026
Preserve valid decoded control characters while rejecting NUL-bearing ambiguous Unicode encodings before any backup or write. Expand encoding, rollback, and unknown-content coverage.

Co-authored-by: Copilot App <[email protected]>
@shanselman

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 26, 2026 •

Copy link
Copy Markdown

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. proof: sufficient Contributor real behavior proof is sufficient. 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 status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 26, 2026
@shanselman
shanselman merged commit 38b4ea3 into openclaw:main Aug 26, 2026
19 checks passed
@shanselman shanselman removed the status: 🚢 actively landing A maintainer or agent is actively driving this item through implementation, validation, or merge. label Aug 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Preserve or reject non-UTF-8 .wslconfig files before modification

2 participants