Repository navigation
fix(models): escape terminal controls in model selection reports - #176007
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis PR sanitizes configured model values in alias, fallback, and status text reports while preserving JSON and stored configuration. Example: An alias contains café followed by ESC[2J, a newline, and forged.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this PR fixes a current terminal-rendering defect with a focused patch and supplied CLI proof; no actionable introduced defects were found. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe models CLI loads configured aliases and model references, resolves status information, and emits human-readable, plain-text, or JSON reports. flowchart LR
A[Configured model values] --> B[Models command owners]
B --> C[JSON writer]
B --> D[Terminal sanitizer]
D --> E[Optional styling]
E --> F[Text output]
Technical reviewBest possible solution: Keep sanitization at the existing text-report boundaries, before styling, with JSON and persisted values preserved. Do we have a high-confidence way to reproduce the issue? Current-main source directly emits configured controls, and supplied built-CLI results demonstrate terminal clearing and forged lines; this read-only review ran no target code. Is this the best way to solve the issue? The patch repairs the existing output owners using the canonical sanitizer, preserves stdout ownership and raw JSON, and retains rich alias colors without introducing state or a competing renderer. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against d3977b073466. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +11, Tests +65. Total +76 across 6 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReviewed October 18, 2026, 2:38 PM ET / 18:38 UTC (Revision 3). |
Alias names are validated on add and the add commands echo the operator's own arguments, so only the list and status reports need the sanitizer.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Sanitize the alias and target before styling them, so the rich Aliases row keeps its base colors.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Landed in 5fb1a75. Thanks @Alix-007 for the fix, and for sharing it with the community. Maintainer follow-up: dropped sanitizing on paths that only echo the operator's own validated arguments, and kept the per-part colors on the |
…nclaw#176007) Text output of `openclaw models aliases list`, `models fallbacks list`, `models image-fallbacks list` and `models status` no longer writes control characters from configured aliases or model refs to the terminal. An alias edited into the config with an escape sequence or newline can no longer clear the screen or forge report lines. `--json` output and the existing colors are unchanged. Proof: real CLI in secretless Docker, output through `od -c`, with a config-file alias containing a clear-screen escape and a newline. On main a79a48b the commands print ESC bytes and forged lines; the candidate prints none. With a clean config, `models status` output matches main in plain and rich (pty, `FORCE_COLOR=1`) mode, including the per-part alias colors. Live gate passed with openai/gpt-5-mini. Thanks @Alix-007. Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
Fixes: configured model references and aliases can clear terminal output or forge extra report lines when operators inspect model selection.
User Impact
User impact: aliases, text/image fallback lists, and model-selection status fields display control characters safely while retaining normal Unicode. JSON consumers and stored configuration keep the original values.
Why This Change Was Made
Use the existing terminal sanitizer at text output boundaries, before styling. Both fallback commands share the same owner. No routing, auth, configuration schema, defaults, dependencies, or migration changes.
Evidence
Built CLI, isolated config/state/HOME, no provider requests or production credentials:
f45fe274c179872cf4078d14e7c1cae247b2f0b729c737d890e2528202ab9d1dfabc20759b590f8a2026-10-18T02:26:11.606Z; Node 26.1.0 on Linux, OpenClaw 2026.10.4.node <checkout>/openclaw.mjs models …; all 12 child processes exited 0.models aliases listmodels fallbacks listmodels image-fallbacks listmodels statusBASE forged extra lines in all eight text modes. HEAD emitted visible
\\ninstead, with zero injected lines. ThecaféUnicode control survived. All four--jsoncontrols retained the original alias/model strings, and the config-file SHA-256 was identical before/after the 12 commands. Readback is captured child stdout/stderr/exit status plus actual config bytes.Focused regressions: 49 passing tests across
aliases.test.ts(11),fallbacks-shared.test.ts(14), andlist.status.test.ts(24). Core and canonical commands-test type checks, changed-file type-aware lint, formatting, line-cap ratchet, and independent adversarial review passed. The final focused fallback invocation wasOPENCLAW_VITEST_RUNTIME=node pnpm test src/commands/models/fallbacks-shared.test.ts --maxWorkers=1(exit 0).Reproduce the actual CLI proof
Use clean checkouts at the two SHAs above, each installed with the pinned pnpm and built normally with
pnpm build qaRuntime. Save the following two files together outside the product checkout, then run the same collector against each:Only the helper import path below is flattened for copying. The fixture, subprocess entry, assertions, and recorder are unchanged between RED/GREEN. Each run creates an independent temporary HOME, config, state, workspace, and log, verifies the clean checkout/build stamp, and records stdout/stderr/exits plus readback in its printed receipt directory.
proof-models.mjs:proof-cli-common.mjs:Scope and validation cost
Six files: production +23/-19 lines in three existing owners; tests +65 lines. Existing-solutions preflight found the canonical terminal sanitizer; no new helper or competing model-report fix was needed. Alias confirmations/catalog warnings and fallback confirmations use the same safe egress; JSON bypasses sanitization. Status coverage is limited to model-selection fields and associated route diagnostics.
Status shard: 128.62 s for 24 tests, predominantly cold compiler/import work. Alias/fallback shard: 19.68 s, with 11 alias tests passing; the final 14-test fallback rerun took 29.54 s (40.20 s including wrapper cleanup). The native changed-test selector hit unrelated gateway/infra root-budget overruns, so the explicit canonical commands test graph was checked instead.
Not tested: provider API probes, auth inventory/profile formatting, interactive PTY colors, Windows/macOS terminals, and the full CI suite locally. No claim that every auth/probe table is terminal-safe. Fixtures remain in the printed temporary directories for inspection; remove those generated fixture directories afterward. No production state or channels were loaded, changed, or messaged.
Maintainer follow-up
Kept the sanitizer only on the configured-value reports (
models aliases list,models fallbacks list,models image-fallbacks list,models status).models aliases addalready rejects any alias outside[A-Za-z0-9_.:-], and the add commands only echo the operator's own arguments, so those hunks were dropped.Real CLI in an isolated container on main
d3b680c03e: a plain JSON config edit with\u001b[2J\n...in an alias and fallback refs passes validation, and all six text modes write ESC/BEL bytes and forged lines (models status: 11 ESC/BEL bytes, 8 forged lines). Ona7da8addafall six modes write 0 ESC/BEL bytes and 0 forged lines.--jsonoutput for all four commands is byte-identical between base and candidate, and the config file is unchanged.The status regression fails against main's source and passes on this head (49 focused tests).
The
models statusAliases row sanitizes the alias and target before styling them (+9 production lines), because the row-level sanitizer would strip the per-part colors. With a clean config, text and rich TTYmodels statusoutput is identical to main apart from profile paths. With a control-character alias, the rich row keeps main's colors and only loses the control bytes.Merge danger: two-way door, text rendering only; no config, state or JSON contract change. Blast radius: the text output of the four
modelsreport commands.