Repository navigation
Under Postgres, knowledge.inspect counts the ingestion jobs ClickHouse holds at an older version - #466
Merged
Conversation
zlareb1
force-pushed
the
feat/knowledge-inspect-pg-jobs
branch
from
November 10, 2026 07:17
ce5158c to
d44cf76
Compare
…e holds at an older version knowledge.inspect's ingestion sections and listed jobs read loom.knowledge_ingestions, the best-effort projection of loom.knowledge_jobs. The report now compares the versions of up to 1,000 of the namespace's open jobs and its 1,000 most recently saved non-pending ones (each read on its partial index) with ClickHouse's, and names in `skipped` the jobs ClickHouse holds older or not at all (`ingestions.projection: ...`), a bounded line when a read finds more than its page, and a not-compared line when the comparison failed. The dashboard notes the count and not-compared lines. Refs #160 Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
zlareb1
force-pushed
the
feat/knowledge-inspect-pg-jobs
branch
from
November 10, 2026 07:47
d44cf76 to
0eb860f
Compare
This was referenced Nov 10, 2026
Merged
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.
Related: #160
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, knowledge.inspect says how many ingestion jobs ClickHouse holds at an older version than Postgres, so the job counts and listed jobs are not read as current when they lag.
Why
Under the Postgres authority, ingestion jobs live in loom.knowledge_jobs. loom.knowledge_ingestions in ClickHouse holds a best-effort copy of each saved version, and the next save, or the next offer of an ended job, repairs a copy that did not land. knowledge.inspect's ingestion sections (the counts by state, the sources without a document, each listed document's jobs) read that copy. Until now nothing told the reader that a job might be at an older state, for example a job shown pending that Postgres already holds as failed. The document sections already say what ClickHouse lacks (
documents.projection,listed.heads), and the job sections now do the same.Scope and risk
ingest_jobs.unprojectedreads from Postgres (pg_jobs.versions) the versions of up to 1,000 of the namespace's open jobs and its 1,000 most recently saved non-pending ones (a processing job can come from both and counts once). Each statement takes the predicate and order of the partial index Under Postgres, knowledge ingestion jobs live in loom.knowledge_jobs, each save fenced by its run's token #447 made for it (knowledge_jobs_open,knowledge_jobs_served), so its LIMIT is an index scan within the namespace, and asks one row more, to learn whether there are more. It then reads ClickHouse's versions of those ids (ingestions.versions: FINAL,ingestion_id IN {ids:Array(UUID)}, in the chunksch_params.chunkscuts to fit one form field, so 2,000 ids go in two statements) and counts the jobs ClickHouse holds older or not at all. The ids are sorted in the order ClickHouse keeps a UUID key (its last 8 bytes, then its first 8), so each chunk reads one stretch of the namespace's granules. The read uses the same default consistency as the job sections it checks, notselect_sequential_consistency. On a single server or a replicated cluster, where each Loom process reads one replica, the later sections never trail it, so a lag can only overcount, which "not ... yet" allows. Where reads may reach another replica, a section can still show a job this read found current. When neither read finds more than its page, every live job is compared. When either does, the bounded line says the comparison stopped short.EXPLAIN (ANALYZE, BUFFERS)on a local Postgres 16 holding a 200,000-job namespace, a 20,000-job namespace saved 25 days ago, and 500 small ones. At the shipped page (LIMIT 1001), a singleORDER BY updated_atover all live jobs, which no full index serves, walked the deployment-wideupdated_atindex for the 20,000-job namespace: 200,021 rows removed by filter, 7,245 buffers, 35 ms. The newest-saved read onknowledge_jobs_servedtook 71 buffers (0.4 ms) there. The generic plans Postgres can switch to for asyncpg's prepared statements (plan_cache_mode = force_generic_plan,PREPARE...EXPLAIN (ANALYZE, BUFFERS) EXECUTE) stay on the same indexes: 258 to 275 buffers for the open read and 54 to 71 for the saved read, each under 1 ms. The open-jobs read in the index's order usedknowledge_jobs_openin every shape measured, including 1,001 open jobs at the end of a 306,000-row table behind 50 other namespaces (1,025 buffers, 3.8 ms); the newest-saved read for one of those busy namespaces took 1,006 buffers (2.6 ms).system.query_logon a local ClickHouse 26.10:FINALagainstmax(version) ... GROUP BY ingestion_id, measured with 100-id batches over 2,000 jobs at two versions in one namespace beside 200,000 jobs in 100 others: both read 42,048 rows (1.04 MiB), andFINALtook 113 ms in total against 143 ms, so theFINALread stays.ingestions.projection: <n> ingestion job(s) whose latest state ClickHouse does not hold yet; ...toskippedwhen any are behind. When either read finds more than its page, it adds a second line saying the comparison was bounded. A comparison that fails addsingestions.projection: <reason>: the jobs were not compared ..., withPOSTGRES_UNAVAILABLEor the exception's name as the reason. A Postgres that does not answer goes through the report's existing single outage line, so the later listing check and the memory wait do not run against it. When Postgres was already down before the comparison, the same not-compared line names it under the section's own name. The outage line itself keeps naming the document and memory sections only: the not-compared line covers the ingestion sections whenever their jobs went uncompared. Theskippedfield's description (its first sentence, which the operations reference shows) now names the sections read in part, and under Postgres what a read section may miss, and docs/reference/operations/knowledge.md is regenerated. The features page links the two storage-authority sections that name those lines.ingestions.projectionline but the bounded one (so not for an outage found later by the listing check), the ingestion section says "Some jobs may be missing or show an older state" when the job counts were read, and the listing says "Some listed jobs may be missing or show an older state" when the listed jobs were read. The notes are shown in addition to the Skipped list, which still prints every line.Compatibility, rollout and rollback
older_open, they are not in the analyzer corpus; the integration test runs them against a server.skippedcan carry newingestions.projection: ...lines.Tests
unprojectedcounts older and missing copies; the two Postgres statements (each index's predicate, the live filter, newest first for the saved read, one row past the page, a job found by both counted once at the later read's version); the ClickHouse read's statement, its key order and its chunks within one form field; the key order, its tie-break included, against ids as ClickHouse returned them and against clickhouse-local'sORDER BYover 300 random UUIDs plus three that share their last 8 bytes; the dashboard's prefixes against the server's names (the UUID binding against a real server is covered by the integration test); the not-compared line when Postgres is down before or at the comparison or the comparison fails otherwise, and none when the outage comes after it; an unstorable namespace key makes no Postgres read; a ClickHouse outage at the comparison fails the call. A gate bundle of analyzer corpus, package contracts, statement digests, knowledge ingest and delivery, pg authority and agent instructions: 937 passed, 2 skipped.skipped, while ClickHouse still shows it pending. test_knowledge_pg_heads.py and test_knowledge_pg_jobs.py: 50 passed.-k "knowledge or inspect"quick pass: 132 passed, 29 skipped.How the measurements were made
Postgres (a local postgres:16 primary with Loom's migrations), rows inserted directly:
ClickHouse (a local server with Loom's migrations): 2,000 jobs at version 1 and again at version 2 in namespace
busy, plus 200,000 jobs in 100 other namespaces. Theningestions.versions("benchorg", "busy", ids)was called underset_query_tag("measure-final"), followed bySYSTEM FLUSH LOGSand: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 design follows the document sections' existing projection lines; checked against the job store's projection and repair rules.
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.main(none).docs/describe the system as it now is.🤖 Generated with Claude Code