Skip to content

fix: exit process after dailyRefinementJob finishes#612

Open
RohanExploit wants to merge 1 commit intomainfrom
jules-6153720936118833140-df92a4b2
Open

fix: exit process after dailyRefinementJob finishes#612
RohanExploit wants to merge 1 commit intomainfrom
jules-6153720936118833140-df92a4b2

Conversation

@RohanExploit
Copy link
Copy Markdown
Owner

@RohanExploit RohanExploit commented Mar 29, 2026

Fixes an issue where scheduler/dailyRefinementJob.ts hangs indefinitely when executed with the --run-now flag. The script now awaits the refinement job and explicitly calls process.exit(0) on success or process.exit(1) on error.


PR created automatically by Jules for task 6153720936118833140 started by @RohanExploit


Summary by cubic

Fixes a hang when running scheduler/dailyRefinementJob.ts with --run-now by awaiting the refinement job. The script now exits with code 0 on success or 1 on error, preventing runaway processes in manual/CI runs.

Written for commit bdcb6fd. Summary will update on new commits.

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced manual job execution to properly handle errors and ensure correct process termination behavior.

Fixes an issue where `scheduler/dailyRefinementJob.ts` hangs indefinitely when executed with the `--run-now` flag.
The script now awaits the refinement job and explicitly calls `process.exit(0)` on success or `process.exit(1)` on error.
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copilot AI review requested due to automatic review settings March 29, 2026 19:18
@netlify
Copy link
Copy Markdown

netlify bot commented Mar 29, 2026

Deploy Preview for fixmybharat canceled.

Name Link
🔨 Latest commit bdcb6fd
🔍 Latest deploy log https://app.netlify.com/projects/fixmybharat/deploys/69c97af7729a8d0008005c55

@github-actions
Copy link
Copy Markdown

🙏 Thank you for your contribution, @RohanExploit!

PR Details:

Quality Checklist:
Please ensure your PR meets the following criteria:

  • Code follows the project's style guidelines
  • Self-review of code completed
  • Code is commented where necessary
  • Documentation updated (if applicable)
  • No new warnings generated
  • Tests added/updated (if applicable)
  • All tests passing locally
  • No breaking changes to existing functionality

Review Process:

  1. Automated checks will run on your code
  2. A maintainer will review your changes
  3. Address any requested changes promptly
  4. Once approved, your PR will be merged! 🎉

Note: The maintainers will monitor code quality and ensure the overall project flow isn't broken.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 29, 2026

📝 Walkthrough

Walkthrough

Updated the --run-now manual execution path in the daily refinement job to properly handle the promise returned by runRefinement(), replacing implicit termination behavior with explicit success/failure exit handlers.

Changes

Cohort / File(s) Summary
Promise Handling Enhancement
scheduler/dailyRefinementJob.ts
Manual execution path now awaits and handles the runRefinement() promise explicitly: resolves with process.exit(0) on success, and logs error then exits with code 1 on failure.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested labels

size/s, ECWoC26-ENDED

Poem

🐰 A promise once lost in the void,
Now caught with care, no task ignored,
Exit codes dance, success or fall,
The refinement job conquers all! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description provides context but lacks comprehensive information required by the repository template. Add missing sections: Type of Change (select appropriate category), Related Issue link, Testing Done checklist with specific details, and verify all checklist items are addressed.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: fixing the process exit behavior in the daily refinement job after it finishes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch jules-6153720936118833140-df92a4b2

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
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses the scheduler CLI hanging when invoked with --run-now by waiting for the refinement to finish and then terminating the Node process with an explicit exit code.

Changes:

  • Await DailyRefinementJob.runRefinement() when --run-now is provided.
  • Exit the process with code 0 on success and 1 on error (intended behavior).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +134 to +138
job.runRefinement().then(() => {
process.exit(0);
}).catch((err) => {
console.error(err);
process.exit(1);
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .catch(...) here likely never runs because runRefinement() catches errors internally and only logs them (it doesn’t rethrow). That means --run-now will still process.exit(0) even when refinement fails. To make the exit code reliable, either let runRefinement() propagate/rethrow errors (or return a success/failure result) and handle it here, instead of swallowing exceptions inside runRefinement().

Copilot uses AI. Check for mistakes.
Comment on lines +135 to +139
process.exit(0);
}).catch((err) => {
console.error(err);
process.exit(1);
});
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using process.exit(...) avoids the hang, but it also bypasses normal cleanup (e.g., leaving the sqlite connection and the cron task running until forced termination). A cleaner fix is to skip cron.schedule(...) entirely when --run-now is set, and explicitly close the sqlite DB after the one-off run so the process can exit naturally (or close it before calling process.exit).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 1 file

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="scheduler/dailyRefinementJob.ts">

<violation number="1" location="scheduler/dailyRefinementJob.ts:134">
P2: `--run-now` can return a false success exit code because `runRefinement()` swallows errors, so this promise chain almost always resolves and exits with 0.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

// For testing/manual trigger, we can also pass a flag or just run immediately if needed
if (process.argv.includes("--run-now")) {
job.runRefinement();
job.runRefinement().then(() => {
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: --run-now can return a false success exit code because runRefinement() swallows errors, so this promise chain almost always resolves and exits with 0.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At scheduler/dailyRefinementJob.ts, line 134:

<comment>`--run-now` can return a false success exit code because `runRefinement()` swallows errors, so this promise chain almost always resolves and exits with 0.</comment>

<file context>
@@ -131,7 +131,12 @@ if (require.main === module) {
   // For testing/manual trigger, we can also pass a flag or just run immediately if needed
   if (process.argv.includes("--run-now")) {
-    job.runRefinement();
+    job.runRefinement().then(() => {
+      process.exit(0);
+    }).catch((err) => {
</file context>
Fix with Cubic

Copy link
Copy Markdown

@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: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@scheduler/dailyRefinementJob.ts`:
- Around line 134-139: The .catch() is unreachable because runRefinement()
swallows errors; modify either runRefinement() or this caller: Option A — change
the runRefinement() implementation (the runRefinement function on the job
object) to re-throw the caught error after logging so job.runRefinement()
returns a rejected promise and the caller's .catch() runs; Option B — change
runRefinement() to return a boolean status (true on success, false on failure)
and update this call site to await the result (const ok = await
job.runRefinement()) and then call process.exit(0) for success or
process.exit(1) for failure instead of relying on .catch(); pick one approach
and apply consistently.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 67663b29-31b6-48ef-ad75-933f2813fbeb

📥 Commits

Reviewing files that changed from the base of the PR and between cf5ed76 and bdcb6fd.

📒 Files selected for processing (1)
  • scheduler/dailyRefinementJob.ts

Comment on lines +134 to +139
job.runRefinement().then(() => {
process.exit(0);
}).catch((err) => {
console.error(err);
process.exit(1);
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

.catch() block is unreachable — runRefinement() swallows all errors.

The runRefinement() method (lines 85-87) catches errors internally and logs them but does not re-throw. The promise always resolves, so this .catch() never executes and the process exits with code 0 even on failure.

Either re-throw the error in runRefinement() or return a status to indicate failure:

Option 1: Re-throw in runRefinement()
     } catch (error) {
       console.error("Error during daily refinement:", error);
+      throw error;
     }
Option 2: Return success/failure and check it here
-    job.runRefinement().then(() => {
-      process.exit(0);
-    }).catch((err) => {
-      console.error(err);
-      process.exit(1);
-    });
+    job.runRefinement().then((success) => {
+      process.exit(success ? 0 : 1);
+    });

And update runRefinement() to return true/false accordingly.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scheduler/dailyRefinementJob.ts` around lines 134 - 139, The .catch() is
unreachable because runRefinement() swallows errors; modify either
runRefinement() or this caller: Option A — change the runRefinement()
implementation (the runRefinement function on the job object) to re-throw the
caught error after logging so job.runRefinement() returns a rejected promise and
the caller's .catch() runs; Option B — change runRefinement() to return a
boolean status (true on success, false on failure) and update this call site to
await the result (const ok = await job.runRefinement()) and then call
process.exit(0) for success or process.exit(1) for failure instead of relying on
.catch(); pick one approach and apply consistently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants