Skip to content

Completed batch waitpoints when we completed the BatchTaskRun #1945

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 3 commits into from
Apr 17, 2025

Conversation

matt-aitken
Copy link
Member

@matt-aitken matt-aitken commented Apr 17, 2025

We were previously completing these waitpoints when we thought all runs had been triggered. There's high contention in the code here.

Some of these waitpoints were not getting completed, even though they should have been. For all of the ones I saw the BatchTaskRun was completed, so I've moved the waitpoint completion code to there instead.

Summary by CodeRabbit

  • New Features

    • Improved handling of batch completion to automatically finalize related waitpoints when all runs in a batch are completed.
  • Refactor

    • Streamlined batch processing by removing explicit unblocking of parent runs and integrating waitpoint completion directly into the batch system.

Copy link

changeset-bot bot commented Apr 17, 2025

⚠️ No Changeset found

Latest commit: b28fd42

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.

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 Apr 17, 2025

Walkthrough

The changes refactor how batch completion and parent run unblocking are handled in the run engine system. The explicit method for unblocking a parent run after batch creation is removed from the RunEngine class. Instead, the responsibility for completing any associated waitpoint when a batch is completed is moved into the BatchSystem class. The BatchSystem is updated to depend on a WaitpointSystem, and upon batch completion, it checks for and completes any relevant waitpoint. Constructor signatures and dependency wiring are updated accordingly.

Changes

File(s) Change Summary
apps/webapp/app/runEngine/services/batchTrigger.server.ts Removed logic that unblocked parent runs after batch creation; now relies on batch completion logic in the batch system.
internal-packages/run-engine/src/engine/index.ts Removed unblockRunForCreatedBatch method; updated RunEngine to inject waitpointSystem into BatchSystem.
internal-packages/run-engine/src/engine/systems/batchSystem.ts Added waitpointSystem dependency; on batch completion, checks for and completes any associated waitpoint.
internal-packages/run-engine/src/engine/tests/batchTriggerAndWait.test.ts Removed calls to unblockRunForCreatedBatch; increased delay after second child run completion from 500ms to 1000ms.
internal-packages/run-engine/src/engine/tests/checkpoints.test.ts Removed call to unblockRunForCreatedBatch in batch resume test case.

Sequence Diagram(s)

sequenceDiagram
    participant RunEngine
    participant BatchSystem
    participant WaitpointSystem

    RunEngine->>BatchSystem: createBatch(...)
    BatchSystem->>BatchSystem: #tryCompleteBatch()
    BatchSystem->>BatchSystem: Mark batch as COMPLETED
    BatchSystem->>WaitpointSystem: completeWaitpoint(waitpointId, output) (if waitpoint exists)
Loading

Suggested reviewers

  • nicktrn

Poem

In the warren of code, a batch hops along,
No more does the parent wait overly long.
The BatchSystem now knows when all kits are through,
And calls on Waitpoint—"It’s time! Hop to you!"
With dependencies tidy and logic anew,
The runs and their waitpoints all bid you adieu.
🐇✨

✨ 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)
internal-packages/run-engine/src/engine/systems/batchSystem.ts (2)

20-29: Reduced job delay from 2000ms to 200ms

The delay for the tryCompleteBatch job has been significantly reduced from what appears to be 2 seconds to 200ms. This should help address the high contention issues mentioned in the PR objectives.

Consider adding a comment explaining why this specific delay was chosen and how it helps with the contention issues.


82-104: Implementation of waitpoint completion logic

The implementation correctly queries for associated waitpoints and completes them when a batch is completed. This aligns with the PR objective of moving waitpoint completion to happen when the BatchTaskRun is completed.

The debug message on line 92 still refers to "RunEngine.unblockRunForBatch()" which should be updated to reflect that this is now in the BatchSystem class, perhaps to "BatchSystem.#tryCompleteBatch()".

-          this.$.logger.debug(
-            "RunEngine.unblockRunForBatch(): Waitpoint not found. This is ok, because only batchTriggerAndWait has waitpoints",
-            {
-              batchId,
-            }
-          );
+          this.$.logger.debug(
+            "BatchSystem.#tryCompleteBatch(): Waitpoint not found. This is ok, because only batchTriggerAndWait has waitpoints",
+            {
+              batchId,
+            }
+          );
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b2f2689 and b28fd42.

📒 Files selected for processing (3)
  • internal-packages/run-engine/src/engine/systems/batchSystem.ts (3 hunks)
  • internal-packages/run-engine/src/engine/tests/batchTriggerAndWait.test.ts (1 hunks)
  • internal-packages/run-engine/src/engine/tests/checkpoints.test.ts (0 hunks)
💤 Files with no reviewable changes (1)
  • internal-packages/run-engine/src/engine/tests/checkpoints.test.ts
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - pnpm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - npm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - pnpm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - npm)
  • GitHub Check: typecheck / typecheck
  • GitHub Check: units / 🧪 Unit Tests
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (4)
internal-packages/run-engine/src/engine/tests/batchTriggerAndWait.test.ts (1)

299-299: Increased timeout to accommodate asynchronous batch completion

The timeout has been increased from 500ms to 1000ms, which is appropriate given the changes to the batch completion mechanism. With the batch waitpoint completion now handled asynchronously in the BatchSystem with a 200ms delay, this additional wait time ensures that all operations complete before assertions are checked.

internal-packages/run-engine/src/engine/systems/batchSystem.ts (3)

4-4: Added dependency on WaitpointSystem

The import of WaitpointSystem is appropriate as part of moving the waitpoint completion responsibility into the BatchSystem.


6-9: Updated BatchSystemOptions to include WaitpointSystem

Good addition of the waitpointSystem dependency to the options interface.


11-18: Proper initialization of WaitpointSystem dependency

The addition of the waitpointSystem property and its initialization in the constructor are well-implemented.

@matt-aitken matt-aitken merged commit bbf397e into main Apr 17, 2025
12 checks passed
@matt-aitken matt-aitken deleted the v4-fix-batch-waitpoint-completion branch April 17, 2025 20:02
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