Skip to content

fix(cli): cdk list pollutes stdout with synthesis time#1637

Merged
iliapolo merged 8 commits into
mainfrom
sai/update-list-suppress-synth-time
Jun 17, 2026
Merged

fix(cli): cdk list pollutes stdout with synthesis time#1637
iliapolo merged 8 commits into
mainfrom
sai/update-list-suppress-synth-time

Conversation

@sai-ray

@sai-ray sai-ray commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Fixes #1632

cdk list prints ✨ Synthesis time: X.XXs to stdout in CI mode (regressed in 2.1127.0). That extra line shows up in machine-readable output, so piping cdk list into a parser (e.g. cdk list --json | jq) breaks.

For example, $ cdk list --json in CI mode gives you:

✨  Synthesis time: 3.72s
MyStack

The parser only expects the stack list, so the Synthesis time line makes it fail.

#1603 routed cdk list through the toolkit-lib list action, which synthesizes via synthAndMeasure. That helper opens a timing span, and ending the span emits CDK_TOOLKIT_I1000 ("Synthesis time"). In CI mode the CLI sends non-error messages to stdout, so the line lands next to the listing.

The CLI now drops the synth-time message (CDK_TOOLKIT_I1000) on the list path before it's written, so stdout carries only the listing.

$ cdk list --json # after fix, CI mode

MyStack

Testing

  • Unit test: cdk list registers a one-shot suppressor for CDK_TOOLKIT_I1000, so the synth-time line is not printed.
  • Integ test: cdk ls in CI produces stdout with only the stack listing, no synthesis-time line.
  • Verified manually against a sample app (cdk list --json in CI → clean stdout).

Checklist

  • This change contains a major version upgrade for a dependency and I confirm all breaking changes are addressed
    • Release notes for the new version:

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@github-actions

github-actions Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@sai-ray sai-ray marked this pull request as ready for review June 16, 2026 23:20
Comment on lines +599 to +601
// Not `synthAndMeasure`: `list` is a read-only query and its synth-time message
// would pollute stdout when the result is piped (e.g. `list --json | jq`).
await using assembly = await assemblyFromSource(ioHelper, cx);

@rix0rrr rix0rrr Jun 17, 2026

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.

I would say this is the wrong fix.

Wouldn't it make more sense to suppress the "synthesis time" message in --json mode, or something to that effect?

Either that, or say "this is query and therefore we're not printing anything other than the output" (which you said on Slack that I also like), but I wouldn't implement that by bypassing the entire method synthAndMeasure method; all synths get routed through that function and I would like to keep it that way. The measuring is NOT JUST printing to the screen, it's also measuring internally.

Maybe we suppress printing by the the IoHost instead or something.

This fix should be about what gets printed, not about what gets done.

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.

+100

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated to follow the same pattern as the rewriteOnce(I2901) line right above, a host-side listener on a library message. That one reshapes the listing, this one suppresses the synth-time line via once(I1000, () => ({ preventDefault: true })). synthAndMeasure stays untouched so synth is still measured, only what's printed changes.

Comment on lines +599 to +601
// Not `synthAndMeasure`: `list` is a read-only query and its synth-time message
// would pollute stdout when the result is piped (e.g. `list --json | jq`).
await using assembly = await assemblyFromSource(ioHelper, cx);

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.

+100

Comment thread packages/aws-cdk/lib/cli/cdk-toolkit.ts Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(cli/list): including informational output in stdout stream in CI environments

5 participants