code · Nov 28, 2026

Crash-safe approval in PostgreSQL

How to make approval and indexing crash-safe in PostgreSQL to prevent invisible entries or duplicate points after a restart?

Part of PostgreSQL constraints, triggers and vector search

Problem: the approval commits, then the index write fails or the process dies. The entry stays invisible, or a retry duplicates the point. Fix: store the approval and an open index job in one transaction; a restarted worker finishes the job. ```sql BEGIN; UPDATE entry_revisions SET review_state = 'approved' WHERE entry_id = $1 AND id = $2 AND review_state = 'pending' RETURNING id; -- must return exactly the wanted id, else ROLLBACK UPDATE entries SET approved_revision_id = $2 WHERE id = $1; INSERT INTO index_jobs (entry_id, revision_id) VALUES ($1, $2); COMMIT; ``` Matching on the revision id, not just the entry, matters: with a revoked target and a pending sibling revision, a filter on `entry_id` alone releases the wrong revision and then points the entry at the revoked one. Worker: claim one job with `WHERE done_at IS NULL ORDER BY created_at LIMIT 1 FOR UPDATE SKIP LOCKED`, set `claimed_at`/`claimed_by` in that transaction, commit the claim, then upsert the point under the entry id with `?wait=true` and require `status=completed`. Mark the job done with a compare-and-set on `claimed_by` only after the write is confirmed. This example assumes at most one active worker. An unfinished job remains eligible immediately after the claim commits. Replaying the same upsert under the stable point ID replaces that point.

Query directly via MCP

This blueprint is also machine-readable: Markdown. Create an API key without an account:

curl -sS -X POST https://solvedlist.com/api/v1/keys \
  -H 'Content-Type: application/json' -d '{"note":"agent"}'
POST https://solvedlist.com/mcp
Authorization: Bearer ***
Content-Type: application/json

{"jsonrpc":"2.0","id":1,"method":"tools/call",
 "params":{"name":"solvedlist_lookup","arguments":{"question":"…"}}}

More: /llms.txt · /openapi.json