Skip to content

Exit the process if status is finished and not in the middle of completing #2378

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 1 commit into from
Aug 11, 2025

Conversation

matt-aitken
Copy link
Member

This solves an issue where a run is system failed from the platform and
the worker is never shut down in the cluster.

…eting

This solves an issue where a run is system failed from the platform and 
the worker is never shut down in the cluster.
Copy link
Contributor

coderabbitai bot commented Aug 10, 2025

Walkthrough

A private boolean flag named isCompletingRun was added to the RunExecution class within the packages/cli-v3/src/entryPoints/managed/execution.ts file. This flag is set to false at the start of each new attempt via the startAttempt method and set to true in the complete method before submitting completion results. The processSnapshotChange method now checks the flag when handling a "FINISHED" status; if isCompletingRun is true, it logs a debug message and skips shutdown logic to prevent redundant actions. No other control flow or error handling changes were made.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Note

🔌 MCP (Model Context Protocol) integration is now available in Early Access!

Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch exit-finished-execution-status

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

Support

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

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.

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)

297-304: Clarify FINISHED handling message and shutdown reason

Logic is correct. Two nits to improve clarity:

  • Update the comment/log to explicitly say we’re skipping shutdown while a completion submission is in-flight.
  • Use a more accurate shutdown reason than "re-queued" for FINISHED.

Apply:

-        // We are finishing the run in handleCompletionResult, so we don't need to do anything here
-        if (this.isCompletingRun) {
-          this.sendDebugLog("run is finished but we're completing it, skipping", snapshotMetadata);
-          return;
-        }
-
-        await this.exitTaskRunProcessWithoutFailingRun({ flush: true, reason: "re-queued" });
+        // If a completion submission is in-flight, skip shutdown here and let the completion flow clean up.
+        if (this.isCompletingRun) {
+          this.sendDebugLog(
+            "run is finished but completion is in-flight, skipping shutdown",
+            snapshotMetadata
+          );
+          return;
+        }
+
+        await this.exitTaskRunProcessWithoutFailingRun({
+          flush: true,
+          reason: "finished (not completing)",
+        });

669-670: Scope isCompletingRun strictly to the completion submission window

Current behavior keeps the flag true after completion. Not harmful (execute() shuts down), but you can make the intent tighter by resetting it in a finally block so it only denotes “in-flight completion”.

Apply:

-    this.isCompletingRun = true;
-
-    const completionResult = await this.httpClient.completeRunAttempt(
-      this.runFriendlyId,
-      this.snapshotManager.snapshotId,
-      { completion }
-    );
-
-    if (!completionResult.success) {
-      throw new Error(`failed to submit completion: ${completionResult.error}`);
-    }
-
-    await this.handleCompletionResult({
-      completion,
-      result: completionResult.data.result,
-    });
+    this.isCompletingRun = true;
+    try {
+      const completionResult = await this.httpClient.completeRunAttempt(
+        this.runFriendlyId,
+        this.snapshotManager.snapshotId,
+        { completion }
+      );
+
+      if (!completionResult.success) {
+        throw new Error(`failed to submit completion: ${completionResult.error}`);
+      }
+
+      await this.handleCompletionResult({
+        completion,
+        result: completionResult.data.result,
+      });
+    } finally {
+      // Reflect that completion submission has finished (success or failure)
+      this.isCompletingRun = 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 a968c23 and bcf20db.

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

79-80: Good state flag to gate shutdown while submitting completion

The isCompletingRun flag is a simple and effective guard for avoiding premature shutdown during completion.


388-390: Resetting the flag at the start of each attempt is correct

This ensures retries start clean and FINISHED events are handled appropriately for the new attempt.

@matt-aitken matt-aitken merged commit c58b78f into main Aug 11, 2025
50 of 58 checks passed
@matt-aitken matt-aitken deleted the exit-finished-execution-status branch August 11, 2025 10:22
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