Skip to content

fix(cli): bound unknown command diagnostics - #120380

Merged
steipete merged 2 commits into
mainfrom
codex/autoqa-cli-unknown-command-safe-output-20260807
Aug 8, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/autoqa-cli-unknown-command-safe-output-20260807

Conversation

@steipete

@steipete steipete commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • sanitize unknown root-command labels before rendering them in CLI failure output
  • cap displayed labels at 128 UTF-16 units and mark truncation without splitting emoji
  • preserve ordinary typo suggestions while skipping suggestion work for transformed or oversized input

Fixes #120379

Root cause

The early unowned-command diagnostic interpolated the raw argv token twice. Control sequences and embedded line breaks therefore reached stderr unchanged, while oversized tokens amplified the error output.

Verification

  • node scripts/run-vitest.mjs run src/cli/run-main.exit.test.ts — 207 passed
  • pnpm build — passed twice, including the packaged CLI and Control UI bundle
  • source-blind built-CLI contract — ordinary typo suggestions preserved; hostile ANSI/newline/tab argv emitted zero ESC/tab control bytes and literal \n/\t; 1,000 emoji produced a bounded 776-byte diagnostic whose displayed label is 127 UTF-16 units including the ellipsis
  • fresh-process hostile-input stress — 40/40 passed
  • node scripts/check-changed.mjs -- src/cli/run-main.ts src/cli/run-main.exit.test.ts — passed on Blacksmith Testbox tbx_01kzf8ab10337p41ms530ex4cb: https://github.com/openclaw/openclaw/actions/runs/31226710750
  • AutoReview — clean at P2, confidence 0.95
  • fresh rebased/correction AutoReviews — clean at P2, confidence 0.99
  • accepted ClawSweeper P2 — truncation now reserves marker space inside the 128-unit display cap

Risk

Low. The change is limited to display formatting for unknown command roots. Command routing, plugin ownership, config, protocol, storage, dependencies, and normal command execution are unchanged.

@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes size: XS maintainer Maintainer-authored PR labels Aug 7, 2026
@steipete steipete self-assigned this Aug 7, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 7, 2026
@clawsweeper clawsweeper Bot added the P2 Normal backlog priority with limited blast radius. label Aug 7, 2026
@clawsweeper

clawsweeper Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed August 7, 2026, 11:47 PM ET / August 8, 2026, 03:47 UTC.

ClawSweeper review

What this changes

This PR sanitizes and bounds unknown root-command diagnostics while preserving typo suggestions for ordinary command mistakes.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

This focused CLI hardening fix is still needed, but the exact head preserves the prior P2 boundary error: a truncated label can reach 129 UTF-16 units despite its 128-unit cap. The maintainer-authored, protected PR should remain open for that mechanical correction and CI completion.

Priority: P2
Reviewed head: b4b72f960e8be5bab3cbc8e3e8b5528cb9634abf

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The patch is narrowly targeted and well-covered in intent, but the unresolved cap violation blocks merge readiness.
Proof confidence 🌊 off-meta tidepool Not applicable: This is a maintainer-authored PR, so the external-contributor proof gate does not apply; its reported built-CLI checks remain useful supplemental evidence.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This is a maintainer-authored PR, so the external-contributor proof gate does not apply; its reported built-CLI checks remain useful supplemental evidence.
Evidence reviewed 5 items Cap overflow in exact PR head: The overflow branch keeps 128 UTF-16 units and then appends an ellipsis, yielding a 129-unit displayed label.
Regression test accepts the overflow: The new emoji case expects 64 two-unit emoji plus the one-unit marker instead of asserting the final label remains within 128 UTF-16 units.
Shared owner boundary: Both early unknown-root failure paths call the same formatter, so correcting this display calculation repairs both paths without adding another branch.
Findings 1 actionable finding [P2] Reserve the truncation marker within the label cap
Security None None.

How this fits together

Before fully loading command metadata, the CLI checks whether the first argv token is owned by a built-in command or plugin. Unknown roots use a shared formatter to produce a terminal error, which this PR makes safe and bounded.

flowchart LR
A[CLI argv token] --> B[Root command ownership check]
B -->|Known command| C[Command routing]
B -->|Unknown root| D[Shared diagnostic formatter]
D --> E[Terminal-safe bounded label]
E --> F[CLI error output]
Loading

Before merge

  • Reserve the truncation marker within the label cap (P2) - The overflow branch retains 128 UTF-16 units and then appends …, so the displayed label is 129 units despite the stated 128-unit cap. Reserve the marker’s unit before calling truncateUtf16Safe, and assert the final label stays within the cap.
  • Resolve merge risk (P1) - The exact-head check suite is incomplete and check-lint is currently failing; its cause was not available for inspection and must be resolved or shown unrelated before merge.
  • Complete next step (P2) - The repair is mechanical, but the maintainer label keeps this PR in human-owned review rather than an automated repair lane.

Findings

  • [P2] Reserve the truncation marker within the label cap — src/cli/run-main.ts:1037-1039
Agent review details

Security

None.

PR surface

Source +9, Tests +34. Total +43 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 11 2 +9
Tests 1 34 0 +34
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 45 2 +43

Review metrics

Metric Value Why it matters
Production vs test LOC production +11/-2; tests +34/-0 The production growth is justified by a terminal-safety display boundary, while the added test coverage should enforce its stated cap rather than accept overflow.

Stored data model

Persistent data-model change detected: vector/embedding metadata: src/cli/run-main.exit.test.ts, vector/embedding metadata: src/cli/run-main.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #120379
Summary: This PR is the direct candidate fix for the canonical unknown-root CLI diagnostic bug.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Reserve the ellipsis unit within the display limit, assert the final rendered label is at most 128 UTF-16 units, then merge after exact-head required checks are green.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Reserve the ellipsis unit within the display limit, assert the final rendered label is at most 128 UTF-16 units, then merge after exact-head required checks are green.

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

Yes—source inspection shows a 1,000-emoji unknown command reaches the overflow branch, retains 128 UTF-16 units, and then appends a further one-unit marker.

Is this the best way to solve the issue?

No—the formatter is the correct owner boundary, but it must reserve marker space before truncation; the existing test currently encodes the incorrect 129-unit result.

Full review comments:

  • [P2] Reserve the truncation marker within the label cap — src/cli/run-main.ts:1037-1039
    The overflow branch retains 128 UTF-16 units and then appends …, so the displayed label is 129 units despite the stated 128-unit cap. Reserve the marker’s unit before calling truncateUtf16Safe, and assert the final label stays within the cap.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: The PR repairs a limited-blast-radius CLI diagnostic defect, but its stated output bound remains off by one unit.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This is a maintainer-authored PR, so the external-contributor proof gate does not apply; its reported built-CLI checks remain useful supplemental evidence.

Evidence

What I checked:

  • Cap overflow in exact PR head: The overflow branch keeps 128 UTF-16 units and then appends an ellipsis, yielding a 129-unit displayed label. (src/cli/run-main.ts:1039, b4b72f960e8b)
  • Regression test accepts the overflow: The new emoji case expects 64 two-unit emoji plus the one-unit marker instead of asserting the final label remains within 128 UTF-16 units. (src/cli/run-main.exit.test.ts:2715, b4b72f960e8b)
  • Shared owner boundary: Both early unknown-root failure paths call the same formatter, so correcting this display calculation repairs both paths without adding another branch. (src/cli/run-main.ts:1316, b4b72f960e8b)
  • UTF-16 helper contract: The helper prevents dangling surrogate halves but caps only at the limit passed by its caller; it does not reserve suffix space itself. (packages/normalization-core/src/utf16-slice.ts:58, 8b8058a68b6a)
  • Source-path provenance: Current-main blame attributes the surrounding formatter path to a recent CLI change, establishing a recent area contributor but not a definitive original owner. (src/cli/run-main.ts:1032, 07680362ffa5)

Likely related people:

  • steipete: The PR author also has substantial prior history on the current CLI entry point, including recent fixes in this file. (role: recent CLI contributor; confidence: high; commits: b4b72f960e8b; files: src/cli/run-main.ts, src/cli/run-main.exit.test.ts)
  • joshavant: Current-main blame associates the nearby formatter and exit-test path with this recent commit. (role: recent source-path contributor; confidence: medium; commits: 07680362ffa5; files: src/cli/run-main.ts, src/cli/run-main.exit.test.ts)

Rank-up moves

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

  • Reserve one UTF-16 unit for the ellipsis and update the emoji regression assertion.
  • Resolve or establish the scope of the exact-head lint failure, then refresh the required checks.

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-07T23:37:14.254Z sha 1755c4edb1ee3a1bf1f3702762a8c957ceebdb66 :: found issues before merge. :: [P2] Reserve space for the truncation marker

@steipete
steipete force-pushed the codex/autoqa-cli-unknown-command-safe-output-20260807 branch from 1755c4e to b4b72f9 Compare August 8, 2026 03:41
@steipete
steipete force-pushed the codex/autoqa-cli-unknown-command-safe-output-20260807 branch from a66a765 to f249399 Compare August 8, 2026 04:21
@steipete

steipete commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Command router queued. I will update this comment with the next step.

@steipete

steipete commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

Land-ready proof for exact head f2493993c7d4213663c82d9f67e1cb128c9d6f52:

  • Current-main symptom: unknown root argv is echoed raw twice, allowing ANSI/newline/tab injection and a 20,266-byte error for a 10,000-character token.
  • Root fix: sanitize one display label, bound it with UTF-16-safe truncation, reserve the ellipsis inside the 128-unit cap, preserve ordinary typo suggestions, and skip suggestion work for transformed or oversized input.
  • Accepted review fix: the prior ClawSweeper P2 found the marker was outside the cap; final source-blind output measures 127 UTF-16 units including the ellipsis.
  • Focused proof: 207/207 on final current-main head; lint/format clean.
  • Built behavior proof: ordinary suggestion preserved; hostile ANSI/newline/tab argv emits zero ESC/tab control bytes and literal \n/\t; 1,000 emoji produces a 776-byte diagnostic with intact Unicode.
  • Stress: 40 original hostile fresh processes, 20 rebased hostile processes, and 10 final marker-boundary processes; zero failures.
  • Final-head-equivalent changed gate: Blacksmith Testbox tbx_01kzfr7dae1bh9xzva8h0147zg, https://github.com/openclaw/openclaw/actions/runs/31238316350; both commits are patch-identical after the final rebase.
  • Exact-head hosted CI: https://github.com/openclaw/openclaw/actions/runs/31239249517 — green, including build artifacts, lint, test types, all four QA Smoke profiles, and all selected compact shards.
  • AutoReview: fresh final current-main P2 review clean at 0.98; accepted boundary-correction review clean at 0.99.
  • Native review artifacts: READY FOR /prepare-pr, zero findings, validated against this exact head.
  • Live-proof boundary: the installed/built CLI stderr path is the exact affected runtime surface; no external account or credential is involved.
  • Public model identifier gate: not applicable; this CLI formatting diff adds no model identifier or model-bearing artifact.
  • Full-suite history: two stale-behind-main runs exposed three baseline failures; the QA-Lab and ClickClack repairs landed as test(qa): derive UX producer aggregate status #120418 and test(clickclack): cover native progress default #120410. A later stale branch exposed a Gateway type failure already green on current main. No failure implicated the CLI diff.

Recommendation: merge after the queued exact-head ClawSweeper re-review clears the prior cap finding or records a publisher-only gap.

@steipete
steipete merged commit 68e3777 into main Aug 8, 2026
120 checks passed
@steipete
steipete deleted the codex/autoqa-cli-unknown-command-safe-output-20260807 branch August 8, 2026 04:39
@steipete

steipete commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 9, 2026
* fix(cli): bound unknown command diagnostics

* fix(cli): include truncation marker in display cap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XS status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLI unknown-command errors can inject terminal control bytes and unbounded output

1 participant