Skip to content

fix(runner): disable warm starts after SIGTERM #2316

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

nicktrn
Copy link
Collaborator

@nicktrn nicktrn commented Jul 24, 2025

Previously, we'd cancel any executing runs and close the socket. But after the run process finishes we try to warm start again, process the next run, warm start again, ad infinitum or until SIGKILL.

Now, all we do is disable warm starts to break the cycle. Executing runs are given a chance to finish until SIGKILL eventually comes.

Copy link

changeset-bot bot commented Jul 24, 2025

🦋 Changeset detected

Latest commit: 28b7374

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

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 Jul 24, 2025

Walkthrough

A patch was implemented to modify how the system responds to a SIGTERM signal. The update introduces a private boolean property to control whether warm starts are enabled. Upon receiving SIGTERM, warm starts are disabled, allowing any ongoing runs to finish without interruption, while preventing new warm start executions. The shutdown logic is adjusted so that the process exits only after current runs complete and cleanup is performed. Additionally, a method responsible for stopping the controller is renamed and extended to ensure proper cleanup and process exit.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c8165cc and 28b7374.

📒 Files selected for processing (2)
  • .changeset/cyan-news-design.md (1 hunks)
  • packages/cli-v3/src/entryPoints/managed/controller.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:

  • packages/cli-v3/src/entryPoints/managed/controller.ts
🧠 Learnings (2)
.changeset/cyan-news-design.md (2)

Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:24.984Z
Learning: Applies to /trigger//*.{ts,tsx,js,jsx} : When using retry, queue, machine, or maxDuration options, configure them as shown in the examples for Trigger.dev tasks.

Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:24.984Z
Learning: Applies to /trigger//*.{ts,tsx,js,jsx} : When using Realtime features, use the runs.subscribeToRun, runs.subscribeToRunsWithTag, and runs.subscribeToBatch APIs as shown.

packages/cli-v3/src/entryPoints/managed/controller.ts (4)

Learnt from: nicktrn
PR: #1418
File: packages/core/src/v3/errors.ts:364-371
Timestamp: 2024-10-18T15:41:52.352Z
Learning: In packages/core/src/v3/errors.ts, within the taskRunErrorEnhancer function, error.message is always defined, so it's safe to directly call error.message.includes("SIGTERM") without additional checks.

Learnt from: nicktrn
PR: #1389
File: apps/coordinator/src/index.ts:403-0
Timestamp: 2024-10-16T01:08:01.788Z
Learning: In apps/coordinator/src/index.ts, moving the exitRun and crashRun functions outside the onConnection method is not feasible because of TypeScript type issues with socket. Keeping these functions inside onConnection is preferred.

Learnt from: nicktrn
PR: #1389
File: apps/coordinator/src/index.ts:403-0
Timestamp: 2024-10-08T15:31:34.807Z
Learning: In apps/coordinator/src/index.ts, moving the exitRun and crashRun functions outside the onConnection method is not feasible because of TypeScript type issues with socket. Keeping these functions inside onConnection is preferred.

Learnt from: nicktrn
PR: #1389
File: apps/coordinator/src/index.ts:403-0
Timestamp: 2024-10-08T13:39:26.553Z
Learning: In apps/coordinator/src/index.ts, moving the exitRun and crashRun functions outside the onConnection method is not feasible because of TypeScript type issues with socket. Keeping these functions inside onConnection is preferred.

⏰ 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). (25)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (7, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (7, 10)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (5, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (9, 10)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (6, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (6, 10)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (8, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (3, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (5, 10)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (4, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (2, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (3, 10)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (1, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (10, 10)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (1, 10)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (8, 10)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (4, 10)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (2, 10)
  • GitHub Check: typecheck / typecheck
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - pnpm)
  • 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: units / packages / 🧪 Unit Tests: Packages (1, 1)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (5)
packages/cli-v3/src/entryPoints/managed/controller.ts (4)

33-35: LGTM! Clean implementation of the warm start control flag.

The private boolean property warmStartEnabled is correctly initialized to true and positioned appropriately with other instance variables.


108-114: Excellent solution to prevent the infinite warm start cycle.

The SIGTERM handler now correctly disables warm starts instead of immediately stopping the controller. This allows ongoing runs to complete naturally while preventing new warm starts, which addresses the core issue described in the PR objectives.


286-293: Perfect early exit logic for disabled warm starts.

The check at the beginning of waitForNextRun() ensures that when warm starts are disabled (after SIGTERM), the process exits gracefully with the success code instead of continuing the warm start cycle. The debug logging provides good visibility into this behavior.


566-599: Rename Safe – No Call Sites to Update

I ran a search for the old stop() method on ManagedRunController and found no references outside its declaration. The new cancelRunsAndExitProcess() name accurately describes its behavior, and adding this.exitProcess(this.successExitCode) ensures the process terminates correctly after cleanup.

• Definition of cancelRunsAndExitProcess() only appears in packages/cli-v3/src/entryPoints/managed/controller.ts
• No usages of new ManagedRunController(...).stop() or direct calls to stop() on this controller

All dependent code remains unaffected.

.changeset/cyan-news-design.md (1)

1-6: Changeset documentation is accurate and well-formatted.

The changeset correctly identifies this as a patch-level change for the "trigger.dev" package and provides a clear, concise description that aligns perfectly with the implementation changes and PR objectives.

✨ 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/no-warm-starts-after-sigterm

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

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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.

1 participant