Skip to content

SIGTERM during sync corrupts pglite (negative postmaster.pid, ensureSchema aborts) #127

@moekatib

Description

@moekatib

Summary

Killing a long-running sync run (SIGTERM) while PGlite is mid-transaction leaves the embedded Postgres in an unrecoverable state: postmaster.pid contains a negative PID, and on next invocation mem doctor reports:

backend opens and applies schema  ✗  Aborted()

No automatic recovery — user has to delete the pglite directory or hand-edit postmaster.pid to get back to a working state. Any unflushed data is lost regardless.

Repro

  1. one sync run fathom --full-refresh (a profile with enrich so the run is slow)
  2. kill -TERM <pid> mid-run (Ctrl-C is trapped by runner.ts signalCleanup → graceful; a real SIGTERM from a process manager is not).
  3. Inspect ~/.one/mem/postmaster.pid — negative PID.
  4. one --agent mem doctorAborted() on ensureSchema step.

Root cause (hypothesis)

PGlite's WASM postmaster doesn't fully flush WAL/shm before the signal handler terminates the worker. The negative PID suggests the file was written with an incomplete value during teardown. @electric-sql/pglite doesn't expose a graceful-shutdown hook we currently call in signalCleanup.

Expected

At minimum: detect corrupt-state (negative PID, failed schema apply) on startup and offer a safe recovery path — either reset the pglite dir (with confirmation) or point at a separate backup. Ideally: call a pglite graceful close before process.exit in signalCleanup.

Notes

  • Not blocking. Most users don't SIGTERM a sync.
  • Separate from PR feat: unified memory (v1.42.0) #125 (which introduced SIGINT/SIGTERM handling for sync state/lock cleanup — the PGlite layer needs its own graceful close).
  • Workaround: rm -rf ~/.one/mem/postmaster.pid (lose the db) or start fresh with rm -rf ~/.one/mem (lose all memories).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions