A local memory daemon (embedded Postgres plus a pinned Python build) reported itself healthy for
A local memory daemon (embedded Postgres plus a pinned Python build) reported itself healthy for three weeks while storing nothing. Every symptom a caller could observe looked like success:
GET /health → {"status":"healthy","database":"connected"}retain_oklast_memory_write_at frozen at an old date, document and fact counts constantasyncpg.exceptions.UndefinedTableError: relation "public.document_attachments" does not exist
ERROR - hindsight_api.engine.memory_engine - Task execution failed: batch_retain, error: UndefinedTableError
WARNING - hindsight_api.worker.poller - Task <uuid> scheduled for retry at ...The user-visible effect was "cross-session memory stopped working", with no error anywhere the caller could see.
Schema drift between the database and the application build, in the direction that fails silently:
hindsight_api 0.10.1) ran once during an auto-update window and applied alembic revision a7c2e9f41b60, which re-keyed attachments and dropped document_attachments.0.10.0 build (the newer one would not start on this machine). The database, however, was already migrated forward — and schema only moves forward.Database is at a newer migration revision than this code version knows about. This is expected during rolling deployments. Skipping migrations. Error: Can't locate revision identified by 'a7c2e9f41b60'fact_storage.sync_document_attachments(), which selects from the dropped table — so every document write dies at the same statement./health tests connectivity, not writability, so it stays green forever.The generalizable shape is a service that (a) is pinned to a build older than its database and (b) acknowledges writes before they are durable. Both conditions are common on their own; together they turn a hard failure into a silent one. Nothing in the request path is lying — the request really was accepted. The lie is in reading "accepted" as "stored".
Put the schema and the code back on one version line. Here that meant reversing the single revision the running build cannot see.
SELECT version_num FROM alembic_version; -- e.g. a7c2e9f41b60Compare that id against the revisions present in the installed build's alembic/versions/. If the database's id is absent there, the database is ahead of the code.
pg_dump -Fc -h localhost -p 5432 -U <user> -d <db> -f pre-downgrade.dumpdowngrade()Do not hand-invent DDL. The revision that was applied has a downgrade() that states exactly what its upgrade() did; reproduce that inverse in SQL, in one transaction with ON_ERROR_STOP so a partial downgrade cannot be committed:
BEGIN;
-- recreate document_attachments (PK (bank_id, document_id, attachment_hash),
-- FK to documents(id, bank_id) ON DELETE CASCADE) as that revision's downgrade() defines it
-- drop the columns the newer revision added to attachments
-- restore PRIMARY KEY (bank_id, attachment_hash) and the unique constraint on short_id
UPDATE alembic_version SET version_num = '<revision-head-the-running-build-knows>';
COMMIT;Restart the daemon so no session keeps a prepared statement against the old shape, then do one synchronous write (async=false) and read the server's own last-write timestamp — not the client's return code.
The durable rule: never leave the database ahead of the code. Either run a build that contains that revision, or reverse the revision back to the running build's head. Pin the migration state and the binary together; pinning only the binary is what produced this outage.
UndefinedTableError and the retry loop drains: previously failing operations reach status completed./health. A connectivity probe cannot fail for this class of bug.devops; the failure is an operational version-alignment issue rather than an application bug in either build.