Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

nicktrn
Copy link
Collaborator

@nicktrn nicktrn commented Sep 16, 2025

This reduces restore times by up to 5s across all runs.

Also fixes the dreaded s is not a function error - turns out it came from @clack/prompts when calling stop on a spinner that hadn't started yet.

Copy link

changeset-bot bot commented Sep 16, 2025

🦋 Changeset detected

Latest commit: 57daf07

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 23 packages
Name Type
trigger.dev Patch
d3-chat Patch
references-d3-openai-agents Patch
references-nextjs-realtime Patch
@trigger.dev/build Patch
@trigger.dev/core Patch
@trigger.dev/python Patch
@trigger.dev/react-hooks Patch
@trigger.dev/redis-worker Patch
@trigger.dev/rsc Patch
@trigger.dev/schema-to-json Patch
@trigger.dev/sdk Patch
@trigger.dev/database Patch
@trigger.dev/otlp-importer Patch
@internal/cache Patch
@internal/clickhouse Patch
@internal/redis Patch
@internal/replication Patch
@internal/run-engine Patch
@internal/schedule-engine Patch
@internal/testcontainers Patch
@internal/tracing Patch
@internal/zod-worker Patch

Not sure what this means? Click here to learn what changesets are.

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

Copy link
Contributor

coderabbitai bot commented Sep 16, 2025

Walkthrough

  • Adds a changeset file declaring a patch update with notes on faster restores and an error fix.
  • Updates managed controller to call processEnvOverrides with an additional boolean on socket disconnect.
  • Extends RunExecution.processEnvOverrides to accept an optional boolean that, when true, immediately polls for snapshot changes ("restore") and ignores errors.
  • Adjusts Windows spinner utility: guard behavior when spinner not active; log messages if inactive; avoid stopping inactive spinner; retain truncation.
  • Updates prerelease script default tag from v3-prerelease to v4-prerelease.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The PR description is a brief summary and does not follow the repository template: it is missing the "Closes #" line, the checklist, concrete testing steps, a changelog section, and screenshots, so it is incomplete relative to the required template. Update the PR description to use the repository template by adding "Closes #" if applicable, completing the checklist, listing the steps you used to test the change, including a short changelog entry, and attaching screenshots or noting why none are needed.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The PR title is concise and accurately highlights the primary change—adding an immediate poll in the runner to decrease restore time—which aligns with edits to execution/controller and the stated PR objectives.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/restore-perf

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/cli-v3/src/utilities/windows.ts (1)

21-38: Fix potential infinite loop when terminal width is very small or unavailable.

availableWidth can become ≤ 0 (e.g., very small terminals), making the while condition always true even for empty strings.

-function truncateMessage(msg: string, maxLength?: number): string {
-  const terminalWidth = maxLength ?? process.stdout.columns ?? 80;
-  const availableWidth = terminalWidth - 5; // Reserve some space for the spinner and padding
+function truncateMessage(msg: string, maxLength?: number): string {
+  const rawWidth = maxLength ?? process.stdout.columns ?? 80;
+  const terminalWidth =
+    typeof rawWidth === "number" && Number.isFinite(rawWidth) ? Math.max(rawWidth, 10) : 80;
+  // Reserve some space for the spinner and padding; clamp to avoid non‑positive widths
+  const availableWidth = Math.max(terminalWidth - 5, 1);
   const visibleLength = getVisibleLength(msg);
 
   if (visibleLength <= availableWidth) {
     return msg;
   }
 
   // We need to truncate based on visible characters, but preserve ANSI sequences
   // Simple approach: truncate character by character until we fit
   let truncated = msg;
-  while (getVisibleLength(truncated) > availableWidth - 3) {
+  // If we have almost no room, just show ellipsis
+  if (availableWidth <= 3) {
+    return "...";
+  }
+  while (getVisibleLength(truncated) > Math.max(availableWidth - 3, 0)) {
     truncated = truncated.slice(0, -1);
   }
 
   return truncated + "...";
 }
🧹 Nitpick comments (7)
.changeset/sharp-cheetahs-end.md (1)

5-6: Clarify claim and trim trailing space.

Wording “by 5s” reads absolute; suggest “up to 5s” to better reflect variability. Also remove trailing space on Line 6.

- - Reduce restore times by 5s due to immediate polling
+ - Reduce restore times by up to 5s due to immediate polling
- - Fix `s is not a function` and surface underlying error messages 
+ - Fix `s is not a function` and surface underlying error messages
scripts/publish-prerelease.sh (2)

26-28: Update the comment to match the new default.

Comment still refers to v3.

-# Use the first argument as version or 'v3-prerelease' if not available
+# Use the first argument as version or 'v4-prerelease' if not available
 version=${1:-'v4-prerelease'}

51-52: Quote $version to avoid accidental word-splitting/globbing.

Defensive shell hygiene; no behavior change.

-echo "Running: pnpm exec changeset version --snapshot $version"
-if output=$(pnpm exec changeset version --snapshot $version 2>&1); then
+echo "Running: pnpm exec changeset version --snapshot \"$version\""
+if output=$(pnpm exec changeset version --snapshot "$version" 2>&1); then
@@
-echo "Going to run: pnpm exec changeset publish --no-git-tag --snapshot --tag $version"
+echo "Going to run: pnpm exec changeset publish --no-git-tag --snapshot --tag \"$version\""
@@
-    pnpm exec changeset publish --no-git-tag --snapshot --tag $version
+    pnpm exec changeset publish --no-git-tag --snapshot --tag "$version"

Also applies to: 71-75

packages/cli-v3/src/utilities/windows.ts (2)

62-69: Also truncate logged messages when spinner wasn’t started.

Keeps output width consistent with active spinner path.

-      if (!isActive) {
+      if (!isActive) {
         // Spinner was never started, just display the message
         if (msg) {
-          log.message(msg);
+          log.message(truncateMessage(msg));
         }
         return;
       }

76-83: Mirror truncation for message() when inactive.

Same rationale as stop().

-      if (!isActive) {
+      if (!isActive) {
         // Spinner was never started, just display the message
         if (msg) {
-          log.message(msg);
+          log.message(truncateMessage(msg));
         }
         return;
       }
packages/cli-v3/src/entryPoints/managed/controller.ts (1)

487-508: Handle string descriptions from socket disconnect.

description can be a plain string; current code would log undefined.

-      const parseDescription = ():
+      const parseDescription = ():
         | {
             description: string;
             context?: string;
           }
         | undefined => {
         if (!description) {
           return undefined;
         }
 
+        if (typeof description === "string") {
+          return { description };
+        }
+
         if (description instanceof Error) {
           return {
             description: description.toString(),
           };
         }
 
         return {
           description: description.description,
           context: description.context ? String(description.context) : undefined,
         };
       };
packages/cli-v3/src/entryPoints/managed/execution.ts (1)

899-958: LGTM — call sites updated; optional: add in-flight guard for snapshot polls

  • Signature is backward compatible. rg found calls at:
    • packages/cli-v3/src/entryPoints/managed/controller.ts:517 — processEnvOverrides("socket disconnected", true)
    • packages/cli-v3/src/entryPoints/managed/execution.ts:868 — processEnvOverrides("restore")
    • packages/cli-v3/src/entryPoints/managed/execution.ts:1195 — processEnvOverrides("snapshots since error")
  • Optional: prevent overlapping snapshot polls by guarding fetchAndProcessSnapshotChanges with a flag and try/finally to clear it on every exit. Example pattern:
    • private fetchingSnapshots = false;
    • public async fetchAndProcessSnapshotChanges(source: string) {
      if (this.fetchingSnapshots) return;
      this.fetchingSnapshots = true;
      try { /* existing logic */ } finally { this.fetchingSnapshots = false; }
      }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 501a383 and 57daf07.

📒 Files selected for processing (5)
  • .changeset/sharp-cheetahs-end.md (1 hunks)
  • packages/cli-v3/src/entryPoints/managed/controller.ts (1 hunks)
  • packages/cli-v3/src/entryPoints/managed/execution.ts (2 hunks)
  • packages/cli-v3/src/utilities/windows.ts (1 hunks)
  • scripts/publish-prerelease.sh (1 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:

  • packages/cli-v3/src/entryPoints/managed/execution.ts
  • packages/cli-v3/src/utilities/windows.ts
  • packages/cli-v3/src/entryPoints/managed/controller.ts
🧬 Code graph analysis (1)
packages/cli-v3/src/entryPoints/managed/execution.ts (1)
packages/cli-v3/src/entryPoints/managed/overrides.ts (1)
  • Metadata (1-13)
⏰ 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 (7, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (7, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (1, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (5, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (4, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (8, 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 (5, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (4, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (2, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (3, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (6, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (2, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (1, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (3, 8)
  • GitHub Check: units / packages / 🧪 Unit Tests: Packages (1, 1)
  • GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - pnpm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - npm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - npm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - pnpm)
  • GitHub Check: typecheck / typecheck
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (1)
packages/cli-v3/src/entryPoints/managed/controller.ts (1)

517-517: Good call: trigger immediate snapshot poll on disconnect.

Passing the boolean to processEnvOverrides should shave the idle window after a disconnect.

@nicktrn nicktrn merged commit 885ae5e into main Sep 16, 2025
31 checks passed
@nicktrn nicktrn deleted the fix/restore-perf branch September 16, 2025 15:17
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.

2 participants