Skip to content

Knowledge reads draw from their own rate bucket, and the extractor-less ingest tests configure no extractor - #291

Merged
zlareb1 merged 14 commits into
mainfrom
fix/main-red-integration
Nov 6, 2026
Merged

zlareb1 merged 14 commits into
mainfrom
fix/main-red-integration

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in a release)

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

Most read-only knowledge ops (knowledge.get, list, ingest_status, formats, source.list, ...) draw from their own knowledge.read rate bucket (50 burst, 10 per second), so a page of reads or an agent polling an ingest no longer spends the budget knowledge.add needs, and is no longer refused after ten calls.

Why

The integration job on main fails three tests.

test_cross_principal_leakage::test_every_read_op_against_a_collection_leaks_nothing: 429 on knowledge ops at @me. op_class_for files every knowledge.* op without an override under knowledge.add, a write-shaped bucket of 10 with 2 per second. The test sends every read op to each namespace. At @me, the caller's own namespace, authorization passes and the limiter is reached. There, 15 of 17 consecutive calls are knowledge ops in that bucket. The calls past its burst are refused whenever those calls take under about 1.5 seconds, as they do on the CI runner. Which calls those are depends on pace: CI has refused source.list with source.inspect, and dataset_approve with source.list. A slower machine refills the bucket in time: on main's limiter the test passed locally. The recent knowledge ops (formats, dataset_get, dataset_approve, synthesize) pushed the count past the burst. The tests are not the only callers hit by this: in test_namespace_tune_documents's log, a knowledge.ingest_status poll is refused right after uploads. The fix is a knowledge.read class for nine read-only knowledge ops, sized like default because none of them embeds. knowledge.inspect is read-only too but stays in knowledge.add. It builds a report over the whole namespace (documents, chunks, ingestions, extraction, decisions and memory findings, with a p99 budget of 4 s), so the tight bucket bounds it, as it does on main. After the fix, 6 knowledge calls at @me in the leakage loop draw on knowledge.add, within its burst of 10. knowledge.search and knowledge.query keep their own buckets, and every other knowledge op stays in knowledge.add, knowledge.synthesize (audited) and knowledge.dedup_list (admin role) included, as they are not read_only. The set is named, as _EXACT_KEY_READS is. A unit test walks the registry, so a new read-only knowledge op that the set leaves out fails there instead of drawing on the write bucket.

test_namespace_tune_documents::test_tune_cuts_the_documents_again_and_writes_nothing and test_knowledge_inspect_ingest::test_backlog_a_missing_extractor_and_missing_access_are_kept_apart: format_mismatch where format_unavailable was expected. Both tests use a Parquet upload to stand for a format no extractor serves. The reference extractor now reads Parquet, and the integration job runs it. So the job reached the extractor, which refused the bytes as not Parquet. The tests now run those jobs in their own process with no extractor configured. That is how the inspect test already models a stopped extractor, and it gives format_unavailable on any deployment. Tune judges a failed source against the server's own extractors. Its test therefore reads knowledge.formats and expects the message for that case: "the service they go to declares it now: upload each original again" when the server's extractor declares Parquet, else "no configured extractor declares parquet". The unit tests in tests/unit/test_namespace_tune_documents.py keep covering the no-extractor branch.

Scope and risk

  • server/core/ratelimit.py: one new class, knowledge.read, and a named set of nine ops.
  • docs/operations/monitoring.md, docs/architecture/failure-and-recovery.md, docs/architecture/security.md and docs/reference/http-api.md: each bucket table now names the new class. The tables that lacked them also gain the existing memory.import and knowledge.query rows.
  • dev/onboard_tenant.py raises knowledge.read with the other anchor classes. Without that, an onboarded tenant's knowledge reads would lose the raised cap they had under knowledge.add. knowledge.query stays out of that list, as it already was on main. It is a scan of up to four datasets with its own bucket (20 / 3 per second), and raising its cap is a sizing decision outside this fix.
  • Two integration tests change their setup.

No write op changes bucket, and memory, code and the other classes are untouched. The limit on the reads is looser than before: a burst of 50 instead of 10. That is the same as default, and none of these reads calls the embedder, which is what the add bucket's size protects.

Compatibility, rollout and rollback

  • Wire: no op or field changes. The X-RateLimit-* headers on those nine ops now report the knowledge.read bucket.
  • Operator steps: a knowledge.add override no longer applies to the nine reads, at either tier. This holds whether it was set through admin/ratelimit.set or by dev/onboard_tenant.py, and whether it sits above or below the default. Those reads take the knowledge.read limits: 50 / 10 per namespace and 150 / 30 per org, unless an override exists on knowledge.read. To keep a tenant's reads at the limit its knowledge.add override gave them, set the same override on knowledge.read (POST /v1/admin/ratelimit.set with op_class: knowledge.read, namespace or org). Running dev/onboard_tenant.py again sets the namespace one, as it now raises knowledge.read. A tenant with no override needs nothing.
  • Rollback: a revert puts the reads back in knowledge.add and leaves nothing behind. A stored knowledge.read override then binds nothing.

Tests

Run against a server started through scripts/serve.sh with 3 workers and its own ClickHouse, with the reference extractor and the end-user issuer set up as CI sets them:

  • tests/integration/test_knowledge_inspect_ingest.py, test_namespace_tune_documents.py, test_cross_principal_leakage.py and test_ratelimit_org.py: 51 passed and 3 skipped. The 3 skips need a code repository (LOOM_CODE_ORG), as they do outside CI.
  • tests/integration/test_onboard_tenant.py, which pins the anchor classes dev/onboard_tenant.py raises: 4 passed.
  • tests/unit/test_ratelimit_read_bucket.py gains two tests: the registry walk, and a burst of 20 knowledge reads that leaves knowledge.add's 10 intact.
  • CI on the merged head e886f2a: every check passed, including the unit job (27,599 passed), all four integration parts and the isolation gates part, which runs test_cross_principal_leakage.py again with auth on. At earlier heads with the same changes, the unit job sometimes failed test_document_extraction.py::test_one_line_sql_with_a_comment_after_every_semicolon_splits_in_bounded_time near its 10 s bound, as main's own unit job did at 515e34f. This diff touches no extractor code.
  • make format lint typecheck is clean. Before the later rebases, the full unit suite run locally gave 27,510 passed and 4 failed. The 4 failures are the four parametrize cases of test_document_extraction_tables.py::test_the_delimiter_is_sniffed_in_bounded_time. They take about 10 s against their 5 s bound on the local Python 3.12.13, whether run alone or in the suite. This diff does not touch that test, and CI's unit job passes it.

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. It reproduced each failure from the CI log and counted the leakage loop's calls per bucket.

  • 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 (see Tests for the one local timing test); the integration suite passes if server behaviour changed.
  • Generated files are regenerated in this PR, not by hand (none are affected).
  • A new migration is additive and numbered after the latest on main; no merged migration is edited (none).
  • A behaviour change to any file a plugin ships bumps both plugin manifests' version (none).
  • The frontend builds and its tests pass, if frontend/ changed (unchanged).
  • Docs under docs/ describe the system as it now is.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers.
  • Commits are signed off (git commit -s).

🤖 Generated with Claude Code

@zlareb1
zlareb1 force-pushed the fix/main-red-integration branch 6 times, most recently from 4f4e1f5 to d6c7e87 Compare November 6, 2026 19:27
zlareb1 and others added 13 commits November 6, 2026 20:09
…ss ingest tests configure no extractor

Every knowledge op without an override drew on the write-shaped
knowledge.add bucket (10 burst, 2 per second), so a run of reads was
refused: the cross-principal leakage test's knowledge.source.list and
inspect at @me were its 14th and 15th calls in a row. The ten read-only
knowledge ops now draw on knowledge.read (sized like default); a unit
test walks the registry so a new read cannot land in the add bucket.

The reference extractor now reads Parquet, so the inspect and tune tests'
Parquet jobs reached it and failed format_mismatch. They run those jobs
with no extractor configured, and the tune test expects the message for
whatever the server's own extractor declares.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…et is registered, and say why the inspect test's Parquet job fails

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ne test's docstring says both messages

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…oarded tenant's raised caps cover knowledge.read

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ed classes, and the bucket tables read the same in every page

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…me words on every page

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…cket table

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…y bucket table

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
… whole-namespace report

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
….add rows name it

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 force-pushed the fix/main-red-integration branch from d6c7e87 to d5dfc4e Compare November 6, 2026 20:11
… discards

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 merged commit 8437ca2 into main Nov 6, 2026
32 checks passed
@zlareb1
zlareb1 deleted the fix/main-red-integration branch November 6, 2026 20:56
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