Skip to content

knowledge.inspect reports each source's ingestion jobs and what its extraction kept - #254

Merged
zlareb1 merged 6 commits into
mainfrom
feat/i160-doc-ingest-state
Nov 4, 2026
Merged

zlareb1 merged 6 commits into
mainfrom
feat/i160-doc-ingest-state

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

Related: #160

Changelog category (leave one):

  • New Feature

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):

knowledge.inspect now reports a namespace's knowledge.ingest jobs and what each extraction kept: jobs by state, sources with a job and no live document (a first ingest, or one after a delete, queued or failed), each listed document's coverage and jobs (with the open job's ingestion_id for knowledge.ingest_status), and findings that tell a backlog, an unavailable extractor, missing access, a rejected file, a job that failed on the server's side and an extraction that lost structure apart.

Why

knowledge.inspect said which documents search serves, but not why a document is missing or stale. A source can wait in the ingest queue, fail because no extractor takes its format or the extractor is down, fail on access (its original is gone, or the extractor refuses the server's token), fail on the file itself, or publish with part of its structure lost. Each has a different fix, and only the first one fixes itself. A caller also had no way to find a source's open job unless it had started the ingest itself, because knowledge.ingest_status takes a job id and nothing listed one.

Scope and risk

  • knowledge.inspect gains four reads: extraction_health over the live documents' coverage, ingestion_health, source_jobs for the listed documents, and sources_without_document. Each of the three job reads is a per-source GROUP BY over loom.knowledge_ingestions FINAL, joined to the namespace's document rows (only the listed ones for source_jobs). The job reads also check the namespace's loom.knowledge_ingest_cancels rows, so a pending job with a cancel requested reads cancelled in the counts, the backlog, open_ingestion_id and the job's state. That is the state knowledge.ingest_status answers, though the row stays pending until a worker takes it. The job's other fields, updated_at among them, are its row's, as knowledge.ingest_status serves them. Each one filters on (org, namespace), the sort-key prefix, binds every value as a parameter, caps its samples at 100 and its lost-capability list at the cap + 1, and is guarded into skipped like the report's other sections. It uses FINAL only on the two ReplacingMergeTree tables.
  • No document text and no job error message is returned. A job's message is read only inside the statement, to classify a retried outage (extractor unreachable vs. credential refused vs. a store or embedder outage). The coverage's failed units are counted, never named, because a failed unit can be one of the source's own TOML keys.
  • A source is judged by its current job: its oldest open job when one is open (the job the worker runs next, or is running), otherwise its newest. A pending job waiting to retry because the extractor is down counts as extractor_unavailable, not as backlog. A retried job that a worker is running again stays processing and keeps the last attempt's retrying code and message until the run ends, so it counts as backlog, whatever stopped the last attempt. A job that published with allow_partial counts as extraction_incomplete, not as rejected content.
  • A source whose jobs a later write replaced is judged by none. Text writes (knowledge.add, knowledge.upsert, a source sync) and deletes write no job row, so a failed job could otherwise keep a source in a finding for the 30 days its row is kept, after a text write fixed it or a delete removed it. A metadata edit without reindex keeps the row's ingested_at, so it replaces nothing and the failure still counts. A reindex rewrites the document, so it counts as a write. A source counts as replaced when none of its jobs is open and its document row was written (ingested_at) or deleted (superseded_at) after its newest job ended. Both columns count whole seconds, so a write stored in the second the job ended is not told apart from one before it and does not replace the job. Replaced sources are counted in ingestions.replaced and flagged on listed[].jobs.replaced. They are left out of every finding and of without_document.
  • Failure classes: retrying means an open job only. invalid_artifact (the extractor answered an artifact that breaks the contract) is extractor_unavailable, not bad content: the fix is a working extractor, not a different file. A failed job whose outage used up knowledge_ingest_max_attempts (a store or embedder outage, or runs cut off before they finished) is retries_exhausted. Together with internal, it makes up the ingest_failed_on_server finding. resource_limit stays in bad content. It has two sources: the extractor passed its own memory or output limit, or its artifact was over LOOM_DOCUMENT_EXTRACTOR_MAX_ARTIFACT_BYTES. The finding's remedy names the limit to raise for each: the extractor's LOOM_EXTRACTOR_MEMORY_MB / LOOM_EXTRACTOR_MAX_ARTIFACT_BYTES, the server's LOOM_DOCUMENT_EXTRACTOR_MAX_ARTIFACT_BYTES, or LOOM_KNOWLEDGE_INGEST_MAX_CHUNKS. A revision_conflict (a later write landed first, or expected_revision did not hold) has no finding by design: it counts in ingestions.failed, and the revision that landed is what search serves. The docs say so.
  • Kinds: ingest_backlog, extractor_unavailable, ingest_missing_access and ingest_failed_on_server are system_state. ingest_content_rejected is contract_violation, because the extractor refused the file against its format. extraction_incomplete is usage_heuristic, because another extractor may keep what this one lost.
  • Read scope: job rows are the namespace's under any scope, the same as documents. knowledge.ingest_status already serves any job of the namespace to its viewers by id, and a job's user_id records authorship (the knowledge. group's reason in the read-scope classification). The op stays VIEWER, read-only and in SCOPED_OPS, with its comment updated.
  • worker_enabled and extractor_configured come from this server's settings. Another replica may be configured differently, so the job rows remain the evidence. Nothing calls an extractor. Parsing LOOM_DOCUMENT_EXTRACTORS_JSON raises on a value that is not a JSON object of strings, so extractor_configured is read as its own guarded section: on a malformed value it is null and named in skipped, and the rest of the report is still read.
  • The classifier relies on the messages server/knowledge/app/extractors.py raises. A unit test reads that module and checks that every ExtractorUnavailable / FormatUnavailable message matches the classifier's prefix, so a reworded message fails the test.

Compatibility, rollout and rollback

  • Wire: knowledge.inspect output gains ingestions, extraction and ingest_findings. listed[] gains extraction and jobs. Nothing is removed or renamed. The op is still experimental.
  • Operator steps: none. There are no new settings, migrations or tables.
  • Rollback: reverting removes the fields. Nothing is written.

Tests

  • Unit tests on fakes (tests/unit/test_knowledge_inspect.py) cover job totals with the server's settings, each ingest finding with its kind, samples, aligned job ids and remedy, clean info findings, lost-capability totals and their cap, a listed document's extraction and jobs (current vs. latest, stalled, ended, next attempt), a skip path for each of the four new reads, and the classifier against the extractor client's messages.

  • clickhouse-local SQL tests (tests/unit/test_knowledge_inspect_ingest_sql.py) run each new statement on the real table definitions. One source sits in each state: queued, published with a stalled run and a later job queued behind it, format unavailable, extractor unreachable and retrying, token refused, original gone, encoding refused, revision conflict, store outage retried, and cancelled. They also cover an outage that used up its attempts (retries_exhausted, "earlier runs stopped before they finished"), an internal failure, a retried job running again with retrying and the extractor's message, a pending job with a cancel row, another namespace's cancel of the same id, a failed job followed by a newer document row and one followed by a delete (both replaced, in no finding), a failed job that ended after its document was written (not replaced), a failed job followed by a metadata edit (not replaced, still in its finding), a failed file ingest over a text document followed by a reindex (replaced), a job that failed at S.400 with its document row stored at second S (not replaced; the case fails if the comparison is made non-strict), an invalid_artifact failure (extractor_unavailable), a job row written twice and folded by FINAL, another namespace's job, and a coverage without complete.

  • Integration (tests/integration/test_knowledge_inspect_ingest.py) uses knowledge.upload, knowledge.ingest and a worker pass in the test process, against the reference extractor (python -m loom_extractor):

    • backlog: a job queued and not yet run, beside a job cancelled while pending, which counts as cancelled and not as backlog;
    • extractor unavailable: a PDF no extractor declares (failed format_unavailable), another such PDF that a knowledge.add of text then replaced (in no finding, counted in ingestions.replaced), and a SQL file with the extractor URL pointed at a closed port (pending, retrying);
    • missing access: an original removed before its job ran (original_gone), and the extractor refusing a wrong token (retries_exhausted after one attempt);
    • bad content: a TOML file the extractor cannot parse, ingested over a published revision (incomplete_extraction; the earlier revision stays live);
    • lost structure: a SQL file with a broken statement, published with allow_partial, with sql_structure lost.

    The test retries a call the per-namespace rate limit refuses. The second test skips when no extractor is configured (LOOM_DOCUMENT_EXTRACTOR_URL unset). The first needs none. The first test cancels and drains the jobs it leaves open, so a later test's single worker pass does not pick them up.

  • make format, make lint and make typecheck pass and print success.

  • Suites: test_knowledge_inspect*.py, test_tunable_constants.py, test_namespace_audit.py, test_knowledge_ingest.py, test_package_contracts.py, test_op_reach_census.py, test_public_copy.py, test_doc_links.py, test_sdk_surface_contract.py, test_mcp_listing_budget.py, test_docs_reference.py, test_op_budgets.py, test_read_scope.py and the SDK generation checks all pass (767 tests). A malformed LOOM_DOCUMENT_EXTRACTORS_JSON skips only extractor_configured; a unit test covers it. tests/analyzer passes, and python -m tests.analyzer.corpus --check reports 0 rejected against a migrated ClickHouse.

  • Cost: measured on a namespace of 2,000 documents with 8,000 chunks, 1,000 extraction coverages, 2,500 job rows across 1,300 sources and 100 cancel rows, read from system.query_log. Each figure is the same over three runs.

    Reads Statements read_rows read_bytes peak memory server ms (sum)
    job reads (new, with the cancels and documents) 3 12,952 653 KiB 13.6 MiB 97–100
    extraction coverage (new) 1 2,000 140 KiB 4.7 MiB 8
    whole report, audit included 33–36 49,083 6.5 MiB 13.6 MiB 274–280

    The whole call took 0.33–0.34 s wall time, inside the op's 4,000 ms budget, which stays as it is. Only its comment changes, to count the new reads. Job rows expire after 30 days, which bounds the job reads.

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 author checks the statements against clickhouse-local and a live ClickHouse, the failure-class mapping against ingest_run.py and extractors.py, and each state end to end with the reference extractor.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • make format-check, make lint, make typecheck and make test-unit pass; the integration suite passes if server behaviour changed. (Format, lint, typecheck and the affected suites pass; the full unit suite is still to run.)
  • Generated files are regenerated in this PR, not by hand: the SDK op tables, docs/reference/configuration.md and the docs/reference/ tables (python scripts/codegen/docs_reference.py), the reach manifest, schemas/schema.sql (make schema-dump) and the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.py).
  • A new migration is additive and numbered after the latest on main; no merged migration is edited.
  • A behaviour change to any file a plugin ships (hooks/, lib/, bin/, skills/, .mcp.json, the Codex plugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version.
  • The frontend builds (npm --prefix frontend run build) and its tests pass, if frontend/ changed.
  • Docs under docs/ describe the system as it now is, and this description names any operator steps and wire changes.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers; the history goes in this description (tests/unit/test_public_copy.py).
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.

🤖 Generated with Claude Code

…xtraction kept

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 force-pushed the feat/i160-doc-ingest-state branch from 91d667a to 3b0eb17 Compare November 4, 2026 06:52
zlareb1 and others added 5 commits November 4, 2026 07:00
…ite in the job's last second

resource_limit is the extractor passing its own memory or output limit, or its artifact
over LOOM_DOCUMENT_EXTRACTOR_MAX_ARTIFACT_BYTES; the remedy names the limit to raise for
each. A SQL case stores a document row at second S beside a job that failed at S.400 and
checks the job is not replaced.

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]>
@zlareb1
zlareb1 merged commit f700c46 into main Nov 4, 2026
21 of 22 checks passed
@zlareb1
zlareb1 deleted the feat/i160-doc-ingest-state branch November 4, 2026 07:29
@pufit pufit mentioned this pull request Nov 4, 2026
9 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant