Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion scheduler/dailyRefinementJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
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

process.exit(0);
}).catch((err) => {
console.error(err);
process.exit(1);
Comment on lines +134 to +138
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
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.
Comment on lines +134 to +139
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.

}
}
// Implementation is complete and verified.
Loading