Skip to content

chore(deps): bump embedded-postgres to 18.6.0-beta.19 - #1429

Merged
allisonmahmood merged 7 commits into
mainfrom
deps/embedded-postgres
Nov 20, 2026
Merged

allisonmahmood merged 7 commits into
mainfrom
deps/embedded-postgres

Conversation

@allisonmahmood

@allisonmahmood allisonmahmood commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

What changed

embedded-postgres goes from 18.4.0-beta.17 to 18.6.0-beta.19, the bump #1424 left out. The newest release is 18.6.0-beta.19, published on 2026-10-30. It and its eight platform packages ship Postgres 18.6, up from 18.4, so the dev instance, the Vitest Postgres template, the postgres-concurrency suite, the browser suites, the packed CLI e2e and the rollback rehearsal now run on 18.6. This is dev and test infrastructure only. People using Patchy notice nothing, and production Postgres doesn't come from this package.

Look at

The shutdown hook changed library, and exit-hook needs a small patch to behave as before. embedded-postgres stops its clusters from a process-exit hook. 18.4 used async-exit-hook, which patches/[email protected] fixed so a failed Vitest run kept its exit code. 18.6 uses exit-hook 5, which keeps process.exitCode on its own, so that patch and its patchedDependencies entry are gone. Nothing else in the tree resolves async-exit-hook, and pnpm refuses an unused patch.

exit-hook differs from async-exit-hook in three ways that matter here. I measured them with a small script that loads embedded-postgres, starts a cluster and exits one way. "Cluster left" means Postgres was still running, with its postmaster.pid, once the process had gone. Node 24 and Bun 1.4.4 gave the same results.

Exit 18.4 (async-exit-hook, patched) 18.6 with exit-hook as published 18.6 with this PR's exit-hook patch
loop drains, exitCode unset / = 1 0 / 1 0 / 1 0 / 1
process.exit(3) with a cluster running 3, cluster stopped, nothing printed 3, cluster left, SYNCHRONOUS TERMINATION NOTICE… on stderr 3, cluster stopped, nothing printed
process.exit(3) after stopping it 3, nothing printed 3, notice 3, nothing printed
SIGINT / SIGTERM 130 / 143, cluster stopped 130 / 143, cluster stopped 130 / 143, cluster stopped
SIGHUP 129, cluster stopped killed by SIGHUP, cluster left 129, cluster stopped

The notice is the visible one. It would print whenever a process that loaded embedded-postgres ends through process.exit() or an uncaught error, which includes packed-cli-e2e's failure and cancel paths and the rollback rehearsal's cancel path. patches/[email protected] restores async-exit-hook's behaviour on those paths:

  • On process.exit(), the hook starts the asynchronous callbacks too, unawaited. embedded-postgres's stop() sends Postgres SIGINT before its first await, so the cluster still shuts down.
  • The notice is no longer printed.
  • SIGHUP (129) and SIGBREAK (149) are hooked again.

scripts/dev/src/postgres.test.ts, which already pinned the exit-code fix, now covers both.

The first new case starts a cluster in a child process that calls process.exit(5) with it running. It checks the code, an empty stderr, and that the postmaster's pid is gone. The child is spawned with Node's own spawn, because Effect's spawner signals a child's process group when it exits non-zero, and that could stop Postgres in the hook's place. Nothing in the test signals Postgres before those checks.

Its cleanup is registered as soon as the probe spawns, before anything waits. The probe leads its own process group, which initdb and Postgres join, and the cleanup interrupts that group, so Postgres shuts down and frees its shared memory, then SIGKILLs whatever is left after 3 s and waits up to 5 s more for the group to empty. It doesn't depend on postmaster.pid, so it also reaches a cluster that was spawned but hasn't written that file. It's a scope finalizer added after the temporary directory, so it runs after the assertions, including on failure and timeout, and before the directory is removed. A spawn error fails the case.

The group cleanup was run outside the suite against three stalls: a probe that never exits with its cluster running (stopped by the interrupt in 250 ms), a timeout while the cluster is still starting (the same), and a Postgres frozen with SIGSTOP right after spawn (SIGKILLed at 3.3 s). Each left the group empty. A frozen Postgres can't act on the interrupt, so that last case leaves its shared-memory segment behind, as any SIGKILL of Postgres does.

The second case checks that a hangup exits 129.

All three cases run on live services (excludeTestServices: true). The first version polled on it.effect's test clock, which never advances: whenever the first check found Postgres still shutting down, the retry never woke. That was the 30 s timeout CI and the loaded local suite hit.

With only the patch's async-callback hunk removed, keeping notice suppression and SIGHUP, the first case fails, and its cleanup still leaves no cluster:

× stops a running cluster on process.exit, keeping its code and printing nothing 10511ms
Unknown Error: still running
      Tests  1 failed | 2 passed (3)

With the whole patch, all three pass, on 18.6 and on 18.4 alike. Without the patch at all, the SIGHUP case fails too, since the process dies by the signal instead of exiting 129.

Who stops the dev supervisor on SIGINT and SIGTERM. exit-hook forces its process out five seconds after either signal, where async-exit-hook allowed ten. The supervisor gives its server five seconds after SIGTERM before SIGKILL, so once the server runs, the hook could end the supervisor in the middle of its own teardown. So the two phases have different owners:

  • While the cluster starts, embedded-postgres's handlers. Start-up runs inside an acquireRelease acquisition, which can't be interrupted, and Postgres's release finalizer doesn't exist until it succeeds. The library's handlers stop the starting cluster and exit within exit-hook's bound, as on main, where it was async-exit-hook's.
  • From the moment the cluster is up, the scope. The supervisor loads embedded-postgres lazily, as the e2e and browser harnesses do. It removes the library's SIGINT and SIGTERM listeners as the very next step after acquisition, before the database is migrated or the server launched. Two synchronous steps can't leave a gap between the owners. NodeRuntime.runMain turns both signals into interruption, and the scope stops the server and then Postgres.

The library's exit, beforeExit and SIGHUP hooks stay throughout.

Manual runs on the real supervisor. SIGSTOP pauses a process so it acts on no SIGTERM, though SIGKILL still works, and it acts on a pending signal once resumed.

Case First push (hook owns all) Second push (scope owns all) This head (library during start-up, then scope)
Postgres paused the moment it writes postmaster.pid (still starting), SIGTERM, Postgres resumed at 8 s — exited only at 8.1 s, once Postgres resumed and finished starting exited at 5.1 s; Postgres shut down on resume; nothing left, no postmaster.pid
the same with SIGINT — — exited at 5.1 s; nothing left
running Postgres and the server both paused, SIGTERM, Postgres resumed at 6 s exited at 5.5 s, no finalizer logged; server left running exited at 6.3 s after postgres stopped; server SIGKILLed at its 5 s grace; nothing left the same: 6.3 s, postgres stopped, nothing left

A Postgres that stays paused forever during start-up would still be left, paused with the SIGINT it was sent, as on main. Only SIGKILL ends a stopped process, and embedded-postgres keeps its child private.

These aren't tests because they need the whole supervisor (plan, server, cluster). SIGHUP isn't fixed by this: exit-hook's hangup handler still exits before the finalizers, and runMain routes only SIGINT and SIGTERM. So the SIGHUP row below is unchanged from main.

The exit paths, before (main, 18.4) and after (this branch). Each ran on this machine, on Node 24.20.0, against throwaway instances. The dev rows ran again on this head, and the other rows don't involve the supervisor. "Stopped" means no postgres or server process was left and no postmaster.pid remained. "Notices" counts SYNCHRONOUS TERMINATION NOTICE in the full output.

Path Before After
Vitest, a failing test exit 1, no notice exit 1, no notice
Vitest, passing (scripts/dev/src/postgres.test.ts) exit 0, no notice exit 0, no notice
pnpm dev stop (SIGTERM to the supervisor) exit 0, "Stopped.", stopped exit 0, "Stopped.", stopped by the scope (postgres stopped logged)
SIGINT to the dev supervisor stopped in 0.25 s stopped in 0.25 s, by the scope
SIGTERM to the dev supervisor stopped in 0.25 s stopped in 0.25 s, by the scope
SIGHUP to the dev supervisor Postgres stopped, server left running Postgres stopped, server left running (unchanged; see below)
pnpm dev down exit 0, state removed, stopped exit 0, state removed, stopped
packed CLI e2e, success exit 0 in 58 s, 0 notices exit 0 in 58 s, 0 notices
packed CLI e2e, SIGTERM once its Postgres is up exit 143, 0 notices, no cluster left exit 143, 0 notices, no cluster left
packed CLI e2e, its Postgres SIGKILLed mid-run exit 1 (the step's error), 0 notices exit 1 (the step's error), 0 notices
rollback rehearsal --live origin/main, success exit 0, four steps in 123 s, 0 notices exit 0, four steps in 116 s, 0 notices
rollback rehearsal, SIGTERM in step 2 exit 143, "Stopped by SIGTERM; …", 0 notices exit 143, same line, 0 notices
rollback rehearsal, its Postgres SIGKILLed in step 2 exit 1, "Step 2 of 4 … failed while exercising", 0 notices exit 1, same, 0 notices

The rehearsal ran with --live origin/main, so it compares main with this branch and never reads production's health endpoint.

IPC. Both hook libraries add the same process.on("message") listener, which acts only on the string "shutdown" (pm2's). Our code opens no IPC channel to a process that loads embedded-postgres. The only channels there are Playwright's workers and Vitest's fork pool, which send structured messages, and the browser and test suites pass.

What Postgres 18.4 to 18.6 changes for us (release notes; 18.5 was never released). It needs no dump or restore within 18, so a worktree's existing .local/dev cluster opens as it is. It's mostly security and crash fixes.

Notes that touch what we use:

  • Parallel GIN index builds now set reltuples correctly. The feedback search tables have GIN indexes. This only affects planner statistics, and dev and test databases are small and fresh.
  • A CREATE now takes a shared lock on the objects it depends on, so a concurrent DROP of the schema it lands in fails one side instead of leaving a broken object.
  • A missed conflict in SERIALIZABLE detection is fixed. Mutations run SERIALIZABLE and retry 40001.

postgres-concurrency, which exercises provisioning, reclamation and those transactions, passes. The release's other headline changes (logical-decoding output-plugin allowlist, pgcrypto ciphers, psql COPY) touch nothing we use.

allowBuilds. 18.6 installs the same eight @embedded-postgres/* platform packages, each with a hydrate-symlinks postinstall that allowBuilds already permits. The new start-up ensureSymlinks check passes on the installed linux-x64 build.

Docs. docs/DEVELOPMENT.md and the patchy-dev-loop skill don't describe the hook workaround, so they don't change. The pnpm-workspace.yaml comment and packed-cli-e2e's import comment now name exit-hook. The other comments about embedded-postgres's process-exiting handlers (dev main.ts, the rollback rehearsal, the browser instances) stay true.

How it was verified

  • The before and after runs in the tables above, on main and on this branch.
  • pnpm verify on Node 24.20.0, on the first push (d144206): format, lint, synth, postgres-concurrency, cli-smoke, install, tier2-smoke and browser (Chromium 187 of 187 and Firefox 10 of 10) passed, with no termination notice anywhere in the output, Playwright's workers included. typecheck failed on the JSON.stringify the old test used. test and test (bun) failed only on that test's frozen-clock timeout. On this head, pnpm test passes 3,615 of 3,615 and pnpm test:bun 3,296 with 3 skipped, again with no notice. The supervisor changes touch only pnpm dev, whose paths ran again above.
  • pnpm format:check, pnpm lint and pnpm typecheck (all 25 tasks, including @patchy/dev's own check of its test files under the base rules): clean on this head.
  • Not run: the live suites and the server image, which needs Docker. CI runs those.

Unchanged and worth knowing, not fixed here.

  • SIGHUP to the dev supervisor stops Postgres but leaves the dev server running, before and after: the hook exits the supervisor before Effect's finalizers stop the server. pnpm dev stop and down send SIGTERM, which doesn't hit this.
  • A rehearsal whose Postgres died ends in Error: kill ESRCH from its own cluster finalizer, before and after.

Small differences the patch leaves, in processes that keep embedded-postgres's signal handlers (the Vitest global setup, HandlerTls.test.ts, the server image smoke):

  • exit-hook forces the exit 5 s after SIGINT or SIGTERM, where async-exit-hook waited 10 s. Their only cleanup there is the cluster stop, which took under 20 ms in the runs above.
  • exit-hook listens for each signal once, so a second Ctrl-C during that shutdown falls to whatever other handler the process has, or to Node's default.
  • SIGBREAK is Windows-only and wasn't exercised by anyone.

Release impact

  • Breaking — requires action from anyone already running this
  • Not breaking — no action required

A dev and test dependency and one dependency patch. No product code, API, schema or CLI change.

  • What does a revert leave behind? Dev clusters that 18.6 started or created. 18.4 opens them, since it's the same major and the same on-disk format.
  • Does the release before it still work with that? Yes. Production doesn't use this package.

Made by Claude Opus 5.5 in T3 Code via Claude Code.

🤖 Generated with Claude Code

@github-actions github-actions Bot added area:ci CI, shared testing infrastructure, development scripts and tooling size:m 100-500 changed lines labels Nov 13, 2026
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Code review (GPT 6.1 Sol, xhigh), four rounds, ending at e51dca1f with no blocker or should-fix open.

Held from round one: the exit-hook patch is needed (as published, process.exit() leaves a running cluster behind, prints a termination notice, and SIGHUP is not hooked); stop() signals Postgres synchronously in every cluster state on Node and Bun; exit codes 0, 1, 5, 130, 143 and 129 are preserved; exit-hook's only dependent is embedded-postgres; the IPC listener matches only the literal "shutdown"; an 18.4 data directory opens under 18.6 and back with its data; versions, patches, allowBuilds and the lockfile agree. embedded-postgres has no option to turn its shutdown hook off, so a narrow patch stays.

Found and fixed:

  • Round one, fixed in 5051f31a. exit-hook's 5-second forced exit could end the dev supervisor at the moment it would SIGKILL a stuck server, leaving children alive; the supervisor now removes the library's SIGINT and SIGTERM handlers and its own scope owns shutdown. The new test polled on a frozen test clock, which is what timed out in CI; it runs on real time. The test could pass without the patch because Effect's spawner signals the child's process group; the probe is spawned with Node's own spawn.
  • Round two, fixed in d4496809. Removing the handlers before start-up left no shutdown path while Postgres was still starting; the library's handlers now stay through start-up and go as the next step once the cluster is up. The test's cleanup was registered too late to survive a timeout.
  • Round three, fixed in e51dca1f. The cleanup read postmaster.pid once, so a timeout before that file existed left Postgres running; the probe now leads its own process group and the cleanup interrupts, then kills, the group.
  • Round four confirmed that fix: with only the patch's async-callback hunk disabled the cluster case fails, and a failing run, a timeout during initialisation, a timeout with the cluster running and an interruption each leave no process, data directory or shared-memory segment.

One nit, partly fixed: the PR body said the cleanup "waits until the group is empty", and it waits a bounded time; the body now says so. The helper's doc comment in scripts/dev/src/postgres.test.ts has the same wording and gets the same correction at this branch's next rebase.

Known and unchanged from main: SIGHUP to the dev supervisor stops Postgres and leaves the dev server running; a Postgres frozen for good during start-up is left behind. Not verified by anyone: SIGBREAK on Windows, and this cleanup on macOS (CI runs the file on Ubuntu only).

allisonmahmood and others added 7 commits November 20, 2026 01:23
embedded-postgres 18.6 ships Postgres 18.6 and moves its shutdown hook
from async-exit-hook, which we patched, to exit-hook 5. exit-hook keeps
a failed run's exit code without help, so the async-exit-hook patch
goes. It differs elsewhere: on process.exit() it prints a termination
notice and never starts the hook, so a running cluster is left behind,
and it no longer stops Postgres on SIGHUP or SIGBREAK. A small patch to
exit-hook restores what async-exit-hook did on those paths, and the
embedded Postgres shutdown test now covers both.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
exit-hook forces a process out five seconds after SIGINT or SIGTERM,
the same five seconds the supervisor gives its server before SIGKILL,
so the hook could end the supervisor with the server still running.
The supervisor now loads embedded-postgres as it starts the cluster and
takes back the library's SIGINT and SIGTERM handlers, as the e2e and
browser harnesses do. runMain turns both into interruption, and the
scope stops the server and Postgres.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…watches the cluster itself

The retry polled on the test clock, which never advances, so a cluster
still shutting down at the first check hung the case until its timeout.
The cluster probe now spawns with node:child_process, since Effect's
spawner signals a failed child's process group and could stop Postgres
in the hook's place, and a pid finalizer cleans up after a failing run.
The child takes its values as arguments rather than JSON in the script.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…up again

Taking the library's SIGINT and SIGTERM handlers back as it loaded left
no way out while Postgres was starting: acquisition can't be
interrupted, and the release that stops the cluster doesn't exist until
it succeeds, so a signal only queued an interruption. The handlers now
stay until the cluster is up, as on main, and go as the next step, so
the scope owns every later phase.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…times out

Its cleanup is registered as soon as it spawns: it SIGKILLs the probe
and the cluster named in the data directory's postmaster.pid, and waits
for both before the directory goes. It still runs after the assertions,
so it can't be what stopped Postgres.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review follow-up. The cleanup read postmaster.pid once, so a case that
timed out after Postgres was spawned but before it wrote that file killed
only the probe and left Postgres running. The probe now leads its own
process group, which initdb and Postgres join, and the finalizer
interrupts the group, so Postgres frees its shared memory, then kills
whatever ignored that.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Acceptance: PASS with notes

Checked 982aab0026574930dafc0cef16ceab09036a2fef (base d2387e59c513891864258e0992dcf752374e6e1c) on team and brightline, by GPT 6.2 Sol in T3 Code.

Done means

  • Dev and test compatibility passed. The pinned pnpm installed the lockfile with its supply-chain policies. On Effect 4.1.4 and Vitest 5.1.0, pnpm test scripts/dev passed 201/201. The shutdown file passed 3/3 in each of five isolated Node runs and 3/3 on Bun. A deliberate assertion failure after importing embedded-postgres exited 1 and printed the assertion error, with no termination notice. The Postgres concurrency suite passed 28/28.

  • Cluster exit behavior passed. A fresh cluster was started for each direct Node 24 probe. Output below excludes the probe's own ready marker. Every cluster stopped, every postmaster.pid disappeared, and no synchronous termination notice appeared.

    Exit Status Output
    Event loop drains, exit code unset 0 Silent
    Event loop drains, exit code set to 1 1 Silent
    process.exit(3), cluster running 3 Silent
    process.exit(3), cluster already stopped 3 Silent
    Uncaught exception 1 The exception stack
    SIGINT 130 Silent
    SIGTERM 143 Silent
    SIGHUP 129 Silent
  • Dev lifecycle passed. pnpm dev up team → down removed the instance. SIGINT and SIGTERM during Postgres startup each ended the supervisor in about 5 seconds while Postgres was paused. After Postgres resumed, cleanup completed and the same state started healthy. On a running instance both signals logged postgres stopped and finished cleanup in under a tenth of a second. With the running server and Postgres both paused, SIGTERM ended the server after its five-second grace period and the supervisor stayed alive to finish Postgres cleanup on resume. Each path left no instance process or stale pid file.

  • Packed CLI cancellation passed. SIGTERM during server startup, with the harness's Postgres already running, returned exit 143 without a termination notice or a leftover process or pid file.

Golden journeys

  • Sign in and machine login passed. Ben got the 401 door, signed in to the requested address, and got the door again after signing out. Ada confirmed the CLI code in Chromium, whoami named the machine, and logout ended its access.
  • Publish a page passed. Ben saw Ada's page content in its frame and found the page on Home. Retire removed the frame. Restore returned HTTP 200 with the original content.
  • Find and open a tool, and use it live, passed. Jordan found Kudos from Home search and opened it. A message he sent appeared in Priya's open frame without navigation.
  • Use a tier 2 tool passed. Jordan moved a sample deal to Discovery and back, and the second viewer's open board reflected both changes. Spend rejected Jordan's attempt to approve his own request. A second viewer approved it, and Jordan saw the update live.
  • Share and unshare passed. Public sharing let a signed-out viewer read the kickoff page and its frame at HTTP 200. Company sharing restored HTTP 401 for a fresh signed-out request.
  • Invite and join passed. Ada invited a persona who joined Acme Co and reached Home. Ada also revoked a pending invitation and deactivated and reactivated the member.

Rollback answers: They match the diff and the observed behavior. The same dev cluster opened on 18.4 → 18.6 → 18.4 → 18.6. Ada published a page on each version, and Ben could read both pages after rollback and after upgrading again.

Not run

  • Windows SIGBREAK and live Clerk. The Chromium journeys used dev personas and recorded invitations.

Notes

  • At posting, five required checks had passed and fourteen were pending on this head. The required browser-firefox job was queued. CI run

@allisonmahmood
allisonmahmood merged commit f30c8e6 into main Nov 20, 2026
29 checks passed
@allisonmahmood
allisonmahmood deleted the deps/embedded-postgres branch November 20, 2026 02:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ci CI, shared testing infrastructure, development scripts and tooling size:m 100-500 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant