Repository navigation
Under Postgres, the publication pipeline reports its search wait, projection lag, backlog and inserts - #469
Merged
Merged
Conversation
zlareb1
force-pushed
the
feat/pg-pipeline-metrics
branch
3 times, most recently
from
November 10, 2026 14:25
2497426 to
2593c50
Compare
…jection lag, backlog and inserts Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…ounts Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…s say what they measure, and health answers each reading's age Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
… the instruments, and the deadline alert says a report reads on Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…ode test, integration cases count their own rows Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…fence out the writer's flush, precise docs Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
… which tables make a part each, settings named by tests, outbox case held from a running worker Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
… starts parked, SLO and insert alert that can fire, error-code claim narrowed Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…pped, outbox case due only in a rolled-back transaction Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…m settings, the lock helper back to one job Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…m (the workers child by default); health always reads its own, cached Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…h max, census rename reverted, health backlog simpler Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
… target everywhere, a long pass named as a gap, error-code comment Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
… starts Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
zlareb1
force-pushed
the
feat/pg-pipeline-metrics
branch
from
November 10, 2026 15:24
2593c50 to
c24e436
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changelog category (leave one):
Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):
Under the Postgres authority, Loom reports how long a search waits for earlier writes to reach ClickHouse, how long a revision takes to become searchable, how many deliveries are owed or parked, and how many ClickHouse inserts its publishers make.
GET /v1/health?include=postgresgains the same backlog, and the monitoring guide states the pipeline's SLOs and alerts.Why
Under the Postgres authority a write answers at its commit and becomes searchable once its memory row and search document are in ClickHouse. An operator had no signal for that gap: neither how long a search waited at the barrier (
pg_validation.admit), nor how far behind the delivery worker was, nor whether a delivery ClickHouse kept refusing had parked. The request counter also counted a 503PROJECTION_BEHINDlike any other failure, with no code to tell it from an outage.What changes
server/observability/pg_pipeline.pyholds the instruments:loom.pg.search_wait_ms: what a read paid at the barrier when ClickHouse was behind, byloom.operation(the op the request invoked),outcome(passed, ordeadlinewhen it reached its deadline,LOOM_PG_PROJECTION_WAIT_MSor what a re-entrant pass had left: the op answers 503PROJECTION_BEHIND, a report that may skip the projection reads on) and traffic class. A read that found nothing behind records nothing, so the histogram is the wait users actually see.loom.pg.projection_lag_ms: from a revision's commit transaction's start to its delivery clearing its last search target (the document landed, or a redelivery settled a revision no longer served unsent), measured on Postgres's clock as the delivery clears and recorded once that commits (pg_memory.complete), bypath(the writer's own flush, or a redelivery).loom.pg.backlog(source,state) andloom.pg.oldest_pending_age_s(source): one reading per delivery pass for memory, the audit outbox and knowledge, taken first in the pass by the worker that owns the source. The process that runs the delivery workers exports them (the workers child by default, else the lease holder); a process that runs none has no reading, and one older than two export periods is dropped;loom.pg.backlog_reading_age_ssays how old each is.loom.ch.insertsandloom.ch.insert_rows(table): the memory write path's inserts of memory rows and search documents and the audit writers' inserts, under either authority. Memory rows and search documents are committed inserts, a part each; audit rows are batched by default.loom.requestscarriesloom.error_code(empty on success), on the counter only: the refusal's own code where it carries one (HTTP reads it from the detail, MCP from the answer); a codeless refusal isHANDLER_HTTP_ERRORon HTTP and its status's code on MCP; so the duration histogram's series still divide by the counter's.GET /v1/health?include=postgresaddspostgres.backlog: per source the pending and parked counts up to the cap,cappedpast it, the oldest one's age andreading_age_s. Each process reads its own, keptLOOM_PG_BACKLOG_HEALTH_CACHE_SECONDS. The block'sparked_*fields keep counting in full.LOOM_PG_BACKLOG_COUNT_CAP(10000), the most deliveries one reading counts per source; past it the reading stops and reportscapped, andLOOM_PG_BACKLOG_HEALTH_CACHE_SECONDS(10).docs/operations/monitoring.mdgains "Pipeline SLOs" (targets, signals, why readiness does not use them) and the alerts;docs/features/observability/telemetry.mdlists the instruments.Scope and risk
count(*)reads (the pending and the parked counts eachLIMITone past the cap, socappedmeans more than the cap) on the deliveries tables' partial indexes, once per delivery pass and at most once per cache period per replica for health.committed_atin the statement that already locks the cleared deliveries; nothing else is added to a write or a search.tests/unit/test_pg_durable_reads.pyclassifies the delivery workers' backlog counts (they feed a gauge and send nothing).Compatibility, rollout and rollback
postgres.backlogis added toGET /v1/health?include=postgres;loom.requestsgains theloom.error_codeattribute on failures. Nothing removed.Tests
tests/unit/test_pg_pipeline_metrics.py: a backlog reading dropped after two export periods; projection lag recorded only when a revision's last search target lands, by path, and only once the completion commits; the barrier records a wait only when something was behind, with its outcome and the op; the error code on the counter alone; health reading the backlog itself once per cache period.More unit cases: the gauges export a process's fresh readings only, nothing where it took none or its last went stale; a backlog read that fails is logged and not raised;
cappedonly past the cap; the HTTP failure counter takes a coded HTTPException's own code (tests/unit/test_transport_internal_error_logging.py); an MCP failure counts under the code it answers (a refusal's, a named 5xx's, orINTERNAL_ERROR).tests/integration/test_pg_pipeline_metrics.py(added to the Postgres authority job) runs the three backlog reads against the real queues. Each memory and knowledge case takes its delivery over (advancinglease_token, so the write's own flush cannot clear it), backdates it so the oldest age must reach it, checks the cap, and counts its parked row by the drop when the row is removed; the outbox case starts its row parked and makes it due only inside a transaction it rolls back, the backlog read in it, so no running worker sees it.tests/unit/test_transport_internal_error_logging.pynow expectserror_codeamong a failed op's attributes.Local runs:
make format-check,make lintand mypy on the changed files pass; the unit files that touch the changed modules pass (6988 tests; one webhook deadline test failed once under load and passes alone 3 of 3, unrelated). The full suite runs in CI.Latency, a small local before/after (100 sequential calls each, two runs, Postgres 16 with a synchronous standby, the local embedder; not a benchmark):
memory.setp50memory.searchp50Within run-to-run noise.
AI assistance in the code (leave one; writing this description with AI is fine):
AI-generated (an agent wrote most of the diff): Claude Code. The label sets, the read bounds and where the readings are taken were checked against the code paths they observe.
I can explain every line of this diff and how it interacts with the rest of Loom.
Checklist
make format-check,make lint,make typecheckandmake test-unitpass; the integration suite passes if server behaviour changed. Locally: format, lint, mypy on the changed files and the affected unit files; the full suites run in CI.docs/reference/configuration.md,loom.example.yaml,schemas/loom-settings.schema.json, the settings defaults snapshot.main; no merged migration is edited: no migration.frontend/changed: not changed.docs/describe the system as it now is, and this description names any operator steps and wire changes.git commit -s).🤖 Generated with Claude Code