Skip to content

fix(install): bake DATABASE_URL env into ecosystem config when canonical pgserve is detected - #1604

Merged
namastex888 merged 1 commit into
devfrom
fix/genie-install-env-canonical
May 1, 2026
Merged

namastex888 merged 1 commit into
devfrom
fix/genie-install-env-canonical

Conversation

@namastex888

Copy link
Copy Markdown
Contributor

Summary

Closes the wish's "shared backbone" loop for genie. Previously, genie install registered genie-serve under pm2 with no env block — meaning genie-serve always fell back to spawning its own embedded pgserve on :19644 regardless of whether canonical pgserve was registered.

Caught live on this server during the canonical migration: I had to hand-edit ~/.genie/genie-serve.config.cjs to add:

env: {
  DATABASE_URL: 'postgresql://postgres:postgres@localhost:8432/genie'
}

…otherwise pm2 restored the wrong env on every restart and genie-serve spawned its own embedded pgserve.

Fix

When pgserve install succeeds AND pgserve port returns a valid port at genie install time, derive the canonical URL and bake it into the pm2 ecosystem config's env block. Omitted when canonical pgserve isn't available (so genie-serve falls back to its embedded auto-spawn path — same as today).

Code shape

Function Change
tryPgservePort() (new) Probes pgserve port to discover canonical port. Uses the real subcommand (NOT --version — that flag doesn't exist in pgserve@^2.1.0; false-negatived in omni doctor --fix historically)
buildGenieDatabaseUrl(port) (new) Composes URL with genie DB (pgserve auto-provisions; mirrors omni's pattern)
buildEcosystemConfigSource(geniePath, databaseUrl?) Threads the URL into an env block. Omits the block when no URL — preventing an empty env from clobbering an operator's shell-set DATABASE_URL
buildPm2StartArgs(geniePath, databaseUrl?) + writeEcosystemConfig Thread the URL through
installCommand Derives URL after pgserve install + logs it on success. Updates "already installed" message to point at pm2 delete genie-serve && genie install for refreshing env

Tests

  • omits env block when no databaseUrl provided (legacy fallback path)
  • bakes DATABASE_URL into env block when canonical pgserve url provided
  • 14/14 tests pass (was 12, +2 env-wiring assertions)
  • typecheck green, no new linter warnings

Wave context

This is the second post-canonical-pgserve fix needed in genie. Once this lands and a new genie publishes, fresh genie install calls auto-wire genie-serve to canonical pgserve — no hand-editing required.

Test plan

  • bun test src/genie-commands/__tests__/install.test.ts — 14/14
  • bun run typecheck — green
  • bun run lint — no new warnings on changed files
  • Live retest after merge: pm2 delete genie-serve && genie install should write the env block; genie-serve should connect to canonical pgserve on :8432 instead of spawning embedded

…cal pgserve is detected

Closes the wish's "shared backbone" loop for genie. Previously, `genie
install` registered genie-serve under pm2 with NO env block — meaning
genie-serve always fell back to spawning its own embedded pgserve on
`:19644` regardless of whether canonical pgserve was registered.
Operators had to hand-edit `~/.genie/genie-serve.config.cjs` to add an
env block (caught live on this server during the canonical migration).

What changes
------------
- `tryPgservePort()` (new) — probes `pgserve port` to discover the
  canonical port. Uses the real subcommand (NOT `--version`, which
  doesn't exist in pgserve@^2.1.0 and false-negatived in `omni doctor
  --fix` historically).
- `buildGenieDatabaseUrl(port)` (new) — composes the canonical URL
  using the `genie` database (auto-provisioned by pgserve on first
  connection, mirrors omni's pattern).
- `buildEcosystemConfigSource(geniePath, databaseUrl?)` — accepts an
  optional `databaseUrl` and bakes it into an `env` block when present.
  Omits the env block entirely when absent (so genie-serve falls back
  to its embedded auto-spawn path without an empty env clobbering an
  operator's shell-set DATABASE_URL).
- `buildPm2StartArgs(geniePath, databaseUrl?)` and
  `writeEcosystemConfig(geniePath, databaseUrl?)` — thread the URL
  through.
- `installCommand` — when `tryPgserveInstall()` succeeds AND
  `tryPgservePort()` returns a valid port, derives the canonical URL
  and passes it through. Logs the URL on success so operators can see
  the wire that was made.
- The "already installed" early-return now hints `pm2 delete genie-serve
  && genie install` as the way to refresh env on URL change.

Tests
-----
- `omits env block when no databaseUrl provided (legacy fallback path)`
- `bakes DATABASE_URL into env block when canonical pgserve url provided`
- 14/14 tests pass (was 12, +2 new env-wiring tests).
- Typecheck green. Linter: no new warnings on changed files.

Validated on khal-os
--------------------
After hand-editing the ecosystem config to include the env block,
genie-serve connects to canonical pgserve via TCP `:8432` and the
embedded `:19644` postgres no longer spawns. This PR codifies that
hand-edit so future installs are correct out of the box.
@coderabbitai

coderabbitai Bot commented May 1, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: b2d65e67-91df-4a79-9fdc-e3e01610db33

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/genie-install-env-canonical

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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5567e202c9

ℹ️ 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".

Comment on lines 288 to +289
if (!options.skipPgserve) {
tryPgserveInstall();
if (tryPgserveInstall()) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Probe canonical pgserve port even when --skip-pgserve is set

The new DATABASE_URL wiring is fully gated by !options.skipPgserve, so users who intentionally pass --skip-pgserve (documented as “don’t run pgserve install first”) never get canonical URL injection even if pgserve is already running and pgserve port would succeed. In that path, genie-serve falls back to embedded pgserve behavior, which defeats the main goal of this change for operator-managed pgserve setups.

Useful? React with 👍 / 👎.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates the genie install command to detect a canonical pgserve instance and bake its connection URL into the PM2 ecosystem configuration, ensuring genie-serve uses the shared database backbone. Key changes include new utility functions for port probing, updates to the PM2 configuration logic to support environment variables, and corresponding unit tests. I have no feedback to provide.

@namastex888
namastex888 merged commit b9e08d8 into dev May 1, 2026
16 checks passed
@automagik-genie
automagik-genie deleted the fix/genie-install-env-canonical branch September 25, 2026 04:50
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.

2 participants