Skip to content

A knowledge source's failure marks Loom degraded only when most orgs' sources fail; ops.incidents lists the caller org's failing sources - #2134

Open
zlareb1 wants to merge 50 commits into
mainfrom
fix/source-failures-not-loom-degraded
Open

zlareb1 wants to merge 50 commits into
mainfrom
fix/source-failures-not-loom-degraded

Conversation

@zlareb1

@zlareb1 zlareb1 commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

Related: #2047

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

One org's failing document sources, such as a folder its account no longer sees or a document that fails to mine, no longer make ops.incidents answer degraded to every org, unless that org holds every source the deployment syncs, every other org's credentials were refused, or it is the only org retiring a removed source and that retirement fails. A credential the provider refuses (credential_invalid) on a namespace's source, such as a revoked one, never does. The knowledge_source_sync worker counts its sources' failures toward a failed pass only when most orgs' sources fail, most orgs' tried documents fail to mine, or most of the orgs retiring removed sources could not retire their documents; a pass that fails outright (its source list or registry unread, or past its deadline) still fails. ops.incidents gains a sources field that lists the caller org's failing sources to a caller that reads the org whole.

Why

knowledge_source_sync called pass_context.note_failure once for each source whose turn failed or raised, mirrored sources included, and once for each source whose mining or retirement failed. The supervisor counts any pass with a noted failure toward the worker's streak. After 3 such passes, ops.incidents lists the worker, and its answer is degraded for every org on the deployment. A single tenant's credential_invalid source therefore marked Loom degraded for every org, for as long as the credential stayed revoked. So did one document whose mining failed: it is retried for _WAIT_PASSES = 3 passes, as many as the streak needs. The incident detail named no source and no count, so it did not show whether 1 of 5,000 sources had failed or all 5,000.

A source's failure is already recorded where its namespace reads it: _record_turn writes status and error into the source's sync state (loom.code_index_state, key knowledge_source:<name>), which knowledge.source.list shows. A document that fails to mine is in its source's extract_error. A removed source whose documents could not be retired is in the server's log, and knowledge.source.add under its name answers SOURCE_DELETE_PENDING while its documents are left. One org's failures tell nothing about the worker's health, however many of the deployment's sources are that org's, short of all of them; a failed retirement, which no tenant causes, is the exception (below). A pass in which most orgs have most of their sources fail does, whether because of an outage of what every source relies on or because one org holds every source the pass syncs.

Scope and risk

  • server/knowledge/app/source_sync.py: each leg of the pass keeps a per-org tally (SourceTally, on PassResult as turns, mining and retiring) of the sources it handled and those that failed, in place of a note per source:

    • sync turns, mirrored ones included: a turn that ended with a status other than ok or raised.
      • Refused credentials: a namespace source's credential_invalid turn is left out of the tally while its stored credential still opens under the deployment's secrets (sources.credential_of). Only its org can rotate a credential the provider refuses, and a deployment where most orgs' credentials lapsed (dormant accounts) would otherwise stay degraded for the active ones.
      • An org whose every turn was refused counts only in a leg that ran for it (mining the documents it stored before, say): counting those orgs as healthy would hide an outage of the active ones.
      • A credential the deployment's secret no longer opens is the deployment's own failure and counts, so dropping LOOM_JWT_SECRET_PREVIOUS before loom secrets reseal has resealed the stored credentials fails every org's sources and is noted.
      • The cost: a provider refusal every org's credentials share is not counted, such as a provider answering every token exchange 400 when the host's clock is off; each org's ops.incidents sources lists them.
      • A folder or shared drive the account no longer sees (a 403 or 404 on _items_visible's check; a quota 403 is a rate limit) ends its turn failed, the status a provider's 5xx also ends with, and the tally reads only the turn's status, so it counts (test_a_lost_folder_counts_toward_the_sync_leg). Loom asking for an item by a wrong id gets the same 404, and the tally cannot tell that from an org unsharing its folder, so leaving these out would hide a fault in Loom's own ids from the streak. The cost: a lost folder fails every turn of its source until it is shared again or the source is removed (a failed turn is not complete, so the next turn is full and checks again), so a deployment where, in most orgs, most sources each lost a folder or shared drive (one failed check fails the source's turn), at once or one by one over months, fails the sync leg every pass. Leaving a failed check out, as a refused credential is, would trade that cost for the hidden fault; this change keeps it counted. The listing's own 403 ends credential_invalid (vendor_failure, unchanged) and is left out as a refusal.
      • A mirrored turn counts as failed for every cause alike, so that nothing about the mirror's cause reaches the pass's status row.
    • mining counts documents tried, not sources: each document the pass tried to mine (_Mined.tries, which replaces the tried flag) and each that failed.
      • Failed whole: a source whose documents could not be read, whose record could not be written, or whose mining raised counts its tries (at least one) as failed. A source with nothing to mine adds nothing.
      • Floor: the leg is judged only when the pass tried at least 2 documents in all, or a source failed whole. So the only document a pass mines failing stays that document's, in the source's extract_error, while one failing document in each of most orgs (a model outage on a quiet deployment) is noted, and so is a failing read of a deployment's only source.
      • The floor is on the pass, not on each org: a per-org floor would never count orgs that each mine one document.
      • Documents, not a source's whole map: judging a source by all of its documents would never fail a source of more documents than a pass tries (LOOM_KNOWLEDGE_SOURCE_SYNC_DOCUMENTS_PER_PASS, 40), even when every document tried failed.
      • The cost: an org with nothing to mine counts as not failed, and so does one whose documents the pass's document bound left waiting (LOOM_KNOWLEDGE_SOURCE_SYNC_DOCUMENTS_PER_PASS, 40 by default, which the retirement and the sync's fetches spend first; while the sync turns finish, the leg starts at the same source each pass). So a model outage is not counted toward the streak while the pass tries documents for no more than half the orgs it serves: while no more than half have changed documents, while one org's backlog takes the bound and leaves the others waiting, and always when the pass serves at least twice as many orgs as the bound. Each source's extract_error shows it. The provider incident does not by default: with LOOM_WORKERS_PROCESS=child the worker's model calls run in a child process whose provider health no request reads. Counting only the orgs that mined, or leaving the waiting ones out, would catch it, but would let one org whose changed documents fail, in passes where it alone mines or its backlog takes the bound, build the streak for every org.
    • retirement of removed sources: a source whose _retire_all raised. No tenant causes such a failure: it deletes Loom's own copies and uses no credential. So this leg serves only the orgs whose removed sources it retired, not every org the pass serves: one org's failing retirement fails the pass when it is the only org retiring, and not beside another org whose retirement succeeds. Judged against every org, the failure only this leg catches (a bug in retiring one org's documents) could never be noted, since a store outage broad enough to reach most orgs already fails the sync leg.

    After each leg, SourceTally.note notes one SourcesFailed under the leg's name (sync, mining or retirement, as other workers name a leg):

    • Rule: most of the orgs the leg serves had most of their units in that leg fail (failed[org] * 2 > ran[org] for more than half of the orgs). For mining the units are documents (failed for most documents in 1 of 1 orgs).
    • Denominator: the orgs of the sources the pass syncs (_usable: the sources this build serves and, with auth on, the mirrored ones and owners' worker copies, outside inactive namespaces), with those the leg ran for; for the retirement, only those it ran for (above). An org the leg had nothing to do for, or that the pass bound left for the next pass, has not failed, and an org with no source the pass syncs is not counted. So on a deployment where one org holds every synced source, that org's failures still build the streak for every org, as on a deployment with one org.
    • Kind: the tally keeps each failure's kind per org (an exception's class, a turn's status, SYNC_FAILED for a mirrored source), never its text, and the note names the one with the most failed units among the orgs that failed. Mining counts each failed document under its own reason (_Mined.reasons, codes such as not_run or refused), not under its source's first one.
    • Where it shows: the worker's status row (loom.worker_status) reads error_class SourcesFailed and error sync: failed for most sources in 3 of 4 orgs (most often failed), the pass event carries partial_leg sync, and an ops.incidents worker incident reads 3 failed passes in a row (SourcesFailed). The incident carries the noted exception's class, so the cause is in the status row, not in the incident.
    • A source another copy holds (LeaseBusy) counts neither way.
    • A turn whose state write itself failed leaves the source's previous status in its sync state. That failure is in the server's log and result.errors, and counts in the tally (a store outage fails every source's write).
    • Unchanged: result.failed and result.errors, the mirrored SYNC_FAILED code, the meet recording provider_removed exclusion, and the tally's absence from the pass summary (outcome()).
  • ops.incidents (server/insights/app/incidents.py):

    • Gate: the new sources field is gated like requests. A caller that does not read the org whole is answered not_permitted and causes no read. sources never changes status.
    • Statement, one in server/knowledge/store/sources.py: loom.code_index_state FINAL for org = {org}, joined to the active loom.knowledge_sources FINAL rows that every reader of their namespace sees (access = 'namespace', credential_mode = 'shared', not a worker row). It leaves out reserved namespaces, the org's inactive namespaces and the statuses '', ok and provider_removed, and returns count() OVER () with a LIMIT 5 sample, newest last_synced_at first. The registry join is needed because a removed source's state row is never deleted. Mirrored and connected sources are left out by the join: their namespace row sits in an ordinary namespace, so a mirror-name test alone would not exclude it. The statement filters on JSONExtractString(detail, 'status') itself, not on its status alias (test_sql_alias_shadow).
    • Cost: it reads only the caller org's rows of its three tables (loom.code_index_state, loom.knowledge_sources, loom.namespaces), whose sort keys start with org, but it parses the detail of every one of the org's source states, which holds the source's map of mined documents (up to LOOM_KNOWLEDGE_SOURCE_MAX_DOCUMENTS entries, 50,000 by default and at most 200,000), and it reads the org's code-index rows in the granules it selects. A status column of its own would make the read independent of the map's size; that is a schema change left out of this one. The measurement is under Tests.
    • Cache and bounds: a source's state changes once a pass (15 minutes by default), so the answer is cached for 60 s (_SOURCES_TTL_S) per org and collection reach in each process, and a failed read as long, so a read slower than the bound is not started again every few seconds. _cached is now generic over what it caches and takes the read's TTL. Each cached ops.incidents read (the worker streaks, the request counts, the failing sources) now runs under statement_timeout(readiness_check_timeout_s), so ClickHouse stops it at the bound the client waits instead of the read class's 30 s, and a poll after a slow read's cached failure never runs beside it.
    • Reach: the caller's collection reach (below) is read through the grant cache before the statement and cut at LOOM_READINESS_CHECK_TIMEOUT_S on the client side only: on a miss, the grant cache's shared load reads it under its own bound, as for every call. Past the bound the sources answer unread. The statement then runs under a bound of its own, so while both are slow an answer waits up to two bounds (docs/operations/monitoring.md). One deadline for both would leave the statement what a slow reach left of it, and _cached would keep that failure for the 60 s the sources are cached, after the grant cache is warm again.
    • Failure: a failed read answers unread and is named in degraded as ops.incidents: sources_unread, cached as long as an answer. When the restricted set cannot be read, or a platform administrator's tenancy check refuses, both requests_unread and sources_unread are named.
  • OpsIncidentSources and status now say a failing source never makes status degraded by itself, and OpsIncidentSources names the Knowledge page section that says when the sync worker is listed; the ops.incidents reach reason in server/identity/domain/read_scope.py names both org reads.

  • Tenant isolation:

    • the statement binds only the caller's org;
    • restricted namespaces stay hidden, because only a caller that reads the org whole, with no restricted namespace hidden from it, gets read;
    • collections are not in the restricted set, and an org admin reaches one only through a grant, so the read also applies collection_clause(org): the statement leaves out every collection the caller cannot read (a platform admin reads every one);
    • the reach is resolved before the cache and keys it (the org and the readable collections, or *), so callers with the same reach share a read and none is served a wider one;
    • sharing.readable adds an end user's own collection to every reach, and such a collection holds no source (PERSONAL_NAMESPACE), so it is left out of the key and the statement: org admins with the same grants share one read;
    • sharing.readable answers an unread tree or grant as no shared collection (fail_closed.note_unreadable); the read then answers unread with sources_unread, not a narrower count, as it does for a backend outage.
  • Read-only change: no table, column or write path, so erasure needs no new step (loom.code_index_state is already erased by the code_index.purge step, as a step-only table).

  • Out of scope:

    • per-unit failures of other workers (code_backport_gaps, code_graph_stats, code_summary, knowledge_gaps);
    • the private-pass streak freeze. A pass that runs any mirrored turn is private, and _after_pass keeps the ordinary streak unchanged for it. On a deployment with an active mirrored source, a leg's note therefore reaches only the private status row (SYNC_FAILED) and never the worker streak;
    • per-source backoff.

Compatibility, rollout and rollback

  • Wire: ops.incidents gains the output field sources: {failing: int, sample: [{namespace, name, status}], read: "read" | "not_permitted" | "unread"}. It is additive. The server model and the Rust SDK default it to {failing: 0, sample: [], read: "unread"}; the Python (NotRequired), TypeScript (optional) and Go (*OpsIncidentSources, omitempty) SDKs type it optional, so a client reading an earlier server, whose answer omits it, finds it absent. No field is removed or renamed.
  • Worker signals: loom.worker.partial_failures{worker="knowledge_source_sync"} and the worker's streak now count at most one note per leg per pass, in which most of the orgs the leg serves had most of their units fail, not one per failing source. An alert on them fires on an outage, not on one tenant's credential or document. Four outages are not noted:
    • one in which every turn fails slowly enough that one pass reaches no more than half the orgs, since an org that the pass bound leaves for the next pass counts as not failed. This favours one org's slow failures never degrading the others. Each affected org's ops.incidents sources lists its failing sources;
    • one of a provider no more than half the orgs use (3 orgs on Drive, 1 on Notion, and Notion down), which fails no more than half the orgs. Those orgs' sources list it;
    • a provider refusal every org's credentials share, such as every token exchange refused because the host's clock is off: a refused credential is left out of the tally. Each org's sources lists its sources as credential_invalid;
    • a model outage while the pass tries documents for no more than half the orgs it serves, since an org with nothing to mine, or one the pass's document bound left waiting, has not failed: while the pass serves at least twice as many orgs as the bound (80 by default), the mining leg never notes one. It shows in each source's extract_error, not in sources.
  • Retry cadence: the supervisor's sooner retry (LOOM_WORKER_PARTIAL_RETRY_S, next_interval_seconds(partial=bool(ctx.count))) follows the same notes. On a deployment whose LOOM_KNOWLEDGE_SOURCE_SYNC_INTERVAL_SECONDS is longer than that setting, one org's failing source no longer brings the next pass forward; only a leg's note does. At the defaults (900 s interval, 3600 s retry) nothing changes, since the sooner retry applies only to an interval longer than the retry. The Knowledge page says so; per-source backoff stays out of scope.
  • Private status row: on a deployment with an active mirrored source, the private pass's status row (_record_private_status) reads failed (SYNC_FAILED) when the pass noted a failure, so it now reads failed only when a leg fails for most orgs, not whenever any source's turn failed. test_one_mirrored_failure_of_three_notes_no_pass_failure pins a count of zero, which _record_private_status records as an ok row (server/workers/supervisor.py, failed = not success or bool(ctx.count) or ...).
  • Rolling upgrade: while N-1 replicas run, their passes still note each failing source, so the worker's streak can still rise until the last N-1 replica is gone. N-1 answers ops.incidents without sources.
  • Design change from the first push: the rule counted failed sources across orgs, so one org that holds most of the sources still built the streak; it now counts orgs, against the orgs whose sources the pass syncs. The mining and retirement legs, which still noted per source, are on the same rule, the retirement against the orgs it retired for, and mining counts the documents it tried.
  • Merged with main (last at 80dcd65), after Owner-only snapshot and selected-refresh worker sources keep a private copy in the mirror #2165 made an owner's worker copy a mirrored turn (_mirrored): the two turn-tally lines this change adds in _sync_turn use _mirrored, so a worker copy's failure counts under SYNC_FAILED like a mirrored source's (test_a_worker_copys_failure_counts_with_the_one_mirrored_code). The generated SDK models are regenerated over both sides.
  • Operator steps: none.
  • Rollback: reverting removes the field and brings back the per-source notes; nothing is stored.

Tests

Each new test fails on origin/main.

  • tests/unit/test_knowledge_source_sync_failures.py (new, over the real run_sync under a real pass context):

    • sync:
      • 1 failing source of 3 notes nothing, both for a turn that ends failed and for one whose state write raises;
      • 2 of 3 of one org note exactly one SourcesFailed, which the status row shows as sync: failed for most sources in 1 of 1 orgs (most often failed);
      • 1 of 1 notes one;
      • 1 of 2 notes nothing;
      • a source another copy holds is not counted;
      • a lost folder's failed turn notes the sync leg (in 1 of 1 orgs, most often failed) and adds no refused org;
    • refused credentials:
      • two of three orgs' only sources ending credential_invalid note nothing;
      • three dormant orgs whose only credential is refused beside two active orgs whose sources fail note in 2 of 2 orgs, and so do the same dormant orgs beside two active orgs whose every changed document fails to mine (the mining leg), while dormant orgs with stored documents still to mine are counted (in 5 of 5 orgs);
      • two orgs' only sources whose stored credential the deployment's secret does not open, ending credential_invalid, note in 2 of 2 orgs (most often credential_invalid);
    • per org:
      • two failing sources of one org beside one healthy source of another note nothing, and with the other org failing too note in 2 of 2 orgs;
      • a pass bound that ends the turns after one org's two failing sources, before the other org's, notes nothing;
      • an org whose only source is in an inactive namespace does not dilute the other org's failing sources, which note in 1 of 1 orgs;
    • mirrored:
      • 2 failing mirrored sources of 3 note one, while their errors stay SYNC_FAILED;
      • an owner's worker copy whose state write raises is tallied under SYNC_FAILED, not its exception's class, and its pass is private;
      • 1 mirrored failure of 3 notes nothing;
    • mining:
      • a store read failing for a deployment's only source notes one in 1 of 1 orgs;
      • a store read failing for two orgs' only sources notes one in 2 of 2 orgs, and so does a failed record write after each org's only source tried one document, and one of documents left waiting (mining switched off for both orgs);
      • one failing document in each of three orgs notes in 3 of 3 orgs;
      • one of 3 sources' documents failing (not_run) notes nothing, and all 3 note one;
      • one document of a deployment's only source failing, of 3, notes nothing, and all 3 note one;
      • a source of 100 documents whose every try fails notes one;
      • one org's 3 failing documents beside an org with nothing to mine note nothing;
      • one org's 100 failing documents taking the pass's bound, beside two orgs it left waiting, note nothing;
      • the only document a pass mines failing notes nothing;
      • a store read failing for every source notes one (it noted 3);
    • retirement:
      • one removed source's failed retirement of 3 notes nothing, and all 3 note one;
      • one org's removed source failing notes one in 1 of 1 orgs beside an org with only an active source, and nothing beside an org whose retirement succeeds;
    • kinds:
      • every note names its most common kind: failed, ConnectionError, SYNC_FAILED, not_run;
      • a tally whose non-failing org holds the most failures of one kind (3 of 7 rate_limited) names the failing orgs' kind (failed);
      • a mining note names the kind of the most failed documents (one source's 40 not_run documents over two sources whose record write raised ConnectionError);
      • one org's refused document and four not_run documents across two orgs note not_run.
  • tests/unit/test_ops_incidents.py:

    • every read carries the readiness bound to ClickHouse (statement_timeout);
    • a sources read serves for 60 s whether it answered or failed;
    • an org admin's read carries its readable collections (col_prefix, col_readable);
    • the same subject as a platform admin is read again with no clause;
    • another org admin with the same reach shares the first read;
    • org admins whose reaches differ only by their own collections share one read, run without them;
    • an unread collection tree (which sharing.readable swallows), a backend outage and a reach slower than the readiness bound each answer unread with no statement run;
    • sources returns the count and sample for the caller's org only (params["org"] == "acme", limit == 5) with status ok;
    • zero failing reads read, 0, [];
    • each org is read once per TTL;
    • a member token is not_permitted and causes no read;
    • a failed read is unread plus a sources_unread note;
    • the analyzer corpus's org admin sources scope is the fragment collection_clause builds.

    The gate tests assert sources.read (not_permitted, unread) and both unread notes. The existing transport, gate and in-flight tests now also cover the sources read.

  • tests/integration/test_ops_incidents.py (new): ops.incidents over the transport against the real store, called with an org admin token, with sources and sync states seeded for two orgs, answers the caller org's two failing sources, latest first, and none of the other org's. Against a server that enforces auth, a member reads not_permitted and an org admin's answer leaves out a failing source of a collection it holds no grant on. CI runs the file in the auth-on isolation gates too (.github/workflows/ci.yml); the auth-on test skips elsewhere. It was not run locally.

  • tests/unit/test_ops_incidents_sql.py: the statement on clickhouse-local over the production DDL. Each of the two filters credential_mode = 'shared' and not_reserved_sql() has a row that only it leaves out (a namespace source on a connected credential, and a source row in a mirror's namespace); with either removed, the count is 5. With no collection clause it returns 4 failing sources in order, among them a collection's and a newer failure over an older ok, a recovered source left out, and a mirrored source, a connected source, a source row in a mirror's namespace, a removed source's stale state, a worker source, provider_removed, a never-run source, an inactive namespace, another state key and another org's source all left out. sample=2 keeps the count. A collection's failing source is counted with no clause, left out under the clause collection_clause gives an org admin with no grant on it, and kept with one.

  • Updated pins: test_knowledge_source_sync_diagnostics.py (a mirrored turn adds only its tally; failures are tallied, not noted), test_knowledge_source_sync.py::test_only_a_retired_meet_turn_is_not_a_pass_failure (the meet exclusion applies to the tally), test_knowledge_source_sync.py::test_a_failed_read_of_a_source_s_documents_is_that_source_s_error (one source's failed read of two notes nothing), and the meet test's credential_invalid case (in result.failed and errors, left out of the tally, its org in result.refused_orgs).

Measured on clickhouse-local 26.7 on a laptop over generated rows, no deployment's data, with the script below, run from the worktree root as .venv/bin/python measure_sources.py N DOCS [VERSIONS]: N sources of one org, DOCS entries in each source's mined map, VERSIONS unmerged versions of each state (1, merged, by default), beside 50 code-index state rows of 200 KB.

  • 20 50000: 62 MB read (19 MB compressed) with an 88 MB memory peak, in 33 to 39 ms;
  • 100 50000: 272 MB read (56 MB compressed) with a 153 MB peak, in 120 to 126 ms;
  • 400 50000: 1,076 MB read (193 MB compressed) with a 388 MB peak, in 444 to 473 ms;
  • 20 50000 3: 234 MB read (41 MB compressed) with a 253 MB peak, in 31 to 53 ms;
  • 200 5000: 61 MB read (19 MB compressed) with a 45 MB peak, in 31 to 35 ms.

Each time is the wall-clock range of five runs, against the op's 250 ms p99 budget; the read runs beside the worker and request reads, not after them. The cost grows with the org's mined entries, about 23 ms per million at 400 sources. At the default cap of 50,000 entries a source, an org past about 200 sources (10 million entries) passes the 250 ms budget on the call that misses the cache, once a minute per org and reach in each process, and one past about 1,700 would pass the 2 s bound and read sources: unread on every answer; at the 200,000 maximum the two figures are about 50 and 430 sources. The 2 s figures are extrapolated, not measured. A status column of its own is the fix, as above.

Moving the sort-key filters to PREWHERE put a PREWHERE in the plan but read the same bytes under FINAL, so it is left out. The statement is new, so no deployment's system.query_log holds it yet; running it by hand against a production deployment was left out of this change.

measure_sources.py
"""Synthetic cost of ops.incidents' failing-sources statement on clickhouse-local.

N sources of one org, each with a sync state whose `mined` map holds DOCS entries,
a fifth of them failing, written in VERSIONS unmerged versions (1: merged), beside 50
code-index state rows of 200 KB. Prints the statement's profile events and five
wall-clock times. No deployment data: the rows are generated here.
Run from the worktree root: .venv/bin/python <this file> N DOCS [VERSIONS]
"""

import re
import subprocess
import sys
import tempfile
from datetime import UTC

from clickhouse_connect.driver.binding import bind_query

from server.knowledge.store.sources import STATE_KEY_PREFIX, _failing_sources_sql
from tests.unit.clickhouse_local import CLICKHOUSE, ddl

n, docs = int(sys.argv[1]), int(sys.argv[2])
versions = int(sys.argv[3]) if len(sys.argv) > 3 else 1
setup = [
    "CREATE DATABASE IF NOT EXISTS loom",
    ddl("knowledge_sources"),
    ddl("code_index_state"),
    ddl("namespaces"),
    "INSERT INTO loom.knowledge_sources (org, namespace, name, source_id, access, "
    "credential_mode, source_kind, active, version) "
    "SELECT 'o1', 'team', concat('s', toString(number)), generateUUIDv4(), 'namespace', "
    f"'shared', 'gdrive', true, 1 FROM numbers({n})",
    "INSERT INTO loom.namespaces (org, namespace, owner_email, active) "
    "VALUES ('o1', 'team', '', true)",
]
state = (
    "INSERT INTO loom.code_index_state (org, namespace, state_key, detail, version) "
    f"SELECT 'o1', 'team', concat('{STATE_KEY_PREFIX}s', toString(number)), "
    "concat('{\"status\":\"', if(number % 5 = 0, 'failed', 'ok'), "
    "'\",\"last_synced_at\":\"2026-01-01T00:00:00+00:00\",\"mined\":{', "
    "arrayStringConcat(arrayMap(j -> concat('\"https://docs.example.com/file/', "
    f"toString(number), '/', toString(j), '\":\"rev-', toString(j), '\"'), range({docs})), "
    "','), '}}'), {v} FROM numbers(" + str(n) + ")"
)
setup += [state.replace("{v}", str(v)) for v in range(1, versions + 1)]
setup.append(
    "INSERT INTO loom.code_index_state (org, namespace, state_key, detail, version) "
    "SELECT 'o1', 'team', concat('code_cursor:repo', toString(number)), "
    "randomPrintableASCII(200000), 1 FROM numbers(50)"
)
if versions == 1:
    setup.append("OPTIMIZE TABLE loom.code_index_state FINAL")
sql = _failing_sources_sql("")
params = {"org": "o1", "prefix": STATE_KEY_PREFIX, "start": len(STATE_KEY_PREFIX) + 1, "limit": 5}
_, bound = bind_query(sql, params, UTC)
binds = [f"--{k}={v}" for k, v in bound.items()]
events = r"(SelectedBytes|ReadCompressedBytes|MemoryTrackerPeakUsage)[^0-9]*?([0-9]+)"

with tempfile.TemporaryDirectory() as path:
    base = [CLICKHOUSE or "clickhouse", "local", "--multiquery", "--session_timezone=UTC"]
    base += ["--path", path]
    subprocess.run(base, input=";\n".join(setup), check=True, text=True)
    out = subprocess.run(
        [*base, "--print-profile-events", "--profile-events-delay-ms=-1", *binds],
        input=f"{sql} FORMAT TSV", capture_output=True, text=True, check=True,
    )
    seen: dict[str, int] = {}
    for m in re.finditer(events, out.stderr):
        seen.setdefault(m.group(1), int(m.group(2)))
    print({k: f"{v / 1e6:.0f} MB" for k, v in seen.items()})
    for _ in range(5):
        out = subprocess.run(
            [*base, "--time", *binds], input=f"{sql} FORMAT Null",
            capture_output=True, text=True, check=True,
        )
        print("elapsed s:", out.stderr.strip().splitlines()[-1])

Commands, on Python 3.12 with LOOM_ENV_FILE=:

make format lint typecheck                       # clean; lint runs every generator --check
.venv/bin/python -m pytest -n auto -p randomly -q tests/unit/test_knowledge_source_sync_failures.py \
  tests/unit/test_knowledge_source_sync.py tests/unit/test_knowledge_source_sync_diagnostics.py \
  tests/unit/test_ops_incidents.py tests/unit/test_ops_incidents_sql.py tests/unit/test_sql_alias_shadow.py
                                                 # 299 passed
.venv/bin/python -m pytest -n auto -p randomly -q tests/unit/test_degraded_unnoted.py \
  tests/unit/test_package_contracts.py tests/unit/test_public_copy.py tests/unit/test_doc_links.py \
  tests/unit/test_tunable_constants.py
                                                 # 307 passed
.venv/bin/python -m pytest -n auto -p randomly -q $(grep -rlE "source_sync|ops_incidents|incidents" tests/unit tests/analyzer --include='*.py')
                                                 # 44 files: 1250 passed
(cd sdk/go && go build ./... && go vet ./wire/)  # clean
(cd sdk/rust && cargo test --test registry_contracts)   # 388 passed

CI at f02d225 (run 47462191362, one commit past the merge with main at 3efe16d) passed every ci job, both storage integration jobs included. At fa62bea (run 47467977917, the merge with main at 5daf4aa) every ci job passed but pytest integration (Postgres 16, storage), which failed only the cell test below. At 8204980 (run 47473680144, the merge with main at 80dcd65) every ci job passed but pytest integration isolation gates, which failed only the memory.for_file positive control below. Three test failures came from outside this change. tests/integration/test_cell_prepared_bot_native.py::test_normal_prepared_later_cell_proves_both_bootstrap_keys failed on c5a64ad, 7d152db and fa62bea (a cell fixture command exited 1); it fails on main too, in ci runs 47447740618 (b43e417, both storage jobs), 47436514278 (027f2db), 47425800151 (f691e30), 47413434538 (7d963b1) and 47388725676 (ec3d632), and this change does not touch cell control. tests/unit/test_code_diff_sides.py::test_a_parse_at_the_parent_that_could_not_run_is_a_failed_read failed once in pytest unit part 5 on 130e7c6; this change does not touch the code index, the file passes locally with CI's seed (474401994441) and order, and the job passed at f80dd9d, 7d152db and f02d225. tests/integration/test_cross_principal_leakage.py::test_positive_control_the_owner_reads_their_row_of_another_namespace_for_its_file failed once in pytest integration isolation gates on 8204980 (1 failed, 264 passed): one of the owner's memory.for_file lookups served nothing after the fixture had seen all of them served. This change does not touch memory.for_file or the default read scope, its test_ops_incidents.py in that job writes only its own orgs' source rows and reads them back through ops.incidents, and the job passed on main at 80dcd65 (run 47472524504). dependency review, a workflow of its own, fails at f02d225, fa62bea and 8204980, as on every earlier head, with "Dependency snapshots are incomplete and snapshot inputs changed": the Rust dependency graph workflow submits a snapshot only on main, and the review refuses a pull request that changes a file under sdk/rust/ without one. This change touches sdk/rust/ only through the generated wire_models.rs and registry_contracts.rs, and #2144 merged with the same failure.

6 of the 17 tests in tests/unit/test_knowledge_source_revisions_sql.py fail locally on a clean main (5daf4aa) too: the local clickhouse-local does not know the setting enable_quantized_codec. This change does not touch it.

Regenerated: sdk_py_gen, sdk_ts_gen, sdk_rust_gen (it numbers its default_N helpers in order, so the four new defaults renumber the later ones), sdk_go_gen, docs_reference (docs/reference/operations/ops.md) and the analyzer corpus (tests/analyzer/shapes.txt: two new shapes, the sources statement unscoped and under an org admin's collection clause). sdk_py_client_gen, sdk_rb_gen, sdk_rust_gen --fixtures and op_reach_census are unchanged. The analyzer's EXPLAIN QUERY TREE check and the full unit and integration suites are left to CI.

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 new tests were run against the unchanged code first, and each failed for the expected reason; the statement was run on clickhouse-local over the production DDL.

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

Checklist

  • Local format, lint, type checks and focused tests pass. The full make test-unit and applicable integration results are reported by CI; a full local run is not required before pushing.
  • 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), the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.py) and the standalone skill bundles (python3 scripts/codegen/standalone_skills.py).
  • (n/a: no migration) A new migration is additive and numbered after the latest on main; no merged migration is edited.
  • (n/a: no plugin file) 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.
  • (n/a: frontend/ unchanged) 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.
  • I signed the Contributor License Agreement (CLA) if CLA assistant requested a signature.

🤖 Generated with Claude Code


Note

Medium Risk
Changes incident/degradation semantics and worker failure streaks across tenants; ops.incidents adds a potentially heavy per-org ClickHouse read cached at 60s with collection-scoped auth.

Overview
Fixes deployment-wide degraded when only one tenant’s knowledge sources fail. The sync worker now records pass failures per leg (sync, mining, retirement) only when most orgs that leg served had most of their units fail—not once per failing source. Refused credentials (credential_invalid), mirrored turns, and several edge cases are tallied per the new rules so a revoked Drive token or one org’s broken folder no longer drives a 3-pass worker streak for every org.

ops.incidents gains a sources block (failing, up to 5 samples, read permission). It lists the caller org’s document sources whose last sync ended failed, rate_limited, or credential_invalid, scoped like request counts (whole-org readers, collection grants). Failing sources are informational: they do not add incidents and do not set status to degraded; the sync worker still appears as a worker incident after three failed passes under the new counting.

Implementation adds a ClickHouse query in knowledge source store, 60s caching per org/collection reach (vs 5s for worker streaks and SLI), statement timeouts on incident reads, and regenerated SDK types. CI adds test_ops_incidents.py to isolation gates; docs describe worker health vs per-org source visibility.

Reviewed by Cursor Bugbot for commit da31b7d. Bugbot is set up for automated code reviews on this repo. Configure here.

…g; ops.incidents lists the caller org's failing sources

knowledge_source_sync noted a pass failure for every source whose turn
failed, so one org's revoked credential built the worker's streak and,
after three passes, made ops.incidents answer degraded to every org. A
source's failure is already in its own sync state. The pass now tallies
the turns that ran and noted failures, mirrored ones included, and notes
one SourcesFailed ("7 of 9 sources failed") only when most of them
failed: an outage, or a deployment's only source. The store and model
legs still note as before.

ops.incidents gains `sources`: the caller org's failing sources that
every reader of their namespace sees (a count and up to 5, latest
failure first), read under the same org-whole gate as `requests`, from
one bounded statement in the knowledge store, cached per org. It never
changes `status`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
@vercel

vercel Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
loom-docs Ready Ready Preview Dec 5, 2026 4:44am UTC
loom-telemetry Ready Ready Preview Dec 5, 2026 4:44am UTC

Request Review

zlareb1 and others added 2 commits December 4, 2026 14:43
The pass counted failed sources across orgs, so one org that holds most
of a deployment's sources still built the worker's streak with its own
revoked credential. The mining and retirement legs still noted each
source's failure, so one document that failed to mine, retried for 3
passes, did the same. Each leg (sync turns, mining, retirement) now
tallies the sources it handled per org and notes one SourcesFailed
("sync failed for most sources in 3 of 4 orgs") only when most of the
orgs it ran for had most of their sources fail.

ops.incidents names sources_unread beside requests_unread when the
restricted set cannot be read. The sources statement filters on the
status expression, not its alias (test_sql_alias_shadow).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
…serves

A leg divided its failing orgs by the orgs it handled, so a leg that
reached one org read as a deployment with one org: one org's removed
source whose retirement kept failing, or a pass bound that ended the
turns inside one org's failing sources, still built the worker's streak.
SourceTally.note now counts against the orgs of every active source the
pass read, with those the leg ran for; an org the leg had nothing to do
for has not failed.

The tally keeps its failures' kinds (an exception's class, a turn's
status, SYNC_FAILED for a mirrored source), and the note names the most
common one: "sync failed for most sources in 3 of 4 orgs (most often
credential_invalid)".

The ops.incidents wire text says a failing source never makes status
degraded by itself, and the read_scope reason names both org reads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread server/knowledge/app/source_sync.py Resolved
zlareb1 and others added 2 commits December 4, 2026 15:25
The denominator held the org of every active registry row, so orgs whose
only rows the pass never syncs (a worker's row, a source in an inactive
namespace) diluted an outage of every org it does sync until no leg
noted it. It is now the orgs of the usable sources, and the retirement
note follows that read.

tests/integration/test_ops_incidents.py reads ops.incidents over the
transport against the real store: the caller org's two failing sources,
latest first, and none of another org's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
The gate lets an org admin over * read the org whole once no restricted
namespace is hidden from it, but collections are not in the restricted
set: an org admin reaches one only through a grant. The sources read
named a collection's failing source to an org admin with no grant on
it, and its per-org cache served that answer to every caller. The read
now applies collection_clause(org), fails closed when the grants cannot
be read, and is cached per org and caller.

A source's mining counts as failed only when it raised or most of its
documents failed: one document that fails to mine is that document's,
in the source's extract_error, even for a deployment's only source.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread server/insights/app/incidents.py Resolved
Comment thread server/insights/app/incidents.py Resolved
Comment thread server/knowledge/app/source_sync.py Resolved
…lure

A deployment where most orgs held a lapsed credential (dormant
accounts) made every pass note SourcesFailed, and ops.incidents answer
degraded to the active orgs. A namespace source's credential_invalid
turn now counts as handled in the tally; it stays in result.failed, the
errors and the source's sync state. A mirrored turn still counts as
failed for every cause alike, so the private status row tells no cause.

ops.incidents resolves the caller's collection reach before its cache
and keys the cache on it, so a subject reading as a platform admin and
as an org admin, or two callers of different reach, are never served
each other's read. sharing.readable answers an unread tree or grant as
no shared collection; the read checks fail_closed.unreadable and answers
unread instead of a narrower count.

The docs name what the rules do not catch: a model outage while a pass
mines few changed documents, and any leg's failure on a deployment with
an active mirrored source, whose passes leave the streak as it was.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread server/knowledge/app/source_sync.py Resolved
Comment thread server/insights/app/incidents.py Resolved
zlareb1 and others added 3 commits December 4, 2026 16:37
The mining leg judged a source by all of its live documents, so a source
of more documents than a pass tries never counted as failed, even when
every document tried failed. Mining now tallies the documents tried per
org, counts only the orgs it mined for, and needs at least two tries
before an org counts as failing. A source that raised, or whose read or
write failed, counts as one failed try at least.

The read field's comment of ops.incidents sources names its other unread
causes: unread collection grants and a refused tenancy check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
The generated Go and Rust wire models are regenerated from the merged
operations.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Counting the mining leg only against the orgs that mined let one org with
changed documents be the majority whenever it alone mined, so its failing
documents built the worker's streak for every org. An org with nothing to
mine now counts as not failed, as in the sync and retirement legs; the
cost, a model outage while fewer than half the orgs mine, is in the docs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread server/knowledge/app/source_sync.py Resolved
zlareb1 and others added 2 commits December 4, 2026 17:18
The note's "most often" kind was counted over every org, so a healthy
org's few failures could name the outage of the others; it is now the
most common kind among the orgs that failed. A mining read, write or
raise fails a source whole, and its org counts however few documents it
has, so a store failure on orgs of one source each is noted.

ops.incidents cuts the caller's collection reach at the readiness bound
and answers the sources unread past it. The integration test calls with
an org admin token, and under auth checks that a member reads none and
that an org admin's ungranted collection is left out; CI runs it in the
auth-on gates. The docs name a pass that fails outright as a worker
failure too, and quote the status row's partial_error as it is.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
SourcesFailed is noted under the leg's name (sync, mining, retirement),
as other workers name a leg, so the status row's partial_leg says which
leg failed. SourceTally.add takes the failed count literally, all of the
units only when none is given.

failing_sources requires its collection scope, so no caller reads every
collection by leaving it out; the analyzer corpus runs the statement
under an org admin's collection clause too.

The docs and the wire text say what the rule does when one org holds
every synced source: its failures still build the streak, as on a
deployment with one org. monitoring.md names how the reads are cached,
the failing sources per org and collection reach.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
@zlareb1 zlareb1 changed the title A failing knowledge source no longer marks Loom degraded for every org; ops.incidents lists the caller org's failing sources A knowledge source's failure marks Loom degraded only when most orgs' sources fail; ops.incidents lists the caller org's failing sources Dec 4, 2026
zlareb1 and others added 2 commits December 4, 2026 18:07
The mining raise path counts a source as failed whole; a test now pins
it with two orgs whose only source tried one document and whose record
write failed. The docs name the worker status row's error_class and
error the note leaves, not the pass event's fields, and drop mirrored
turns from the legs that move the streak, since their pass is private.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
With the floor on each org, orgs that each mined one changed document
never counted, so a model outage on a quiet deployment never built the
streak. The leg is now judged once the pass tried two documents in all;
the only document a pass tries failing stays that document's. A source
that failed whole no longer needs its own exemption.

SourceTally.add names its failure argument kind. ops.incidents builds
its unread sources answer one way. The docs drop the provider incident
as a signal of a mining outage: the worker's model calls run in the
worker child process by default, whose provider health no request reads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread server/knowledge/app/source_sync.py Resolved
zlareb1 and others added 9 commits December 4, 2026 18:51
The two-try floor is for documents: a source whose mining read, write or
run fails has failed whole, and the leg is judged however few units it
handled, so a store read that fails for a deployment's only source every
pass builds the streak as it did.

The docs name the denominator in full (the orgs with a synced source and
those the leg ran for) and the cost of never counting a refused
credential: a refusal every org's credentials share is not counted
either. _LEAST_TRIES says why it is not a setting.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
The sources cache key is built from the readable collections only when a
collection clause applies, so a renamed parameter raises instead of
sharing the platform admin's entry. The docs say the worker streak
catches an outage of what most orgs' sources rely on, a provider most of
them use included, and that one fewer than half the orgs use is not
counted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
A refused credential's turn counted as handled, so an org whose every
source's credential was refused counted as an org that did not fail and
diluted the active orgs' failures: three dormant orgs beside two failing
active ones noted nothing. Such a turn is now left out of the tally, and
an org with no other turn is not one the leg counts.

ops.incidents calls each cached read a read, not a source, now that one
of them reads document sources, and its cache comment names the sources
key as the org and the collection reach.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Mining and retirement were judged against every org with a usable source,
dormant ones included, so three orgs whose only credential is refused beside
two active orgs whose documents all fail to mine read 2 of 5 and noted
nothing. run_sync now drops those orgs once the turns are done, and judges
retirement there too.

ops.incidents names its read cache's TTL for what it bounds (every read).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
The tally counted a kind once per source while it counted failures per
document, so a mining note could name two sources' failed writes over one
source's 40 failed documents. A kind now weighs its failed units; the sync
and retirement legs add one unit per source and are unchanged.

The orgs whose credential was refused move from the turns tally to
PassResult, the one place that reads them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
The docs and comments said no leg counts such an org, but mining still
counts one whose stored documents it mines, which is right: mining needs
no credential. The text now says so, and a test pins both cases.

A mirrored source is left out of ops.incidents' sources without the wrong
reason that its state is its mirror's, and the HTTP reference names the
incidents cache by its reads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
The generated Go and Rust wire models conflicted; both are regenerated
from the merged registry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
…reads

The comment said a deployment-scoped op reads no namespace's data, with
the request counts as its one org-wide read; the failing sources name
namespaces and sources too. The knowledge and monitoring paragraphs on
source failures are rewrapped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
…rker's failure

Every credential_invalid turn was left out of the tally, so dropping the
previous root secret before the reseal failed every org's sources and
noted nothing. Only a credential the provider refuses is its org's to
rotate; one the deployment cannot open now counts.

Mining counts each failed document under its own reason, not its source's
first, so the note names the reason of most failed documents.

ops.incidents caches a sources answer for a minute: a source's state
changes once a pass and each read parses every state's detail, its
documents' map included. A failed read is still tried again after 5
seconds.

The failure-counting rules are one list in the knowledge page, which the
monitoring page links to.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread server/knowledge/app/sources.py Resolved
A read was cut at the readiness bound on the client only, so the server
ran it on for up to the read class's 30 seconds, and a poll after its
cached failure could start another beside it. Every read now carries the
bound as its statement timeout.

The source sync tally takes `handled` and `fail` in place of one `add`
keyed on argument shape, and the credential check calls credential_of
directly: its only caller sees shared sources alone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread server/knowledge/app/source_sync.py Resolved
zlareb1 and others added 3 commits December 4, 2026 23:18
A failed sources read was tried again after 5 seconds while an answer
was kept a minute, so a read slower than the bound ran every 5 seconds
per process and reach. A failed read is now kept for its read's TTL; a
cached failure names its read in degraded and never changes status.

The knowledge page names the dormant-orgs case beside the one-org case,
and says what ops.incidents' sources lists (the last sync turn) and what
it does not (mining failures). A test covers a failed record write of
documents left waiting.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
`failed` was already the tally's counter and the turn's bool, so the
keyword that holds a failure's kind is `kind`, as in `fail`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
The generated Go and Rust wire models conflicted; both are regenerated
from the merged registry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

There are 3 total unresolved issues (including 2 from previous reviews).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 8607d75. Configure here.

Comment thread server/knowledge/app/source_sync.py Resolved
zlareb1 and others added 24 commits December 5, 2026 00:18
The test built its own clock; the tests rule sends time through
tests/unit/clock_fake.py. It still patches the module's time, so
asyncio.timeout keeps the loop's clock.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
sharing.readable adds each end user's personal collection to the reach,
so every org admin had a read of the failing sources of their own. A
personal collection holds no source (PERSONAL_NAMESPACE), so it is left
out: admins with the same grants share one read, and the answer is the
same. The TTL test now also checks that an answered read serves a
minute, and the monitoring page says each cache is per process.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
… org

The worker streaks are cached under one key for every org; the module
docstring and the cache comment said each read is per org.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
`whole` read as the tally being complete; it says a source's mining
failed whole, so the leg is judged however few units it handled. The
provider-refusal test gave its turn the text of a credential that no
longer opens, the next test's case. The knowledge page says a private
pass reads SYNC_FAILED only when a leg failed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
The monitoring page said sources.read answers as requests does; it is
also unread when the caller's collection grants are not read within the
readiness bound. The reach test's docstring said no caller is served
another's read, while its third caller shares the first one's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
A failed retirement writes no sync state, so the page names the server's
log, the pass's failed count and SOURCE_DELETE_PENDING. A single org's
failures note the pass only when most of its sources, or of the
documents it tried, fail; the page said every failure did. The test
module's docstring names mining's units too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Nothing a tenant does fails a retirement: it deletes Loom's own copies
with no credential. Judged against every org the pass serves, the
failure only this leg catches, a bug in retiring one org's documents,
could never be noted, since a store outage broad enough to reach most
orgs already fails the sync leg. The leg now serves only the orgs whose
removed sources it retired. SourceTally.fail takes its count before its
kind, as handled does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
A failing retirement fails the pass when it fails for most of the orgs
it retired for; half is not most. The knowledge page and the
OpsIncidentSources docstring name it beside the other ways one org's
failures fail the pass, and the orgs comment in run_sync names the legs
judged against them. The Go models' schema hash follows the docstring.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
A pass whose tried documents fail to mine in most orgs fails it too. The
knowledge page sets the failing retirement apart from the two ways one
org becomes the only org the pass serves. The Go models' schema hash
follows the docstring.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
… rule

A platform admin reads every collection; only an org admin's sources
leave out the collections it holds no grant for. _org_reads names its
read verdict `whole`, so `reach` means the collection reach alone, and
the SourcesFailed docstring reads as one clause. The Go models' schema
hash follows the description.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
The corpus case copied the org admin fragment by hand; it is a named
constant now, and a unit test asserts collection_clause builds it.
OpsIncidentSources says a pass that runs a mirrored turn leaves the
streak as it was, and the knowledge page says a lost folder ends its
turn failed and counts like a provider's error. The Go models' schema
hash follows the docstring.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
The tally reads only a turn's status, so a folder the account no longer
sees counts as a provider's error does; most orgs' folders lost in one
pass are more likely Loom's own failure than every org unsharing at
once. The knowledge page gives that reason.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
A lost folder fails every turn of its source until it is shared again or the
source is removed, so losses that build up one by one count as one at once
would. The doc now gives the reason the code has (a wrong stored id gets the
same answer) and that cost. The new test drops a line that repeated the
fixture's default.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
An org whose documents the pass's document bound left waiting counts as
not failed, as one with nothing to mine does, so a model outage is noted
only while a pass's tries reach most orgs; past twice as many orgs as the
bound it never is. The doc states that, and a test pins it: leaving those
orgs out would let one org's failing backlog build the streak alone.

The lost-folder test moves beside the other note tests and asserts the
sync leg's note, the lost-folder threshold is stated per source, and the
mining tally's comment gives `error` its own line.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
The leg notes only when more than half of the orgs the pass serves fail,
so an outage at exactly half is not noted either, and the count is of the
orgs the pass serves, not the deployment's. The retirement spends the
document bound before the sync's fetches do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
…heir own

The fixture's only connected source was also mirrored, and the mirror's
state row had no registry row, so removing `credential_mode = 'shared'` or
`not_reserved_sql()` from the statement failed no test. A namespace source
on a connected credential and a source row in a mirror's namespace now
leave the count at 4 only while both filters stand.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
main's #2165 made an owner's worker copy a mirrored turn (`_mirrored`): the
two turn-tally lines this branch adds in `_sync_turn` use `_mirrored` too,
so a worker copy's failure counts under `SYNC_FAILED`. The generated SDK
models are regenerated over both sides.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
An owner's worker copy whose state write raises is tallied under
`SYNC_FAILED`, never its exception's class, and its pass is private.
OpsIncidentSources keeps what its fields mean and names the Knowledge page
section for when the sync worker is listed, in place of a copy of the rule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
The caller's collection reach is resolved before the sources' statement
starts, each under LOOM_READINESS_CHECK_TIMEOUT_S, so while both are slow
an ops.incidents answer can wait for two bounds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
The generated SDK models are regenerated over both sides.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
The leg counts only when more than half the orgs it serves fail, so an
outage of a provider exactly half the orgs use is not counted either.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
The generated SDK models are regenerated over both sides.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
…me count

The supervisor retries a pass with a noted failed leg after
LOOM_WORKER_PARTIAL_RETRY_S when the worker's interval is longer than that.
Since a failing source now counts only as part of an outage of most orgs,
on such a deployment a failing source outside one waits the whole interval.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
`loom knowledge sync` runs a namespace's sources at once, so the paragraph
says when the worker tries a failing source again, not when anything does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>

This branch has not been deployed

No deployments
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