Repository navigation
feat(db): embed pgserve as genie's persistent brain - #673
Conversation
Embed pgserve as genie's persistent brain with lazy initialization. Adds postgres.js client with singleton connection pool, port fallback, health check, and graceful shutdown.
Create db-migrations.ts with runMigrations() and getMigrationStatus() for incremental schema versioning. Add 001_initial.sql with core scheduler tables (schedules, triggers, runs, heartbeats, audit_events), agent_checkpoints for session resume, and LISTEN/NOTIFY trigger for real-time trigger-due notifications.
Call runMigrations() from getConnection() so the schema is automatically applied when any command first touches the database.
Wire up database management commands to the CLI router: - `genie db status` shows pgserve health, port, data dir, table counts - `genie db migrate` runs pending migrations manually - `genie db query "<sql>"` executes ad-hoc SQL with tabular output - Clean up knip config now that db modules are consumed by CLI
|
| GitGuardian id | GitGuardian status | Secret | Commit | Filename | |
|---|---|---|---|---|---|
| 18760271 | Triggered | Generic Password | faf11f4 | src/lib/db.ts | View secret |
🛠 Guidelines to remediate hardcoded secrets
- Understand the implications of revoking this secret by investigating where it is used in your code.
- Replace and store your secret safely. Learn here the best practices.
- Revoke and rotate this secret.
- If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.
To avoid such incidents in the future consider
- following these best practices for managing and storing secrets including API keys and other credentials
- install secret detection on pre-commit to catch secret before it leaves your machine and ease remediation.
🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
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. Comment |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances Genie's capabilities by embedding a persistent PostgreSQL database ( Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e7287961f1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| * Falls back to the project root if the relative path doesn't work (bundled builds). | ||
| */ | ||
| async function loadMigrationFiles(): Promise<MigrationFile[]> { | ||
| const candidates = [getMigrationsDir(), join(process.cwd(), 'src', 'db', 'migrations')]; |
There was a problem hiding this comment.
Resolve migrations from package root, not caller cwd
The migration loader only checks ../db/migrations relative to import.meta.dir and process.cwd()/src/db/migrations, so in the packaged CLI (dist/genie.js) invoked from a normal project directory it can fail to find src/db/migrations entirely and return no migrations. In that case _genie_migrations is created but the actual schema (e.g., schedules, triggers, etc.) is never applied, causing runtime failures or empty behavior in DB-backed commands outside the repo root.
Useful? React with 👍 / 👎.
| if (await isPortListening(port, DEFAULT_HOST)) { | ||
| activePort = port; |
There was a problem hiding this comment.
Verify Postgres readiness before reusing an occupied port
This branch treats any TCP listener on the configured port as a valid pgserve instance, but isPortListening only performs a socket connect and does not confirm PostgreSQL protocol/auth readiness. If another local service is bound to 127.0.0.1:19642, ensurePgserve() returns success here and getConnection() later fails instead of starting pgserve on a fallback port, breaking all genie db commands on machines with a port conflict.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Code Review
This pull request introduces pgserve as a persistent brain for genie, along with connection management, schema versioning, migration system, and a genie db CLI. The changes include adding dependencies, creating database management files, modifying the genie.ts file, and adding a pgserve type definition file. I have provided feedback to address potential issues and improve the code.
| console.warn(`Warning: pgserve failed to start: ${message}`); | ||
| throw new Error(`pgserve failed to start on port ${port} (and fallbacks ${port + 1}-${port + 3}): ${message}`); |
There was a problem hiding this comment.
The console.warn call here is duplicated in the catch block below. Consider refactoring this to a single place to avoid duplication.
const message = err instanceof Error ? err.message : String(err);
console.warn(`Warning: pgserve failed to start: ${message}`);
throw new Error(`pgserve failed to start on port ${port} (and fallbacks ${port + 1}-${port + 3}): ${message}`);pgserve depends on the bun npm package, whose postinstall script must run to set up the binary. Without trusting it, CI build fails with "Bun's postinstall script was not run".
Summary
src/lib/db.ts) withensurePgserve(),getConnection(),isAvailable(), andshutdown()src/lib/db-migrations.ts) with initial schema including scheduler tables (schedules, triggers, runs, heartbeats, audit_events) and agent_checkpointsgenie dbCLI commands:status,migrate,queryTest plan
genie db statusauto-starts pgserve, runs migrations, reports healthgenie db migrateruns pending migrationsgenie db query "SELECT 1"returns result~/.genie/data/pgserve/bun run checkpasses (verified: 786 tests, 0 failures)Wish: pgserve-embed