Skip to content

Fix Refinement Job DB Path#571

Open
RohanExploit wants to merge 1 commit intomainfrom
fix-refinement-db-path-7028637919654626701
Open

Fix Refinement Job DB Path#571
RohanExploit wants to merge 1 commit intomainfrom
fix-refinement-db-path-7028637919654626701

Conversation

@RohanExploit
Copy link
Owner

@RohanExploit RohanExploit commented Mar 21, 2026

Fixed the dailyRefinementJob.ts database path pointing to the incorrect backend/app.db path by switching it to data/issues.db which is what the python backend generates and uses. Also added tests to verify the job successfully runs.


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


Summary by cubic

Fixes the daily refinement job by pointing it to data/issues.db so it reads real issues and runs without errors. Adds a small runner and sample data to verify execution.

  • Bug Fixes
    • Update default DB path from ../../backend/app.db to ../data/issues.db (still overridable via DB_PATH).
    • Add test_run.ts and sample files in data/ to validate the job completes successfully.

Written for commit 0d9a2eb. Summary will update on new commits.

Summary by CodeRabbit

  • Chores
    • Added system infrastructure for daily snapshot data storage.
    • Configured model weights for issue categorization across five categories.
    • Updated database path configuration.
    • Added test script for system validation.

Update the SQLite database path in scheduler/dailyRefinementJob.ts to match the correct data/issues.db path used by the backend. This allows the refinement job to analyze the actual issues submitted rather than a nonexistent backend/app.db file.
@google-labs-jules
Copy link
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 21, 2026 19:03
@netlify
Copy link

netlify bot commented Mar 21, 2026

Deploy Preview for fixmybharat canceled.

Name Link
🔨 Latest commit 0d9a2eb
🔍 Latest deploy log https://app.netlify.com/projects/fixmybharat/deploys/69beeb7ac8367c00084f1ce2

@github-actions
Copy link

🙏 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

coderabbitai bot commented Mar 21, 2026

📝 Walkthrough

Walkthrough

Two new JSON configuration and snapshot data files are introduced for model weights and daily snapshots. The default database path in the daily refinement scheduler is updated to use a relative path, and a test runner script is added to execute the refinement job.

Changes

Cohort / File(s) Summary
Data Configuration
data/modelWeights.json, data/dailySnapshots/2026-03-21.json
Added new JSON files: model weights configuration with category weights and duplicate threshold; daily snapshot record with empty keywords and concerns arrays.
Scheduler Database Path
scheduler/dailyRefinementJob.ts
Updated default SQLite database path from ../../backend/app.db to ../data/issues.db when DB_PATH environment variable is not set.
Test Runner
test_run.ts
Added new script that instantiates DailyRefinementJob, executes runRefinement(), logs completion, and exits with code 0.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰 Hoppy schedules and snapshots so neat,
Model weights aligned, a data-driven beat,
From daily refinement to tests we run true,
Configuration flows in paths old and new! 📊✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning PR description lacks required template structure with Type of Change, Related Issue, Testing Done, and Checklist sections. Fill out the complete PR description template including Type of Change checkbox, Related Issue link, Testing Done checkboxes, and Checklist items for consistency and traceability.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: fixing the incorrect database path in the refinement job from backend/app.db to data/issues.db.
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 fix-refinement-db-path-7028637919654626701

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

No issues found across 4 files

Copy link
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 updates the TypeScript daily refinement scheduler to point at the SQLite DB path that matches the Python backend’s default (./data/issues.db), instead of the previously incorrect backend/app.db path.

Changes:

  • Updated DailyRefinementJob DB fallback path to data/issues.db.
  • Added a standalone test_run.ts script to run the job manually.
  • Added data/modelWeights.json and a dated snapshot file under data/dailySnapshots/ (appear to be runtime-generated state).

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
scheduler/dailyRefinementJob.ts Fixes the default SQLite DB path used by the daily refinement job.
test_run.ts Adds a manual runner script (not wired into Jest/CI).
data/modelWeights.json Adds adaptive weights state/config file (currently includes timestamp/history).
data/dailySnapshots/2026-03-21.json Adds one daily snapshot output file.

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

Comment on lines +1 to +6
import { DailyRefinementJob } from './scheduler/dailyRefinementJob';
const job = new DailyRefinementJob();
job.runRefinement().then(() => {
console.log("Done");
process.exit(0);
});
Copy link

Copilot AI Mar 21, 2026

Choose a reason for hiding this comment

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

This file is not a Jest test (jest.config.js only runs /tests//*.test.ts), so it won’t be executed in CI. If the intent is automated verification that the job runs (as stated in the PR description), convert this into a proper Jest test under tests/ (or wire it into an npm script), and avoid using process.exit() which can mask async failures.

Copilot uses AI. Check for mistakes.
Comment on lines +10 to +23
"lastUpdated": "2026-03-21T19:01:11.261Z",
"history": [
{
"date": "2026-03-21",
"categoryWeights": {
"Pothole": 5,
"Garbage": 3,
"Water Supply": 4,
"Streetlight": 2,
"Flooding": 8
},
"duplicateThreshold": 0.85
}
]
Copy link

Copilot AI Mar 21, 2026

Choose a reason for hiding this comment

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

This looks like runtime-generated state (lastUpdated timestamp + non-empty history + duplicateThreshold already mutated). Committing this will create noisy diffs every time the refinement job runs and makes the repository state-dependent. Consider removing this from the PR and generating it on first run, or commit a stable seed file (e.g., empty history and a non-time-based lastUpdated) and/or add it to .gitignore if it’s intended to be mutable local state.

Suggested change
"lastUpdated": "2026-03-21T19:01:11.261Z",
"history": [
{
"date": "2026-03-21",
"categoryWeights": {
"Pothole": 5,
"Garbage": 3,
"Water Supply": 4,
"Streetlight": 2,
"Flooding": 8
},
"duplicateThreshold": 0.85
}
]
"lastUpdated": "1970-01-01T00:00:00.000Z",
"history": []

Copilot uses AI. Check for mistakes.
Comment on lines +2 to +6
"date": "2026-03-21",
"indexScore": 50,
"delta": 0,
"topKeywords": [],
"emergingConcerns": []
Copy link

Copilot AI Mar 21, 2026

Choose a reason for hiding this comment

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

This appears to be a daily, date-stamped output artifact from IntelligenceIndex.saveSnapshot(). Checking in per-day snapshots will grow the repo over time and cause frequent merge conflicts/stale data. Consider removing this file from the PR and adding data/dailySnapshots/*.json to .gitignore (or keep snapshots in an external/persistent volume only).

Suggested change
"date": "2026-03-21",
"indexScore": 50,
"delta": 0,
"topKeywords": [],
"emergingConcerns": []
"placeholder": "This file is intentionally kept as a non-snapshot example. Actual daily snapshots should not be committed to the repository."

Copilot uses AI. Check for mistakes.
@@ -8,7 +8,7 @@ import { Issue } from "../services/types";

// Load environmental or fallback to test.db or production db
Copy link

Copilot AI Mar 21, 2026

Choose a reason for hiding this comment

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

The comment above dbPath is now misleading (it mentions “test.db or production db” and uses “environmental” rather than “environment variable”). Please update it to reflect the actual fallback path (data/issues.db) and terminology, so future readers don’t assume a different DB layout.

Suggested change
// Load environmental or fallback to test.db or production db
// Use DB_PATH environment variable if set; otherwise fall back to data/issues.db

Copilot uses AI. Check for mistakes.
Copy link

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

🤖 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 10-11: The scheduler currently hardcodes SQLite via the dbPath
constant and ignores DATABASE_URL, causing it to run against a local DB while
the backend may use Postgres; change the scheduler
(scheduler/dailyRefinementJob.ts) to detect process.env.DATABASE_URL and branch:
if DATABASE_URL is present and begins with "postgres" use a Postgres client
(e.g., node-postgres) to connect and run the same queries/transactions the
scheduler uses, otherwise fall back to the existing sqlite logic using dbPath;
ensure connection creation/teardown mirrors backend behavior (pool vs file DB)
and that any SQL differences are handled, or alternatively update README to
explicitly document that the scheduler is SQLite-only and must not be used in
Postgres production deployments.

In `@test_run.ts`:
- Around line 1-6: The current invocation of DailyRefinementJob.runRefinement()
lacks rejection handling; update the promise chain on the job instance
(DailyRefinementJob and its runRefinement method call) to add a .catch(...) that
logs the error (including stack/message) and calls process.exit with a non-zero
code (e.g., process.exit(1)); ensure success still logs "Done" and exits 0, and
any thrown error is handled to avoid unhandled promise rejections.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 971d4bc1-5985-476f-a7c6-9af0a9ea6343

📥 Commits

Reviewing files that changed from the base of the PR and between c73144f and 0d9a2eb.

📒 Files selected for processing (4)
  • data/dailySnapshots/2026-03-21.json
  • data/modelWeights.json
  • scheduler/dailyRefinementJob.ts
  • test_run.ts

Comment on lines 10 to +11
const dbPath =
process.env.DB_PATH || path.join(__dirname, "../../backend/app.db");
process.env.DB_PATH || path.join(__dirname, "../data/issues.db");
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify the relative path resolution is correct
# From scheduler/ directory, ../data/issues.db should resolve to data/issues.db

echo "=== Checking directory structure ==="
fd -t d -d 1 "^(scheduler|data)$" .

echo -e "\n=== Verifying Python backend default paths ==="
rg -n "issues\.db" backend/

Repository: RohanExploit/VishwaGuru

Length of output: 547


🏁 Script executed:

cat -n scheduler/dailyRefinementJob.ts | head -40

Repository: RohanExploit/VishwaGuru

Length of output: 1775


🏁 Script executed:

rg -n "DATABASE_URL|dbPath" scheduler/ -A 3 -B 1

Repository: RohanExploit/VishwaGuru

Length of output: 1044


🏁 Script executed:

fd -t f "\.(ts|js)$" scheduler/ | head -10

Repository: RohanExploit/VishwaGuru

Length of output: 98


🏁 Script executed:

rg -n "production|Production|PROD" scheduler/ backend/ | head -20

Repository: RohanExploit/VishwaGuru

Length of output: 1773


🏁 Script executed:

fd -t f "\.(md|txt)$" . -path "*/scheduler/*" -o -path "*/docs/*"

Repository: RohanExploit/VishwaGuru

Length of output: 235


🏁 Script executed:

cat -n backend/README.md | grep -A 5 -B 5 "scheduler\|DATABASE_URL" | head -40

Repository: RohanExploit/VishwaGuru

Length of output: 1426


Path fix is correct, but scheduler's hardcoded SQLite creates a production issue with Postgres deployments.

The updated path ../data/issues.db correctly aligns with the Python backend's SQLite default (sqlite:///./data/issues.db in backend/database.py and backend/config.py).

However, the scheduler hardcodes sqlite3 and only respects DB_PATH environment variable, completely ignoring DATABASE_URL. The backend explicitly supports both SQLite (development) and PostgreSQL (production), but the scheduler will always use local SQLite regardless of the backend's database choice. In production with Postgres, this scheduler will operate on stale or empty data.

Consider:

  1. Refactor the scheduler to support DATABASE_URL for Postgres connections, or
  2. Document that the scheduler is SQLite-only and production setups must not rely on it with Postgres backends.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scheduler/dailyRefinementJob.ts` around lines 10 - 11, The scheduler
currently hardcodes SQLite via the dbPath constant and ignores DATABASE_URL,
causing it to run against a local DB while the backend may use Postgres; change
the scheduler (scheduler/dailyRefinementJob.ts) to detect
process.env.DATABASE_URL and branch: if DATABASE_URL is present and begins with
"postgres" use a Postgres client (e.g., node-postgres) to connect and run the
same queries/transactions the scheduler uses, otherwise fall back to the
existing sqlite logic using dbPath; ensure connection creation/teardown mirrors
backend behavior (pool vs file DB) and that any SQL differences are handled, or
alternatively update README to explicitly document that the scheduler is
SQLite-only and must not be used in Postgres production deployments.

Comment on lines +1 to +6
import { DailyRefinementJob } from './scheduler/dailyRefinementJob';
const job = new DailyRefinementJob();
job.runRefinement().then(() => {
console.log("Done");
process.exit(0);
});
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Add error handling for promise rejection.

If runRefinement() throws or rejects, the error goes unhandled and the process may exit with a non-zero code or warning, but without meaningful output.

🛠️ Proposed fix
 import { DailyRefinementJob } from './scheduler/dailyRefinementJob';
 const job = new DailyRefinementJob();
-job.runRefinement().then(() => {
-    console.log("Done");
-    process.exit(0);
-});
+job.runRefinement()
+    .then(() => {
+        console.log("Done");
+        process.exit(0);
+    })
+    .catch((err) => {
+        console.error("Refinement failed:", err);
+        process.exit(1);
+    });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test_run.ts` around lines 1 - 6, The current invocation of
DailyRefinementJob.runRefinement() lacks rejection handling; update the promise
chain on the job instance (DailyRefinementJob and its runRefinement method call)
to add a .catch(...) that logs the error (including stack/message) and calls
process.exit with a non-zero code (e.g., process.exit(1)); ensure success still
logs "Done" and exits 0, and any thrown error is handled to avoid unhandled
promise rejections.

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