Skip to content

Conversation

ericallam
Copy link
Member

@ericallam ericallam commented Sep 25, 2025

Truncate run error message and stacktrace to 16kb

Copy link

changeset-bot bot commented Sep 25, 2025

⚠️ No Changeset found

Latest commit: 9d52cdf

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

Copy link
Contributor

coderabbitai bot commented Sep 25, 2025

Walkthrough

  • Added a private helper method #truncateTaskRunError to sanitize BUILT_IN_ERROR TaskRunError objects by truncating name, message, and stackTrace to fixed lengths.
  • Introduced a general truncateString utility to cap strings at specified lengths, used by #truncateTaskRunError.
  • Integrated truncation into permanent failure handling: task run updates now store truncatedError in the error field.
  • Updated waitpoint reporting to send JSON.stringify(truncatedError) for BUILT_IN_ERROR outputs.
  • Ensured finalization and error reporting paths consistently use truncated error data for BUILT_IN_ERROR to limit payload size.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The pull request description is missing entirely and does not include any sections from the required template such as the issue reference, checklist, testing steps, changelog, or screenshots. Please fill out the description using the repository’s template by specifying the issue closed, completing the checklist, describing your testing steps, summarizing the changes in the changelog, and adding any relevant screenshots.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title Check ✅ Passed The title succinctly and accurately describes the core change by noting that engine errors are truncated before being stored in both run records and waitpoint output, reflecting the main modifications in the changeset.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ea-branch-91

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.

@ericallam ericallam merged commit e22c321 into main Sep 25, 2025
27 of 28 checks passed
@ericallam ericallam deleted the ea-branch-91 branch September 25, 2025 12:39
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
internal-packages/run-engine/src/engine/systems/runAttemptSystem.ts (2)

1920-1926: Improve truncation UX and edge-case handling.

Append an ellipsis when truncated and guard zero/negative lengths.

Apply this diff:

-function truncateString(str: string | undefined, maxLength: number): string {
-  if (!str) {
-    return "";
-  }
-
-  return str.slice(0, maxLength);
-}
+function truncateString(str: string | undefined, maxLength: number): string {
+  if (!str) return "";
+  if (maxLength <= 0) return "";
+  if (str.length <= maxLength) return str;
+  const limit = Math.max(1, maxLength);
+  return str.slice(0, limit - 1) + "…";
+}

1549-1552: Add error output type and emit truncatedError in runFailed event

internal-packages/run-engine/src/engine/systems/runAttemptSystem.ts
@@ 1549,1552
-      await this.waitpointSystem.completeWaitpoint({
-        id: run.associatedWaitpoint.id,
-        output: { value: JSON.stringify(truncatedError), isError: true },
-      });
+      await this.waitpointSystem.completeWaitpoint({
+        id: run.associatedWaitpoint.id,
+        output: { value: JSON.stringify(truncatedError), type: "application/json", isError: true },
+      });

@@ 1554,1559
-      this.$.eventBus.emit("runFailed", {
-        time: failedAt,
-        run: {
-          id: runId,
-          status: run.status,
-          spanId: run.spanId,
-          error,
+      this.$.eventBus.emit("runFailed", {
+        time: failedAt,
+        run: {
+          id: runId,
+          status: run.status,
+          spanId: run.spanId,
+          error: truncatedError,
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 59df4af and 9d52cdf.

📒 Files selected for processing (1)
  • internal-packages/run-engine/src/engine/systems/runAttemptSystem.ts (5 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.{ts,tsx}: Always prefer using isomorphic code like fetch, ReadableStream, etc. instead of Node.js specific code
For TypeScript, we usually use types over interfaces
Avoid enums
No default exports, use function declarations

Files:

  • internal-packages/run-engine/src/engine/systems/runAttemptSystem.ts
🧠 Learnings (1)
📚 Learning: 2025-08-14T12:13:20.455Z
Learnt from: myftija
PR: triggerdotdev/trigger.dev#2392
File: packages/cli-v3/src/utilities/gitMeta.ts:195-218
Timestamp: 2025-08-14T12:13:20.455Z
Learning: In the GitMeta schema (packages/core/src/v3/schemas/common.ts), all fields are intentionally optional to handle partial data from various deployment contexts (local, GitHub Actions, GitHub App). Functions like getGitHubAppMeta() are designed to work with missing environment variables rather than validate their presence.

Applied to files:

  • internal-packages/run-engine/src/engine/systems/runAttemptSystem.ts
🧬 Code graph analysis (1)
internal-packages/run-engine/src/engine/systems/runAttemptSystem.ts (1)
packages/core/src/v3/schemas/common.ts (2)
  • TaskRunError (200-205)
  • TaskRunError (207-207)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (23)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (8, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (4, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (6, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (1, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (1, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (5, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (7, 8)
  • GitHub Check: units / packages / 🧪 Unit Tests: Packages (1, 1)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (7, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (4, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (3, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (5, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (2, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (8, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (6, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (2, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (3, 8)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - npm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - npm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - pnpm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - pnpm)
  • GitHub Check: typecheck / typecheck
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (2)
internal-packages/run-engine/src/engine/systems/runAttemptSystem.ts (2)

1479-1490: Good call: truncate before persisting the error.

This prevents oversized payloads in the taskRun.error column.


1898-1909: Implement truncation for STRING_ERROR.raw and replace magic numbers with named constants. zod schemas for TaskRunBuiltInError (name, message, stackTrace) and TaskRunStringError (raw) require string fields, and the proposed diff using ERROR_NAME_MAX and ERROR_TEXT_MAX satisfies them.

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.

3 participants