From 710f92ecfce5e541042c0d49ba9cffa7b8c177fa Mon Sep 17 00:00:00 2001 From: Simon Gagnon Date: Mon, 31 Aug 2026 00:53:06 -0400 Subject: [PATCH 1/2] fix(host): do not attach acquire to a stopped autopg port Registered pm2 with no listener was treated as live, so cedarpg acquire hit ECONNREFUSED on 25432. Treat status/TCP as liveness and start an owned postmaster when local install cannot bring a host up. --- AGENTS.md | 2 +- CHANGELOG.md | 2 + README.md | 21 +++++----- scripts/smoke-pg.mjs | 27 +++++++++---- src/providers/autopg.ts | 23 +++++++++-- src/providers/host.ts | 85 ++++++++++++++++++++++------------------- tests/autopg.test.ts | 25 ++++++++++-- tests/host.test.ts | 28 +++++--------- 8 files changed, 129 insertions(+), 84 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 9d4dfb5..7efafea 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -89,7 +89,7 @@ Keep logic in the canonical layer. Prefer reuse over one-off branches in adapter **Migrate stays app-owned.** Stock `@cedarjs/pg/jest` / `vitest` only acquire/dispose. TEMPLATE adapters require `createGlobalSetup({ migrate })`; string-resolving the package entry without a migrate hook must throw. -**Host bootstrap stays internal.** Callers use `acquire` (and `adminUrl`). Do not re-export `ensureHostRunning` or grow a public host-options bag; ephemeral behavior is env-driven (`CI`, `CEDAR_PG_EPHEMERAL_HOST`). +**Host bootstrap stays internal.** Callers use `acquire` (and `adminUrl`). Do not re-export `ensureHostRunning` or grow a public host-options bag; ephemeral behavior is env-driven (`CI`, `CEDAR_PG_EPHEMERAL_HOST`). Default local acquire may start an owned postmaster after a no-op `autopg install` (stopped pm2); `CEDAR_PG_EPHEMERAL_HOST=0` disables that fallback. ## Env and policy (easy to get wrong) diff --git a/CHANGELOG.md b/CHANGELOG.md index e1fa0f0..8c33ba8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ ### Fixed +- Attach liveness: `parseHostStatus` reads autopg v3 `status` / `runtime.live` (a stopped pm2 registration is not live). `ensureHostRunning` requires TCP on the discovered port before attaching. `cedarpg acquire` with no listening host no longer talks to registered port 25432 (`ECONNREFUSED`); after a failed or no-op `autopg install` it starts an owned postmaster on 55432 unless `CEDAR_PG_EPHEMERAL_HOST=0`. +- Ephemeral host: start detached `autopg postmaster` only. Do not run `install --no-pm2` (that rewrites `~/.autopg/admin.json` and fails with `supervisor mismatch` next to a local pm2 install). - TEMPLATE `cloneWorkerDatabase`: default clone name is unique per call (`__