Skip to content

Neutralize terminal control characters in server-supplied text output - #8129

Open
denik wants to merge 12 commits into
mainfrom
neutralize-control-chars
Open

denik wants to merge 12 commits into
mainfrom
neutralize-control-chars

Conversation

@denik

@denik denik commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • New helpers in libs/textutil:
    • EscapeControl replaces 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.
    • EscapeControlOneLine also escapes line breaks and tabs, for a value shown in a table cell.
    • EscapeControlKeepColors leaves 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.
  • Root error printer (cmd/root) and the error printer of aitools mcp serve: Error: ... escapes the error text.
  • Friendly log handler (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:
    • what a text template renders is escaped. This covers Render, RenderWithTemplate, RenderIterator (paged or not), diagnostics and select prompts;
    • LogString (and so LogProgress), the spinner text and Ask questions are escaped;
    • in both, colors are kept only when colors are on. On a pipe or with NO_COLOR the CLI adds none, so none is kept. Select prompts are the exception: they use bold, faint and underline with NO_COLOR too, so they always keep them;
    • new LogRawString for output that is passed through. Bundle scripts, the SSH setup steps and the validation output of apps validate and apps deploy use it, so their output is unchanged;
    • the color helpers (cmdio.Yellow and 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;
    • the pager's column width ignores the same SGR sequences the escaper keeps (the : 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 export writes 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: stripControl is replaced by EscapeControlOneLine, so names are now shown escaped instead of having the characters removed. Escaping is also applied where air writes 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, the air cancel --all preview and the error shown in the air list detail 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 by EscapeControlOneLine, and column names are escaped too.

JSON output is unchanged: the JSON encoder already escapes control characters. One air field differs: mlflow_run_name in air get -o json is 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 list and air get show; this change does it once at the output boundary for every command.

Design choices

  • Escape at the boundary, not per field. One call in each place where text leaves the CLI, instead of one per printed field in every command.
  • Composed text keeps colors only where the CLI adds them. LogString, log messages, the spinner, Ask and 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 with NO_COLOR), log messages and the trace of a failed task (bundle run logs 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, the air fields) nothing is kept.
  • Templates: the rendered output is escaped, not the data. The first version of this PR escaped the data before the template ran. That broke values the CLI styles before passing them to a template (the SQL warehouse picker, the cropped pipelines table), broke pretty_json on 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.
  • Visible escape instead of removal. An error that names an object shows the name it has, and no sequence parser is needed (removing an unterminated sequence means deciding how much of the following text belongs to it).
  • JSON-style escapes (\u001b), so text output shows a control character the way -o json does, and a value copied from text output is valid in a --json argument.
  • air uses the same helper, so air names change from stripped to escaped. Column widths are measured on the escaped text.
  • Raw passthrough stays where escape sequences are the content: workload logs (air logs, apps logs, bundle run output), file content (fs cat, workspace export), --download-to files and the output of local scripts.

Tests

Acceptance tests print through a new show_control.py filter 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), a jobs list table with control characters in a job name, jobs list -o json for the same job, and workspace export of a file with control characters and a tab, to stdout, to --file and as JSON.
  • acceptance/bundle/resources/jobs/create-error-control-chars: a bundle deploy error diagnostic that quotes the API's message. The control characters are in the request (a task's python_file), and the fake server's own validation quotes them.
  • acceptance/air/control-chars (extended): air get of a failed run whose state message quotes a path, next to air 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; in libs/cmdio one test per place that escapes (select prompts, LogString, Ask, the spinner), and TestRenderersKeepColorsOnlyWhenColorsAreOn, which runs Render, RenderIterator (a full batch and the rest), the pager and diagnostics with colors on and off; TestFriendlyHandlerEscapesControlCharacters; in cmd/air, cmd/aitools and experimental/postgres the sinks the acceptance tests do not reach; TestJobRunnerLogsFailedTaskTraceWithItsColors and TestColorHelpersStyleEachLine. 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

  • Not covered: code that writes to stdout or stderr directly (fmt.Fprint(cmd.OutOrStdout(), ...)) with a server value in it. This PR covers the shared paths, cmd/air and the two sinks named above; other direct writers were not audited one by one.
  • On a color terminal, colors and styles from a server value pass through the composed-text paths, up to the end of the line or cell. In a prompt that is the rest of the prompt line. With colors off they still pass through select prompts, log messages and a failed task's trace in bundle run (see Design choices). bundle run also logs a failed task's error text through the logger, so its colors are kept in that second copy.
  • With CLICOLOR_FORCE=1 and no terminal, text styled by lipgloss's default renderer (the header and done lines of the apps prompts) goes through LogString and is shown with its color codes escaped: cmdio does not honor CLICOLOR_FORCE. Follow-up: mint those styles with cmdio.NewRenderer.
  • bundle summary and bundle validate execute their own text templates (bundle/render), which this PR does not change.
  • air get of 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.
  • A color that spans a tab in the CLI's own text, or a line break in a failed task's trace, ends there.
  • Line breaks and tabs are kept (except in air and postgres cells), 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.
  • Unicode format characters (bidirectional overrides, zero-width characters) are left as they are.
  • JSON output is unchanged, so it has what encoding/json does: C0 controls are escaped, DEL and C1 are not. This now applies to mlflow_run_name in air get -o json as well.
  • A message, diagnostic or error that quotes a local tool's output (a failed artifact build, a Python mutator's stderr, an error from uv, docker or 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 (see LogRawString above).
  • Tables that fit their columns before printing (pipelines, the interactive air 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 list caches 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.
  • The interactive paths (spinner, select prompt, pager, air list TUI) are covered by unit tests only.
  • Risk: medium. The change is small per call site but sits on the output path of every command.

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.

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>
@github-actions github-actions Bot added DABs DABs related issues AIR Databricks AI Runtime CLI labels Nov 27, 2026
@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Regression test report ✅

Commit: c082c71c3 | Workflow run

Selected 5 changed tests (limit=20, 0 not selected)

7 tests: regression=4 unreleased=0 coverage=3 failing=0
test branch main (e6f3460) latest (v1.28.0)
TestAccept/air/control-chars ✅ ❌ ❌
TestAccept/apps/validate ✅ ✅ ✅
TestAccept/bundle/resources/jobs/create-error-control-chars/DMS= ✅ ❌ ❌
TestAccept/bundle/resources/jobs/create-error-control-chars/DMS=true ✅ ❌ ❌
TestAccept/bundle/scripts/no-trailing-newline/DMS= ✅ ✅ ✅
TestAccept/bundle/scripts/no-trailing-newline/DMS=true ✅ ✅ ✅
TestAccept/cmd/workspace/control-chars ✅ ❌ ❌
TestAccept/air/control-chars: branch ✅ | main (e6f3460) ❌ | latest (v1.28.0) ❌

main (e6f3460):

acceptance_test.go:1402: Diff:
        --- air/control-chars/output.txt
        +++ /tmp/TestAcceptaircontrol-chars2598158159/002/output.txt
        @@ -11,18 +11,18 @@
         │  Retries       0                                               │
         │  Max Retries   N/A                                             │
         │  Duration      12s                                             │
        -│  Experiment    my\u001b]0;pwned\u0007-exp                      │
        -│  MLflow Run    \u001b]0;pwned\u0007my\u001b[2J-run\r           │
        -│  User          user\u001b[31m@example.com                      │
        +│  Experiment    my-exp                                          │
        +│  MLflow Run    my-run                                          │
        +│  User          user@example.com                                │
         │  Accelerators  1x A10                                          │
        -│  Environment   databricks_ai\u001b]0;pwned\u0007_v6            │
        +│  Environment   databricks_ai_v6                                │
         │                                                                │
         ╰────────────────────────────────────────────────────────────────╯
         
        -Failure reason: Task train failed with message: Unable to access the notebook "/Shared/train\u001b]0;pwned\u0007\u001b[2J\u001b[31m\r-nb". Either it does not exist, or the identity used to run this job lacks the required permissions.
        +Failure reason: Task train failed with message: Unable to access the notebook "/Shared/train<0x1b>]0;pwned<0x07><0x1b>[2J<0x1b>[31m<0x0d>-nb". Either it does not exist, or the identity used to run this job lacks the required permissions.
         
         Run URL:    [DATABRICKS_URL]/jobs/runs/123?o=[WORKSPACE_ID]
        -MLflow URL: [DATABRICKS_URL]/ml/experiments/exp1/runs/run1\u001b]0;pwned\u0007\u001b[31m
        +MLflow URL: [DATABRICKS_URL]/ml/experiments/exp1/runs/run1<0x1b>]0;pwned<0x07><0x1b>[31m
         
         === get (json): strings are passed through as the server sent them
         
        @@ -51,7 +45,7 @@
             "environment_version": null,
             "base_environment": "workspace-base-environments/databricks_ai\u001b]0;pwned\u0007_v6",
             "max_retries": null,
        -    "mlflow_run_name": "\u001b]0;pwned\u0007my\u001b[2J-run\r",
        +    "mlflow_run_name": "my-run",
             "sweep": null
           }
         }
        @@ -59,8 +53,8 @@
         === list (text): control characters are escaped in the table
         
         >>> [CLI] air list --all-users
        -   Run ID  Experiment                  Status    Started              Duration  Progress  MLflow                  User                        Accelerators
        -   123     my\u001b]0;pwned\u0007-exp  ● FAILED  [TIMESTAMP]       12s         -  …0007my\u001b[2J-run\r  user\u001b[31m@example.com  1x A10
        +   Run ID  Experiment  Status    Started              Duration  Progress  MLflow                  User              Accelerators
        +   123     my-exp      ● FAILED  [TIMESTAMP]       12s         -  my-run                  user@example.com  1x A10
         
         === list (json): strings are passed through as the server sent them

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):

acceptance_test.go:1402: 
        	Error Trace:	/home/runner/work/cli/cli/libs/testdiff/testdiff.go:22
        	            				/home/runner/work/cli/cli/acceptance/acceptance_test.go:1402
        	            				/home/runner/work/cli/cli/acceptance/acceptance_test.go:1143
        	            				/home/runner/work/cli/cli/acceptance/acceptance_test.go:704
        	Error:      	Not equal: 
        	            	expected: "\n>>> musterr [CLI] bundle deploy\nUploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files...\nError: cannot create resources.jobs.foo: Invalid python file reference: src/main\\u001b]0;title\\u0007\\u001b[2J\\u001b[31m\\rtask.py. Please visit the Databricks user guide for supported python references (400 INVALID_PARAMETER_VALUE)\n\nEndpoint: POST [DATABRICKS_URL]/api/2.2/jobs/create\nHTTP Status: 400 Bad Request\nAPI error_code: INVALID_PARAMETER_VALUE\nAPI message: Invalid python file reference: src/main\\u001b]0;title\\u0007\\u001b[2J\\u001b[31m\\rtask.py. Please visit the Databricks user guide for supported python references\n\nFiles: 1 uploaded, 0 deleted\n"
        	            	actual  : "\n>>> musterr [CLI] bundle deploy\nUploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files...\nError: cannot create resources.jobs.foo: Invalid python file reference: src/main<0x1b>]0;title<0x07><0x1b>[2J<0x1b>[31m<0x0d>task.py. Please visit the Databricks user guide for supported python references (400 INVALID_PARAMETER_VALUE)\n\nEndpoint: POST [DATABRICKS_URL]/api/2.2/jobs/create\nHTTP Status: 400 Bad Request\nAPI error_code: INVALID_PARAMETER_VALUE\nAPI message: Invalid python file reference: src/main<0x1b>]0;title<0x07><0x1b>[2J<0x1b>[31m<0x0d>task.py. Please visit the Databricks user guide for supported python references\n\nFiles: 1 uploaded, 0 deleted\n"
        	            	
        	            	Diff:
        	            	--- Expected
        	            	+++ Actual
        	            	@@ -3,3 +3,3 @@
        	            	 Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files...
        	            	-Error: cannot create resources.jobs.foo: Invalid python file reference: src/main\u001b]0;title\u0007\u001b[2J\u001b[31m\rtask.py. Please visit the Databricks user guide for supported python references (400 INVALID_PARAMETER_VALUE)
        	            	+Error: cannot create resources.jobs.foo: Invalid python file reference: src/main<0x1b>]0;title<0x07><0x1b>[2J<0x1b>[31m<0x0d>task.py. Please visit the Databricks user guide for supported python references (400 INVALID_PARAMETER_VALUE)
        	            	 
        	            	@@ -8,3 +8,3 @@
        	            	 API error_code: INVALID_PARAMETER_VALUE
        	            	-API message: Invalid python file reference: src/main\u001b]0;title\u0007\u001b[2J\u001b[31m\rtask.py. Please visit the Databricks user guide for supported python references
        	            	+API message: Invalid python file reference: src/main<0x1b>]0;title<0x07><0x1b>[2J<0x1b>[31m<0x0d>task.py. Please visit the Databricks user guide for supported python references
        	            	 
        	Test:       	TestAccept/bundle/resources/jobs/create-error-control-chars/DMS=
        	Messages:   	bundle/resources/jobs/create-error-control-chars/output.txt vs /tmp/TestAcceptbundleresourcesjobscreate-error-control-charsDMS=3982967513/002/output.txt

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):

acceptance_test.go:1402: 
        	Error Trace:	/home/runner/work/cli/cli/libs/testdiff/testdiff.go:22
        	            				/home/runner/work/cli/cli/acceptance/acceptance_test.go:1402
        	            				/home/runner/work/cli/cli/acceptance/acceptance_test.go:1143
        	            				/home/runner/work/cli/cli/acceptance/acceptance_test.go:704
        	Error:      	Not equal: 
        	            	expected: "\n>>> musterr [CLI] bundle deploy\nUploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files...\nError: cannot create resources.jobs.foo: Invalid python file reference: src/main\\u001b]0;title\\u0007\\u001b[2J\\u001b[31m\\rtask.py. Please visit the Databricks user guide for supported python references (400 INVALID_PARAMETER_VALUE)\n\nEndpoint: POST [DATABRICKS_URL]/api/2.2/jobs/create\nHTTP Status: 400 Bad Request\nAPI error_code: INVALID_PARAMETER_VALUE\nAPI message: Invalid python file reference: src/main\\u001b]0;title\\u0007\\u001b[2J\\u001b[31m\\rtask.py. Please visit the Databricks user guide for supported python references\n\nFiles: 1 uploaded, 0 deleted\n"
        	            	actual  : "\n>>> musterr [CLI] bundle deploy\nUploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files...\nError: cannot create resources.jobs.foo: Invalid python file reference: src/main<0x1b>]0;title<0x07><0x1b>[2J<0x1b>[31m<0x0d>task.py. Please visit the Databricks user guide for supported python references (400 INVALID_PARAMETER_VALUE)\n\nEndpoint: POST [DATABRICKS_URL]/api/2.2/jobs/create\nHTTP Status: 400 Bad Request\nAPI error_code: INVALID_PARAMETER_VALUE\nAPI message: Invalid python file reference: src/main<0x1b>]0;title<0x07><0x1b>[2J<0x1b>[31m<0x0d>task.py. Please visit the Databricks user guide for supported python references\n\nFiles: 1 uploaded, 0 deleted\n"
        	            	
        	            	Diff:
        	            	--- Expected
        	            	+++ Actual
        	            	@@ -3,3 +3,3 @@
        	            	 Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files...
        	            	-Error: cannot create resources.jobs.foo: Invalid python file reference: src/main\u001b]0;title\u0007\u001b[2J\u001b[31m\rtask.py. Please visit the Databricks user guide for supported python references (400 INVALID_PARAMETER_VALUE)
        	            	+Error: cannot create resources.jobs.foo: Invalid python file reference: src/main<0x1b>]0;title<0x07><0x1b>[2J<0x1b>[31m<0x0d>task.py. Please visit the Databricks user guide for supported python references (400 INVALID_PARAMETER_VALUE)
        	            	 
        	            	@@ -8,3 +8,3 @@
        	            	 API error_code: INVALID_PARAMETER_VALUE
        	            	-API message: Invalid python file reference: src/main\u001b]0;title\u0007\u001b[2J\u001b[31m\rtask.py. Please visit the Databricks user guide for supported python references
        	            	+API message: Invalid python file reference: src/main<0x1b>]0;title<0x07><0x1b>[2J<0x1b>[31m<0x0d>task.py. Please visit the Databricks user guide for supported python references
        	            	 
        	Test:       	TestAccept/bundle/resources/jobs/create-error-control-chars/DMS=true
        	Messages:   	bundle/resources/jobs/create-error-control-chars/output.txt vs /tmp/TestAcceptbundleresourcesjobscreate-error-control-charsDMS=1220754485/002/output.txt
FAIL

latest (v1.28.0): same output as main (e6f3460)

TestAccept/cmd/workspace/control-chars: branch ✅ | main (e6f3460) ❌ | latest (v1.28.0) ❌

main (e6f3460):

acceptance_test.go:1402: 
        	Error Trace:	/home/runner/work/cli/cli/libs/testdiff/testdiff.go:22
        	            				/home/runner/work/cli/cli/acceptance/acceptance_test.go:1402
        	            				/home/runner/work/cli/cli/acceptance/acceptance_test.go:1143
        	            				/home/runner/work/cli/cli/acceptance/acceptance_test.go:686
        	Error:      	Not equal: 
        	            	expected: "\n=== API error message: the server quotes the scope name\n\n>>> musterr [CLI] secrets put-secret --json @secret.json\nError: Scope scope\\u001b]0;title\\u0007\\u001b[2J\\u001b[31m\\rname does not exist\n\n=== list as a table\n\n>>> [CLI] jobs list\n[JOB_ID]  nightly\\u001b]0;title\\u0007\\u001b[2J\\rETL \\u001b[31mred\\u001b[0m\n\n=== list as JSON: unchanged, the JSON encoder escapes the name itself\n\n>>> [CLI] jobs list -o json\njson[0].settings.name = \"nightly\\u001b]0;title\\u0007\\u001b[2J\\rETL \\u001b[31mred\\u001b[0m\";\n\n=== an exported file is written as is, tabs included\n\n>>> MSYS_NO_PATHCONV=1 [CLI] workspace export /Users/raw.txt\nline 1<0x0d>line 2<0x1b>[2J\n\tindented\n\n>>> MSYS_NO_PATHCONV=1 [CLI] workspace export /Users/raw.txt --file exported.txt\n\n>>> cmp raw.txt exported.txt\n\n=== export as JSON: the response, with the content in base64\n\n>>> MSYS_NO_PATHCONV=1 [CLI] workspace export /Users/raw.txt -o json\njson.content = \"bGluZSAxDWxpbmUgMhtbMkoKCWluZGVudGVkCg==\";\n"
        	            	actual  : "\n=== API error message: the server quotes the scope name\n\n>>> musterr [CLI] secrets put-secret --json @secret.json\nError: Scope scope<0x1b>]0;title<0x07><0x1b>[2J<0x1b>[31m<0x0d>name does not exist\n\n=== list as a table\n\n>>> [CLI] jobs list\n[JOB_ID]  nightly<0x1b>]0;title<0x07><0x1b>[2J<0x0d>ETL <0x1b>[31mred<0x1b>[0m\n\n=== list as JSON: unchanged, the JSON encoder escapes the name itself\n\n>>> [CLI] jobs list -o json\njson[0].settings.name = \"nightly\\u001b]0;title\\u0007\\u001b[2J\\rETL \\u001b[31mred\\u001b[0m\";\n\n=== an exported file is written as is, tabs included\n\n>>> MSYS_NO_PATHCONV=1 [CLI] workspace export /Users/raw.txt\nline 1<0x0d>line 2<0x1b>[2J\n  indented\n\n>>> MSYS_NO_PATHCONV=1 [CLI] workspace export /Users/raw.txt --file exported.txt\n\n>>> cmp raw.txt exported.txt\n\n=== export as JSON: the response, with the content in base64\n\n>>> MSYS_NO_PATHCONV=1 [CLI] workspace export /Users/raw.txt -o json\njson.content = \"bGluZSAxDWxpbmUgMhtbMkoKCWluZGVudGVkCg==\";\n"
        	            	
        	            	Diff:
        	            	--- Expected
        	            	+++ Actual
        	            	@@ -4,3 +4,3 @@
        	            	 >>> musterr [CLI] secrets put-secret --json @secret.json
        	            	-Error: Scope scope\u001b]0;title\u0007\u001b[2J\u001b[31m\rname does not exist
        	            	+Error: Scope scope<0x1b>]0;title<0x07><0x1b>[2J<0x1b>[31m<0x0d>name does not exist
        	            	 
        	            	@@ -9,3 +9,3 @@
        	            	 >>> [CLI] jobs list
        	            	-[JOB_ID]  nightly\u001b]0;title\u0007\u001b[2J\rETL \u001b[31mred\u001b[0m
        	            	+[JOB_ID]  nightly<0x1b>]0;title<0x07><0x1b>[2J<0x0d>ETL <0x1b>[31mred<0x1b>[0m
        	            	 
        	            	@@ -20,3 +20,3 @@
        	            	 line 1<0x0d>line 2<0x1b>[2J
        	            	-	indented
        	            	+  indented
        	            	 
        	Test:       	TestAccept/cmd/workspace/control-chars
        	Messages:   	cmd/workspace/control-chars/output.txt vs /tmp/TestAcceptcmdworkspacecontrol-chars1981545541/002/output.txt

latest (v1.28.0): same output as main (e6f3460)

@eng-dev-ecosystem-bot

eng-dev-ecosystem-bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Integration test report

Commit: c082c71

Run: 46084926095

Env ✅​pass 🙈​skip Time
✅​ aws linux-2core-8gb 174 22 3:44
✅​ aws-windows-latest-4core-16gb 174 22 3:28
✅​ azure linux-2core-8gb 173 22 3:27
✅​ azure-windows-latest-4core-16gb 173 22 3:16
✅​ gcp linux-2core-8gb 174 22 3:27
✅​ gcp-windows-latest-4core-16gb 174 22 3:05
Top 6 slowest tests (at least 2 minutes):
duration env testname
3:33 aws linux-2core-8gb TestAccept
3:27 aws-windows-latest-4core-16gb TestAccept
3:20 azure linux-2core-8gb TestAccept
3:19 gcp linux-2core-8gb TestAccept
3:14 azure-windows-latest-4core-16gb TestAccept
3:03 gcp-windows-latest-4core-16gb TestAccept

denik and others added 5 commits November 27, 2026 16:00
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>
@github-actions github-actions Bot added the aitools AI tools (databricks aitools) related changes label Nov 27, 2026
denik and others added 4 commits November 27, 2026 17:50
…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>
@denik
denik marked this pull request as ready for review November 27, 2026 20:08
@denik
denik requested review from a team and lennartkats-db as code owners November 27, 2026 20:08

@review-oss-bot review-oss-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread libs/cmdio/spinner.go Resolved
Comment thread libs/cmdio/paged_template.go Resolved
Comment thread libs/log/handler/friendly.go Resolved
Comment thread libs/cmdio/render.go Resolved

@Sankalp-Mittal Sankalp-Mittal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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:99 apps validate and apps deploy (deploy_bundle.go:167) print captured npm/vite output through LogString, which now escapes it, so CI logs show \u001b[31m. Use LogRawString as for bundle scripts?

Comment thread experimental/postgres/cmd/render.go Resolved
Comment thread libs/cmdio/log.go Resolved
…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>
@denik
denik requested a review from andrewnester November 27, 2026 23:10

@Sankalp-Mittal Sankalp-Mittal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Comment thread libs/cmdio/log.go Resolved
…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>
@denik

denik commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 Re the review comment on cmd/apps/validate.go:99 and cmd/apps/deploy_bundle.go:167 (captured npm/vite output printed through LogString):

Yes, changed in c082c71c3. Both print the failed step's output with LogRawString now, like bundle script output. acceptance/apps/validate has a color code in the failed step's stderr and shows it passed through; with LogString it fails.

Same class, checked across cmd, libs, bundle and experimental: these two were the only places left that print a local process's whole output through an escaping call. The other places quote a tool's error text inside a CLI message, a diagnostic or an error (a failed artifact build, a Python mutator's stderr, an error from uv, docker or an agent's CLI). Those keep the escaping, and the Gaps list in the description says so: control characters in the quoted text are shown escaped, color codes too when colors are off.

AI agent (fable5.2, isaac_claude)

@denik
denik requested a review from Sankalp-Mittal November 27, 2026 23:52

@Sankalp-Mittal Sankalp-Mittal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AIR Databricks AI Runtime CLI aitools AI tools (databricks aitools) related changes DABs DABs related issues factory-generated

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants