Skip to content

fix(cli): optimize truncateMessage to O(n) and bypass if not TTY#3860

Closed
rohanranjan0902 wants to merge 1 commit into
triggerdotdev:mainfrom
rohanranjan0902:fix/cli-truncate-message-o-n
Closed

fix(cli): optimize truncateMessage to O(n) and bypass if not TTY#3860
rohanranjan0902 wants to merge 1 commit into
triggerdotdev:mainfrom
rohanranjan0902:fix/cli-truncate-message-o-n

Conversation

@rohanranjan0902
Copy link
Copy Markdown

@rohanranjan0902 rohanranjan0902 commented Jun 7, 2026

Closes #3826

✅ Checklist

  • I have followed every step in the contributing guide
  • The PR title follows the convention.
  • I ran and tested the code works

Testing

  1. Created a script to measure the execution time of truncateMessage using heavily repeated ANSI strings.
  2. Verified that the original logic (O(n²)) took >2.4s for a long string, whereas the new regex-based logic takes <1ms.
  3. Verified the resulting truncated string accurately preserves ANSI codes.
  4. Ensured that if the CI runner does not allocate a TTY (!process.stdout.isTTY), it bypasses the truncateMessage function logic entirely to prevent hang in environments where process.stdout.columns may be undefined.
  5. Successfully ran pnpm run build --filter trigger.dev locally to verify there are no typescript or compilation errors.

Changelog

Optimized the truncateMessage algorithm in the CLI from O(n²) to O(n) using an ANSI regex. Additionally, bypassed message truncation for non-TTY processes. This resolves an issue where trigger deploy could hang indefinitely with 100% CPU usage in CI environments while trying to process large spinner messages.


Screenshots

N/A

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jun 7, 2026

⚠️ No Changeset found

Latest commit: dfdf06c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 7, 2026

Hi @rohanranjan0902, thanks for your interest in contributing!

This project requires that pull request authors are vouched, and you are not in the list of vouched users.

This PR will be closed automatically. See https://github.com/triggerdotdev/trigger.dev/blob/main/CONTRIBUTING.md for more details.

@github-actions github-actions Bot closed this Jun 7, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 7, 2026

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: a85b0579-6f98-4e88-a181-cf989baf84ee

📥 Commits

Reviewing files that changed from the base of the PR and between fa15438 and dfdf06c.

📒 Files selected for processing (1)
  • packages/cli-v3/src/utilities/windows.ts

Walkthrough

The truncateMessage utility function was refactored to improve handling of non-TTY output and terminal display. It now skips truncation entirely when the output stream is not a TTY and no explicit width is provided. The truncation algorithm itself was rewritten to be ANSI-aware: it scans the message preserving ANSI color codes and terminal hyperlinks while counting only visible characters, truncates visible content to the available terminal width, and appends an ellipsis only when necessary.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

Tools execution failed with the following error:

Failed to run tools: 13 INTERNAL: Received RST_STREAM with code 2 (Internal server error)


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 4 additional findings.

Open in Devin Review

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: CLI deploy hangs (100% CPU) in non-TTY CI — truncateMessage() is O(n²)

1 participant