Repository navigation
Conversation
Text the CLI did not write itself (API error messages, names of remote objects, state messages) was printed as received, so control characters in it reached the terminal. Escape them visibly (\x1b, \r, ...) where text output leaves the CLI: - the root error printer; - the friendly log handler (messages and attribute values); - cmdio: data rendered through text templates (tables, diagnostics, select items), LogString, the spinner text and Ask questions; - cmd/air: the failure reason, the Configuration box, status and accelerator cells, the no-logs line, pools, the cancel preview and hyperlink targets. JSON output is unchanged. Workload logs and the output of local scripts are passed through as before. Co-authored-by: Isaac <no-reply@databricks.com>
Regression test report ✅Commit: Selected 5 changed tests (limit=20, 0 not selected) 7 tests: regression=4 unreleased=0 coverage=3 failing=0
TestAccept/air/control-chars: branch ✅ | main (e6f3460) ❌ | latest (v1.28.0) ❌main (e6f3460): latest (v1.28.0): same output as main (e6f3460) TestAccept/bundle/resources/jobs/create-error-control-chars/DMS=: branch ✅ | main (e6f3460) ❌ | latest (v1.28.0) ❌main (e6f3460): latest (v1.28.0): same output as main (e6f3460) TestAccept/bundle/resources/jobs/create-error-control-chars/DMS=true: branch ✅ | main (e6f3460) ❌ | latest (v1.28.0) ❌main (e6f3460): latest (v1.28.0): same output as main (e6f3460) TestAccept/cmd/workspace/control-chars: branch ✅ | main (e6f3460) ❌ | latest (v1.28.0) ❌main (e6f3460): latest (v1.28.0): same output as main (e6f3460) |
✅ Integration test reportCommit: c082c71
Top 6 slowest tests (at least 2 minutes):
|
Review found that escaping template data before execution breaks values the CLI styled itself (the SQL warehouse picker, the cropped pipelines table, a diagnostic detail), breaks pretty_json on a pre-escaped JSON document, misses what a template prints through methods and functions, and needs a reflection walk. Escape what the template rendered instead, keeping color sequences as LogString does. - textutil: escapes are JSON-style (\u001b), CRLF becomes a newline, and EscapeControlKeepColors resets a style left on at the end. - workspace export writes the file content as is instead of through a template. - air: the MLflow run name is kept as the server sent it (JSON output) and escaped in the label; the no-logs line is escaped as a whole; a link target that is not valid UTF-8 gets no hyperlink. - Tests for the wiring in Ask, the spinner, select prompts, the pager and Render; show_control.py also shows C1 characters and invalid bytes. - Changelog fragments. Co-authored-by: Isaac <no-reply@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
Second review round: - With colors off the CLI adds no color sequences, so templates, LogString and Ask now escape them like any other sequence; they are kept only with colors on (and in select prompts, which style text with colors off too). - A style a value leaves on is reset at the end of its line or table cell instead of at the end of the text, so it cannot hide the next cell or row, and no reset lands on a line of its own. - EscapeControlOneLine moves to textutil and replaces the local helpers in cmd/air and experimental/postgres; the postgres text table now escapes control characters too. - More sinks: the MLflow URL in the air list logs pane, template errors in select prompts, the error printed by aitools mcp serve. - workspace export: tests for JSON output and --file; changelog entry. Co-authored-by: Isaac <no-reply@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
…test portable jq prints CRLF on Windows, which base64 -d rejects: print the base64 content field instead of decoding it. Co-authored-by: Isaac <no-reply@databricks.com>
… in tables - bundle run prints a failed task's error and trace with LogRawString: they are the task's own output, like its logs, and a notebook's trace is colored, which with colors off would have been shown escaped. - EscapeControlKeepColors resets a style left on at the end of the text only, so the CLI's own multi-line colored messages keep their color on every line. Rendered templates use EscapeControlKeepColorsPerCell, which also resets at the end of a line or cell. Co-authored-by: Isaac <no-reply@databricks.com>
…self Review of the previous commit: - bundle run wrote the whole failed-task event raw, which also let the task's error text through (it can quote a path). Only the trace's colors are kept now; the task key and the error are escaped. - Resetting a style only at the end of a message let a value hide the later lines of the same message. EscapeControlKeepColors resets at the end of each line and cell again, and the per-cell variant is gone. So that the CLI's own multi-line colored text keeps its color on every line, the cmdio color helpers now style each line by itself. Co-authored-by: Isaac <no-reply@databricks.com>
…key escaping Co-authored-by: Isaac <no-reply@databricks.com>
There was a problem hiding this comment.
Automated review at aa9c80b. Each finding was verified against the code.
No blocking issues found. 5 non-blocking comment(s) below.
This PR escapes terminal control characters in server-supplied text wherever text output leaves the CLI: the root error printer, templates, LogString/Ask/spinner, the friendly log handler and the air sinks. Local passthrough output goes through a new LogRawString. The approach holds up, and I found no blocking defects. The spinner keeps a server value's SGR codes even with colors off, which contradicts what the description promises. The pager measures column width with a pattern that misses the : SGR forms the escaper now keeps. The remaining points are about test conventions and an inconsistent escape style in log attributes.
Sankalp-Mittal
left a comment
There was a problem hiding this comment.
[AI Generated] Review by review-factory (Claude Opus 5.5 + Claude Opus 5.5 + Claude Sonnet 5.5, cross-verified). Only points the reviewers agreed on are posted.
cmd/apps/validate.go:99apps validateandapps deploy(deploy_bundle.go:167) print captured npm/vite output throughLogString, which now escapes it, so CI logs show\u001b[31m. UseLogRawStringas for bundle scripts?
…on with a test - The spinner text keeps colors only when colors are on, like LogString. - The pager's width pattern accepts ':' in an SGR sequence, as the escaper does. - A log attribute value with a control character is quoted like one with a space. - Select prompt functions style each line of a multi-line value by itself. - Postgres text tables escape column names like cells. - Tests run every renderer with colors on and off, and the strict call sites with a color code in the value. - The bundle acceptance test gets the control characters into the request and uses the fake server's own validation instead of a response stub. Co-authored-by: Isaac <no-reply@databricks.com>
Sankalp-Mittal
left a comment
There was a problem hiding this comment.
[AI Generated] Review by review-factory (Claude Opus 5.5 + Claude Opus 5.5 + Claude Sonnet 5.5, cross-verified). Only points the reviewers agreed on are posted.
…eploy The output of a failed validation step was printed with LogString, which now escapes control characters. It is a local process's output, so it goes through LogRawString, like bundle script output. Also: say in the air changelog entry that mlflow_run_name in air get -o json is the server's value again, and that LogRawString is also for text whose values the caller escaped. Co-authored-by: Isaac <no-reply@databricks.com>
|
🤖 Re the review comment on Yes, changed in c082c71c3. Both print the failed step's output with Same class, checked across AI agent (fable5.2, isaac_claude) |
Sankalp-Mittal
left a comment
There was a problem hiding this comment.
[AI Generated] Follow-up review by review-factory (Claude Opus 5.5 + Claude Opus 5.5 + Claude Sonnet 5.5, cross-verified). Only points the reviewers agreed on are posted.
Earlier findings: 1 fixed.
No new issues found.
Changes
Text the CLI did not write itself (API error messages, names of remote objects, state messages) is now printed with terminal control characters escaped, wherever text output leaves the CLI:
libs/textutil:EscapeControlreplaces C0 and C1 control characters and DEL with the escape JSON output shows for them (\u001b,\u0007,\r), and a byte that is not valid UTF-8 with�. Newline and tab are kept and CRLF becomes a newline, so the result has no other control character.EscapeControlOneLinealso escapes line breaks and tabs, for a value shown in a table cell.EscapeControlKeepColorsleaves SGR (color and style) sequences alone, for text the CLI composed and colored itself. A style still on at the end of a line or table cell is reset there.cmd/root) and the error printer ofaitools mcp serve:Error: ...escapes the error text.libs/log/handler): the message keeps colors. An attribute value with a control character is quoted with%q, like a value with a space, so attributes have one escape style.libs/cmdio:Render,RenderWithTemplate,RenderIterator(paged or not), diagnostics and select prompts;LogString(and soLogProgress), the spinner text andAskquestions are escaped;NO_COLORthe CLI adds none, so none is kept. Select prompts are the exception: they use bold, faint and underline withNO_COLORtoo, so they always keep them;LogRawStringfor output that is passed through. Bundle scripts, the SSH setup steps and the validation output ofapps validateandapps deployuse it, so their output is unchanged;cmdio.Yellowand the others) and the select prompt functions style each line of a multi-line text by itself, so the CLI's own colored text is not cut short by that reset;:forms were counted).bundle run: the error trace of a failed task keeps its colors with colors off too (a notebook's trace is colored); the task key and the error text are escaped.workspace exportwrites the file content to stdout directly instead of through a text template. The content is now written as is; the template path used to replace tabs with padding spaces.cmd/air:stripControlis replaced byEscapeControlOneLine, so names are now shown escaped instead of having the characters removed. Escaping is also applied whereairwrites to the terminal directly and did not strip before: the failure reason, the Configuration box, the status and accelerator cells, the "No logs available" line, the MLflow URL lines,air pools, theair cancel --allpreview and the error shown in theair listdetail pane. A link target with a control character in it gets no OSC 8 hyperlink.experimental/postgres: the text table's local cell escaper (tabs and line breaks only) is replaced byEscapeControlOneLine, and column names are escaped too.JSON output is unchanged: the JSON encoder already escapes control characters. One
airfield differs:mlflow_run_nameinair get -o jsonis now the name as the server sent it, like the other fields, where #7601 stripped it.Why
The CLI printed server-supplied text as received. API error messages often quote a value the caller or another user chose (a path, a name), and list and get commands print names other users chose. A control character in such a value reached the terminal of whoever ran the command, where an escape sequence can clear the screen, retitle the window, move the cursor so that later text overwrites earlier output, or (on terminals that allow it) write the clipboard. #7601 fixed this for the names
air listandair getshow; this change does it once at the output boundary for every command.Design choices
LogString, log messages, the spinner,Askand rendered templates get finished text in which the CLI's own colors and a server value can no longer be told apart. With colors on, SGR sequences are kept there and everything else is escaped; a server value can then still set a color or style (including concealed text) up to the end of its line or table cell, where it is reset, and nothing else. With colors off nothing is kept. Three places keep them with colors off too, each for a reason: select prompts (they style withNO_COLOR), log messages and the trace of a failed task (bundle runlogs a notebook's colored trace, and escaping it would print its color codes as text in every CI log). Where the CLI has the value by itself (errors, log attributes, theairfields) nothing is kept.pipelinestable), brokepretty_jsonon a pre-escaped document, missed what a template prints through methods and functions, and needed a reflection walk over the data. Escaping the output is a few lines and covers everything a template prints.\u001b), so text output shows a control character the way-o jsondoes, and a value copied from text output is valid in a--jsonargument.airuses the same helper, soairnames change from stripped to escaped. Column widths are measured on the escaped text.air logs,apps logs,bundle runoutput), file content (fs cat,workspace export),--download-tofiles and the output of local scripts.Tests
Acceptance tests print through a new
show_control.pyfilter that shows a raw control character as<0x1b>, so an output file never holds a raw escape sequence. The first three fail on main:acceptance/cmd/workspace/control-chars: an API error printed by the root error printer (secrets put-secret, the server quotes the scope name), ajobs listtable with control characters in a job name,jobs list -o jsonfor the same job, andworkspace exportof a file with control characters and a tab, to stdout, to--fileand as JSON.acceptance/bundle/resources/jobs/create-error-control-chars: abundle deployerror diagnostic that quotes the API's message. The control characters are in the request (a task'spython_file), and the fake server's own validation quotes them.acceptance/air/control-chars(extended):air getof a failed run whose state message quotes a path, next toair get -o json; the existing name cases now show escapes.acceptance/bundle/scripts/no-trailing-newline(extended): pins that bundle script output is passed through as is (passes on main too).acceptance/apps/validate(extended): the failed step's output has a color code and is passed through as is (passes on main too).Unit tests:
TestEscapeControl,TestEscapeControlOneLine; inlibs/cmdioone test per place that escapes (select prompts,LogString,Ask, the spinner), andTestRenderersKeepColorsOnlyWhenColorsAreOn, which runsRender,RenderIterator(a full batch and the rest), the pager and diagnostics with colors on and off;TestFriendlyHandlerEscapesControlCharacters; incmd/air,cmd/aitoolsandexperimental/postgresthe sinks the acceptance tests do not reach;TestJobRunnerLogsFailedTaskTraceWithItsColorsandTestColorHelpersStyleEachLine. Each escaping call was removed in turn to check that a test fails without it. Each keep-colors decision was flipped both ways, and each strict call was switched to the color-keeping one, with the same check.No other acceptance output changed.
Gaps and risks
fmt.Fprint(cmd.OutOrStdout(), ...)) with a server value in it. This PR covers the shared paths,cmd/airand the two sinks named above; other direct writers were not audited one by one.bundle run(see Design choices).bundle runalso logs a failed task's error text through the logger, so its colors are kept in that second copy.CLICOLOR_FORCE=1and no terminal, text styled by lipgloss's default renderer (the header and done lines of theappsprompts) goes throughLogStringand is shown with its color codes escaped:cmdiodoes not honorCLICOLOR_FORCE. Follow-up: mint those styles withcmdio.NewRenderer.bundle summaryandbundle validateexecute their own text templates (bundle/render), which this PR does not change.air getof a sweep run is drawn by a text template, so its task keys and experiment names follow the template rule (colors kept with colors on, line breaks kept), not the strict one of the single-run view.airandpostgrescells), so a value with a line break still starts a new line in a table. A carriage return right before a line break is dropped as part of a CRLF.encoding/jsondoes: C0 controls are escaped, DEL and C1 are not. This now applies tomlflow_run_nameinair get -o jsonas well.uv,dockeror an agent's CLI) goes through the same escaping: control characters in it are shown escaped, color codes too when colors are off. Only output printed as a whole is passed through (seeLogRawStringabove).pipelines, the interactiveair list) measure some values before they are escaped, so a value with a control character can be cut short or widen its column. In tables that are not paged, a color code kept in a value (and the reset added after it) counts toward the column width, as the CLI's own color codes already do.air listcaches the MLflow label for 60 days. Labels cached before this change have control characters removed, new ones have them escaped; a cached label is escaped again when shown.air listTUI) are covered by unit tests only.Dashboard: no dashboard test or error is tied to this change.
🤖 AI agent (fable5.2, isaac_claude)
This pull request and its description were written by Isaac.