Skip to content

refactor(setup): route SetupSteps WSL quoting through WslShellQuoting - #1001

Merged
shanselman merged 1 commit into
mainfrom
bkudiess-setupsteps-wsl-quoting
Jul 17, 2026
Merged

shanselman merged 1 commit into
mainfrom
bkudiess-setupsteps-wsl-quoting

Conversation

@bkudiess

Copy link
Copy Markdown
Collaborator

Summary

Migrates SetupSteps.cs off three divergent private ShellEscape helpers onto the shared WslShellQuoting contract (added in PR 2, #994), then deletes the duplicates. This is a net-negative dedup and is behavior-preserving — the generated WSL scripts are byte-identical.

The three deleted helpers had two different wrap semantics; each call site was audited individually and mapped by the semantics of the helper it used:

Step class Old ShellEscape semantics Call sites New helper
InstallCliStep escape-only (caller supplies its own '...') BuildInstallCommand: installUrl, trimmedVersion WslShellQuoting.EscapePosixSingleQuoteInner
ConfigureGatewayStep fully-wrapped standalone token allowedCommandsJson, inline defaultPublicUrl, ExtraConfig value WslShellQuoting.QuotePosixSingleQuote
WindowsNodeBootstrapContextStep fully-wrapped standalone token RunOpenclawSetupAsync workspaceArg; BuildApplyScript / BuildRollbackScript bash-assignment lines WslShellQuoting.QuotePosixSingleQuote

The dangerous inversion — a wrapped variant where the caller already supplies '...' (yielding ''x''), or an escape-only variant on a standalone token (yielding an unquoted/splittable arg) — does not occur: only the two escape-only sites have caller-supplied outer quotes.

WslShellQuoting stays internal; it is reachable from OpenClaw.SetupEngine via the existing InternalsVisibleTo("OpenClaw.SetupEngine") in OpenClaw.Shared.csproj. Making it public would needlessly widen the Shared surface, so it was left internal per existing repo convention.

Validation

  • ./build.ps1 — all projects succeeded.
  • dotnet test tests/OpenClaw.Shared.Tests — 2864 passed / 31 skipped (WSL/device integration skips).
  • dotnet test tests/OpenClaw.Tray.Tests — 1717 passed.
  • dotnet test tests/OpenClaw.SetupEngine.Tests — 426 passed.
  • E2E setup suite — not run (gated/slow, requires a real WSL host). This PR is quoting-in-setup-scripts, not system.run/MXC; no migrated site feeds system.run/exec, and RunOpenclawSetupAsync / apply / rollback still deliver scripts via inputViaStdin: true, so no MXC/exec-approval surface is touched.

Real behavior proof

Characterization tests pin the generated command/script strings byte-for-byte for representative inputs containing an embedded single quote, proving the migration is output-identical:

  • curl … '…install'\''s.sh' … --version '2026.5.22'\''a' — InstallCli_BuildInstallCommand_EscapesSingleQuotesInUrlAndVersion (pre-existing, escape-only variant).
  • openclaw config set gateway.custom.note 'a'\''b' — ConfigureGateway_QuotesExtraConfigValueWithEmbeddedSingleQuote (new).
  • workspace='/home/o'\''brien/.openclaw/workspace' — WindowsNodeContext_BuildApplyScript_QuotesWorkspacePathWithEmbeddedSingleQuote and …RollbackScript… (new).

Architecture ledger

  • wsl-posix-quoting: residue cleared, invariant/retirement updated to reflect the migration is complete.
  • New setup-shellescape-closed row (closed, source-shape) guarded by SetupStepsShellEscapeClosureTests.SetupSteps_DoesNotReintroduce_PrivateShellEscape — fails CI if a local ShellEscape reappears in SetupSteps.cs (the behavioral WslShellQuotingTests can't catch a re-added local helper).
  • Updated the "when you touch SetupSteps.cs" extraction guidance.
  • ArchitectureLedgerConsistencyTests remains green.

Reviews (adversarial, multi-model) — GO

  • Author multi-model review — 6 models, all GO, no blocking issues: GPT-5.5 and Claude Opus 4.8 (rubber-duck), then expanded to Gemini 3.1 Pro, GPT-5.3-Codex, Claude Sonnet 5, and GPT-5.6 Sol (code-review). Each independently re-derived all 13 call-site variant mappings and confirmed byte-identity, unchanged stdin/WSL delivery, correct $$"""...""" raw-string interpolation, and a correct/false-positive-free ledger guard regex. Gemini additionally injected a fake helper to prove the guard fires.
  • Coordinator independent dual review — GPT-5.5 + Claude Opus 4.8, both GO: re-derived all 13 sites and confirmed correct escape-only vs wrapped mapping and byte-identity; no blocking issues.
  • One condition flagged by review (satisfied): the new closure guard test file tests/OpenClaw.Shared.Tests/Architecture/SetupStepsShellEscapeClosureTests.cs must ship with the PR so the ledger doesn't reference an absent guard — it is included in this PR.

Co-authored-by: Copilot App [email protected]

Migrate SetupSteps.cs off three divergent private ShellEscape helpers onto
the shared WslShellQuoting contract (added in PR 2), then delete the
duplicates. Behavior-preserving: generated scripts are byte-identical.

- InstallCliStep (escape-only, caller supplies its own outer quotes) ->
  WslShellQuoting.EscapePosixSingleQuoteInner.
- ConfigureGatewayStep + WindowsNodeBootstrapContextStep (standalone
  fully-wrapped tokens) -> WslShellQuoting.QuotePosixSingleQuote.
- Delete all three private ShellEscape methods.

WslShellQuoting stays internal, reachable via the existing
InternalsVisibleTo("OpenClaw.SetupEngine").

Add characterization tests pinning generated command/script output for
embedded-quote inputs, and a source-shape ledger guard
(setup-shellescape-closed) that fails CI if a local ShellEscape reappears
in SetupSteps.cs.

Co-authored-by: Copilot App <[email protected]>
@clawsweeper clawsweeper Bot added 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. P3 Low-risk cleanup, docs, polish, ergonomics, or speculative feature. merge-risk: 🚨 security-boundary 🚨 Merging this PR could weaken sandboxing, authorization, credentials, or sensitive data. labels Jul 16, 2026
@clawsweeper

clawsweeper Bot commented Jul 16, 2026

Copy link
Copy Markdown

Codex review: needs maintainer review before merge. Reviewed July 16, 2026, 3:48 PM ET / 19:48 UTC.

Summary
The PR replaces three private setup-script shell escaping helpers with the shared WSL quoting contract and adds characterization, architecture-ledger, and source-shape coverage.

Reproducibility: not applicable. This PR is presented as a behavior-preserving refactor rather than a report of failing current-main behavior.

Review metrics: 3 noteworthy metrics.

  • Quoting call sites: 13 migrated. Each site must preserve the distinction between inner escaping and a fully wrapped POSIX token.
  • Patch surface: 4 files affected. The change covers setup generation, architecture policy, behavioral tests, and a source-shape guard.
  • Duplicate helpers: 3 removed. Removing the local helpers establishes one shared source of truth for WSL single-quote handling.

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🦪 silver shellfish
Patch quality: 🐚 platinum hermit
Result: blocked until real behavior proof from a real setup is added.

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

Rank-up moves:

  • Attach redacted terminal or live-output evidence from a real WSL setup run covering representative quote-containing values.

Proof guidance:

  • [P1] Needs real behavior proof before merge: The byte-oriented characterization tests are useful supplemental evidence but do not show the generated scripts executing on a real WSL host; add redacted terminal or live output, update the PR body, and request @clawsweeper re-review if review does not rerun automatically.

Risk before merge

  • [P1] The migrated code constructs security-sensitive shell commands across 13 call sites; a quote-mode mismatch could make an argument split, execute incorrectly, or expose content to shell interpretation.
  • [P1] No current-head real WSL execution demonstrates that representative install, gateway configuration, apply, and rollback scripts still run successfully with quote-containing values.

Maintainer options:

  1. Add live WSL setup proof (recommended)
    Exercise representative install, gateway configuration, apply, and rollback paths with quote-containing values and attach redacted terminal output showing successful execution.
  2. Accept characterization-only evidence
    A maintainer may explicitly accept the focused string tests without live WSL proof, owning the remaining shell-execution uncertainty.

Next step before merge

  • Normal maintainer review should continue, but merge should wait for contributor-supplied real WSL behavior proof rather than an automated code repair.

Security
Cleared: The patch centralizes existing POSIX quoting semantics without adding dependencies, permissions, secret access, artifact downloads, or new execution surfaces.

Review details

Best possible solution:

Keep the centralized quoting implementation and architecture guard, then attach redacted current-head terminal proof from representative real WSL setup paths using values containing embedded single quotes.

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

Not applicable; this PR is presented as a behavior-preserving refactor rather than a report of failing current-main behavior.

Is this the best way to solve the issue?

Yes, using the shared contract with separate inner-escape and fully wrapped operations is the narrowest maintainable solution; only the required real setup proof remains outstanding.

AGENTS.md: found and applied where relevant.

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

Label changes

Label changes:

  • add P3: This is a focused internal cleanup with limited blast radius rather than an urgent regression or new user-facing capability.
  • add merge-risk: 🚨 security-boundary: Incorrect POSIX quote-mode selection in generated WSL setup scripts could expose values to shell splitting or interpretation, and no live execution proof currently closes that risk.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The byte-oriented characterization tests are useful supplemental evidence but do not show the generated scripts executing on a real WSL host; add redacted terminal or live output, update the PR body, and request @clawsweeper re-review if review does not rerun automatically.

Label justifications:

  • P3: This is a focused internal cleanup with limited blast radius rather than an urgent regression or new user-facing capability.
  • merge-risk: 🚨 security-boundary: Incorrect POSIX quote-mode selection in generated WSL setup scripts could expose values to shell splitting or interpretation, and no live execution proof currently closes that risk.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The byte-oriented characterization tests are useful supplemental evidence but do not show the generated scripts executing on a real WSL host; add redacted terminal or live output, update the PR body, and request @clawsweeper re-review if review does not rerun automatically.
Evidence reviewed

What I checked:

Likely related people:

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.

@shanselman
shanselman merged commit b8b1dc3 into main Jul 17, 2026
19 checks passed
@shanselman
shanselman deleted the bkudiess-setupsteps-wsl-quoting branch July 17, 2026 00:36
calebeden added a commit to calebeden/openclaw-windows-node that referenced this pull request Jul 17, 2026
Preserve the finalized WSL quoting ownership rows from openclaw#1001 and append the WSL distro install-path policy row.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: f19f98b7-f377-4da5-a7ce-0f1ae34153cf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 security-boundary 🚨 Merging this PR could weaken sandboxing, authorization, credentials, or sensitive data. P3 Low-risk cleanup, docs, polish, ergonomics, or speculative feature. 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants