Skip to content

Fix stalled run detection #1934

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

Merged
merged 6 commits into from
Apr 16, 2025
Merged

Fix stalled run detection #1934

merged 6 commits into from
Apr 16, 2025

Conversation

nicktrn
Copy link
Collaborator

@nicktrn nicktrn commented Apr 16, 2025

Run heartbeats are now driven via the worker child process again.

Summary by CodeRabbit

  • Bug Fixes
    • Improved detection of stalled runs to enhance reliability.
    • Updated heartbeat mechanism for better tracking and accuracy during task execution.
    • Reduced heartbeat interval default from 30 to 20 seconds for more responsive monitoring.

Copy link
Contributor

coderabbitai bot commented Apr 16, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

The changes replace the previous heartbeat management approach in the run execution workflow. The heartbeat mechanism, previously handled by a dedicated service, is now triggered directly by task run process events, with heartbeat signals sent via HTTP calls. The worker's heartbeat message now uses the run ID instead of the attempt ID. Additionally, a new changeset file documents a patch update for stalled run detection. The default heartbeat interval environment variable was adjusted from 30 to 20 seconds. No public APIs or exported entity declarations are altered, aside from internal class property and method adjustments and removal of the heartbeat service class.

Changes

File(s) Change Summary
.changeset/tiny-buckets-teach.md Added a changeset file documenting a patch update for the "trigger.dev" component related to stalled run detection.
packages/cli-v3/src/entryPoints/managed-run-worker.ts Modified the worker's heartbeat message to use the run ID instead of the attempt ID.
packages/cli-v3/src/entryPoints/managed/execution.ts Removed the heartbeat service; implemented direct heartbeat via HTTP on task run process events; updated debug logging.
packages/cli-v3/src/entryPoints/managed/env.ts Changed default heartbeat interval environment variable from 30 to 20 seconds.
packages/cli-v3/src/entryPoints/managed/heartbeat.ts Removed the entire RunExecutionHeartbeat class and related types responsible for managing periodic heartbeat signals.

Sequence Diagram(s)

sequenceDiagram
    participant TaskRunProcess
    participant RunExecution
    participant HttpClient

    TaskRunProcess->>RunExecution: emit onTaskRunHeartbeat(runId)
    RunExecution->>RunExecution: validate runId
    RunExecution->>HttpClient: heartbeatRun(runId, snapshotId)
    HttpClient-->>RunExecution: heartbeat response
    RunExecution->>RunExecution: log heartbeat, update lastHeartbeat
Loading

Possibly related PRs

  • Retry heartbeat timeouts by putting back in the queue #1689: Refactors heartbeat handling by removing the RunExecutionHeartbeat service and implementing heartbeat calls triggered by task run process events. This PR focuses on retrying heartbeat timeouts by requeuing stalled runs, addressing related heartbeat concerns but modifying different parts of the mechanism.

Poem

In the warren, heartbeats thump anew,
No more old service, just signals right through.
Task runs now whisper, "I'm here, I'm alive!"
With run IDs guiding, our processes thrive.
A patch for the stall, a hop in our stride—
The code keeps on running, with rabbits as guide!
🐇💓

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.

📜 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 c0fcd83 and 1c7160a.

📒 Files selected for processing (1)
  • packages/cli-v3/src/entryPoints/managed/execution.ts (6 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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

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)
packages/cli-v3/src/entryPoints/managed/execution.ts (2)

127-146: Consider handling repeated heartbeat failures.
The event subscription and check for mismatched run ID are solid. If this.onHeartbeat() fails too often, you may want to retry or escalate beyond just logging the error.


871-891: Enhance error handling in onHeartbeat method.
Even though a failed heartbeat logs an error, consider designing a fallback or retry mechanism to detect multiple consecutive failures and prevent silent run stalls.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1f6a283 and 3e7f701.

📒 Files selected for processing (3)
  • .changeset/tiny-buckets-teach.md (1 hunks)
  • packages/cli-v3/src/entryPoints/managed-run-worker.ts (1 hunks)
  • packages/cli-v3/src/entryPoints/managed/execution.ts (5 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/cli-v3/src/entryPoints/managed/execution.ts (2)
packages/cli-v3/src/executions/taskRunProcess.ts (1)
  • TaskRunProcess (64-495)
packages/core/src/utils.ts (1)
  • tryCatch (5-18)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - pnpm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - npm)
  • GitHub Check: units / 🧪 Unit Tests
🔇 Additional comments (5)
packages/cli-v3/src/entryPoints/managed/execution.ts (3)

67-68: No concerns with introducing a lastHeartbeat field.
Tracking the last heartbeat timestamp is a sensible addition that aligns with the new approach.


108-108: Initialization of TaskRunProcess looks correct.
Merging environment variables and then initializing is cohesive and follows a clear pattern.


907-907: Appending lastHeartbeat to debug log is clear and helpful.
Using toISOString() ensures a standardized UTC timestamp, which is typically best for distributed logging.

packages/cli-v3/src/entryPoints/managed-run-worker.ts (1)

579-579: Switching heartbeat messages to use the run ID is consistent.
This aligns perfectly with the new run-based heartbeat approach, ensuring the correct ID is tracked.

.changeset/tiny-buckets-teach.md (1)

1-5: Changeset accurately reflects the fix for stalled run detection.
The patch update is succinct and aligned with the new heartbeat strategy.

Copy link

changeset-bot bot commented Apr 16, 2025

🦋 Changeset detected

Latest commit: 1c7160a

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 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 (3)
packages/cli-v3/src/entryPoints/managed/execution.ts (3)

108-127: Validate heartbeat interval environment variable.

Passing HEARTBEAT_INTERVAL_MS is a clear way to communicate the interval to the child process. However, consider validating that TRIGGER_HEARTBEAT_INTERVAL_SECONDS is non-zero and positive to avoid unexpected behaviors if the environment variable is missing or misconfigured.


128-149: Attach heartbeat event listener to run checks.

This block appropriately verifies the incoming run ID before triggering the heartbeat. As a minor improvement, you might consider early-returning if the run is already canceled/aborted to skip sending extraneous heartbeats. Otherwise, this logic appears robust.


872-893: Handle failed heartbeat attempts with optional retries.

The new onHeartbeat() implementation works well for sending run heartbeat signals. For added resilience against transient network issues, consider implementing a lightweight retry or backoff strategy in the event of repeated failures, rather than stopping at a log message.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3e7f701 and c0fcd83.

📒 Files selected for processing (3)
  • packages/cli-v3/src/entryPoints/managed/env.ts (1 hunks)
  • packages/cli-v3/src/entryPoints/managed/execution.ts (5 hunks)
  • packages/cli-v3/src/entryPoints/managed/heartbeat.ts (0 hunks)
💤 Files with no reviewable changes (1)
  • packages/cli-v3/src/entryPoints/managed/heartbeat.ts
✅ Files skipped from review due to trivial changes (1)
  • packages/cli-v3/src/entryPoints/managed/env.ts
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/cli-v3/src/entryPoints/managed/execution.ts (2)
packages/cli-v3/src/executions/taskRunProcess.ts (1)
  • TaskRunProcess (64-495)
packages/core/src/utils.ts (1)
  • tryCatch (5-18)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - pnpm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - npm)
  • GitHub Check: units / 🧪 Unit Tests
🔇 Additional comments (2)
packages/cli-v3/src/entryPoints/managed/execution.ts (2)

67-68: Storing lastHeartbeat for improved diagnostics.

Introducing a dedicated lastHeartbeat property helps track heartbeat timestamps in a straightforward way. This looks good and should enhance run troubleshooting.


908-908: Include lastHeartbeat in debug logs.

Adding lastHeartbeat to the log properties makes it easier to pinpoint the most recent successful heartbeat. This is a beneficial addition for monitoring and debugging.

@nicktrn nicktrn merged commit 8b182ce into main Apr 16, 2025
10 of 12 checks passed
@nicktrn nicktrn deleted the fix/run-heartbeat branch April 16, 2025 18:49
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