diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2f4d65d402..0fac01ed2f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1038,6 +1038,7 @@ jobs: tests/integration/test_projection_failures_restricted.py tests/integration/test_mirror_checked_search_http.py tests/integration/test_mirror_checked_list_http.py + tests/integration/test_ops_incidents.py # The statement corpus: every builder's shapes through # EXPLAIN QUERY TREE on the migrated service, and shapes.txt in step # with the builders. ~10 s; a rejection here is a statement that would diff --git a/docs/architecture/document-sources.md b/docs/architecture/document-sources.md index 0f9fd919ef..6ebfe0a13e 100644 --- a/docs/architecture/document-sources.md +++ b/docs/architecture/document-sources.md @@ -636,9 +636,11 @@ the public fallback. No reranking provider receives the provisional pools. source's status, a worker's pass notes, logs, spans and metrics, the extractor service's logs and traces) carries codes only (exceptions 3 and 4 apart). Worker pass summaries exclude mirrored turns' completed-source counts, document - figures and cut flags. A failed mirrored turn contributes only `SYNC_FAILED`, for - every cause; returned turn details remain private. Mirrored per-file failures emit - no log record, since the number of records would disclose a document figure. + figures and cut flags. A failed mirrored turn contributes only `SYNC_FAILED` and + counts as failed in the pass's per-org tally of turns, for every cause, a refused + credential included; returned turn details remain private. `ops.incidents`' + `sources` counts no mirrored source. Mirrored per-file failures emit no log record, + since the number of records would disclose a document figure. A sync turn enters its private diagnostic scope before taking its source lease or listing files; retirement enters it before reading its queue. That scope suppresses client and provider instrumentation, database diff --git a/docs/features/knowledge.md b/docs/features/knowledge.md index 884490b185..b21ecdeea7 100644 --- a/docs/features/knowledge.md +++ b/docs/features/knowledge.md @@ -679,6 +679,65 @@ A source's `sync` in `list` and `inspect` shows what its last turn did: | `unextracted` | Documents it gave up on: three failed tries, or too large for a pass. | | `extract_error` | Why an extraction failed in the last mining turn (`not_run`, `refused`, `out_of_time`, `too_large_for_pass`, `failed:`), or why documents wait (`over_cap`, `switched_off`, `switch_unread`, `no_model`, `held`, `held:`, `pass_bound`). | +### Source failures and the worker's health + +A failed turn belongs to its source: its `status` and `error` here, and for an org admin +the org's failing sources in +[`ops.incidents`](../operations/monitoring.md#opsincidents)' `sources`. It counts toward +the worker's failure streak only as part of an outage of most orgs: + +- A leg of a pass (the sync turns, the mining, the retirement of removed sources) fails + the pass when most of the orgs it serves had most of their units fail: sources, or + for the mining the documents it tried. The worker's status row then reads + `SourcesFailed`, with an error that names the leg, such as + `sync: failed for most sources in 3 of 4 orgs (most often failed)`. +- The sync turns and the mining serve the orgs with a source the pass syncs and those + they ran for. An org a leg had nothing to do for, or that the pass bound left for the + next pass, has not failed. +- The retirement serves only the orgs whose removed sources it retired: nothing a + tenant does fails a retirement, which deletes Loom's own copies with no credential, so + one org's failing retirement fails the pass when it fails for most of the orgs it + retired for, as when that org is the only one retiring. +- So what most orgs' sources rely on counts: the store, a provider most of them use, the + model, or the deployment's secret, when it no longer opens the stored credentials. So + does a failure of most of an org's sources, or of the documents it tried, where that + org is the only one the pass serves: it holds every source the pass syncs, or every + other org's turns were refused. So does the failing retirement above. Otherwise one + org's failing sources, however many they are, never degrade the worker or + `ops.incidents` for the other orgs, and neither does an outage of a provider fewer + than half the orgs use. +- A source another copy holds counts neither way. +- A credential the provider refuses (`credential_invalid`) on a namespace's source is + its org's to rotate, so the turn is left out. An org whose every turn was refused + counts only in a leg that ran for it, such as mining the documents it stored before, + so dormant orgs never hide an outage of the active ones. A refusal every org's + credentials share, such as a provider refusing every token exchange of a host whose + clock is off, is not counted either. +- A folder or shared drive the account no longer sees ends its turn `failed`, as a + provider's error does, and counts: Loom asking for an item by a wrong id gets the same + answer. The cost: a lost folder fails every turn of its source until it is shared + again or the source is removed, so on a deployment where, in most orgs, most sources + each lost a folder or shared drive, at once or one by one, the sync leg fails every + pass. +- The mining leg is judged from two documents tried in the pass, or from one source that + failed whole: its documents unread, its record unwritten, or its mining raised. The + only document a pass tries failing to mine is that document's. An org with nothing to + mine has not failed, nor has one whose documents the pass's document bound + (`LOOM_KNOWLEDGE_SOURCE_SYNC_DOCUMENTS_PER_PASS`, which the retirement and the sync's + fetches spend first) left waiting. So a model outage is not counted 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. +- A pass that runs any mirrored turn is private, and the worker's streak stays as it + was: while auth is on, on a deployment with an active mirrored source, no leg's failure + reaches the streak, and a pass with a failed leg reads `SYNC_FAILED` in its status row. + +Counted or not, a source whose last sync turn failed shows in its `status` and in its +org's `ops.incidents` `sources`, and a document that failed to mine shows in its +source's `extract_error`. A removed source whose documents could not be retired shows +in the server's log, and `add` with its name answers `SOURCE_DELETE_PENDING` until its +documents are retired; the next pass tries again. + ### A recording source A `recording` source reads transcripts, never audio or video, and nothing in Loom diff --git a/docs/operations/monitoring.md b/docs/operations/monitoring.md index 1dca93dd08..90ad946ee6 100644 --- a/docs/operations/monitoring.md +++ b/docs/operations/monitoring.md @@ -164,17 +164,43 @@ token (never an org admin) and a `*` token that names no org read none. The othe are deployment state, the same for every org: a readiness or provider incident names the check or provider and an error's kind, as `/v1/health` does, and a worker incident names a worker of any of the deployment's processes with its streak and error kind, where -`/v1/health?include=workers` shows only the answering process's workers. Each ClickHouse -source is read at most once every 5 seconds per process, however many clients poll during -an outage, and each read is cut at `LOOM_READINESS_CHECK_TIMEOUT_S`. A source that failed -is named in the response's `degraded` while its failure is cached, and the other sources -still answer. +`/v1/health?include=workers` shows only the answering process's workers. In each +process, each of its ClickHouse reads runs at most once every 5 seconds (the worker +streaks, and the request counts per org), and the failing sources once a minute per org +and collection reach, since a source's sync state changes once a pass and each read +parses every one of the org's. A person's own collection holds no source and is left out +of the reach, so org admins with the same grants share a read. That holds however many +clients poll during an outage, and each read is cut at `LOOM_READINESS_CHECK_TIMEOUT_S`. +A read that failed is named in the response's `degraded` while its failure is cached, as +long as an answer would be, and the other reads still answer. +The caller's collection reach, which the failing sources need, comes from the grant +cache every call uses and is cut at the same bound. It is resolved before the sources' +statement starts, so while both are slow an answer can wait for two bounds. Every answer says in `requests` whether the org's call counts were read, since `ok` covers the org's calls only when they were: `read`; `not_permitted` when the call names no single org or the caller does not read the org whole; `unread` when the counts, the restricted set or a restricted namespace's grant could not be read. +`sources` lists the org's own +[document sources](../features/knowledge.md#syncing-a-source) whose last sync turn +failed: `failing`, how many, and `sample`, at most 5 of them (`{namespace, name, +status}`), the latest failure first, with `status` `failed`, `rate_limited` or +`credential_invalid`. It counts only the sources every reader of their namespace sees, +never a mirrored or a person's connected one. It is read under the same rule as the +request counts, and `sources.read` answers in the same words; it is also `unread` when +the caller's collection grants could not be read within +`LOOM_READINESS_CHECK_TIMEOUT_S`. It leaves out the collections the caller holds no +grant for, since an org admin reaches a collection only through a grant (a platform +admin reads every one). A failing document source is never +an incident and never by itself makes `status` `degraded`: a revoked credential is its +org's to rotate, and `status` stays Loom's own health. The `knowledge_source_sync` +worker becomes a `worker` incident after 3 failed passes in a row, like any worker. A +pass fails when it fails outright (its source list or registry unread, or past its +deadline), or when a leg of it fails for most of the orgs it serves, as +[source failures and the worker's health](../features/knowledge.md#source-failures-and-the-workers-health) +describes. + ### Smoke test After a deploy, write and read one memory end to end: diff --git a/docs/reference/http-api.md b/docs/reference/http-api.md index 3bbaebda03..9bc61772c8 100644 --- a/docs/reference/http-api.md +++ b/docs/reference/http-api.md @@ -376,7 +376,9 @@ error's kind only; the full text is in the server log. - `LOOM_CODE_PR_OVERLAY_FILE_TTL_S`: the PR overlay's per-file parse and edge results, including a parse or call extraction that failed, which each overlay built from them names; - - 5 seconds: each of `ops.incidents`' ClickHouse sources. + - 5 seconds: `ops.incidents`' worker streaks and the org's request counts; 60 + seconds: its failing sources per collection reach. A read that failed is cached as + long. - A later page of `code.search`, `code.grep` or `memory.search` names the entries of the run that ranked its pool. What each page reads for itself (the risk block, context lines, definitions, tags, bodies) it notes on its own. diff --git a/docs/reference/operations/ops.md b/docs/reference/operations/ops.md index 430bcab4d6..76a985b830 100644 --- a/docs/reference/operations/ops.md +++ b/docs/reference/operations/ops.md @@ -55,10 +55,11 @@ Whether Loom is degraded now, from its checks, providers, workers and calls. | Output field | Type | Meaning | | --- | --- | --- | -| `status` | `Literal['ok', 'degraded']` | `degraded` when an incident is listed, else `ok`. | +| `status` | `Literal['ok', 'degraded']` | `degraded` when an incident is listed, else `ok`; failing `sources` are no incident. | | `incidents` | `list[OpsIncident]` | Errors first, at most 20. | | `window_minutes` | `int` | Minutes of history a `provider` or `requests` incident reads. | | `requests` | `Literal['read', 'not_permitted', 'unread']` | Whether the org's call counts were read, so `ok` covers its calls only with `read`: `not_permitted` when the call names no single org or the caller does not read the org whole (a member, a narrowed, pinned or delegated token, a restricted… | +| `sources` | `OpsIncidentSources` | The org's document sources whose last sync failed, for its admin to fix; by default none, unread (`{failing: 0, sample: [], read: "unread"}`). | ## `ops.projection_failures.list` diff --git a/sdk/go/client.gen.go b/sdk/go/client.gen.go index 8f4efe685d..d36de32400 100644 --- a/sdk/go/client.gen.go +++ b/sdk/go/client.gen.go @@ -2429,6 +2429,9 @@ type OpsCapabilitiesInput = wire.OpsCapabilitiesInput // OpsCapabilitiesOutput is the response from ops.capabilities. type OpsCapabilitiesOutput = wire.OpsCapabilitiesOutput +// OpsFailingSource is a model used by Loom operations. +type OpsFailingSource = wire.OpsFailingSource + // OpsHealthCheck is a model used by Loom operations. type OpsHealthCheck = wire.OpsHealthCheck @@ -2441,6 +2444,9 @@ type OpsHealthOutput = wire.OpsHealthOutput // OpsIncident is a model used by Loom operations. type OpsIncident = wire.OpsIncident +// OpsIncidentSources is a model used by Loom operations. +type OpsIncidentSources = wire.OpsIncidentSources + // OpsIncidentsInput is the request to ops.incidents. type OpsIncidentsInput = wire.OpsIncidentsInput diff --git a/sdk/go/wire/models.gen.go b/sdk/go/wire/models.gen.go index e570c3de4c..c317b7f956 100644 --- a/sdk/go/wire/models.gen.go +++ b/sdk/go/wire/models.gen.go @@ -1,5 +1,5 @@ // Code generated by scripts/codegen/sdk_go_gen.py; DO NOT EDIT. -// Registry model schema SHA-256: b16f6d929017e2e8c78f781b61ad1c470911724f386c47e92f1206c1222a6b95 +// Registry model schema SHA-256: 90a544a003f1da51c5c966513cffb36932a55baa9b68ecd8d036b40231bf9842 // Package wire contains the Go requests and responses for Loom operations. package wire @@ -10210,6 +10210,13 @@ type OpsCapabilitiesOutput struct { ConsumerField *string `json:"consumer_field,omitempty"` } +// OpsFailingSource is a model used by Loom operations. +type OpsFailingSource struct { + Namespace string `json:"namespace"` + Name string `json:"name"` + Status string `json:"status"` +} + // OpsHealthCheck is a model used by Loom operations. type OpsHealthCheck struct { Name string `json:"name"` @@ -10245,6 +10252,13 @@ type OpsIncident struct { AgeS Optional[float64] `json:"age_s,omitempty"` } +// OpsIncidentSources is a model used by Loom operations. +type OpsIncidentSources struct { + Failing *int64 `json:"failing,omitempty"` + Sample *[]OpsFailingSource `json:"sample,omitempty"` + Read *string `json:"read,omitempty"` +} + // OpsIncidentsInput is the request to ops.incidents. type OpsIncidentsInput struct { Org *string `json:"org,omitempty"` @@ -10252,14 +10266,15 @@ type OpsIncidentsInput struct { // OpsIncidentsOutput is the response from ops.incidents. type OpsIncidentsOutput struct { - IgnoredArgs *[]string `json:"ignored_args,omitempty"` - DidYouMean *map[string]string `json:"did_you_mean,omitempty"` - Mirrored *bool `json:"mirrored,omitempty"` - Degraded *[]string `json:"degraded,omitempty"` - Status string `json:"status"` - Incidents *[]OpsIncident `json:"incidents,omitempty"` - WindowMinutes int64 `json:"window_minutes"` - Requests string `json:"requests"` + IgnoredArgs *[]string `json:"ignored_args,omitempty"` + DidYouMean *map[string]string `json:"did_you_mean,omitempty"` + Mirrored *bool `json:"mirrored,omitempty"` + Degraded *[]string `json:"degraded,omitempty"` + Status string `json:"status"` + Incidents *[]OpsIncident `json:"incidents,omitempty"` + WindowMinutes int64 `json:"window_minutes"` + Requests string `json:"requests"` + Sources *OpsIncidentSources `json:"sources,omitempty"` } // OpsProjectionFailuresListInput is the request to ops.projection_failures.list. diff --git a/sdk/python/loom/ops.py b/sdk/python/loom/ops.py index 5bafc079a0..421301a289 100644 --- a/sdk/python/loom/ops.py +++ b/sdk/python/loom/ops.py @@ -18857,6 +18857,7 @@ class OpsIncidentsOutput(TypedDict, total=False): incidents: NotRequired[list["OpsIncident"]] window_minutes: Required[int] requests: Required[Literal["read", "not_permitted", "unread"]] + sources: NotRequired["OpsIncidentSources"] class OpsIncident(TypedDict, total=False): @@ -18867,6 +18868,20 @@ class OpsIncident(TypedDict, total=False): age_s: NotRequired[Optional[float]] +class OpsIncidentSources(TypedDict, total=False): + "The org's own document sources whose last sync turn failed." + + failing: NotRequired[int] + sample: NotRequired[list["OpsFailingSource"]] + read: NotRequired[Literal["read", "not_permitted", "unread"]] + + +class OpsFailingSource(TypedDict, total=False): + namespace: Required[str] + name: Required[str] + status: Required[str] + + class OpsProjectionFailuresListInput(TypedDict, total=False): org: Required[str] namespace: NotRequired[Optional[str]] diff --git a/sdk/rust/src/wire_models.rs b/sdk/rust/src/wire_models.rs index c667a6cafe..b306d6491f 100644 --- a/sdk/rust/src/wire_models.rs +++ b/sdk/rust/src/wire_models.rs @@ -50704,6 +50704,36 @@ pub enum OpsIncidentsOutputRequests { Unread, } +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[non_exhaustive] +pub struct OpsFailingSource { + pub namespace: String, + pub name: String, + pub status: String, +} + +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[non_exhaustive] +pub enum OpsIncidentSourcesRead { + #[serde(rename = "read")] + Read, + #[serde(rename = "not_permitted")] + NotPermitted, + #[serde(rename = "unread")] + Unread, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[non_exhaustive] +pub struct OpsIncidentSources { + #[serde(default = "default_2233")] + pub failing: Integer, + #[serde(default = "default_2234")] + pub sample: Vec, + #[serde(default = "default_2235")] + pub read: OpsIncidentSourcesRead, +} + #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[non_exhaustive] pub struct OpsIncidentsOutput { @@ -50712,6 +50742,8 @@ pub struct OpsIncidentsOutput { pub incidents: Vec, pub window_minutes: Integer, pub requests: OpsIncidentsOutputRequests, + #[serde(default = "default_2236")] + pub sources: OpsIncidentSources, } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] @@ -50752,26 +50784,26 @@ pub struct ProjectionFailureRow { pub failure_id: String, pub org: String, pub namespace: String, - #[serde(default = "default_2233")] + #[serde(default = "default_2237")] pub agent: String, pub projection: String, - #[serde(default = "default_2234")] + #[serde(default = "default_2238")] pub source_operation: String, - #[serde(default = "default_2235")] + #[serde(default = "default_2239")] pub source_resource_id: String, - #[serde(default = "default_2236")] + #[serde(default = "default_2240")] pub memory_keys: Vec, - #[serde(default = "default_2237")] + #[serde(default = "default_2241")] pub error_type: String, - #[serde(default = "default_2238")] + #[serde(default = "default_2242")] pub error_message: String, - #[serde(default = "default_2239")] + #[serde(default = "default_2243")] pub payload: std::collections::HashMap, - #[serde(default = "default_2240")] + #[serde(default = "default_2244")] pub status: String, - #[serde(default = "default_2241")] + #[serde(default = "default_2245")] pub created_at: Option, - #[serde(default = "default_2242")] + #[serde(default = "default_2246")] pub resolved_at: Option, } @@ -50925,22 +50957,22 @@ pub struct ProjectionFailureRetryRow { pub projection: String, pub retried: bool, pub resolved: bool, - #[serde(default = "default_2243")] + #[serde(default = "default_2247")] pub abandoned: bool, - #[serde(default = "default_2244")] + #[serde(default = "default_2248")] pub reason: String, - #[serde(default = "default_2245")] + #[serde(default = "default_2249")] pub error: String, } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[non_exhaustive] pub struct ProjectionFailureRetryOutput { - #[serde(default = "default_2246")] + #[serde(default = "default_2250")] pub results: Vec, pub retried: Integer, pub resolved: Integer, - #[serde(default = "default_2247")] + #[serde(default = "default_2251")] pub abandoned: Integer, } @@ -51022,15 +51054,15 @@ impl ProjectionFailureRetryInput { pub struct OrgModelCallsOutput { pub org: String, pub enabled: bool, - #[serde(default = "default_2248")] + #[serde(default = "default_2252")] pub reason: String, - #[serde(default = "default_2249")] + #[serde(default = "default_2253")] pub updated_by: String, - #[serde(default = "default_2250")] + #[serde(default = "default_2254")] pub updated_at: Option, - #[serde(default = "default_2251")] + #[serde(default = "default_2255")] pub locked: bool, - #[serde(default = "default_2252")] + #[serde(default = "default_2256")] pub locked_by: String, } @@ -51369,7 +51401,7 @@ impl PolicyDecisionsInput { #[non_exhaustive] pub struct PolicyDeleteOutput { pub removed: bool, - #[serde(default = "default_2253")] + #[serde(default = "default_2257")] pub widening: bool, } @@ -51435,12 +51467,12 @@ pub struct PolicyRuleOut { pub condition: std::collections::HashMap, pub description: String, pub enabled: bool, - #[serde(default = "default_2254")] + #[serde(default = "default_2258")] pub mode: String, pub created_by: String, - #[serde(default = "default_2255")] + #[serde(default = "default_2259")] pub created_at: Option, - #[serde(default = "default_2256")] + #[serde(default = "default_2260")] pub updated_at: Option, } @@ -51512,9 +51544,9 @@ impl PolicyListInput { pub struct PolicySetOutput { pub rule: PolicyRuleOut, pub leaf_count: Integer, - #[serde(default = "default_2257")] + #[serde(default = "default_2261")] pub widening: bool, - #[serde(default = "default_2258")] + #[serde(default = "default_2262")] pub change: Vec, } @@ -51784,37 +51816,37 @@ pub struct ProcedureEvolveOutput { pub revision: Integer, pub changed: bool, pub template: bool, - #[serde(default = "default_2259")] + #[serde(default = "default_2263")] pub folded_runs: Integer, - #[serde(default = "default_2260")] + #[serde(default = "default_2264")] pub gate: ProcedureEvolveOutputGate, - #[serde(default = "default_2261")] + #[serde(default = "default_2265")] pub gate_mode: String, - #[serde(default = "default_2262")] + #[serde(default = "default_2266")] pub gate_llr: f64, - #[serde(default = "default_2263")] + #[serde(default = "default_2267")] pub gate_before: std::collections::HashMap, - #[serde(default = "default_2264")] + #[serde(default = "default_2268")] pub gate_after: std::collections::HashMap, - #[serde(default = "default_2265")] + #[serde(default = "default_2269")] pub gate_cost_before: std::collections::HashMap, - #[serde(default = "default_2266")] + #[serde(default = "default_2270")] pub gate_cost_after: std::collections::HashMap, - #[serde(default = "default_2267")] + #[serde(default = "default_2271")] pub gate_reason: String, - #[serde(default = "default_2268")] + #[serde(default = "default_2272")] pub dead_end_steps: Vec, - #[serde(default = "default_2269")] + #[serde(default = "default_2273")] pub fail_prone_steps: Vec, - #[serde(default = "default_2270")] + #[serde(default = "default_2274")] pub fail_prone_transitions: Vec, - #[serde(default = "default_2271")] + #[serde(default = "default_2275")] pub run_stats: std::collections::HashMap, - #[serde(default = "default_2272")] + #[serde(default = "default_2276")] pub strikes: Integer, - #[serde(default = "default_2273")] + #[serde(default = "default_2277")] pub quarantined: bool, - #[serde(default = "default_2274")] + #[serde(default = "default_2278")] pub retention: std::collections::HashMap, } @@ -52037,9 +52069,9 @@ pub struct ProcedureForkOutput { pub memory_key: String, pub version: Integer, pub name: String, - #[serde(default = "default_2275")] + #[serde(default = "default_2279")] pub steps: Vec, - #[serde(default = "default_2276")] + #[serde(default = "default_2280")] pub forked_from: std::collections::HashMap, } @@ -52299,32 +52331,32 @@ pub enum ProcedureLocateOutputStatus { #[non_exhaustive] pub struct ProcedureLocateOutput { pub memory_key: String, - #[serde(default = "default_2277")] + #[serde(default = "default_2281")] pub name: String, - #[serde(default = "default_2278")] + #[serde(default = "default_2282")] pub status: ProcedureLocateOutputStatus, pub matched: bool, - #[serde(default = "default_2279")] + #[serde(default = "default_2283")] pub active: Option>, - #[serde(default = "default_2280")] + #[serde(default = "default_2284")] pub hops: Vec>>, - #[serde(default = "default_2281")] + #[serde(default = "default_2285")] pub entry_nodes: Vec, - #[serde(default = "default_2282")] + #[serde(default = "default_2286")] pub dominant_next: Vec, - #[serde(default = "default_2283")] + #[serde(default = "default_2287")] pub revisits: std::collections::HashMap, - #[serde(default = "default_2284")] + #[serde(default = "default_2288")] pub looping: bool, - #[serde(default = "default_2285")] + #[serde(default = "default_2289")] pub exits: Vec, - #[serde(default = "default_2286")] + #[serde(default = "default_2290")] pub failure_notes: Vec>, - #[serde(default = "default_2287")] + #[serde(default = "default_2291")] pub rendered: String, - #[serde(default = "default_2288")] + #[serde(default = "default_2292")] pub run_stats: std::collections::HashMap, - #[serde(default = "default_2289")] + #[serde(default = "default_2293")] pub for_agent: std::collections::HashMap, } @@ -52479,43 +52511,43 @@ pub struct ProcedureMatch { pub name: String, pub situation: String, pub steps: Vec, - #[serde(default = "default_2290")] + #[serde(default = "default_2294")] pub tags: Vec, - #[serde(default = "default_2291")] + #[serde(default = "default_2295")] pub metadata: std::collections::HashMap, pub similarity: f64, pub memory_key: String, pub namespace: String, - #[serde(default = "default_2292")] + #[serde(default = "default_2296")] pub graph: Option>, - #[serde(default = "default_2293")] + #[serde(default = "default_2297")] pub template: bool, - #[serde(default = "default_2294")] + #[serde(default = "default_2298")] pub run_stats: std::collections::HashMap, - #[serde(default = "default_2295")] + #[serde(default = "default_2299")] pub status: ProcedureMatchStatus, - #[serde(default = "default_2296")] + #[serde(default = "default_2300")] pub quarantined: Option>, - #[serde(default = "default_2297")] + #[serde(default = "default_2301")] pub fail_prone_steps: Vec, - #[serde(default = "default_2298")] + #[serde(default = "default_2302")] pub revision: Integer, - #[serde(default = "default_2299")] + #[serde(default = "default_2303")] pub rejected_revisions: Vec>, - #[serde(default = "default_2300")] + #[serde(default = "default_2304")] pub tool_overlap: f64, - #[serde(default = "default_2301")] + #[serde(default = "default_2305")] pub score: f64, - #[serde(default = "default_2302")] + #[serde(default = "default_2306")] pub utility: f64, - #[serde(default = "default_2303")] + #[serde(default = "default_2307")] pub goal_similarity: Option, - #[serde(default = "default_2304")] + #[serde(default = "default_2308")] pub for_agent: std::collections::HashMap, - #[serde(default = "default_2305")] + #[serde(default = "default_2309")] pub run_stats_by_agent: std::collections::HashMap>, - #[serde(default = "default_2306")] + #[serde(default = "default_2310")] pub actor: String, } @@ -52523,11 +52555,11 @@ pub struct ProcedureMatch { #[non_exhaustive] pub struct ProcedureMatchOutput { pub matches: Vec, - #[serde(default = "default_2307")] + #[serde(default = "default_2311")] pub matched: Integer, - #[serde(default = "default_2308")] + #[serde(default = "default_2312")] pub procedure_key: String, - #[serde(default = "default_2309")] + #[serde(default = "default_2313")] pub score: f64, } @@ -52919,9 +52951,9 @@ pub struct ProcedureReviseOutput { pub revision: Integer, pub prior_revision: Integer, pub digest: String, - #[serde(default = "default_2310")] + #[serde(default = "default_2314")] pub steps: Vec, - #[serde(default = "default_2311")] + #[serde(default = "default_2315")] pub outcome: ProcedureReviseOutputOutcome, } @@ -53033,14 +53065,14 @@ pub struct ProfileActivityEntry { pub agent: String, pub last_activated_at: String, pub event_count: Integer, - #[serde(default = "default_2312")] + #[serde(default = "default_2316")] pub operations: Vec, } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[non_exhaustive] pub struct ProfileActivityOutput { - #[serde(default = "default_2313")] + #[serde(default = "default_2317")] pub entries: Vec, } @@ -53148,17 +53180,17 @@ impl ProfileActivityInput { #[non_exhaustive] pub struct ProfileMutationOutput { pub version: Integer, - #[serde(default = "default_2314")] + #[serde(default = "default_2318")] pub memory_id: String, - #[serde(default = "default_2315")] + #[serde(default = "default_2319")] pub content_sha256: String, - #[serde(default = "default_2316")] + #[serde(default = "default_2320")] pub namespace: String, - #[serde(default = "default_2317")] + #[serde(default = "default_2321")] pub label: String, - #[serde(default = "default_2318")] + #[serde(default = "default_2322")] pub char_limit: Option, - #[serde(default = "default_2319")] + #[serde(default = "default_2323")] pub value_length: Integer, } @@ -53267,7 +53299,7 @@ pub struct ProfileRenderOutput { pub rendered: String, pub section_count: Integer, pub total_chars: Integer, - #[serde(default = "default_2320")] + #[serde(default = "default_2324")] pub labels: Vec, } @@ -53652,17 +53684,17 @@ pub enum ProfileStructuredOutputStatus { #[non_exhaustive] pub struct ProfileStructuredOutput { pub status: ProfileStructuredOutputStatus, - #[serde(default = "default_2321")] + #[serde(default = "default_2325")] pub profile: std::collections::HashMap, - #[serde(default = "default_2322")] + #[serde(default = "default_2326")] pub built_at: Option, - #[serde(default = "default_2323")] + #[serde(default = "default_2327")] pub memory_id: String, - #[serde(default = "default_2324")] + #[serde(default = "default_2328")] pub version: Integer, - #[serde(default = "default_2325")] + #[serde(default = "default_2329")] pub version_text: String, - #[serde(default = "default_2326")] + #[serde(default = "default_2330")] pub schema_sha256: String, } @@ -53779,13 +53811,13 @@ impl ProfileStructuredInput { #[non_exhaustive] pub struct ProfileSchemaOutput { pub found: bool, - #[serde(default = "default_2327")] + #[serde(default = "default_2331")] pub json_schema: std::collections::HashMap, - #[serde(default = "default_2328")] + #[serde(default = "default_2332")] pub schema_sha256: String, - #[serde(default = "default_2329")] + #[serde(default = "default_2333")] pub updated_by: String, - #[serde(default = "default_2330")] + #[serde(default = "default_2334")] pub updated_at: Option, } @@ -53938,10 +53970,10 @@ pub enum RunBeginOutputStatus { #[non_exhaustive] pub struct RunBeginOutput { pub run_id: String, - #[serde(default = "default_2331")] + #[serde(default = "default_2335")] pub status: RunBeginOutputStatus, pub started_at: String, - #[serde(default = "default_2332")] + #[serde(default = "default_2336")] pub next: String, } @@ -54149,31 +54181,31 @@ pub struct RunCompleteOutput { pub run_id: String, pub status: RunCompleteOutputStatus, pub duration_ms: Integer, - #[serde(default = "default_2333")] + #[serde(default = "default_2337")] pub used_applied: Integer, - #[serde(default = "default_2334")] + #[serde(default = "default_2338")] pub undelivered: Integer, - #[serde(default = "default_2335")] + #[serde(default = "default_2339")] pub evidence_applied: Integer, - #[serde(default = "default_2336")] + #[serde(default = "default_2340")] pub harm_applied: Integer, - #[serde(default = "default_2337")] + #[serde(default = "default_2341")] pub memories_written: Vec, - #[serde(default = "default_2338")] + #[serde(default = "default_2342")] pub recalled: Integer, - #[serde(default = "default_2339")] + #[serde(default = "default_2343")] pub observations: Integer, - #[serde(default = "default_2340")] + #[serde(default = "default_2344")] pub procedure_runs_recorded: Integer, - #[serde(default = "default_2341")] + #[serde(default = "default_2345")] pub reflection_key: String, - #[serde(default = "default_2342")] + #[serde(default = "default_2346")] pub retain: String, - #[serde(default = "default_2343")] + #[serde(default = "default_2347")] pub retained: Integer, - #[serde(default = "default_2344")] + #[serde(default = "default_2348")] pub demoted: Integer, - #[serde(default = "default_2345")] + #[serde(default = "default_2349")] pub expiring: Integer, } @@ -54714,25 +54746,25 @@ pub enum RunGetOutputOverBudgetItem { #[non_exhaustive] pub struct RunGetOutput { pub found: bool, - #[serde(default = "default_2346")] + #[serde(default = "default_2350")] pub run: Option, - #[serde(default = "default_2347")] + #[serde(default = "default_2351")] pub recalled: Integer, - #[serde(default = "default_2348")] + #[serde(default = "default_2352")] pub recalled_keys: Vec, - #[serde(default = "default_2349")] + #[serde(default = "default_2353")] pub memories_written: Vec, - #[serde(default = "default_2350")] + #[serde(default = "default_2354")] pub observations: Integer, - #[serde(default = "default_2351")] + #[serde(default = "default_2355")] pub turns: Integer, - #[serde(default = "default_2352")] + #[serde(default = "default_2356")] pub unpriced_turns: Integer, - #[serde(default = "default_2353")] + #[serde(default = "default_2357")] pub cost_usd: f64, - #[serde(default = "default_2354")] + #[serde(default = "default_2358")] pub elapsed_seconds: Integer, - #[serde(default = "default_2355")] + #[serde(default = "default_2359")] pub over_budget: Vec, } @@ -54799,17 +54831,17 @@ pub struct RunGradeProposal { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[non_exhaustive] pub struct RunGradeOutput { - #[serde(default = "default_2356")] + #[serde(default = "default_2360")] pub graded: Integer, - #[serde(default = "default_2357")] + #[serde(default = "default_2361")] pub run_ids: Vec, - #[serde(default = "default_2358")] + #[serde(default = "default_2362")] pub skipped_active: Integer, - #[serde(default = "default_2359")] + #[serde(default = "default_2363")] pub unchanged: Integer, - #[serde(default = "default_2360")] + #[serde(default = "default_2364")] pub memories_counted: Integer, - #[serde(default = "default_2361")] + #[serde(default = "default_2365")] pub proposals_decided: Vec, } @@ -54924,7 +54956,7 @@ impl RunGradeInput { #[non_exhaustive] pub struct RunListOutput { pub runs: Vec, - #[serde(default = "default_2362")] + #[serde(default = "default_2366")] pub total: Option, } @@ -55161,7 +55193,7 @@ pub enum RunRelianceItemState { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[non_exhaustive] pub struct RunRelianceRevision { - #[serde(default = "default_2363")] + #[serde(default = "default_2367")] pub versions: Vec, } @@ -55171,9 +55203,9 @@ pub struct RunRelianceItem { pub kind: String, pub key: String, pub state: RunRelianceItemState, - #[serde(default = "default_2364")] + #[serde(default = "default_2368")] pub revisions: Vec, - #[serde(default = "default_2365")] + #[serde(default = "default_2369")] pub last_served_at: String, } @@ -55181,9 +55213,9 @@ pub struct RunRelianceItem { #[non_exhaustive] pub struct RunRelianceOutput { pub found: bool, - #[serde(default = "default_2366")] + #[serde(default = "default_2370")] pub items: Vec, - #[serde(default = "default_2367")] + #[serde(default = "default_2371")] pub truncated: bool, } @@ -55232,19 +55264,19 @@ impl RunRelianceInput { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[non_exhaustive] pub struct RunRetractCreditOutput { - #[serde(default = "default_2368")] + #[serde(default = "default_2372")] pub run_id: String, - #[serde(default = "default_2369")] + #[serde(default = "default_2373")] pub used_retracted: Integer, - #[serde(default = "default_2370")] + #[serde(default = "default_2374")] pub evidence_retracted: Integer, - #[serde(default = "default_2371")] + #[serde(default = "default_2375")] pub harm_retracted: Integer, - #[serde(default = "default_2372")] + #[serde(default = "default_2376")] pub events_written: Integer, - #[serde(default = "default_2373")] + #[serde(default = "default_2377")] pub more: bool, - #[serde(default = "default_2374")] + #[serde(default = "default_2378")] pub dry_run: bool, } @@ -55401,39 +55433,39 @@ pub struct LiveSearchHit { pub title: String, pub url: String, pub provider: LiveSearchHitProvider, - #[serde(default = "default_2377")] + #[serde(default = "default_2381")] pub content: String, - #[serde(default = "default_2378")] + #[serde(default = "default_2382")] pub live: LiveSearchHitLive, } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[non_exhaustive] pub struct LiveSearchResults { - #[serde(default = "default_2376")] + #[serde(default = "default_2380")] pub live: LiveSearchResultsLive, - #[serde(default = "default_2379")] + #[serde(default = "default_2383")] pub results: Vec, } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[non_exhaustive] pub struct SearchOutput { - #[serde(default = "default_2375")] + #[serde(default = "default_2379")] pub tracker: Option>, - #[serde(default = "default_2380")] + #[serde(default = "default_2384")] pub live: Option, - #[serde(default = "default_2381")] + #[serde(default = "default_2385")] pub memory: std::collections::HashMap, - #[serde(default = "default_2382")] + #[serde(default = "default_2386")] pub knowledge: std::collections::HashMap, - #[serde(default = "default_2383")] + #[serde(default = "default_2387")] pub profile: std::collections::HashMap, - #[serde(default = "default_2384")] + #[serde(default = "default_2388")] pub conversations: std::collections::HashMap, - #[serde(default = "default_2385")] + #[serde(default = "default_2389")] pub withheld: Option>, - #[serde(default = "default_2386")] + #[serde(default = "default_2390")] pub namespaces_skipped: Vec, } @@ -55637,7 +55669,7 @@ impl SearchInput { pub struct SessionBriefDeleteOutput { pub deleted: bool, pub brief_key: String, - #[serde(default = "default_2387")] + #[serde(default = "default_2391")] pub revision: Integer, } @@ -55730,67 +55762,67 @@ impl SessionBriefDeleteInput { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[non_exhaustive] pub struct BriefDecision { - #[serde(default = "default_2396")] + #[serde(default = "default_2400")] pub what: String, - #[serde(default = "default_2397")] + #[serde(default = "default_2401")] pub why: String, } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[non_exhaustive] pub struct BriefDeadEnd { - #[serde(default = "default_2399")] + #[serde(default = "default_2403")] pub tried: String, - #[serde(default = "default_2400")] + #[serde(default = "default_2404")] pub why_not: String, } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[non_exhaustive] pub struct BriefDone { - #[serde(default = "default_2402")] + #[serde(default = "default_2406")] pub what: String, - #[serde(rename = "ref", default = "default_2403")] + #[serde(rename = "ref", default = "default_2407")] pub r#ref: String, } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[non_exhaustive] pub struct BriefFile { - #[serde(default = "default_2407")] + #[serde(default = "default_2411")] pub path: String, - #[serde(default = "default_2408")] + #[serde(default = "default_2412")] pub role: String, } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[non_exhaustive] pub struct BriefSections { - #[serde(default = "default_2393")] + #[serde(default = "default_2397")] pub goal: String, - #[serde(default = "default_2394")] + #[serde(default = "default_2398")] pub status: String, - #[serde(default = "default_2395")] + #[serde(default = "default_2399")] pub verification: String, - #[serde(default = "default_2398")] + #[serde(default = "default_2402")] pub decisions: Vec, - #[serde(default = "default_2401")] + #[serde(default = "default_2405")] pub dead_ends: Vec, - #[serde(default = "default_2404")] + #[serde(default = "default_2408")] pub done: Vec, - #[serde(default = "default_2405")] + #[serde(default = "default_2409")] pub open_questions: Vec, - #[serde(default = "default_2406")] + #[serde(default = "default_2410")] pub next_steps: Vec, - #[serde(default = "default_2409")] + #[serde(default = "default_2413")] pub files: Vec, - #[serde(default = "default_2410")] + #[serde(default = "default_2414")] pub constraints: Vec, - #[serde(default = "default_2411")] + #[serde(default = "default_2415")] pub pointers: Vec, - #[serde(default = "default_2412")] + #[serde(default = "default_2416")] pub client_summary: String, - #[serde(default = "default_2413")] + #[serde(default = "default_2417")] pub client_summary_at: String, } @@ -55798,45 +55830,45 @@ pub struct BriefSections { #[non_exhaustive] pub struct SessionBriefGetOutput { pub found: bool, - #[serde(default = "default_2388")] + #[serde(default = "default_2392")] pub brief_key: String, - #[serde(default = "default_2389")] + #[serde(default = "default_2393")] pub revision: Integer, - #[serde(default = "default_2390")] + #[serde(default = "default_2394")] pub snapshot_id: String, - #[serde(default = "default_2391")] + #[serde(default = "default_2395")] pub snapshot_key: String, - #[serde(default = "default_2392")] + #[serde(default = "default_2396")] pub rendered: String, - #[serde(default = "default_2414")] + #[serde(default = "default_2418")] pub sections: Option, - #[serde(default = "default_2415")] + #[serde(default = "default_2419")] pub project: String, - #[serde(default = "default_2416")] + #[serde(default = "default_2420")] pub branch: String, - #[serde(default = "default_2417")] + #[serde(default = "default_2421")] pub head_sha: String, - #[serde(default = "default_2418")] + #[serde(default = "default_2422")] pub author: String, - #[serde(default = "default_2419")] + #[serde(default = "default_2423")] pub trigger: String, - #[serde(default = "default_2420")] + #[serde(default = "default_2424")] pub actor: String, - #[serde(default = "default_2421")] + #[serde(default = "default_2425")] pub source_sessions: Vec, - #[serde(default = "default_2422")] + #[serde(default = "default_2426")] pub updated_at: Option, - #[serde(default = "default_2423")] + #[serde(default = "default_2427")] pub age_seconds: Integer, - #[serde(default = "default_2424")] + #[serde(default = "default_2428")] pub revisions: Integer, - #[serde(default = "default_2425")] + #[serde(default = "default_2429")] pub events_total: Integer, - #[serde(default = "default_2426")] + #[serde(default = "default_2430")] pub source_chars: Integer, - #[serde(default = "default_2427")] + #[serde(default = "default_2431")] pub brief_chars: Integer, - #[serde(default = "default_2428")] + #[serde(default = "default_2432")] pub deleted: bool, } @@ -56011,34 +56043,34 @@ impl SessionBriefGetInput { pub struct SessionBriefSummary { pub brief_key: String, pub revision: Integer, - #[serde(default = "default_2429")] + #[serde(default = "default_2433")] pub project: String, - #[serde(default = "default_2430")] + #[serde(default = "default_2434")] pub branch: String, - #[serde(default = "default_2431")] + #[serde(default = "default_2435")] pub agent: String, - #[serde(default = "default_2432")] + #[serde(default = "default_2436")] pub goal: String, - #[serde(default = "default_2433")] + #[serde(default = "default_2437")] pub status: String, - #[serde(default = "default_2434")] + #[serde(default = "default_2438")] pub author: String, - #[serde(default = "default_2435")] + #[serde(default = "default_2439")] pub actor: String, - #[serde(default = "default_2436")] + #[serde(default = "default_2440")] pub updated_at: Option, - #[serde(default = "default_2437")] + #[serde(default = "default_2441")] pub age_seconds: Integer, - #[serde(default = "default_2438")] + #[serde(default = "default_2442")] pub brief_chars: Integer, } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[non_exhaustive] pub struct SessionBriefListOutput { - #[serde(default = "default_2439")] + #[serde(default = "default_2443")] pub briefs: Vec, - #[serde(default = "default_2440")] + #[serde(default = "default_2444")] pub rendered: String, } @@ -56178,25 +56210,25 @@ impl SessionBriefListInput { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[non_exhaustive] pub struct SessionBriefStats { - #[serde(default = "default_2444")] + #[serde(default = "default_2448")] pub events_in: Integer, - #[serde(default = "default_2445")] + #[serde(default = "default_2449")] pub windows: Integer, - #[serde(default = "default_2446")] + #[serde(default = "default_2450")] pub events_total: Integer, - #[serde(default = "default_2447")] + #[serde(default = "default_2451")] pub source_chars: Integer, - #[serde(default = "default_2448")] + #[serde(default = "default_2452")] pub brief_chars: Integer, - #[serde(default = "default_2449")] + #[serde(default = "default_2453")] pub compression_ratio: f64, - #[serde(default = "default_2450")] + #[serde(default = "default_2454")] pub dropped_ungrounded: Integer, - #[serde(default = "default_2451")] + #[serde(default = "default_2455")] pub tokens_in: Integer, - #[serde(default = "default_2452")] + #[serde(default = "default_2456")] pub tokens_out: Integer, - #[serde(default = "default_2453")] + #[serde(default = "default_2457")] pub llm_model: String, } @@ -56206,13 +56238,13 @@ pub struct SessionBriefSaveOutput { pub brief_key: String, pub revision: Integer, pub changed: bool, - #[serde(default = "default_2441")] + #[serde(default = "default_2445")] pub author: String, - #[serde(default = "default_2442")] + #[serde(default = "default_2446")] pub reason: String, - #[serde(default = "default_2443")] + #[serde(default = "default_2447")] pub rendered: String, - #[serde(default = "default_2454")] + #[serde(default = "default_2458")] pub stats: SessionBriefStats, } @@ -56957,39 +56989,39 @@ pub struct TaskPayload { pub priority: Integer, pub disclosure: TaskPayloadDisclosure, pub status: TaskPayloadStatus, - #[serde(default = "default_2455")] + #[serde(default = "default_2459")] pub reason: String, - #[serde(default = "default_2456")] + #[serde(default = "default_2460")] pub blocked_on: String, - #[serde(default = "default_2457")] + #[serde(default = "default_2461")] pub not_before: Option, - #[serde(default = "default_2458")] + #[serde(default = "default_2462")] pub resume_at: Option, - #[serde(default = "default_2459")] + #[serde(default = "default_2463")] pub deadline: Option, - #[serde(default = "default_2460")] + #[serde(default = "default_2464")] pub defer_count: Integer, pub title: String, - #[serde(default = "default_2461")] + #[serde(default = "default_2465")] pub brief: std::collections::HashMap, pub from_agent: String, - #[serde(default = "default_2462")] + #[serde(default = "default_2466")] pub from_subject: String, - #[serde(default = "default_2463")] + #[serde(default = "default_2467")] pub origin: String, - #[serde(default = "default_2464")] + #[serde(default = "default_2468")] pub parent_task_id: Option, - #[serde(default = "default_2465")] + #[serde(default = "default_2469")] pub owner: String, - #[serde(default = "default_2466")] + #[serde(default = "default_2470")] pub attempt: Integer, - #[serde(default = "default_2467")] + #[serde(default = "default_2471")] pub fence: Integer, - #[serde(default = "default_2468")] + #[serde(default = "default_2472")] pub lease_until: Option, - #[serde(default = "default_2469")] + #[serde(default = "default_2473")] pub outcome: std::collections::HashMap, - #[serde(default = "default_2470")] + #[serde(default = "default_2474")] pub last_actor: String, pub created_at: String, pub updated_at: String, @@ -57000,7 +57032,7 @@ pub struct TaskPayload { #[non_exhaustive] pub struct TaskOutput { pub task: TaskPayload, - #[serde(default = "default_2471")] + #[serde(default = "default_2475")] pub seq: Integer, } @@ -57401,10 +57433,10 @@ impl TaskCompleteInput { pub struct InboxCount { pub inbox: String, pub status: String, - #[serde(default = "default_2472")] + #[serde(default = "default_2476")] pub blocked_on: String, pub n: Integer, - #[serde(default = "default_2473")] + #[serde(default = "default_2477")] pub oldest: Option, } @@ -57491,7 +57523,7 @@ pub struct TaskCreateOutput { pub task: TaskPayload, pub created: bool, pub seq: Integer, - #[serde(default = "default_2474")] + #[serde(default = "default_2478")] pub next: String, } @@ -57830,7 +57862,7 @@ impl TaskFailInput { #[non_exhaustive] pub struct TaskGetOutput { pub found: bool, - #[serde(default = "default_2475")] + #[serde(default = "default_2479")] pub task: Option, } @@ -57964,23 +57996,23 @@ pub struct TaskEventPayload { pub task_id: String, pub inbox: String, pub event: String, - #[serde(default = "default_2476")] + #[serde(default = "default_2480")] pub from_status: String, - #[serde(default = "default_2477")] + #[serde(default = "default_2481")] pub to_status: String, - #[serde(default = "default_2478")] + #[serde(default = "default_2482")] pub actor: String, - #[serde(default = "default_2479")] + #[serde(default = "default_2483")] pub agent: String, - #[serde(default = "default_2480")] + #[serde(default = "default_2484")] pub fence: Integer, - #[serde(default = "default_2481")] + #[serde(default = "default_2485")] pub version: Integer, - #[serde(default = "default_2482")] + #[serde(default = "default_2486")] pub reason: String, - #[serde(default = "default_2483")] + #[serde(default = "default_2487")] pub patch: std::collections::HashMap, - #[serde(default = "default_2484")] + #[serde(default = "default_2488")] pub note: String, pub ts: String, } @@ -58320,7 +58352,7 @@ pub struct TaskPullOutput { pub tasks: Vec, pub waited_ms: Integer, pub backend: String, - #[serde(default = "default_2485")] + #[serde(default = "default_2489")] pub note: String, } @@ -58716,7 +58748,7 @@ impl TaskUnblockInput { pub struct TaskUpdateOutput { pub task: TaskPayload, pub seq: Integer, - #[serde(default = "default_2486")] + #[serde(default = "default_2490")] pub conflict: bool, } @@ -59079,19 +59111,19 @@ impl TaskReasonInput { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[non_exhaustive] pub struct TrackerAnswerOutput { - #[serde(default = "default_2487")] + #[serde(default = "default_2491")] pub intent: String, - #[serde(default = "default_2488")] + #[serde(default = "default_2492")] pub anchors: std::collections::HashMap, - #[serde(default = "default_2489")] + #[serde(default = "default_2493")] pub sections: Vec>, - #[serde(default = "default_2490")] + #[serde(default = "default_2494")] pub searched: Vec, - #[serde(default = "default_2491")] + #[serde(default = "default_2495")] pub lines: Vec, - #[serde(default = "default_2492")] + #[serde(default = "default_2496")] pub restricted: bool, - #[serde(default = "default_2493")] + #[serde(default = "default_2497")] pub verdict: String, } @@ -59187,17 +59219,17 @@ impl TrackerAnswerInput { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[non_exhaustive] pub struct TrackerBindingOutput { - #[serde(default = "default_2494")] + #[serde(default = "default_2498")] pub tracker_namespace: String, - #[serde(default = "default_2495")] + #[serde(default = "default_2499")] pub tracker_namespaces: Vec, - #[serde(default = "default_2496")] + #[serde(default = "default_2500")] pub restricted: bool, - #[serde(default = "default_2497")] + #[serde(default = "default_2501")] pub kind: String, - #[serde(default = "default_2498")] + #[serde(default = "default_2502")] pub authorized: bool, - #[serde(default = "default_2499")] + #[serde(default = "default_2503")] pub templates: Vec, } @@ -59250,13 +59282,13 @@ impl TrackerBindingInput { #[non_exhaustive] pub struct TrackerComponentOutput { pub component: String, - #[serde(default = "default_2500")] + #[serde(default = "default_2504")] pub risk: std::collections::HashMap, - #[serde(default = "default_2501")] + #[serde(default = "default_2505")] pub open_issues: Vec>, - #[serde(default = "default_2502")] + #[serde(default = "default_2506")] pub known: bool, - #[serde(default = "default_2503")] + #[serde(default = "default_2507")] pub tracker_unavailable: bool, } @@ -59317,9 +59349,9 @@ impl TrackerComponentInput { #[non_exhaustive] pub struct TrackerContractOutput { pub database: String, - #[serde(default = "default_2504")] + #[serde(default = "default_2508")] pub tables: Vec>, - #[serde(default = "default_2505")] + #[serde(default = "default_2509")] pub templates: std::collections::HashMap, } @@ -59372,66 +59404,66 @@ impl TrackerContractInput { #[non_exhaustive] pub struct TrackerLegStatus { pub name: String, - #[serde(default = "default_2516")] + #[serde(default = "default_2520")] pub status: String, - #[serde(default = "default_2517")] + #[serde(default = "default_2521")] pub reason: String, - #[serde(default = "default_2518")] + #[serde(default = "default_2522")] pub message: String, - #[serde(default = "default_2519")] + #[serde(default = "default_2523")] pub retried: bool, - #[serde(default = "default_2520")] + #[serde(default = "default_2524")] pub ms: Integer, - #[serde(default = "default_2521")] + #[serde(default = "default_2525")] pub cause: String, - #[serde(default = "default_2522")] + #[serde(default = "default_2526")] pub namespace: String, } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[non_exhaustive] pub struct TrackerDuplicateCheckOutput { - #[serde(default = "default_2506")] + #[serde(default = "default_2510")] pub verdict: String, - #[serde(default = "default_2507")] + #[serde(default = "default_2511")] pub items: Vec>, - #[serde(default = "default_2508")] + #[serde(default = "default_2512")] pub undecided: bool, - #[serde(default = "default_2509")] + #[serde(default = "default_2513")] pub epistemic: String, - #[serde(default = "default_2510")] + #[serde(default = "default_2514")] pub thresholds: std::collections::HashMap, - #[serde(default = "default_2511")] + #[serde(default = "default_2515")] pub judge: std::collections::HashMap, - #[serde(default = "default_2512")] + #[serde(default = "default_2516")] pub fit_at: String, - #[serde(default = "default_2513")] + #[serde(default = "default_2517")] pub fit: std::collections::HashMap, - #[serde(default = "default_2514")] + #[serde(default = "default_2518")] pub query: std::collections::HashMap, - #[serde(default = "default_2515")] + #[serde(default = "default_2519")] pub legs: std::collections::HashMap, - #[serde(default = "default_2523")] + #[serde(default = "default_2527")] pub leg_status: Vec, - #[serde(default = "default_2524")] + #[serde(default = "default_2528")] pub tracker_unavailable: bool, - #[serde(default = "default_2525")] + #[serde(default = "default_2529")] pub namespaces: Vec, - #[serde(default = "default_2526")] + #[serde(default = "default_2530")] pub by_namespace: std::collections::HashMap>, - #[serde(default = "default_2527")] + #[serde(default = "default_2531")] pub closest: Vec>, - #[serde(default = "default_2528")] + #[serde(default = "default_2532")] pub needs: Vec>, - #[serde(default = "default_2529")] + #[serde(default = "default_2533")] pub closest_note: String, - #[serde(default = "default_2530")] + #[serde(default = "default_2534")] pub nearest: Vec>, - #[serde(default = "default_2531")] + #[serde(default = "default_2535")] pub rerank: std::collections::HashMap, - #[serde(default = "default_2532")] + #[serde(default = "default_2536")] pub answer: String, - #[serde(default = "default_2533")] + #[serde(default = "default_2537")] pub related_prs: Vec>, } @@ -59638,17 +59670,17 @@ impl TrackerDuplicateCheckInput { #[non_exhaustive] pub struct TrackerFlakyOutput { pub test_name: String, - #[serde(default = "default_2534")] + #[serde(default = "default_2538")] pub known_flaky: bool, - #[serde(default = "default_2535")] + #[serde(default = "default_2539")] pub open_issues: Integer, - #[serde(default = "default_2536")] + #[serde(default = "default_2540")] pub issues: Vec>, - #[serde(default = "default_2537")] + #[serde(default = "default_2541")] pub verdict: String, - #[serde(default = "default_2538")] + #[serde(default = "default_2542")] pub tracker_unavailable: bool, - #[serde(default = "default_2539")] + #[serde(default = "default_2543")] pub signal: Option>, } @@ -59731,9 +59763,9 @@ impl TrackerFlakyInput { #[non_exhaustive] pub struct TrackerItemOutput { pub items: Vec>, - #[serde(default = "default_2540")] + #[serde(default = "default_2544")] pub unknown: Vec, - #[serde(default = "default_2541")] + #[serde(default = "default_2545")] pub tracker_unavailable: bool, } @@ -59782,19 +59814,19 @@ impl TrackerItemInput { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[non_exhaustive] pub struct TrackerLinksOutput { - #[serde(default = "default_2542")] + #[serde(default = "default_2546")] pub subject: std::collections::HashMap, - #[serde(default = "default_2543")] + #[serde(default = "default_2547")] pub verdict: String, - #[serde(default = "default_2544")] + #[serde(default = "default_2548")] pub items: Vec>, - #[serde(default = "default_2545")] + #[serde(default = "default_2549")] pub epistemic: String, - #[serde(default = "default_2546")] + #[serde(default = "default_2550")] pub record: std::collections::HashMap, - #[serde(default = "default_2547")] + #[serde(default = "default_2551")] pub computed_at: String, - #[serde(default = "default_2548")] + #[serde(default = "default_2552")] pub tracker_unavailable: bool, } @@ -59892,11 +59924,11 @@ impl TrackerLinksInput { pub struct TrackerReleaseOutput { pub version: String, pub blockers: Vec>, - #[serde(default = "default_2549")] + #[serde(default = "default_2553")] pub active_blockers: Integer, - #[serde(default = "default_2550")] + #[serde(default = "default_2554")] pub health: std::collections::HashMap, - #[serde(default = "default_2551")] + #[serde(default = "default_2555")] pub tracker_unavailable: bool, } @@ -59945,17 +59977,17 @@ impl TrackerReleaseInput { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[non_exhaustive] pub struct TrackerSimilarOutput { - #[serde(default = "default_2552")] + #[serde(default = "default_2556")] pub items: Vec>, - #[serde(default = "default_2553")] + #[serde(default = "default_2557")] pub query: std::collections::HashMap, - #[serde(default = "default_2554")] + #[serde(default = "default_2558")] pub legs: std::collections::HashMap, - #[serde(default = "default_2555")] + #[serde(default = "default_2559")] pub epistemic: String, - #[serde(default = "default_2556")] + #[serde(default = "default_2560")] pub tracker_unavailable: bool, - #[serde(default = "default_2557")] + #[serde(default = "default_2561")] pub namespaces: Vec, } @@ -60076,19 +60108,19 @@ pub struct TrackerSourceAddOutput { pub name: String, pub host: String, pub database: String, - #[serde(default = "default_2558")] + #[serde(default = "default_2562")] pub namespaces: Vec>, - #[serde(default = "default_2559")] + #[serde(default = "default_2563")] pub contract: std::collections::HashMap, - #[serde(default = "default_2560")] + #[serde(default = "default_2564")] pub roles: Vec, - #[serde(default = "default_2561")] + #[serde(default = "default_2565")] pub my_role: String, - #[serde(default = "default_2562")] + #[serde(default = "default_2566")] pub dry_run: bool, - #[serde(default = "default_2563")] + #[serde(default = "default_2567")] pub written: bool, - #[serde(default = "default_2564")] + #[serde(default = "default_2568")] pub view_templates: std::collections::HashMap, } @@ -60251,13 +60283,13 @@ impl TrackerSourceAddInput { #[non_exhaustive] pub struct TrackerSourceCheckOutput { pub name: String, - #[serde(default = "default_2565")] + #[serde(default = "default_2569")] pub database: String, - #[serde(default = "default_2566")] + #[serde(default = "default_2570")] pub reachable: bool, - #[serde(default = "default_2567")] + #[serde(default = "default_2571")] pub contract: std::collections::HashMap, - #[serde(default = "default_2568")] + #[serde(default = "default_2572")] pub view_templates: std::collections::HashMap, } @@ -60297,11 +60329,11 @@ impl TrackerSourceCheckInput { pub struct TrackerSourceInspectOutput { pub host: String, pub database: String, - #[serde(default = "default_2569")] + #[serde(default = "default_2573")] pub tables: Vec>, - #[serde(default = "default_2570")] + #[serde(default = "default_2574")] pub roles: Vec, - #[serde(default = "default_2571")] + #[serde(default = "default_2575")] pub proposal: std::collections::HashMap, } @@ -60430,9 +60462,9 @@ impl TrackerSourceInspectInput { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[non_exhaustive] pub struct TrackerSourceListOutput { - #[serde(default = "default_2572")] + #[serde(default = "default_2576")] pub sources: Vec>, - #[serde(default = "default_2573")] + #[serde(default = "default_2577")] pub self_service: bool, } @@ -60485,9 +60517,9 @@ impl TrackerSourceListInput { #[non_exhaustive] pub struct TrackerSourceRemoveOutput { pub name: String, - #[serde(default = "default_2574")] + #[serde(default = "default_2578")] pub deactivated: bool, - #[serde(default = "default_2575")] + #[serde(default = "default_2579")] pub namespaces_retired: Vec, } @@ -60528,9 +60560,9 @@ impl TrackerSourceRemoveInput { #[non_exhaustive] pub struct TrackerSourceRotateOutput { pub name: String, - #[serde(default = "default_2576")] + #[serde(default = "default_2580")] pub contract: std::collections::HashMap, - #[serde(default = "default_2577")] + #[serde(default = "default_2581")] pub rotated_at: String, } @@ -60577,11 +60609,11 @@ impl TrackerSourceRotateInput { #[non_exhaustive] pub struct TrackerSourceSetMappingOutput { pub name: String, - #[serde(default = "default_2578")] + #[serde(default = "default_2582")] pub contract: std::collections::HashMap, - #[serde(default = "default_2579")] + #[serde(default = "default_2583")] pub dry_run: bool, - #[serde(default = "default_2580")] + #[serde(default = "default_2584")] pub written: bool, } @@ -60648,45 +60680,45 @@ impl TrackerSourceSetMappingInput { #[non_exhaustive] pub struct TrackerTestSignalOutput { pub test_name: String, - #[serde(default = "default_2581")] + #[serde(default = "default_2585")] pub verdict: String, - #[serde(default = "default_2582")] + #[serde(default = "default_2586")] pub why: Vec, - #[serde(default = "default_2583")] + #[serde(default = "default_2587")] pub lower_bound: f64, - #[serde(default = "default_2584")] + #[serde(default = "default_2588")] pub window_days: Integer, - #[serde(default = "default_2585")] + #[serde(default = "default_2589")] pub since: String, - #[serde(default = "default_2586")] + #[serde(default = "default_2590")] pub features: std::collections::HashMap, - #[serde(default = "default_2587")] + #[serde(default = "default_2591")] pub infra: std::collections::HashMap, - #[serde(default = "default_2588")] + #[serde(default = "default_2592")] pub churn: std::collections::HashMap, - #[serde(default = "default_2589")] + #[serde(default = "default_2593")] pub thresholds: std::collections::HashMap, - #[serde(default = "default_2590")] + #[serde(default = "default_2594")] pub source: String, - #[serde(default = "default_2591")] + #[serde(default = "default_2595")] pub timings_ms: std::collections::HashMap, - #[serde(default = "default_2592")] + #[serde(default = "default_2596")] pub tracker_unavailable: bool, - #[serde(default = "default_2593")] + #[serde(default = "default_2597")] pub rollup: std::collections::HashMap, - #[serde(default = "default_2594")] + #[serde(default = "default_2598")] pub streak: std::collections::HashMap, - #[serde(default = "default_2595")] + #[serde(default = "default_2599")] pub smells: std::collections::HashMap, - #[serde(default = "default_2596")] + #[serde(default = "default_2600")] pub prior: std::collections::HashMap, - #[serde(default = "default_2597")] + #[serde(default = "default_2601")] pub unavailable_reason: String, - #[serde(default = "default_2598")] + #[serde(default = "default_2602")] pub candidates: Vec>, - #[serde(default = "default_2599")] + #[serde(default = "default_2603")] pub candidate_matches: Integer, - #[serde(default = "default_2600")] + #[serde(default = "default_2604")] pub resolved_from: String, } @@ -60790,9 +60822,9 @@ impl TrackerTestSignalInput { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[non_exhaustive] pub struct UiVitalsOutput { - #[serde(default = "default_2601")] + #[serde(default = "default_2605")] pub recorded: bool, - #[serde(default = "default_2602")] + #[serde(default = "default_2606")] pub route: String, } @@ -60976,7 +61008,7 @@ pub struct WebhookDelivery { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[non_exhaustive] pub struct WebhookDeliveriesOutput { - #[serde(default = "default_2603")] + #[serde(default = "default_2607")] pub deliveries: Vec, } @@ -61098,14 +61130,14 @@ pub struct WebhookInfo { pub secret_ref: String, pub events: Vec, pub created_at: String, - #[serde(default = "default_2604")] + #[serde(default = "default_2608")] pub secret_present: bool, } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[non_exhaustive] pub struct WebhookListOutput { - #[serde(default = "default_2605")] + #[serde(default = "default_2609")] pub webhooks: Vec, } @@ -61287,7 +61319,7 @@ pub struct WorkingMemoryMutationOutput { pub version: Integer, pub char_limit: Integer, pub value_length: Integer, - #[serde(default = "default_2606")] + #[serde(default = "default_2610")] pub fill_ratio: f64, } @@ -61511,15 +61543,15 @@ impl WorkingMemoryDeleteInput { pub struct WorkingMemoryGetOutput { pub found: bool, pub block_key: String, - #[serde(default = "default_2607")] + #[serde(default = "default_2611")] pub content: String, - #[serde(default = "default_2608")] + #[serde(default = "default_2612")] pub char_limit: Integer, - #[serde(default = "default_2609")] + #[serde(default = "default_2613")] pub version: Integer, - #[serde(default = "default_2610")] + #[serde(default = "default_2614")] pub updated_at: Option, - #[serde(default = "default_2611")] + #[serde(default = "default_2615")] pub fill_ratio: f64, } @@ -61630,7 +61662,7 @@ pub struct WorkingMemoryBlock { pub content: String, pub char_limit: Integer, pub version: Integer, - #[serde(default = "default_2612")] + #[serde(default = "default_2616")] pub updated_at: Option, } @@ -61638,7 +61670,7 @@ pub struct WorkingMemoryBlock { #[non_exhaustive] pub struct WorkingMemoryRenderOutput { pub rendered: String, - #[serde(default = "default_2613")] + #[serde(default = "default_2617")] pub blocks: Vec, pub block_count: Integer, pub total_chars: Integer, @@ -68720,1146 +68752,1159 @@ fn default_2231() -> Option { fn default_2232() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2233() -> String { +fn default_2233() -> Integer { + serde_json::from_str("0").expect("schema default") +} +fn default_2234() -> Vec { + serde_json::from_str("[]").expect("schema default") +} +fn default_2235() -> OpsIncidentSourcesRead { + serde_json::from_str("\"unread\"").expect("schema default") +} +fn default_2236() -> OpsIncidentSources { + serde_json::from_str("{\"failing\":0,\"sample\":[],\"read\":\"unread\"}") + .expect("schema default") +} +fn default_2237() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2234() -> String { +fn default_2238() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2235() -> String { +fn default_2239() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2236() -> Vec { +fn default_2240() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2237() -> String { +fn default_2241() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2238() -> String { +fn default_2242() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2239() -> std::collections::HashMap { +fn default_2243() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2240() -> String { +fn default_2244() -> String { serde_json::from_str("\"active\"").expect("schema default") } -fn default_2241() -> Option { +fn default_2245() -> Option { serde_json::from_str("null").expect("schema default") } -fn default_2242() -> Option { +fn default_2246() -> Option { serde_json::from_str("null").expect("schema default") } -fn default_2243() -> bool { +fn default_2247() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2244() -> String { +fn default_2248() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2245() -> String { +fn default_2249() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2246() -> Vec { +fn default_2250() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2247() -> Integer { +fn default_2251() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2248() -> String { +fn default_2252() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2249() -> String { +fn default_2253() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2250() -> Option { +fn default_2254() -> Option { serde_json::from_str("null").expect("schema default") } -fn default_2251() -> bool { +fn default_2255() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2252() -> String { +fn default_2256() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2253() -> bool { +fn default_2257() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2254() -> String { +fn default_2258() -> String { serde_json::from_str("\"inherit\"").expect("schema default") } -fn default_2255() -> Option { +fn default_2259() -> Option { serde_json::from_str("null").expect("schema default") } -fn default_2256() -> Option { +fn default_2260() -> Option { serde_json::from_str("null").expect("schema default") } -fn default_2257() -> bool { +fn default_2261() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2258() -> Vec { +fn default_2262() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2259() -> Integer { +fn default_2263() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2260() -> ProcedureEvolveOutputGate { +fn default_2264() -> ProcedureEvolveOutputGate { serde_json::from_str("\"none\"").expect("schema default") } -fn default_2261() -> String { +fn default_2265() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2262() -> f64 { +fn default_2266() -> f64 { serde_json::from_str("0.0").expect("schema default") } -fn default_2263() -> std::collections::HashMap { +fn default_2267() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2264() -> std::collections::HashMap { +fn default_2268() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2265() -> std::collections::HashMap { +fn default_2269() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2266() -> std::collections::HashMap { +fn default_2270() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2267() -> String { +fn default_2271() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2268() -> Vec { +fn default_2272() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2269() -> Vec { +fn default_2273() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2270() -> Vec { +fn default_2274() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2271() -> std::collections::HashMap { +fn default_2275() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2272() -> Integer { +fn default_2276() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2273() -> bool { +fn default_2277() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2274() -> std::collections::HashMap { +fn default_2278() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2275() -> Vec { +fn default_2279() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2276() -> std::collections::HashMap { +fn default_2280() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2277() -> String { +fn default_2281() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2278() -> ProcedureLocateOutputStatus { +fn default_2282() -> ProcedureLocateOutputStatus { serde_json::from_str("\"authored\"").expect("schema default") } -fn default_2279() -> Option> { +fn default_2283() -> Option> { serde_json::from_str("null").expect("schema default") } -fn default_2280() -> Vec>> { +fn default_2284() -> Vec>> { serde_json::from_str("[]").expect("schema default") } -fn default_2281() -> Vec { +fn default_2285() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2282() -> Vec { +fn default_2286() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2283() -> std::collections::HashMap { +fn default_2287() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2284() -> bool { +fn default_2288() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2285() -> Vec { +fn default_2289() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2286() -> Vec> { +fn default_2290() -> Vec> { serde_json::from_str("[]").expect("schema default") } -fn default_2287() -> String { +fn default_2291() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2288() -> std::collections::HashMap { +fn default_2292() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2289() -> std::collections::HashMap { +fn default_2293() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2290() -> Vec { +fn default_2294() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2291() -> std::collections::HashMap { +fn default_2295() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2292() -> Option> { +fn default_2296() -> Option> { serde_json::from_str("null").expect("schema default") } -fn default_2293() -> bool { +fn default_2297() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2294() -> std::collections::HashMap { +fn default_2298() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2295() -> ProcedureMatchStatus { +fn default_2299() -> ProcedureMatchStatus { serde_json::from_str("\"authored\"").expect("schema default") } -fn default_2296() -> Option> { +fn default_2300() -> Option> { serde_json::from_str("null").expect("schema default") } -fn default_2297() -> Vec { +fn default_2301() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2298() -> Integer { +fn default_2302() -> Integer { serde_json::from_str("1").expect("schema default") } -fn default_2299() -> Vec> { +fn default_2303() -> Vec> { serde_json::from_str("[]").expect("schema default") } -fn default_2300() -> f64 { +fn default_2304() -> f64 { serde_json::from_str("0.0").expect("schema default") } -fn default_2301() -> f64 { +fn default_2305() -> f64 { serde_json::from_str("0.0").expect("schema default") } -fn default_2302() -> f64 { +fn default_2306() -> f64 { serde_json::from_str("0.0").expect("schema default") } -fn default_2303() -> Option { +fn default_2307() -> Option { serde_json::from_str("null").expect("schema default") } -fn default_2304() -> std::collections::HashMap { +fn default_2308() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2305() -> std::collections::HashMap> { +fn default_2309() -> std::collections::HashMap> { serde_json::from_str("{}").expect("schema default") } -fn default_2306() -> String { +fn default_2310() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2307() -> Integer { +fn default_2311() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2308() -> String { +fn default_2312() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2309() -> f64 { +fn default_2313() -> f64 { serde_json::from_str("0.0").expect("schema default") } -fn default_2310() -> Vec { +fn default_2314() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2311() -> ProcedureReviseOutputOutcome { +fn default_2315() -> ProcedureReviseOutputOutcome { serde_json::from_str("\"opened\"").expect("schema default") } -fn default_2312() -> Vec { +fn default_2316() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2313() -> Vec { +fn default_2317() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2314() -> String { +fn default_2318() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2315() -> String { +fn default_2319() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2316() -> String { +fn default_2320() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2317() -> String { +fn default_2321() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2318() -> Option { +fn default_2322() -> Option { serde_json::from_str("null").expect("schema default") } -fn default_2319() -> Integer { +fn default_2323() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2320() -> Vec { +fn default_2324() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2321() -> std::collections::HashMap { +fn default_2325() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2322() -> Option { +fn default_2326() -> Option { serde_json::from_str("null").expect("schema default") } -fn default_2323() -> String { +fn default_2327() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2324() -> Integer { +fn default_2328() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2325() -> String { +fn default_2329() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2326() -> String { +fn default_2330() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2327() -> std::collections::HashMap { +fn default_2331() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2328() -> String { +fn default_2332() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2329() -> String { +fn default_2333() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2330() -> Option { +fn default_2334() -> Option { serde_json::from_str("null").expect("schema default") } -fn default_2331() -> RunBeginOutputStatus { +fn default_2335() -> RunBeginOutputStatus { serde_json::from_str("\"active\"").expect("schema default") } -fn default_2332() -> String { +fn default_2336() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2333() -> Integer { +fn default_2337() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2334() -> Integer { +fn default_2338() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2335() -> Integer { +fn default_2339() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2336() -> Integer { +fn default_2340() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2337() -> Vec { +fn default_2341() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2338() -> Integer { +fn default_2342() -> Integer { serde_json::from_str("-1").expect("schema default") } -fn default_2339() -> Integer { +fn default_2343() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2340() -> Integer { +fn default_2344() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2341() -> String { +fn default_2345() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2342() -> String { +fn default_2346() -> String { serde_json::from_str("\"keep\"").expect("schema default") } -fn default_2343() -> Integer { +fn default_2347() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2344() -> Integer { +fn default_2348() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2345() -> Integer { +fn default_2349() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2346() -> Option { +fn default_2350() -> Option { serde_json::from_str("null").expect("schema default") } -fn default_2347() -> Integer { +fn default_2351() -> Integer { serde_json::from_str("-1").expect("schema default") } -fn default_2348() -> Vec { +fn default_2352() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2349() -> Vec { +fn default_2353() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2350() -> Integer { +fn default_2354() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2351() -> Integer { +fn default_2355() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2352() -> Integer { +fn default_2356() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2353() -> f64 { +fn default_2357() -> f64 { serde_json::from_str("0.0").expect("schema default") } -fn default_2354() -> Integer { +fn default_2358() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2355() -> Vec { +fn default_2359() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2356() -> Integer { +fn default_2360() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2357() -> Vec { +fn default_2361() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2358() -> Integer { +fn default_2362() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2359() -> Integer { +fn default_2363() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2360() -> Integer { +fn default_2364() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2361() -> Vec { +fn default_2365() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2362() -> Option { +fn default_2366() -> Option { serde_json::from_str("null").expect("schema default") } -fn default_2363() -> Vec { +fn default_2367() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2364() -> Vec { +fn default_2368() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2365() -> String { +fn default_2369() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2366() -> Vec { +fn default_2370() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2367() -> bool { +fn default_2371() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2368() -> String { +fn default_2372() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2369() -> Integer { +fn default_2373() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2370() -> Integer { +fn default_2374() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2371() -> Integer { +fn default_2375() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2372() -> Integer { +fn default_2376() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2373() -> bool { +fn default_2377() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2374() -> bool { +fn default_2378() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2375() -> Option> { +fn default_2379() -> Option> { serde_json::from_str("null").expect("schema default") } -fn default_2376() -> LiveSearchResultsLive { +fn default_2380() -> LiveSearchResultsLive { serde_json::from_str("true").expect("schema default") } -fn default_2377() -> String { +fn default_2381() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2378() -> LiveSearchHitLive { +fn default_2382() -> LiveSearchHitLive { serde_json::from_str("true").expect("schema default") } -fn default_2379() -> Vec { +fn default_2383() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2380() -> Option { +fn default_2384() -> Option { serde_json::from_str("null").expect("schema default") } -fn default_2381() -> std::collections::HashMap { +fn default_2385() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2382() -> std::collections::HashMap { +fn default_2386() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2383() -> std::collections::HashMap { +fn default_2387() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2384() -> std::collections::HashMap { +fn default_2388() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2385() -> Option> { +fn default_2389() -> Option> { serde_json::from_str("null").expect("schema default") } -fn default_2386() -> Vec { +fn default_2390() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2387() -> Integer { +fn default_2391() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2388() -> String { +fn default_2392() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2389() -> Integer { +fn default_2393() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2390() -> String { +fn default_2394() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2391() -> String { +fn default_2395() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2392() -> String { +fn default_2396() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2393() -> String { +fn default_2397() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2394() -> String { +fn default_2398() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2395() -> String { +fn default_2399() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2396() -> String { +fn default_2400() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2397() -> String { +fn default_2401() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2398() -> Vec { +fn default_2402() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2399() -> String { +fn default_2403() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2400() -> String { +fn default_2404() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2401() -> Vec { +fn default_2405() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2402() -> String { +fn default_2406() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2403() -> String { +fn default_2407() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2404() -> Vec { +fn default_2408() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2405() -> Vec { +fn default_2409() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2406() -> Vec { +fn default_2410() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2407() -> String { +fn default_2411() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2408() -> String { +fn default_2412() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2409() -> Vec { +fn default_2413() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2410() -> Vec { +fn default_2414() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2411() -> Vec { +fn default_2415() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2412() -> String { +fn default_2416() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2413() -> String { +fn default_2417() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2414() -> Option { +fn default_2418() -> Option { serde_json::from_str("null").expect("schema default") } -fn default_2415() -> String { +fn default_2419() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2416() -> String { +fn default_2420() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2417() -> String { +fn default_2421() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2418() -> String { +fn default_2422() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2419() -> String { +fn default_2423() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2420() -> String { +fn default_2424() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2421() -> Vec { +fn default_2425() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2422() -> Option { +fn default_2426() -> Option { serde_json::from_str("null").expect("schema default") } -fn default_2423() -> Integer { +fn default_2427() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2424() -> Integer { +fn default_2428() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2425() -> Integer { +fn default_2429() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2426() -> Integer { +fn default_2430() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2427() -> Integer { +fn default_2431() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2428() -> bool { +fn default_2432() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2429() -> String { +fn default_2433() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2430() -> String { +fn default_2434() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2431() -> String { +fn default_2435() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2432() -> String { +fn default_2436() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2433() -> String { +fn default_2437() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2434() -> String { +fn default_2438() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2435() -> String { +fn default_2439() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2436() -> Option { +fn default_2440() -> Option { serde_json::from_str("null").expect("schema default") } -fn default_2437() -> Integer { +fn default_2441() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2438() -> Integer { +fn default_2442() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2439() -> Vec { +fn default_2443() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2440() -> String { +fn default_2444() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2441() -> String { +fn default_2445() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2442() -> String { +fn default_2446() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2443() -> String { +fn default_2447() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2444() -> Integer { +fn default_2448() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2445() -> Integer { +fn default_2449() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2446() -> Integer { +fn default_2450() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2447() -> Integer { +fn default_2451() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2448() -> Integer { +fn default_2452() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2449() -> f64 { +fn default_2453() -> f64 { serde_json::from_str("0.0").expect("schema default") } -fn default_2450() -> Integer { +fn default_2454() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2451() -> Integer { +fn default_2455() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2452() -> Integer { +fn default_2456() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2453() -> String { +fn default_2457() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2454() -> SessionBriefStats { +fn default_2458() -> SessionBriefStats { serde_json::from_str("{\"events_in\":0,\"windows\":0,\"events_total\":0,\"source_chars\":0,\"brief_chars\":0,\"compression_ratio\":0.0,\"dropped_ungrounded\":0,\"tokens_in\":0,\"tokens_out\":0,\"llm_model\":\"\"}").expect("schema default") } -fn default_2455() -> String { +fn default_2459() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2456() -> String { +fn default_2460() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2457() -> Option { +fn default_2461() -> Option { serde_json::from_str("null").expect("schema default") } -fn default_2458() -> Option { +fn default_2462() -> Option { serde_json::from_str("null").expect("schema default") } -fn default_2459() -> Option { +fn default_2463() -> Option { serde_json::from_str("null").expect("schema default") } -fn default_2460() -> Integer { +fn default_2464() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2461() -> std::collections::HashMap { +fn default_2465() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2462() -> String { +fn default_2466() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2463() -> String { +fn default_2467() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2464() -> Option { +fn default_2468() -> Option { serde_json::from_str("null").expect("schema default") } -fn default_2465() -> String { +fn default_2469() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2466() -> Integer { +fn default_2470() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2467() -> Integer { +fn default_2471() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2468() -> Option { +fn default_2472() -> Option { serde_json::from_str("null").expect("schema default") } -fn default_2469() -> std::collections::HashMap { +fn default_2473() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2470() -> String { +fn default_2474() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2471() -> Integer { +fn default_2475() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2472() -> String { +fn default_2476() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2473() -> Option { +fn default_2477() -> Option { serde_json::from_str("null").expect("schema default") } -fn default_2474() -> String { +fn default_2478() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2475() -> Option { +fn default_2479() -> Option { serde_json::from_str("null").expect("schema default") } -fn default_2476() -> String { +fn default_2480() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2477() -> String { +fn default_2481() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2478() -> String { +fn default_2482() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2479() -> String { +fn default_2483() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2480() -> Integer { +fn default_2484() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2481() -> Integer { +fn default_2485() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2482() -> String { +fn default_2486() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2483() -> std::collections::HashMap { +fn default_2487() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2484() -> String { +fn default_2488() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2485() -> String { +fn default_2489() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2486() -> bool { +fn default_2490() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2487() -> String { +fn default_2491() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2488() -> std::collections::HashMap { +fn default_2492() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2489() -> Vec> { +fn default_2493() -> Vec> { serde_json::from_str("[]").expect("schema default") } -fn default_2490() -> Vec { +fn default_2494() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2491() -> Vec { +fn default_2495() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2492() -> bool { +fn default_2496() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2493() -> String { +fn default_2497() -> String { serde_json::from_str("\"unknown\"").expect("schema default") } -fn default_2494() -> String { +fn default_2498() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2495() -> Vec { +fn default_2499() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2496() -> bool { +fn default_2500() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2497() -> String { +fn default_2501() -> String { serde_json::from_str("\"none\"").expect("schema default") } -fn default_2498() -> bool { +fn default_2502() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2499() -> Vec { +fn default_2503() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2500() -> std::collections::HashMap { +fn default_2504() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2501() -> Vec> { +fn default_2505() -> Vec> { serde_json::from_str("[]").expect("schema default") } -fn default_2502() -> bool { +fn default_2506() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2503() -> bool { +fn default_2507() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2504() -> Vec> { +fn default_2508() -> Vec> { serde_json::from_str("[]").expect("schema default") } -fn default_2505() -> std::collections::HashMap { +fn default_2509() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2506() -> String { +fn default_2510() -> String { serde_json::from_str("\"none\"").expect("schema default") } -fn default_2507() -> Vec> { +fn default_2511() -> Vec> { serde_json::from_str("[]").expect("schema default") } -fn default_2508() -> bool { +fn default_2512() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2509() -> String { +fn default_2513() -> String { serde_json::from_str("\"calibrated\"").expect("schema default") } -fn default_2510() -> std::collections::HashMap { +fn default_2514() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2511() -> std::collections::HashMap { +fn default_2515() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2512() -> String { +fn default_2516() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2513() -> std::collections::HashMap { +fn default_2517() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2514() -> std::collections::HashMap { +fn default_2518() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2515() -> std::collections::HashMap { +fn default_2519() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2516() -> String { +fn default_2520() -> String { serde_json::from_str("\"ok\"").expect("schema default") } -fn default_2517() -> String { +fn default_2521() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2518() -> String { +fn default_2522() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2519() -> bool { +fn default_2523() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2520() -> Integer { +fn default_2524() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2521() -> String { +fn default_2525() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2522() -> String { +fn default_2526() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2523() -> Vec { +fn default_2527() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2524() -> bool { +fn default_2528() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2525() -> Vec { +fn default_2529() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2526() -> std::collections::HashMap> { +fn default_2530() -> std::collections::HashMap> { serde_json::from_str("{}").expect("schema default") } -fn default_2527() -> Vec> { +fn default_2531() -> Vec> { serde_json::from_str("[]").expect("schema default") } -fn default_2528() -> Vec> { +fn default_2532() -> Vec> { serde_json::from_str("[]").expect("schema default") } -fn default_2529() -> String { +fn default_2533() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2530() -> Vec> { +fn default_2534() -> Vec> { serde_json::from_str("[]").expect("schema default") } -fn default_2531() -> std::collections::HashMap { +fn default_2535() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2532() -> String { +fn default_2536() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2533() -> Vec> { +fn default_2537() -> Vec> { serde_json::from_str("[]").expect("schema default") } -fn default_2534() -> bool { +fn default_2538() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2535() -> Integer { +fn default_2539() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2536() -> Vec> { +fn default_2540() -> Vec> { serde_json::from_str("[]").expect("schema default") } -fn default_2537() -> String { +fn default_2541() -> String { serde_json::from_str("\"no_flaky_signal\"").expect("schema default") } -fn default_2538() -> bool { +fn default_2542() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2539() -> Option> { +fn default_2543() -> Option> { serde_json::from_str("null").expect("schema default") } -fn default_2540() -> Vec { +fn default_2544() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2541() -> bool { +fn default_2545() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2542() -> std::collections::HashMap { +fn default_2546() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2543() -> String { +fn default_2547() -> String { serde_json::from_str("\"not_computed\"").expect("schema default") } -fn default_2544() -> Vec> { +fn default_2548() -> Vec> { serde_json::from_str("[]").expect("schema default") } -fn default_2545() -> String { +fn default_2549() -> String { serde_json::from_str("\"candidate\"").expect("schema default") } -fn default_2546() -> std::collections::HashMap { +fn default_2550() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2547() -> String { +fn default_2551() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2548() -> bool { +fn default_2552() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2549() -> Integer { +fn default_2553() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2550() -> std::collections::HashMap { +fn default_2554() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2551() -> bool { +fn default_2555() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2552() -> Vec> { +fn default_2556() -> Vec> { serde_json::from_str("[]").expect("schema default") } -fn default_2553() -> std::collections::HashMap { +fn default_2557() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2554() -> std::collections::HashMap { +fn default_2558() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2555() -> String { +fn default_2559() -> String { serde_json::from_str("\"lower_bound\"").expect("schema default") } -fn default_2556() -> bool { +fn default_2560() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2557() -> Vec { +fn default_2561() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2558() -> Vec> { +fn default_2562() -> Vec> { serde_json::from_str("[]").expect("schema default") } -fn default_2559() -> std::collections::HashMap { +fn default_2563() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2560() -> Vec { +fn default_2564() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2561() -> String { +fn default_2565() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2562() -> bool { +fn default_2566() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2563() -> bool { +fn default_2567() -> bool { serde_json::from_str("true").expect("schema default") } -fn default_2564() -> std::collections::HashMap { +fn default_2568() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2565() -> String { +fn default_2569() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2566() -> bool { +fn default_2570() -> bool { serde_json::from_str("true").expect("schema default") } -fn default_2567() -> std::collections::HashMap { +fn default_2571() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2568() -> std::collections::HashMap { +fn default_2572() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2569() -> Vec> { +fn default_2573() -> Vec> { serde_json::from_str("[]").expect("schema default") } -fn default_2570() -> Vec { +fn default_2574() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2571() -> std::collections::HashMap { +fn default_2575() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2572() -> Vec> { +fn default_2576() -> Vec> { serde_json::from_str("[]").expect("schema default") } -fn default_2573() -> bool { +fn default_2577() -> bool { serde_json::from_str("true").expect("schema default") } -fn default_2574() -> bool { +fn default_2578() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2575() -> Vec { +fn default_2579() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2576() -> std::collections::HashMap { +fn default_2580() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2577() -> String { +fn default_2581() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2578() -> std::collections::HashMap { +fn default_2582() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2579() -> bool { +fn default_2583() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2580() -> bool { +fn default_2584() -> bool { serde_json::from_str("true").expect("schema default") } -fn default_2581() -> String { +fn default_2585() -> String { serde_json::from_str("\"no_signal\"").expect("schema default") } -fn default_2582() -> Vec { +fn default_2586() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2583() -> f64 { +fn default_2587() -> f64 { serde_json::from_str("0.0").expect("schema default") } -fn default_2584() -> Integer { +fn default_2588() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2585() -> String { +fn default_2589() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2586() -> std::collections::HashMap { +fn default_2590() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2587() -> std::collections::HashMap { +fn default_2591() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2588() -> std::collections::HashMap { +fn default_2592() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2589() -> std::collections::HashMap { +fn default_2593() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2590() -> String { +fn default_2594() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2591() -> std::collections::HashMap { +fn default_2595() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2592() -> bool { +fn default_2596() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2593() -> std::collections::HashMap { +fn default_2597() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2594() -> std::collections::HashMap { +fn default_2598() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2595() -> std::collections::HashMap { +fn default_2599() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2596() -> std::collections::HashMap { +fn default_2600() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2597() -> String { +fn default_2601() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2598() -> Vec> { +fn default_2602() -> Vec> { serde_json::from_str("[]").expect("schema default") } -fn default_2599() -> Integer { +fn default_2603() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2600() -> String { +fn default_2604() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2601() -> bool { +fn default_2605() -> bool { serde_json::from_str("true").expect("schema default") } -fn default_2602() -> String { +fn default_2606() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2603() -> Vec { +fn default_2607() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2604() -> bool { +fn default_2608() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2605() -> Vec { +fn default_2609() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2606() -> f64 { +fn default_2610() -> f64 { serde_json::from_str("0.0").expect("schema default") } -fn default_2607() -> String { +fn default_2611() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2608() -> Integer { +fn default_2612() -> Integer { serde_json::from_str("4096").expect("schema default") } -fn default_2609() -> Integer { +fn default_2613() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2610() -> Option { +fn default_2614() -> Option { serde_json::from_str("null").expect("schema default") } -fn default_2611() -> f64 { +fn default_2615() -> f64 { serde_json::from_str("0.0").expect("schema default") } -fn default_2612() -> Option { +fn default_2616() -> Option { serde_json::from_str("null").expect("schema default") } -fn default_2613() -> Vec { +fn default_2617() -> Vec { serde_json::from_str("[]").expect("schema default") } diff --git a/sdk/rust/tests/registry_contracts.rs b/sdk/rust/tests/registry_contracts.rs index 7968b05515..001ba5e1b2 100644 --- a/sdk/rust/tests/registry_contracts.rs +++ b/sdk/rust/tests/registry_contracts.rs @@ -6930,6 +6930,14 @@ fn ops_incidents() { serde_json::from_str::("[]").unwrap(), "ops.incidents:incidents" ); + assert_eq!( + encoded["sources"], + serde_json::from_str::( + "{\"failing\":0,\"sample\":[],\"read\":\"unread\"}" + ) + .unwrap(), + "ops.incidents:sources" + ); } #[test] fn ops_projection_failures_list() { diff --git a/sdk/typescript/src/generated/ops.ts b/sdk/typescript/src/generated/ops.ts index f89578f5be..7b118f7d48 100644 --- a/sdk/typescript/src/generated/ops.ts +++ b/sdk/typescript/src/generated/ops.ts @@ -9161,11 +9161,24 @@ export interface OpsIncident { age_s?: number | null; } +export interface OpsIncidentSources { + failing?: number; + sample?: OpsFailingSource[]; + read?: "read" | "not_permitted" | "unread"; +} + +export interface OpsFailingSource { + namespace: string; + name: string; + status: string; +} + export interface OpsIncidentsOutput { status: "ok" | "degraded"; incidents?: OpsIncident[]; window_minutes: number; requests: "read" | "not_permitted" | "unread"; + sources?: OpsIncidentSources; } export interface OpsProjectionFailuresListInput { diff --git a/server/identity/domain/read_scope.py b/server/identity/domain/read_scope.py index d559ee14d4..61b183e835 100644 --- a/server/identity/domain/read_scope.py +++ b/server/identity/domain/read_scope.py @@ -410,7 +410,8 @@ def pin_read_filters[M: BaseModel](input: M, auth: Any) -> tuple[M, bool]: "ops.capabilities": "the deployment's capabilities", "ops.health": "deployment health", "ops.incidents": ( - "the deployment's incidents; a narrowed token reads no request counts, no memory" + "the deployment's incidents; a narrowed token reads no request counts or failing" + " sources, no memory" ), "mentor.guide": "the deployment's static agent guide, no memory", "help.search": "the deployment's shipped documentation, no memory", diff --git a/server/insights/api/models_ops.py b/server/insights/api/models_ops.py index a7acb12e64..1ed18d4d0b 100644 --- a/server/insights/api/models_ops.py +++ b/server/insights/api/models_ops.py @@ -168,8 +168,11 @@ class OpsIncidentsInput(BaseModel): """Whether Loom is degraded now, from its checks, providers, workers and calls. It lists failing readiness checks, providers and workers, and the share of the org's - calls that failed on the server, which only a caller that reads the org whole (an - org admin over `*`, a platform admin) reads; `requests` says whether they were read. + calls that failed on the server; beside them, the org's document sources whose last + sync failed. Only a caller that reads the org whole (an org admin over `*`, a platform + admin) reads the calls and the sources, and for an org admin the sources leave out the + collections it holds no grant for; `requests` and `sources.read` say whether they were + read. Identity is optional: the org is the token's (role check only; no namespace is addressed).""" @@ -196,7 +199,37 @@ class OpsIncident(BaseModel): age_s: float | None = None -RequestsRead = Literal["read", "not_permitted", "unread"] +OrgRead = Literal["read", "not_permitted", "unread"] + + +class OpsFailingSource(BaseModel): + # The namespace the source's documents live in. + namespace: str + # The source's name, as `knowledge.source.list` lists it. + name: str + # How its last sync turn ended: `failed`, `rate_limited` or `credential_invalid`. + status: str + + +class OpsIncidentSources(BaseModel): + """The org's own document sources whose last sync turn failed. + + Those every reader of their namespace sees, never a mirrored one, in the namespaces + and the collections the caller reads. A source's failure is its own (its + `sync.status` in `knowledge.source.list`), so it never makes `status` `degraded` by + itself: a revoked credential is its org's to fix, not a Loom outage. The Knowledge + page, under "Source failures and the worker's health", says when the sync worker + itself is listed.""" + + # Sources whose last turn failed; 0 unless `read` is `read`. + failing: int = 0 + # At most 5 of them, the latest failure first. + sample: list[OpsFailingSource] = Field(default_factory=list) + # Whether they were read, as for `requests`: `read`; `not_permitted` when the call + # names no single org or the caller does not read the org whole; `unread` when they, + # the restricted set, a restricted namespace's grant or the caller's collection + # grants could not be read, or a platform admin's tenancy check refused. + read: OrgRead = "unread" class OpsIncidentsOutput(BaseModel): @@ -204,7 +237,7 @@ class OpsIncidentsOutput(BaseModel): client polls it, through `loom_op` over MCP, to tell a Loom outage from an empty answer. Nothing here names another org.""" - # `degraded` when an incident is listed, else `ok`. + # `degraded` when an incident is listed, else `ok`; failing `sources` are no incident. status: Literal["ok", "degraded"] # Errors first, at most 20. incidents: list[OpsIncident] = Field(default_factory=list) @@ -215,4 +248,7 @@ class OpsIncidentsOutput(BaseModel): # org whole (a member, a narrowed, pinned or delegated token, a restricted namespace # hidden from it); `unread` when the counts, the restricted set or a restricted # namespace's grant could not be read. - requests: RequestsRead + requests: OrgRead + # The org's document sources whose last sync failed, for its admin to fix; by + # default none, unread (`{failing: 0, sample: [], read: "unread"}`). + sources: OpsIncidentSources = Field(default_factory=OpsIncidentSources) diff --git a/server/insights/app/incidents.py b/server/insights/app/incidents.py index a7a6ca73bb..0043bff4c2 100644 --- a/server/insights/app/incidents.py +++ b/server/insights/app/incidents.py @@ -4,14 +4,20 @@ incident. The answer comes from what the server already keeps: its readiness checks, the outcome of the provider calls it made (`provider_health`), the failure streaks of the workers this deployment runs (`loom.worker_status`) and the org's request failures -(`loom_telemetry.sli_minute`). Nothing names another org: a provider or worker incident -carries an error's kind, never its text, and the request counts are those of the org the -call acts in, read only by a token over every namespace of it (the rollup keeps no -namespace or user). Each ClickHouse source is read at most once per `_SOURCE_TTL_S` per -process, so clients polling during an outage do not add load. A source that cannot be -read within a readiness check's bound (`readiness_check_timeout_s`) is named in the -answer's `degraded`, as long as that failure is cached; the others still answer, so the -op answers during a ClickHouse outage too. +(`loom_telemetry.sli_minute`). Beside the incidents it names the org's document sources +whose last sync failed (their sync states), which are the org's to fix and never make +the answer `degraded`. Nothing names another org: a provider or worker incident carries +an error's kind, never its text, and the request counts and the sources are those of the +org the call acts in, read only by a token over every namespace of it (the rollup keeps +no namespace or user; a source names its namespace). In each process, each of its +ClickHouse reads runs at most once per `_READ_TTL_S` (the worker streaks, and per org the +request counts), and the failing sources once per `_SOURCES_TTL_S` (per org and +collection reach), so clients polling during an outage do not add load. Each read is +cut at a readiness check's bound (`readiness_check_timeout_s`) on both sides, and one +that does not answer within it is named in the answer's `degraded` as long as that +failure is cached; the others still answer, so the op answers during a +ClickHouse outage too. The caller's collection reach, which the sources need, comes +from the grant cache every call uses and is cut at the same bound. """ from __future__ import annotations @@ -22,12 +28,15 @@ from datetime import UTC, datetime from typing import Any +from server.core.ch import statement_timeout from server.core.errors import LoomServerError, caller_text, error_kind from server.insights.api.models_ops import ( + OpsFailingSource, OpsIncident, OpsIncidentsInput, + OpsIncidentSources, OpsIncidentsOutput, - RequestsRead, + OrgRead, ) from server.insights.store import ops as ops_store from server.observability import degradations, provider_health @@ -35,19 +44,26 @@ # not a setting: the bound the output model documents MAX_INCIDENTS = 20 +# not a setting: the bound the output model documents +MAX_SOURCE_SAMPLE = 5 # A failure streak whose last pass is older is no current incident (the worker stopped, # or runs less often than this). # not a setting: what "current" means for a worker, documented with the op _WORKER_WINDOW_HOURS = 6 -# not a setting: polls within it share one read of each ClickHouse source -_SOURCE_TTL_S = 5.0 -# The request-count entries are one per org polling; past this the cache starts over. +# not a setting: polls within it share each ClickHouse read +_READ_TTL_S = 5.0 +# Each read parses every one of the org's sync states, their documents' maps included. +# not a setting: a source's sync state changes once a pass (15 minutes by default) +_SOURCES_TTL_S = 60.0 +# Each org polling holds an entry for its request counts and one for each collection +# reach its callers have; past this the cache starts over. # not a setting: a memory bound, not a behaviour _CACHE_MAX = 1024 -# (source, org) -> (read at, incidents, the read's failure or ""), and the lock its polls -# share while one reads -_cache: dict[tuple[str, str], tuple[float, list[OpsIncident], str]] = {} +# (read, key) -> (read at, what it read, the read's failure or ""), and the lock its +# polls share while one reads; the key is the org (`""` for the worker streaks), for the +# sources the org and the caller's collection reach +_cache: dict[tuple[str, str], tuple[float, Any, str]] = {} _locks: dict[tuple[str, str], asyncio.Lock] = {} @@ -55,31 +71,40 @@ def _line(text: object) -> str: return " ".join(str(text).split())[:200] -async def _cached( - source: str, org: str, read: Callable[[], Awaitable[list[OpsIncident]]] -) -> tuple[list[OpsIncident], bool]: - """(`read()`'s incidents, or the ones it gave within `_SOURCE_TTL_S`; whether that - read answered). Polls that arrive while it reads wait for that read rather than start - their own. A failed read is cached too, and named in `degraded` on every answer that - serves it.""" - key = (source, org) - lock = _locks.get(key) +async def _cached[T]( + name: str, + key: str, + read: Callable[[], Awaitable[T]], + unread: T, + *, + ttl: float = _READ_TTL_S, +) -> tuple[T, bool]: + """(`read()`'s answer, or the one it gave within `ttl`, or `unread` when it failed; + whether that read answered). Polls that arrive while it reads wait for that read + rather than start their own. The server stops the read at the bound the client + waits, so a poll after a slow read's failure never runs beside it. A failed read is + cached as long, so a read slower than the bound is not started again sooner, and it + is named in `degraded` on every answer that serves it.""" + entry = (name, key) + lock = _locks.get(entry) if lock is None: if len(_locks) >= _CACHE_MAX: _locks.clear() _cache.clear() - lock = _locks[key] = asyncio.Lock() + lock = _locks[entry] = asyncio.Lock() async with lock: - hit = _cache.get(key) - if hit is None or time.monotonic() - hit[0] >= _SOURCE_TTL_S: + hit = _cache.get(entry) + if hit is None or time.monotonic() - hit[0] >= ttl: try: - async with asyncio.timeout(settings.readiness_check_timeout_s): - incidents, failure = await read(), "" - except Exception as e: # noqa: BLE001 — an unread source is noted; the others answer - incidents, failure = [], caller_text(e) - hit = _cache[key] = (time.monotonic(), incidents, failure) + bound = settings.readiness_check_timeout_s + async with asyncio.timeout(bound): + with statement_timeout(bound): + answer, failure = await read(), "" + except Exception as e: # noqa: BLE001 — a failed read is noted; the others answer + answer, failure = unread, caller_text(e) + hit = _cache[entry] = (time.monotonic(), answer, failure) if hit[2]: - degradations.partial("ops.incidents", f"{source}_unread", hit[2]) + degradations.partial("ops.incidents", f"{name}_unread", hit[2]) return hit[1], not hit[2] @@ -157,17 +182,19 @@ async def _workers() -> list[OpsIncident]: return out -async def _reads_org_calls(org: str) -> RequestsRead: - """`read` when the caller may read `org`'s call counts. The rollup keeps no namespace - or user, so only a caller that reads the org whole does (`reads_every_namespace`, the - org-wide rollups' rule), reading whole namespaces, with no restricted namespace - hidden from it; with auth off, the install's caller. The counts include calls to - collections it cannot read, which they do not name. Fails closed: a member, a - narrowed or pinned token, a delegated one (never an org admin), or no token where one - is required, is `not_permitted`; an unknown restricted set, a restricted - namespace whose grant could not be read, or an org whose tenancy a platform - administrator's repository read could not check (`tenancy.ensure_held`: a cell that - cannot tell, or another cell's org), is `unread`.""" +async def _reads_org_whole(org: str) -> OrgRead: + """`read` when the caller may read `org`'s call counts and failing sources. The rollup + keeps no namespace or user, and the sources span every namespace, so only a caller + that reads the org whole does (`reads_every_namespace`, the org-wide rollups' rule), + reading whole namespaces, with no restricted namespace hidden from it; with auth off, + the install's caller. The counts include calls to collections it cannot read, which + they do not name. Fails closed: a member, a narrowed or pinned token, a delegated one + (never an org admin), or no token where one is required, is `not_permitted`; an + unknown restricted set, a restricted namespace whose grant could not be read, or an + org whose tenancy a platform administrator's repository read could not check + (`tenancy.ensure_held`: a cell that cannot tell, or another cell's org), is + `unread`. An unknown restricted set and a refused tenancy check name both reads in + `degraded` (`_org_unread`); an unread grant is named there by `restricted_hidden`.""" from server.auth.context import current_auth, reads_every_namespace, restricted_hidden from server.identity.app.request_scope import request_narrowed @@ -179,16 +206,21 @@ async def _reads_org_calls(org: str) -> RequestsRead: try: hidden, unverified = await restricted_hidden(org) except LoomServerError as e: - degradations.partial("ops.incidents", "requests_unread", error_kind(e)) - return "unread" + return _org_unread(error_kind(e)) if hidden == ["*"]: # the restricted set is unread - degradations.partial("ops.incidents", "requests_unread", "ClassificationUnavailable") - return "unread" + return _org_unread("ClassificationUnavailable") if unverified: return "unread" return "not_permitted" if hidden else "read" +def _org_unread(kind: str) -> OrgRead: + """Neither org read is served: both are named in `degraded`.""" + for read in ("requests", "sources"): + degradations.partial("ops.incidents", f"{read}_unread", kind) + return "unread" + + async def _requests(org: str, minutes: int) -> list[OpsIncident]: """An SLO class of the org's calls whose server-side failures reach the share.""" rows = await ops_store.request_errors_by_class(org, minutes) @@ -210,22 +242,85 @@ async def _requests(org: str, minutes: int) -> list[OpsIncident]: return out -async def _request_incidents(org: str, minutes: int) -> tuple[list[OpsIncident], RequestsRead]: - """The org's request incidents, and whether its counts were read. No single org to - read (an org-wide token that named none) is `not_permitted`, as is a token that may - not read the whole org's counts.""" - reach: RequestsRead = await _reads_org_calls(org) if org and org != "*" else "not_permitted" - if reach != "read": - return [], reach - calls, answered = await _cached("requests", org, lambda: _requests(org, minutes)) - return calls, "read" if answered else "unread" +async def _sources(org: str, scope: str, params: dict[str, Any]) -> OpsIncidentSources: + """The org's failing document sources in the namespaces and collections `scope` + admits: how many, and the latest few.""" + from server.knowledge.app.sources import failing_sources + + failing, sample = await failing_sources( + org, sample=MAX_SOURCE_SAMPLE, scope=scope, scope_params=params + ) + return OpsIncidentSources( + failing=failing, + sample=[OpsFailingSource(**row) for row in sample], + read="read", + ) + + +def _sources_unread(kind: str) -> OpsIncidentSources: + degradations.partial("ops.incidents", "sources_unread", kind) + return OpsIncidentSources() + + +async def _sources_read(org: str) -> OpsIncidentSources: + """The org's failing sources the caller may read. A collection shows only to whom its + grants reach, org admins included; a platform admin reads every one. The reach is + resolved first and keys the cache, so callers that read the same collections share + a read and none is served a wider one. A reach that could not be read is `unread`: + `sharing.readable` answers an unread tree or grant as no shared collection, which + would be a narrower count passed off as the whole.""" + from server.auth import fail_closed, sharing + from server.auth.context import collection_clause + + fail_closed.reset() + try: + async with asyncio.timeout(settings.readiness_check_timeout_s): + scope, params = await collection_clause(org) + except Exception as e: # noqa: BLE001 — an unread reach leaves the sources unread; the rest answers + return _sources_unread(error_kind(e)) + if fail_closed.unreadable(): + return _sources_unread("CollectionsUnread") + if scope: + # A person's own collection holds no source: left out, so callers with the same + # grants share a read. + shared = [ns for ns in params["col_readable"] if not sharing.is_personal(ns)] + params = {**params, "col_readable": shared} + # The readable collections the statement runs with; no clause reads every one. + reach = ",".join(params["col_readable"]) if scope else "*" + sources, _ = await _cached( + "sources", + f"{org}\n{reach}", + lambda: _sources(org, scope, params), + OpsIncidentSources(), + ttl=_SOURCES_TTL_S, + ) + return sources + + +async def _org_reads( + org: str, minutes: int +) -> tuple[list[OpsIncident], OrgRead, OpsIncidentSources]: + """The org's request incidents, whether its counts were read, and its failing + sources. No single org to read (an org-wide token that named none) is + `not_permitted`, as is a token that may not read the whole org.""" + whole: OrgRead = await _reads_org_whole(org) if org and org != "*" else "not_permitted" + if whole != "read": + return [], whole, OpsIncidentSources(read=whole) + (calls, answered), sources = await asyncio.gather( + _cached("requests", org, lambda: _requests(org, minutes), list[OpsIncident]()), + _sources_read(org), + ) + return calls, "read" if answered else "unread", sources async def handle_ops_incidents(input: OpsIncidentsInput) -> OpsIncidentsOutput: - """The current incidents, errors first.""" + """The current incidents, errors first, and the org's failing sources, which are no + incident: a source's refused credential is its org's to fix.""" minutes = settings.ops_incidents_window_minutes - ready, (workers, _), (calls, requests) = await asyncio.gather( - _readiness(), _cached("workers", "", _workers), _request_incidents(input.org, minutes) + ready, (workers, _), (calls, requests, sources) = await asyncio.gather( + _readiness(), + _cached("workers", "", _workers, list[OpsIncident]()), + _org_reads(input.org, minutes), ) incidents = [*ready, *_providers(minutes * 60.0), *workers, *calls] incidents.sort(key=lambda i: (i.severity != "error", i.kind, i.subject)) @@ -234,4 +329,5 @@ async def handle_ops_incidents(input: OpsIncidentsInput) -> OpsIncidentsOutput: incidents=incidents[:MAX_INCIDENTS], window_minutes=minutes, requests=requests, + sources=sources, ) diff --git a/server/knowledge/app/source_sync.py b/server/knowledge/app/source_sync.py index 6c6568aaa6..643e4d6f78 100644 --- a/server/knowledge/app/source_sync.py +++ b/server/knowledge/app/source_sync.py @@ -91,6 +91,7 @@ import functools import logging import time +from collections import Counter, defaultdict from collections.abc import AsyncIterator, Awaitable, Callable, Iterator from dataclasses import dataclass, field from datetime import UTC, datetime, timedelta @@ -192,6 +193,63 @@ class SourceGone(Exception): """The source was removed or replaced during its turn: the turn stops.""" +class SourcesFailed(RuntimeError): + """A leg of the pass failed for most of what it handled (sources, or, for the mining, + the documents tried) in most of the orgs it serves: its one failure note. A source's + failure is in its sync state, and one org's failures are its own unless most orgs' + fail; a retirement, which no tenant fails, serves only the orgs it retired for.""" + + +# not a setting: one document tried tells nothing of the model, so a pass's mining is +# judged from two (or from a source that failed whole) +_LEAST_TRIES = 2 + + +@dataclass +class SourceTally: + """Per org, what one leg of a pass handled and what of it failed (sources for the + sync and retirement legs, documents tried for mining), and the kinds of the + failures, each weighed by its failed units.""" + + ran: Counter[str] = field(default_factory=Counter) + failed: Counter[str] = field(default_factory=Counter) + kinds: defaultdict[str, Counter[str]] = field(default_factory=lambda: defaultdict(Counter)) + # A source failed whole (its mining's read, write or raise): the leg is judged however + # few units it handled. + failed_whole: bool = False + + def handled( + self, src: KnowledgeSource, n: int = 1, *, kind: str = "", failed_whole: bool = False + ) -> None: + """`n` units of a source the leg handled, every one of them failing when `kind` + names a failure's kind (`fail`).""" + self.ran[src.org] += n + self.failed_whole |= failed_whole + if kind: + self.fail(src, n, kind=kind) + + def fail(self, src: KnowledgeSource, n: int = 1, *, kind: str) -> None: + """`n` of a source's handled units failing as `kind`: an exception's class, a + turn's status, `SYNC_FAILED` for a mirrored source, or a mining reason + (`not_run`, `refused`, `out_of_time`, `too_large_for_pass`, `failed:`); + a code, never a text.""" + self.failed[src.org] += n + self.kinds[src.org][kind] += n + + def note(self, leg: str, orgs: set[str], *, unit: str = "sources", least: int = 1) -> None: + """One failure for the pass, under the leg's name, when the leg handled at least + `least` units (or a source failed whole) and most of the orgs it serves (`orgs`, + with those the leg ran for) had most of their units fail.""" + serving = orgs | set(self.ran) + failing = [o for o, n in self.ran.items() if self.failed[o] * 2 > n] + judged = self.failed_whole or sum(self.ran.values()) >= least + if judged and len(failing) * 2 > len(serving): + # The kind most common in the orgs that failed, not in those that did not. + kind = sum((self.kinds[o] for o in failing), Counter[str]()).most_common(1)[0][0] + msg = f"failed for most {unit} in {len(failing)} of {len(serving)} orgs" + pass_context.note_failure(SourcesFailed(f"{msg} (most often {kind})"), leg) + + # Why a turn stopped short: they lead its error text, and the dashboard reads a note that # starts with one as "Incomplete" (frontend/src/lib/knowledgeSources.ts, CUT_SHORT). class TurnMark(StrEnum): @@ -303,6 +361,18 @@ class PassResult: # Sources whose turn ended with a status other than ok or failed outright, plus one # for each document's failed extraction try. failed: int = 0 + # Per leg, what it handled and failed: sync turns that ran to an end (mirrored ones + # included), the documents mining tried, and retirement. Each notes at most one + # failure for the pass (`SourceTally.note`). Not in the pass summary + # (`workers.source_sync.outcome`). + turns: SourceTally = field(default_factory=SourceTally) + mining: SourceTally = field(default_factory=SourceTally) + retiring: SourceTally = field(default_factory=SourceTally) + # Orgs with a turn whose credential the provider refused, a turn left out of the + # tally: only its org can rotate it, however many orgs hold one (dormant accounts), so + # it tells nothing of the worker. An org whose every turn was refused counts only in a + # leg that ran for it (mining the documents it stored before, say). + refused_orgs: set[str] = field(default_factory=set) # The pass bound stopped the pass before every source, or every file of one, was # handled. cut: bool = False @@ -359,6 +429,8 @@ async def run_sync( await repo_registry.refresh_db_repos() require_registry_read() usable = await _usable(found) + # The orgs the pass serves: the sync and mining notes count against them. + orgs = {s.org for s in usable} if full: for src in usable: await source_ops.request_full_sync(src) @@ -391,7 +463,13 @@ async def run_sync( # holds the others back; a requested source goes first anyway. pass_context.set_cursor(_cursor_of(src)) break + orgs -= result.refused_orgs - set(result.turns.ran) # see `PassResult.refused_orgs` + # Nothing a tenant does fails a retirement (it deletes Loom's own copies, with no + # credential), so it is judged against the orgs it retired for alone. + result.retiring.note("retirement", set()) + result.turns.note("sync", orgs) await _extract_pending(order, run, result) + result.mining.note("mining", orgs, unit="documents", least=_LEAST_TRIES) if not order and not mirrored and not result.retired: pass_context.mark_idle() return result @@ -502,15 +580,17 @@ async def _sync_turn( log.info("knowledge_source_sync: %s is being synced by another copy", _cursor_of(src)) return None except Exception as e: # noqa: BLE001 — one source's failure must not stop the others + result.turns.handled(src, kind="SYNC_FAILED" if _mirrored(src) else type(e).__name__) if _mirrored(src): _mirror_failure(src, result) return None result.errors.append(f"{_cursor_of(src)}: {type(e).__name__}") result.failed += 1 log.warning("knowledge_source_sync: %s failed: %s", _cursor_of(src), e) - pass_context.note_failure(e, _cursor_of(src)) return None if _mirrored(src): + # Every cause alike: a mirror's turn leaves no more than its one code. + result.turns.handled(src, kind="" if turn.status == "ok" else "SYNC_FAILED") if turn.status != "ok": _mirror_failure(src, result) return turn @@ -520,14 +600,20 @@ async def _sync_turn( result.unconverted += turn.unconverted result.skipped += turn.skipped result.cut |= turn.cut - if turn.status != "ok" and not ( + failed = turn.status != "ok" and not ( turn.status == "provider_removed" and src.kind == "recording" and src.config.get("provider") == "meet" - ): + ) + # A refused credential is left out of the tally (`PassResult.refused_orgs`); one the + # deployment's secret no longer opens is the deployment's, and counts. + if failed and turn.status == "credential_invalid" and source_ops.credential_of(src, warn=False): + result.refused_orgs.add(src.org) + else: + result.turns.handled(src, kind=turn.status if failed else "") + if failed: result.failed += 1 result.errors.append(f"{_cursor_of(src)}: {turn.status} {turn.error}".strip()) - pass_context.note_failure(RuntimeError(turn.error or turn.status), _cursor_of(src)) return turn @@ -550,7 +636,6 @@ async def _registered(src: KnowledgeSource) -> KnowledgeSource | None: def _mirror_failure(src: KnowledgeSource, result: PassResult) -> None: """Report the same code for every cause without exporting turn details.""" result.errors.append(f"{_cursor_of(src)}: SYNC_FAILED") - pass_context.note_failure(RuntimeError("SYNC_FAILED"), _cursor_of(src)) def _turn_of(src: KnowledgeSource) -> Callable[..., Awaitable[TurnResult]]: @@ -1548,7 +1633,9 @@ async def _retire_removed_sources( result.errors.append(f"{_cursor_of(src)}: {type(e).__name__}") result.failed += 1 log.warning("knowledge_source_sync: retiring %s failed: %s", _cursor_of(src), e) - pass_context.note_failure(e, _cursor_of(src)) + result.retiring.handled(src, kind=type(e).__name__) + continue + result.retiring.handled(src) async def _retire_all(src: KnowledgeSource, run: Pass, result: PassResult) -> None: @@ -1631,12 +1718,14 @@ class _Mined: waits: dict[str, list[Any]] # Documents settled at a revision: mined, or given up on. settled: dict[str, str] = field(default_factory=dict) - # A document's extraction was tried and came back (mined or failed), not held. - tried: bool = False + # Documents whose extraction was tried and came back (mined or failed), not held. + tries: int = 0 extracted: int = 0 flagged: int = 0 unextracted: int = 0 - failures: int = 0 + # Each failed document's reason (a code, never a text). + reasons: Counter[str] = field(default_factory=Counter) + # The first failed document's reason. error: str = "" # Why the turn left documents for a later pass (`over_cap`, `held:`, # `pass_bound`). @@ -1648,6 +1737,10 @@ class _Mined: # ends with nothing recorded, and the leg goes on to the next source. lease_lost: bool = False + @property + def failures(self) -> int: + return sum(self.reasons.values()) + async def _extract_pending(order: list[KnowledgeSource], run: Pass, result: PassResult) -> None: """The extraction leg: mine each source's unmined documents while the pass has @@ -1669,7 +1762,7 @@ async def _extract_pending(order: list[KnowledgeSource], run: Pass, result: Pass except Exception as e: # noqa: BLE001 — one source's failed read must not stop the others result.errors.append(f"{_cursor_of(src)}: extraction {type(e).__name__}") result.failed += 1 - pass_context.note_failure(e, _cursor_of(src)) + result.mining.handled(src, kind=type(e).__name__, failed_whole=True) continue todo = _unmined(docs, detail) # A source with nothing to mine and no stale count to clear needs no write. @@ -1702,7 +1795,7 @@ async def _extract_pending(order: list[KnowledgeSource], run: Pass, result: Pass result.errors.append(f"{_cursor_of(src)}: extraction {type(e).__name__}") result.failed += 1 log.warning("knowledge_source_sync: recording %s failed: %s", _cursor_of(src), e) - pass_context.note_failure(e, _cursor_of(src)) + result.mining.handled(src, kind=type(e).__name__, failed_whole=True) continue stop = await _extract_source(src, docs, run, result) @@ -1763,6 +1856,7 @@ async def _extract_source( leg (`_Mined.stop`), else ''. A pass stopped or cancelled records nothing: the documents it did not settle are unmined still.""" mined = _Mined(waits={}) + raised = "" try: async with _source_turn(src) as lease: with sequential_reads(): @@ -1793,14 +1887,20 @@ def may_write() -> bool: result.errors.append(f"{_cursor_of(src)}: extraction {type(e).__name__}") result.failed += 1 log.warning("knowledge_source_sync: mining %s failed: %s", _cursor_of(src), e) - pass_context.note_failure(e, _cursor_of(src)) + raised = type(e).__name__ + # The documents it tried, and those that failed; a raise fails the source's whole try. + if raised: + result.mining.handled(src, max(mined.tries, 1), kind=raised, failed_whole=True) + elif mined.tries: + result.mining.handled(src, mined.tries) + for reason, n in mined.reasons.items(): + result.mining.fail(src, n, kind=reason) result.extracted += mined.extracted result.flagged_pinned += mined.flagged result.unextracted += mined.unextracted result.failed += mined.failures if mined.failures: result.errors.append(f"{_cursor_of(src)}: extraction {mined.error}") - pass_context.note_failure(RuntimeError(mined.error), _cursor_of(src)) if mined.deferred: result.extract_deferred += 1 if mined.deferred.startswith("held:"): @@ -1854,7 +1954,7 @@ async def _extract_one( report = await asyncio.create_task(_mine(src, uri, _read_deadline(run), may_write)) except Exception as e: # noqa: BLE001 — one document's failure must not stop the others log.warning("knowledge_source_sync: mining %s failed: %s", uri, e) - mined.tried = True + mined.tries += 1 _extract_failed(mined, uri, revision, f"failed:{type(e).__name__}") return True if report.held is not None or report.write_stopped: @@ -1870,7 +1970,7 @@ async def _extract_one( elif report.held is not None: mined.deferred = mined.stop = f"held:{report.held.code}" return False - mined.tried = True + mined.tries += 1 if report.out_of_time and read_s >= _full_read_s(): # It had all the read time a pass gives and did not finish: no pass will do. _give_up_mining(mined, uri, revision, "too_large_for_pass") @@ -1934,7 +2034,7 @@ def _give_up_mining(mined: _Mined, uri: str, revision: str, reason: str) -> None mined.waits.pop(uri, None) mined.settled[uri] = revision mined.unextracted += 1 - mined.failures += 1 + mined.reasons[reason] += 1 mined.error = mined.error or reason @@ -1946,7 +2046,7 @@ def _extract_failed(mined: _Mined, uri: str, revision: str, reason: str) -> None _give_up_mining(mined, uri, revision, reason) return mined.waits[uri] = [revision, tries, reason] - mined.failures += 1 + mined.reasons[reason] += 1 mined.error = mined.error or reason @@ -1981,7 +2081,7 @@ async def _write_mined( known = {u: r for u, r in {**_mined_of(detail), **mined.settled}.items() if u in live} detail["mined"] = known detail["extract_waits"] = {u: w for u, w in mined.waits.items() if u in live} - if mined.tried: + if mined.tries: detail.update( last_extracted_at=_now_iso(), extracted=mined.extracted, diff --git a/server/knowledge/app/sources.py b/server/knowledge/app/sources.py index e758bc7590..fddacaf538 100644 --- a/server/knowledge/app/sources.py +++ b/server/knowledge/app/sources.py @@ -107,13 +107,13 @@ def _now_iso() -> str: return datetime.now(UTC).replace(microsecond=0).isoformat() -def credential_of(src: KnowledgeSource) -> str: +def credential_of(src: KnowledgeSource, *, warn: bool = True) -> str: """The source's credential, '' when it no longer opens.""" if src.credential_mode != "shared": return "" # A connected source never falls back to an ingestion credential. if src.secret_enc: - return unseal(_SECRET_PURPOSE, src.secret_enc) - return unseal(_CREDENTIAL_PURPOSE, src.credential_enc) + return unseal(_SECRET_PURPOSE, src.secret_enc, warn=warn) + return unseal(_CREDENTIAL_PURPOSE, src.credential_enc, warn=warn) async def credential_for(src: KnowledgeSource, *, deadline: float) -> Credential: @@ -523,6 +523,16 @@ async def handle_knowledge_source_list( ) +async def failing_sources( + org: str, *, sample: int, scope: str, scope_params: dict[str, Any] +) -> tuple[int, list[dict[str, str]]]: + """How many of the org's sources that every reader of their namespace sees ended their + last sync turn failing, and `sample` of them ({namespace, name, status}), the latest + failure first. A mirrored source is not counted. The caller decides who may read + them: they span every namespace of the org.""" + return await store.failing_sources(org, sample=sample, scope=scope, scope_params=scope_params) + + async def handle_knowledge_source_inspect( input: KnowledgeSourceInspectInput, ) -> KnowledgeSourceInspectOutput: @@ -1445,6 +1455,7 @@ def source_rotate_audit_subject(input: KnowledgeSourceRotateInput, response: Any __all__ = [ "credential_of", "deactivate_namespace_sources", + "failing_sources", "retire_sources_of", "request_full_sync", "sources_lease", diff --git a/server/knowledge/store/sources.py b/server/knowledge/store/sources.py index 3364722ef5..64ba0707e8 100644 --- a/server/knowledge/store/sources.py +++ b/server/knowledge/store/sources.py @@ -29,6 +29,7 @@ from server.core.ch import own_write_reads, sequential_reads from server.core.datetimes import naive_utc_now_seconds +from server.core.naming import not_reserved_sql from server.core.repo_base import _CHClient, _default_client from server.knowledge.domain.live_chunks import has_live_chunks_sql from server.knowledge.domain.mcp_worker_source import decode_worker_source @@ -42,6 +43,7 @@ from server.knowledge.domain.sources import ( MIRRORED_ACCESS, NAMESPACE_ACCESS, + STATE_KEY_PREFIX, SYNC_WORKER_ACTOR, KnowledgeSource, WorkerSourceHistory, @@ -597,6 +599,73 @@ async def read_states( } +# The org's sources shown to every reader of their namespace (`domain.served`) whose last +# turn failed, newest failure first, each row with how many there are. The state of a +# removed source stays, so the registry's active row is joined in; a mirror's own state +# rows and a mirrored or worker source's are left out. `provider_removed` ends only a meet +# recording source's turn, which the sync does not count as failed. +def _failing_sources_sql(scope: str) -> str: + return f""" +SELECT + namespace, + substring(state_key, {{start:UInt64}}) AS source_name, + JSONExtractString(detail, 'status') AS status, + count() OVER () AS failing +FROM {STATE_TABLE} FINAL +WHERE org = {{org:String}} + AND startsWith(state_key, {{prefix:String}}) + AND {not_reserved_sql()}{scope} + AND JSONExtractString(detail, 'status') NOT IN ('', 'ok', 'provider_removed') + AND (namespace, state_key) IN ( + SELECT namespace, concat({{prefix:String}}, name) + FROM {TABLE} FINAL + WHERE org = {{org:String}} AND active + AND access = '{NAMESPACE_ACCESS}' AND credential_mode = 'shared' + AND NOT {WORKER_HISTORY} + ) + AND namespace NOT IN ( + SELECT namespace FROM loom.namespaces FINAL + WHERE org = {{org:String}} AND active = false + ) +ORDER BY JSONExtractString(detail, 'last_synced_at') DESC, namespace, source_name +LIMIT {{limit:UInt64}} +""" + + +async def failing_sources( + org: str, + *, + sample: int, + scope: str, + scope_params: dict[str, Any], + ch: _CHClient | None = None, +) -> tuple[int, list[dict[str, str]]]: + """How many of the org's sources shown to their namespace's readers ended their last + turn failing, and `sample` of them ({namespace, name, status}), the latest first. + `scope` is a WHERE fragment on `namespace` with its `scope_params`: the collections + the caller cannot read (`collection_clause`), `""` only for a caller that reads + every one.""" + rows = await (ch or _default_client()).query_all( + _failing_sources_sql(scope), + params={ + **scope_params, + "org": org, + "prefix": STATE_KEY_PREFIX, + "start": len(STATE_KEY_PREFIX) + 1, + "limit": sample, + }, + ) + failing = int(rows[0]["failing"]) if rows else 0 + return failing, [ + { + "namespace": str(r["namespace"]), + "name": str(r["source_name"]), + "status": str(r["status"]), + } + for r in rows + ] + + async def write_state( org: str, namespace: str, diff --git a/server/operations/base.py b/server/operations/base.py index b8b7d4c92b..758088995b 100644 --- a/server/operations/base.py +++ b/server/operations/base.py @@ -108,9 +108,10 @@ class Operation: # by caller role); the handler enforces its own rules. Role check still runs. skip_namespace_authz: bool = False # The op reads facts about the DEPLOYMENT (its build, its op registry, its - # incidents) and no namespace's data; an org-wide aggregate it also answers is - # authorized by its handler (ops.incidents' request counts). A scoped token — whose - # authority is per-namespace and which the transport would otherwise refuse with + # incidents) and no namespace's memory; an org-wide read it also answers + # (ops.incidents' request counts, and its failing sources, which name namespaces and + # sources) is authorized by its handler. A scoped token — whose authority is + # per-namespace and which the transport would otherwise refuse with # IDENTITY_INCOMPLETE for want of a namespace — passes the role gate with its best # per-namespace role, in its own org only. deployment_scoped: bool = False diff --git a/tests/analyzer/cases/workers.py b/tests/analyzer/cases/workers.py index da8bd121b3..59cd602c80 100644 --- a/tests/analyzer/cases/workers.py +++ b/tests/analyzer/cases/workers.py @@ -10,6 +10,14 @@ from tests.analyzer.cases._common import NS, ORG, rows_by_substring from tests.analyzer.corpus import Case, RecordingCH +# The fragment `collection_clause` gives an org admin with one grant (pinned to the builder +# in tests/unit/test_ops_incidents.py). +SOURCES_SCOPE = ( + " AND (NOT startsWith(namespace, {col_prefix:String})" + " OR namespace IN {col_readable:Array(String)})" +) +SOURCES_SCOPE_PARAMS = {"col_prefix": "col-", "col_readable": ["col-board"]} + async def _pure_builders(ch: RecordingCH, c: dict[str, Any]) -> None: from server.identity.app.traffic_class_registry import REGISTRY_CLASS_SQL @@ -128,11 +136,19 @@ async def _worker_passes(ch: RecordingCH, c: dict[str, Any]) -> None: await status_store.latest_rows(ch=ch) await status_store.resume_cursor("embedding_worker", ch=ch) - # ops.incidents: the deployment's failing workers and the org's request failures. + # ops.incidents: the deployment's failing workers, the org's request failures and its + # failing document sources. from server.insights.store import ops as ops_store + from server.knowledge.store import sources as source_store await status_store.failing_streaks(["embedding_worker"], "deploy:web:blue", 3, 6, ch=ch) await ops_store.request_errors_by_class(ORG, 15, ch=ch) + # A platform admin's read of every collection, and an org admin's, which leaves out + # the collections it cannot read (`collection_clause`). + await source_store.failing_sources(ORG, sample=5, scope="", scope_params={}, ch=ch) + await source_store.failing_sources( + ORG, sample=5, scope=SOURCES_SCOPE, scope_params=SOURCES_SCOPE_PARAMS, ch=ch + ) # The cost-cap verdict for a pass's namespaces in one statement. from server.observability import budget diff --git a/tests/analyzer/shapes.txt b/tests/analyzer/shapes.txt index af3ecd2098..4830e17996 100644 --- a/tests/analyzer/shapes.txt +++ b/tests/analyzer/shapes.txt @@ -709,6 +709,7 @@ 50baf1256eb9 SELECT count() AS n FROM loom.memory_code_links FINAL WHERE org = {org:String} AND namespace = {ns:String} AND tombstoned_at IS NULL 51005813e7c3 SELECT unit_id, path, churn, amp, tested, callees, computed_at FROM loom.code_unit_risk FINAL WHERE org = {org:String} AND namespace = {ns:String} AND unit_id IN {ids:Array(String)} 511151c6fd23 ALTER TABLE loom.memory UPDATE tombstoned_at = {now:DateTime} WHERE (org = {org:String} AND tombstoned_at IS NULL AND has(tags, ?) AND hasAny(tags, {src:Array(String)}) AND hasAny(arrayMap(t -> (names +515e1c1ee3a5 SELECT namespace, substring(state_key, {start:UInt64}) AS source_name, JSONExtractString(detail, ?) AS status, count() OVER () AS failing FROM loom.code_index_state FINAL WHERE org = {org:String} AND 5163c1fd8d3c SELECT count() AS n FROM loom.memory_record_versions WHERE org = {org:String} AND namespace = {ns:String} 516db52eddcc SELECT count() AS n FROM loom.session_brief_revisions WHERE org = {org:String} AND namespace = {ns:String} AND ? 51af520b7286 SELECT DISTINCT tier, qualified_name, symbol_id FROM loom.code_symbol_names WHERE org = {org:String} AND namespace = {ns:String} AND name IN {names:Array(String)} AND (qualified_name = {full:String} O @@ -1948,6 +1949,7 @@ d0be57c846ee SELECT if(consumer = ?, args[?], consumer) AS consumer_key, count() d0c38ecb1040 SELECT chunk_id, path, scope, kind, start_line, end_line, content, symbol_ids, context_description FROM loom.code_chunks FINAL WHERE org = {org:String} AND namespace = {ns:String} AND embedding_model d0c98dde6333 SELECT concat(?, toString(c.session_id), ?, toString(c.chunk_index)) AS memory_key, ? AS memory_type, substring(c.content, ?, ?) AS content_excerpt, c.content AS content_full, c.agent AS agent, c.user d11e82174d2d SELECT concat(?, toString(c.session_id), ?, toString(c.chunk_index)) AS memory_key, ? AS memory_type, substring(c.content, ?, ?) AS content_excerpt, c.content AS content_full, c.agent AS agent, c.user +d132548714c3 SELECT namespace, substring(state_key, {start:UInt64}) AS source_name, JSONExtractString(detail, ?) AS status, count() OVER () AS failing FROM loom.code_index_state FINAL WHERE org = {org:String} AND d143302e86ef SELECT memory_id, org, namespace, agent, user_id, session_id, memory_key, memory_type, if(length(toString(value_json)) > ?, toString(value_json), value) AS value, -- The stored bytes, for version rows d19be6e39b44 SELECT org, namespace, agent, user_id, session_id, scope, embedding_model, memory_key, created_at, version FROM loom.memory_embeddings FINAL PREWHERE (org, namespace, agent, user_id, session_id, memor d19d31a3306d SELECT count() AS n FROM loom.memory_reinforcement WHERE org = {org:String} AND user_id = {uid:String} AND ? diff --git a/tests/integration/test_ops_incidents.py b/tests/integration/test_ops_incidents.py new file mode 100644 index 0000000000..1018220d5d --- /dev/null +++ b/tests/integration/test_ops_incidents.py @@ -0,0 +1,86 @@ +"""ops.incidents over the transport against the real store: the caller org's failing +document sources, read from their sync states, and nothing of another org's; under auth, +nothing for a member and no collection the caller holds no grant for.""" + +from __future__ import annotations + +import json +from typing import Any + +import httpx +import pytest + +from tests.integration._resources import unique_org +from tests.integration._sources import seed_source + +NS = "team-incidents" +BOARD = "col-board" + + +def _sync_state(ch: Any, org: str, name: str, status: str, synced_at: str, ns: str = NS) -> None: + detail = json.dumps({"status": status, "last_synced_at": synced_at}, sort_keys=True) + ch.insert( + "loom.code_index_state", + [[org, ns, f"knowledge_source:{name}", detail]], + column_names=["org", "namespace", "state_key", "detail"], + ) + + +def _sources(url: str, org: str, token: str) -> dict[str, Any]: + resp = httpx.post( + f"{url}/v1/ops.incidents", + json={"org": org}, + headers={"Authorization": f"Bearer {token}"}, + timeout=30.0, + ) + assert resp.status_code == 200, resp.text + return resp.json()["sources"] + + +def test_the_answer_lists_the_callers_failing_sources_only( + control_plane_url: str, ch_client: Any, mint_test_token: Any +) -> None: + org, other = unique_org("incidents"), unique_org("incidents") + for each in (org, other): + for name in ("decks", "notes", "wiki"): + seed_source(ch_client, each, NS, name) + _sync_state(ch_client, org, "decks", "credential_invalid", "2026-01-02T00:00:00+00:00") + _sync_state(ch_client, org, "wiki", "rate_limited", "2026-01-03T00:00:00+00:00") + _sync_state(ch_client, org, "notes", "ok", "2026-01-04T00:00:00+00:00") + _sync_state(ch_client, other, "notes", "failed", "2026-01-05T00:00:00+00:00") + admin = mint_test_token(org=org, roles=["org_admin"], subject="incidents-admin") + + assert _sources(control_plane_url, org, admin) == { + "failing": 2, + "sample": [ + {"namespace": NS, "name": "wiki", "status": "rate_limited"}, + {"namespace": NS, "name": "decks", "status": "credential_invalid"}, + ], + "read": "read", + } + + +def test_a_member_reads_none_and_an_ungranted_collection_is_left_out( + control_plane_url: str, ch_client: Any, mint_test_token: Any +) -> None: + if httpx.post(f"{control_plane_url}/v1/ops.incidents", json={}, timeout=30).status_code != 401: + pytest.skip("needs a server that enforces auth (LOOM_AUTH_REQUIRED=true)") + org = unique_org("incidents") + seed_source(ch_client, org, NS, "wiki") + seed_source(ch_client, org, BOARD, "minutes") + _sync_state(ch_client, org, "wiki", "failed", "2026-01-02T00:00:00+00:00") + _sync_state(ch_client, org, "minutes", "failed", "2026-01-03T00:00:00+00:00", ns=BOARD) + admin = mint_test_token(org=org, roles=["org_admin"], subject="incidents-admin") + member = mint_test_token(org=org, roles=["viewer"], subject="incidents-member") + + # An org admin reaches a collection only through a grant, and holds none on the board. + assert _sources(control_plane_url, org, admin) == { + "failing": 1, + "sample": [{"namespace": NS, "name": "wiki", "status": "failed"}], + "read": "read", + } + assert _sources(control_plane_url, org, member) == { + "failing": 0, + "sample": [], + "read": "not_permitted", + } diff --git a/tests/unit/test_knowledge_source_sync.py b/tests/unit/test_knowledge_source_sync.py index 7a3c3faac0..ad656d2d8a 100644 --- a/tests/unit/test_knowledge_source_sync.py +++ b/tests/unit/test_knowledge_source_sync.py @@ -2822,7 +2822,8 @@ async def _then(*a: Any, **kw: Any) -> None: monkeypatch.setattr(pass_context, "note_failure", lambda e, what="": failures.append(what)) result = asyncio.run(source_sync.run_sync()) assert result.errors == [f"{ORG}/{NS}/decks: extraction ConnectionError"] - assert result.failed == 1 and failures == [f"{ORG}/{NS}/decks"] + # One source of two: its own failure, in the leg's tally, and no failure of the pass. + assert result.failed == 1 and failures == [] # The leg goes on: the other source's document is mined. assert [uri for uri, _, _ in world.mined] == [DOC2] @@ -3437,7 +3438,13 @@ async def _turn(source: Any, state: Any, run: Any) -> source_sync.TurnResult: run = source_sync.Pass(source_sync._budget(), left=5) turn = asyncio.run(source_sync._sync_turn(src, world.states[src.name], run, result)) assert turn is not None and turn.status == status and not turn.complete - assert result.failed == len(result.errors) == len(failures) == expected_failures + assert result.failed == len(result.errors) == expected_failures + # A refused credential is its org's to rotate: it is left out of the tally. + if status == "credential_invalid": + assert (result.turns.ran, result.refused_orgs) == ({}, {ORG}) + else: + assert (result.turns.ran, result.turns.failed[ORG]) == ({ORG: 1}, expected_failures) + assert failures == [] # the pass notes its tally, not the turn assert (result.changed, result.removed, result.unconverted, result.skipped) == (0, 0, 0, 0) assert world.states[src.name]["state_value"] == "old-stamp" detail = _detail(world, src.name) diff --git a/tests/unit/test_knowledge_source_sync_diagnostics.py b/tests/unit/test_knowledge_source_sync_diagnostics.py index a05d19409b..38d8c2d6b3 100644 --- a/tests/unit/test_knowledge_source_sync_diagnostics.py +++ b/tests/unit/test_knowledge_source_sync_diagnostics.py @@ -6,6 +6,7 @@ import contextlib import dataclasses import logging +from collections import Counter from typing import Any import pytest @@ -64,7 +65,9 @@ async def run(*args: Any, answer: Any = turn) -> Any: assert boundary["states"][-1] is turn answers.append(outcome(result)) if mirrored: - assert result == sync.PassResult(sources=1, private_work=True) + # The pass's tally of turns is all a mirrored turn adds: no document figure. + turns = sync.SourceTally(ran=Counter(acme=1)) + assert result == sync.PassResult(sources=1, private_work=True, turns=turns) else: assert result.changed == count and result.cut assert (answers[0] == answers[1]) is mirrored @@ -101,7 +104,9 @@ async def state(*args: Any, exc: Exception = error) -> None: assert "private-file" not in caplog.text assert result.errors == ["acme/code-acme-app/decks: SYNC_FAILED"] assert result.failed == 0 - assert boundary["failures"] == [("RuntimeError", "SYNC_FAILED")] + # Counted toward the pass's tally, never noted on its own. + assert (result.turns.ran, result.turns.failed) == ({"acme": 1}, {"acme": 1}) + assert boundary["failures"] == [] answers.append((dataclasses.asdict(result), caplog.messages[:])) assert answers[0] == answers[1] @@ -118,7 +123,9 @@ async def run(*args: Any) -> Any: assert result.synced == result.failed == 1 assert result.errors == ["acme/code-acme-app/decks: failed ValueError"] assert "namespace diagnostic" in caplog.text - assert boundary["failures"] == [("RuntimeError", "ValueError")] + # The source's failure is its own; the pass notes the tally once (run_sync). + assert (result.turns.ran, result.turns.failed) == ({"acme": 1}, {"acme": 1}) + assert boundary["failures"] == [] @pytest.mark.parametrize("mirrored", [False, True]) diff --git a/tests/unit/test_knowledge_source_sync_failures.py b/tests/unit/test_knowledge_source_sync_failures.py new file mode 100644 index 0000000000..ee580f29b9 --- /dev/null +++ b/tests/unit/test_knowledge_source_sync_failures.py @@ -0,0 +1,790 @@ +"""What a pass of the source sync tells the worker supervisor about its sources' failures. + +A source whose turn failed has its failure in its own sync state (`status`, `error`), +which its namespace's readers see; the pass notes no failure for it. Each leg of the +pass (the sync turns, the mining, the retirement of removed sources) notes one failure +only when most of the orgs it serves had most of their units (sources, or the documents +mining tried) fail: an outage of what every source relies on, or a deployment with a +single org. One org's failures, however many of the sources are its own, are no failure +of the worker every org shares. A retirement, which no tenant fails, serves only the +orgs it retired for.""" + +from __future__ import annotations + +import asyncio +import contextlib +import dataclasses +from typing import Any + +import pytest + +from server.knowledge.app import source_sync +from server.knowledge.domain.sources import KnowledgeSource +from server.workers import pass_context +from tests.unit.test_knowledge_source_sync import FOLDER, NS, ORG, _detail, _source, _World +from tests.unit.test_knowledge_source_sync import world as world # the fixture +from tests.unit.test_knowledge_source_sync_mirror import _mirrored + + +def _sources(world: _World, *names: str) -> None: + world.sources = [_source(name) for name in names] + + +def _noted(leg: str, kind: str, orgs: str = "1 of 1") -> list[tuple[str, str, str]]: + unit = "documents" if leg == "mining" else "sources" + msg = f"failed for most {unit} in {orgs} orgs (most often {kind})" + return [(leg, "SourcesFailed", msg)] + + +_KIND = {"status": "failed", "raises": "ConnectionError"} + + +def _turns(monkeypatch: pytest.MonkeyPatch, failing: set[str], *, how: str = "status") -> None: + """Each source's turn: those in `failing` end `failed` (`status`), or their state write + raises (`raises`); the others end ok.""" + + async def turn(src: KnowledgeSource, state: Any, run: Any) -> source_sync.TurnResult: + out = source_sync.TurnResult() + if src.name in failing and how == "status": + out.fail("failed", "ConnectionError") + return out + + monkeypatch.setattr(source_sync, "_turn_of", lambda src: turn) + if how != "raises": + return + write_state = source_sync._write_state + + async def state(src: KnowledgeSource, read: Any, turn: Any) -> None: + if src.name in failing: + raise ConnectionError("state store down") + await write_state(src, read, turn) + + monkeypatch.setattr(source_sync, "_write_state", state) + + +async def _supervised( + *, full: bool = False +) -> tuple[source_sync.PassResult, pass_context.PassContext]: + """One pass under a pass context, as the supervisor binds it.""" + ctx = pass_context.begin(source_sync.WORKER) + try: + return await source_sync.run_sync(full=full), ctx + finally: + pass_context.clear() + + +@pytest.mark.parametrize("how", ["status", "raises"]) +def test_one_failing_source_of_three_notes_no_pass_failure( + world: _World, monkeypatch: pytest.MonkeyPatch, how: str +) -> None: + _sources(world, "a", "b", "c") + _turns(monkeypatch, {"b"}, how=how) + + result, ctx = asyncio.run(_supervised()) + + assert (ctx.count, ctx.failures) == (0, []) + assert result.failed == 1 and len(result.errors) == 1 + assert result.errors[0].startswith(f"{ORG}/{NS}/b: ") + if how == "status": + # The failure is the source's own, in the sync state its readers see. + assert _detail(world, "b")["status"] == "failed" + assert _detail(world, "a")["status"] == "ok" + + +@pytest.mark.parametrize("how", ["status", "raises"]) +def test_two_failing_sources_of_three_note_one_pass_failure( + world: _World, monkeypatch: pytest.MonkeyPatch, how: str +) -> None: + _sources(world, "a", "b", "c") + _turns(monkeypatch, {"a", "c"}, how=how) + + result, ctx = asyncio.run(_supervised()) + + assert (ctx.count, ctx.failures) == (1, _noted("sync", _KIND[how])) + assert result.failed == 2 and len(result.errors) == 2 + + +def test_the_only_source_failing_notes_one_pass_failure( + world: _World, monkeypatch: pytest.MonkeyPatch +) -> None: + """A deployment with one source still builds the worker's streak, however many orgs + it has besides: an org with no source the pass syncs is not one it serves.""" + _sources(world, "a") + _turns(monkeypatch, {"a"}) + + _, ctx = asyncio.run(_supervised()) + + assert ctx.failures == _noted("sync", "failed") + + +@pytest.mark.parametrize("other_fails", [False, True], ids=["other-ok", "other-fails"]) +def test_one_orgs_failing_sources_are_not_the_others_failure( + world: _World, monkeypatch: pytest.MonkeyPatch, other_fails: bool +) -> None: + """Most of the pass's sources are one org's, and all of them fail: the other org's + source syncs, so the worker has not failed. Both orgs failing is the worker's.""" + world.sources = [ + _source("a"), + _source("b"), + dataclasses.replace(_source("c"), org="other"), + ] + _turns(monkeypatch, {"a", "b", "c"} if other_fails else {"a", "b"}) + + result, ctx = asyncio.run(_supervised()) + + assert result.failed == (3 if other_fails else 2) + assert ctx.failures == (_noted("sync", "failed", "2 of 2") if other_fails else []) + + +def test_an_org_the_pass_does_not_sync_does_not_dilute_an_outage( + world: _World, monkeypatch: pytest.MonkeyPatch +) -> None: + """The other org's only source is in an inactive namespace: the pass syncs nothing of + it, so every org the pass serves failing is still the worker's failure.""" + world.sources = [_source("a"), _source("b"), dataclasses.replace(_source("c"), org="other")] + world.inactive = {("other", NS)} + _turns(monkeypatch, {"a", "b", "c"}) + + result, ctx = asyncio.run(_supervised()) + + assert result.failed == 2 + assert ctx.failures == _noted("sync", "failed") + + +def test_refused_credentials_in_most_orgs_are_no_failure_of_the_worker( + world: _World, monkeypatch: pytest.MonkeyPatch +) -> None: + """A refused credential is its org's to rotate, however many orgs hold one (dormant + accounts whose credentials lapsed): it never counts toward the worker's failure.""" + world.sources = [ + _source("a"), + dataclasses.replace(_source("b"), org="o2"), + dataclasses.replace(_source("c"), org="o3"), + ] + + async def turn(src: KnowledgeSource, state: Any, run: Any) -> source_sync.TurnResult: + out = source_sync.TurnResult() + if src.name in {"a", "b"}: + out.fail("credential_invalid", "the provider refused the credential") + return out + + monkeypatch.setattr(source_sync, "_turn_of", lambda src: turn) + + result, ctx = asyncio.run(_supervised()) + + assert result.failed == 2 and _detail(world, "a")["status"] == "credential_invalid" + assert ctx.failures == [] + + +def test_dormant_orgs_whose_credentials_are_refused_do_not_hide_an_outage( + world: _World, monkeypatch: pytest.MonkeyPatch +) -> None: + """Three orgs hold only refused credentials and the two active orgs' sources fail: + an org whose every turn was refused tells nothing of the worker, so it is not one + the pass counts, and the outage of the active orgs is noted.""" + world.sources = [ + dataclasses.replace(_source(name), org=org) + for name, org in (("d1", "o1"), ("d2", "o2"), ("d3", "o3"), ("a", ORG), ("b", "o5")) + ] + + async def turn(src: KnowledgeSource, state: Any, run: Any) -> source_sync.TurnResult: + out = source_sync.TurnResult() + if src.name.startswith("d"): + out.fail("credential_invalid", "the provider refused the credential") + else: + out.fail("failed", "ConnectionError") + return out + + monkeypatch.setattr(source_sync, "_turn_of", lambda src: turn) + + _, ctx = asyncio.run(_supervised()) + + assert ctx.failures == _noted("sync", "failed", "2 of 2") + + +def test_credentials_the_deployment_no_longer_opens_are_the_workers_failure( + world: _World, monkeypatch: pytest.MonkeyPatch +) -> None: + """A stored credential the deployment's secret does not open (a secret rotated + without its previous one) is the deployment's failure, not its org's: every org's + only source ending `credential_invalid` so notes one.""" + world.sources = [ + dataclasses.replace(_source(name), org=org, credential_enc="sealed-elsewhere") + for name, org in (("a", ORG), ("b", "o2")) + ] + + async def turn(src: KnowledgeSource, state: Any, run: Any) -> source_sync.TurnResult: + out = source_sync.TurnResult() + out.fail("credential_invalid", "the stored credential no longer opens; rotate it") + return out + + monkeypatch.setattr(source_sync, "_turn_of", lambda src: turn) + + _, ctx = asyncio.run(_supervised()) + + assert ctx.failures == _noted("sync", "credential_invalid", "2 of 2") + + +def test_a_mining_note_names_the_reason_of_most_failed_documents( + world: _World, monkeypatch: pytest.MonkeyPatch +) -> None: + """Each failed document counts under its own reason, not its source's first: one + `refused` and four `not_run` documents note `not_run`.""" + from server.memory.app import decision_extract + from server.memory.app.decision_extract import ExtractReport + + world.sources = [ + dataclasses.replace(_source(name), org=org) for name, org in (("a", ORG), ("b", "o2")) + ] + docs = {"source:a": 3, "source:b": 2} + + async def ok(src: KnowledgeSource, state: Any, run: Any) -> source_sync.TurnResult: + return source_sync.TurnResult() + + async def revisions(at: str, ns: str, tag: str, **kw: Any) -> list[dict[str, str]]: + return [ + {"source_uri": f"https://docs.example.com/{tag}/{i}", "source_revision": "r1"} + for i in range(docs.get(tag, 0)) + ] + + async def down(org: str, ns: str, uri: str, **kw: Any) -> ExtractReport: + if uri.endswith("source:a/0"): + return ExtractReport(uri, False, refused=["k: refused: busy"]) + return ExtractReport(uri, False, error="model down") + + monkeypatch.setattr(source_sync, "_turn_of", lambda src: ok) + monkeypatch.setattr(source_sync.store, "source_revisions", revisions) + monkeypatch.setattr(decision_extract, "extract_document", down) + + _, ctx = asyncio.run(_supervised()) + + assert ctx.failures == _noted("mining", "not_run", "2 of 2") + + +@pytest.mark.parametrize(("dormant_docs", "orgs"), [(False, "2 of 2"), (True, "5 of 5")]) +def test_dormant_orgs_do_not_hide_a_model_outage_of_the_active_ones( + world: _World, monkeypatch: pytest.MonkeyPatch, dormant_docs: bool, orgs: str +) -> None: + """An org whose every turn was refused counts only in a leg that ran for it: the + active orgs' changed documents all failing to mine is noted against them alone, and + the dormant orgs' stored documents still to mine count those orgs too.""" + from server.memory.app import decision_extract + from server.memory.app.decision_extract import ExtractReport + + world.sources = [ + dataclasses.replace(_source(name), org=org) + for name, org in (("d1", "o1"), ("d2", "o2"), ("d3", "o3"), ("a", ORG), ("b", "o5")) + ] + + async def turn(src: KnowledgeSource, state: Any, run: Any) -> source_sync.TurnResult: + out = source_sync.TurnResult() + if src.name.startswith("d"): + out.fail("credential_invalid", "the provider refused the credential") + return out + + async def revisions(at: str, ns: str, tag: str, **kw: Any) -> list[dict[str, str]]: + if tag.startswith("source:d") and not dormant_docs: + return [] + return [{"source_uri": f"https://docs.example.com/{tag}/0", "source_revision": "r1"}] + + async def down(org: str, ns: str, uri: str, **kw: Any) -> ExtractReport: + return ExtractReport(uri, False, error="model down") + + monkeypatch.setattr(source_sync, "_turn_of", lambda src: turn) + monkeypatch.setattr(source_sync.store, "source_revisions", revisions) + monkeypatch.setattr(decision_extract, "extract_document", down) + + _, ctx = asyncio.run(_supervised()) + + assert ctx.failures == _noted("mining", "not_run", orgs) + + +def test_a_pass_cut_inside_one_orgs_failing_sources_is_not_the_others_failure( + world: _World, monkeypatch: pytest.MonkeyPatch +) -> None: + """The pass bound ends the turns after one org's failing sources: the org whose + source the pass did not reach has not failed.""" + world.sources = [_source("a"), _source("b"), dataclasses.replace(_source("c"), org="other")] + _turns(monkeypatch, {"a", "b"}) + ran: list[str] = [] + sync_one = source_sync._sync_one + + async def counted(src: KnowledgeSource, *args: Any) -> Any: + ran.append(src.name) + return await sync_one(src, *args) + + monkeypatch.setattr(source_sync, "_sync_one", counted) + monkeypatch.setattr(source_sync.Pass, "spent", lambda self: len(ran) >= 2) + + result, ctx = asyncio.run(_supervised()) + + assert ran == ["a", "b"] and result.cut and result.failed == 2 + assert ctx.failures == [] + + +def test_half_the_sources_failing_is_not_most_of_them( + world: _World, monkeypatch: pytest.MonkeyPatch +) -> None: + _sources(world, "a", "b") + _turns(monkeypatch, {"a"}) + + result, ctx = asyncio.run(_supervised()) + + assert ctx.count == 0 and result.failed == 1 + + +def test_a_lost_folder_counts_toward_the_sync_leg(world: _World) -> None: + """A folder the account no longer sees ends its source's turn `failed`, which counts as + a provider's error does: it is not a refused credential (`PassResult.refused_orgs`).""" + world.lost_folders = {FOLDER} + + result, ctx = asyncio.run(_supervised(full=True)) + + assert _detail(world)["status"] == "failed" and result.refused_orgs == set() + assert ctx.failures == _noted("sync", "failed") + + +def test_a_source_another_copy_holds_is_not_counted( + world: _World, monkeypatch: pytest.MonkeyPatch +) -> None: + """Only the sources whose turn ran count: one another copy syncs is neither.""" + from server.core import leases + + _sources(world, "a", "b", "c") + _turns(monkeypatch, {"a"}) + held = leases.cluster_lease + + @contextlib.asynccontextmanager + async def busy(name: str, **kw: Any) -> Any: + if not name.endswith("/a"): + raise leases.LeaseBusy(name) + async with held(name, **kw) as lease: + yield lease + + monkeypatch.setattr(leases, "cluster_lease", busy) + + _, ctx = asyncio.run(_supervised()) + + assert ctx.failures == _noted("sync", "failed") + + +def test_mirrored_failures_count_toward_the_pass_with_their_one_code( + world: _World, monkeypatch: pytest.MonkeyPatch +) -> None: + world.sources = [_mirrored(name="m1"), _mirrored(name="m2"), _source("plain")] + _turns(monkeypatch, {"m1", "m2"}) + + result, ctx = asyncio.run(_supervised()) + + assert result.private_work and ctx.private_work + assert result.errors == [f"{ORG}/{NS}/m1: SYNC_FAILED", f"{ORG}/{NS}/m2: SYNC_FAILED"] + assert result.failed == 0 # a mirrored turn contributes its code, never a figure + assert ctx.failures == _noted("sync", "SYNC_FAILED") + + +def test_one_mirrored_failure_of_three_notes_no_pass_failure( + world: _World, monkeypatch: pytest.MonkeyPatch +) -> None: + world.sources = [_mirrored(name="m1"), _source("a"), _source("b")] + _turns(monkeypatch, {"m1"}) + + result, ctx = asyncio.run(_supervised()) + + assert result.errors == [f"{ORG}/{NS}/m1: SYNC_FAILED"] + assert ctx.count == 0 + + +def test_a_worker_copys_failure_counts_with_the_one_mirrored_code( + world: _World, monkeypatch: pytest.MonkeyPatch +) -> None: + """An owner's worker copy is written into the mirror like a mirrored source: a turn + whose state write raises is tallied under `SYNC_FAILED`, never its exception's class.""" + from server.settings import settings + from tests.unit.test_worker_source_copies import _source as _worker_source + + monkeypatch.setattr(settings, "knowledge_source_worker_copies_enabled", True) + src = _worker_source() + world.sources = [src] + _turns(monkeypatch, {src.name}, how="raises") + + result, ctx = asyncio.run(_supervised()) + + assert result.private_work and ctx.private_work + assert result.errors == [f"{src.org}/{src.namespace}/{src.name}: SYNC_FAILED"] + assert ctx.failures == _noted("sync", "SYNC_FAILED") + + +def test_a_failed_store_read_every_source_shares_notes_once( + world: _World, monkeypatch: pytest.MonkeyPatch +) -> None: + """The mining leg's read of each source's documents is the store's: when it fails + for every source, the leg notes one failure, though every turn was ok.""" + _sources(world, "a", "b", "c") + _turns(monkeypatch, set()) + + async def down(*args: Any, **kw: Any) -> Any: + raise ConnectionError("store down") + + monkeypatch.setattr(source_sync.store, "source_revisions", down) + + result, ctx = asyncio.run(_supervised()) + + assert (ctx.count, ctx.failures) == (1, _noted("mining", "ConnectionError")) + assert result.errors == [f"{ORG}/{NS}/{n}: extraction ConnectionError" for n in "abc"] + + +@pytest.mark.parametrize("failing", ["b", "abc"]) +def test_a_documents_failed_mining_is_its_sources_unless_most_fail( + world: _World, monkeypatch: pytest.MonkeyPatch, failing: str +) -> None: + """One document that fails to mine is retried for `_WAIT_PASSES` passes, as many as + the worker's streak needs: it is its source's failure, in its sync state. Every + source's mining failing (the model) is the worker's.""" + from server.memory.app.decision_extract import ExtractReport + + _sources(world, "a", "b", "c") + _turns(monkeypatch, set()) + + async def revisions(org: str, ns: str, tag: str, **kw: Any) -> list[dict[str, str]]: + return [{"source_uri": f"https://docs.example.com/{tag}", "source_revision": "r1"}] + + monkeypatch.setattr(source_sync.store, "source_revisions", revisions) + world.mine_answer = lambda uri: ( + ExtractReport(uri, False, error="no chunks") if uri[-1] in failing else None + ) + + result, ctx = asyncio.run(_supervised()) + + assert len(world.mined) == 3 and result.failed == len(failing) + assert _detail(world, "b")["extract_error"] == "not_run" + assert ctx.failures == (_noted("mining", "not_run") if failing == "abc" else []) + + +@pytest.mark.parametrize("failing", ["1", "123"]) +def test_one_failing_document_does_not_fail_its_source( + world: _World, monkeypatch: pytest.MonkeyPatch, failing: str +) -> None: + """A deployment with one source of three documents: one document that fails to mine + is that document's, in its source's `extract_error`; most of them failing is the + source's mining failing.""" + from server.memory.app.decision_extract import ExtractReport + + _sources(world, "a") + _turns(monkeypatch, set()) + + async def revisions(org: str, ns: str, tag: str, **kw: Any) -> list[dict[str, str]]: + return [ + {"source_uri": f"https://docs.example.com/{tag}/{i}", "source_revision": "r1"} + for i in "123" + ] + + monkeypatch.setattr(source_sync.store, "source_revisions", revisions) + world.mine_answer = lambda uri: ( + ExtractReport(uri, False, error="no chunks") if uri[-1] in failing else None + ) + + result, ctx = asyncio.run(_supervised()) + + assert len(world.mined) == 3 and result.failed == len(failing) + assert ctx.failures == (_noted("mining", "not_run") if failing == "123" else []) + + +def test_a_store_read_failing_for_each_orgs_only_source_notes_once( + world: _World, monkeypatch: pytest.MonkeyPatch +) -> None: + """A read that fails fails the source's mining whole, so it counts however few + documents an org has: two orgs of one source each are an outage of the store.""" + world.sources = [_source("a"), dataclasses.replace(_source("c"), org="other")] + _turns(monkeypatch, set()) + + async def down(*args: Any, **kw: Any) -> Any: + raise ConnectionError("store down") + + monkeypatch.setattr(source_sync.store, "source_revisions", down) + + _, ctx = asyncio.run(_supervised()) + + assert ctx.failures == _noted("mining", "ConnectionError", "2 of 2") + + +def test_a_failed_store_read_of_a_deployments_only_source_notes_once( + world: _World, monkeypatch: pytest.MonkeyPatch +) -> None: + """The two-try floor is for documents: a read of the only source's documents failing + every pass is the store's, and the worker's failure, however few sources there are.""" + _sources(world, "a") + _turns(monkeypatch, set()) + + async def down(*args: Any, **kw: Any) -> Any: + raise ConnectionError("store down") + + monkeypatch.setattr(source_sync.store, "source_revisions", down) + + _, ctx = asyncio.run(_supervised()) + + assert ctx.failures == _noted("mining", "ConnectionError") + + +def test_a_failed_record_write_of_each_orgs_only_source_notes_once( + world: _World, monkeypatch: pytest.MonkeyPatch +) -> None: + """Each org's only source mines its one document, and the write of what it mined + fails: a source whose mining raised failed whole, so its org counts though it tried + a single document.""" + world.sources = [_source("a"), dataclasses.replace(_source("c"), org="other")] + _turns(monkeypatch, set()) + + async def revisions(at: str, ns: str, tag: str, **kw: Any) -> list[dict[str, str]]: + return [{"source_uri": f"https://docs.example.com/{tag}/0", "source_revision": "r1"}] + + async def one_try(src: Any, todo: Any, run: Any, result: Any, mined: Any, *a: Any) -> None: + mined.tries += 1 + + async def write(src: Any, mined: Any, *a: Any, **kw: Any) -> None: + if mined is not None: + raise ConnectionError("record store down") + + monkeypatch.setattr(source_sync.store, "source_revisions", revisions) + monkeypatch.setattr(source_sync, "_extract_all", one_try) + monkeypatch.setattr(source_sync, "_write_mined", write) + + _, ctx = asyncio.run(_supervised()) + + assert ctx.failures == _noted("mining", "ConnectionError", "2 of 2") + + +def test_a_failed_record_write_of_documents_left_waiting_notes_once( + world: _World, monkeypatch: pytest.MonkeyPatch +) -> None: + """Documents left for later (mining switched off for the org) still record why they + wait; that write failing for each org's only source (a store outage) fails the + source whole.""" + world.sources = [_source("a"), dataclasses.replace(_source("c"), org="other")] + _turns(monkeypatch, set()) + + async def revisions(at: str, ns: str, tag: str, **kw: Any) -> list[dict[str, str]]: + return [{"source_uri": f"https://docs.example.com/{tag}/0", "source_revision": "r1"}] + + async def off() -> frozenset[str]: + return frozenset({ORG, "other"}) + + async def write(src: Any, mined: Any, *a: Any, **kw: Any) -> None: + if mined is None: + raise ConnectionError("record store down") + + monkeypatch.setattr(source_sync.store, "source_revisions", revisions) + monkeypatch.setattr(source_sync.customer, "switched_off_orgs", off) + monkeypatch.setattr(source_sync, "_write_mined", write) + + _, ctx = asyncio.run(_supervised()) + + assert ctx.failures == _noted("mining", "ConnectionError", "2 of 2") + + +def _documents(monkeypatch: pytest.MonkeyPatch, count: int, org: str = ORG) -> None: + """Each source of `org` holds `count` unmined documents; another org's none.""" + + async def revisions(at: str, ns: str, tag: str, **kw: Any) -> list[dict[str, str]]: + if at != org: + return [] + return [ + {"source_uri": f"https://docs.example.com/{tag}/{i}", "source_revision": "r1"} + for i in range(count) + ] + + monkeypatch.setattr(source_sync.store, "source_revisions", revisions) + + +def test_a_model_outage_on_a_large_source_is_the_workers_failure( + world: _World, monkeypatch: pytest.MonkeyPatch +) -> None: + """A source of more documents than a pass mines: every document it tried failing is + its mining failing, however many it has left.""" + from server.memory.app.decision_extract import ExtractReport + + _sources(world, "a") + _turns(monkeypatch, set()) + _documents(monkeypatch, 100) + world.mine_answer = lambda uri: ExtractReport(uri, False, error="model down") + + _, ctx = asyncio.run(_supervised()) + + assert 1 < len(world.mined) < 100 + assert ctx.failures == _noted("mining", "not_run") + + +def test_one_orgs_failing_documents_are_not_the_others_failure( + world: _World, monkeypatch: pytest.MonkeyPatch +) -> None: + """The only org with documents to mine has all of them fail: an org with nothing to + mine has not failed, so one org never makes the worker fail for the other.""" + from server.memory.app.decision_extract import ExtractReport + + world.sources = [_source("a"), dataclasses.replace(_source("c"), org="other")] + _turns(monkeypatch, set()) + _documents(monkeypatch, 3) + world.mine_answer = lambda uri: ExtractReport(uri, False, error="no chunks") + + result, ctx = asyncio.run(_supervised()) + + assert len(world.mined) == 3 and result.failed == 3 + assert ctx.failures == [] + + +def test_a_model_outage_on_one_document_of_each_org_is_the_workers_failure( + world: _World, monkeypatch: pytest.MonkeyPatch +) -> None: + """Every org mines one changed document and each fails: three tries in the pass, most + of every org's failing, is an outage however few each org tried.""" + from server.memory.app import decision_extract + from server.memory.app.decision_extract import ExtractReport + + world.sources = [ + _source("a"), + dataclasses.replace(_source("b"), org="o2"), + dataclasses.replace(_source("c"), org="o3"), + ] + _turns(monkeypatch, set()) + + async def revisions(at: str, ns: str, tag: str, **kw: Any) -> list[dict[str, str]]: + return [{"source_uri": f"https://docs.example.com/{tag}/0", "source_revision": "r1"}] + + async def down(org: str, ns: str, uri: str, **kw: Any) -> ExtractReport: + return ExtractReport(uri, False, error="model down") + + monkeypatch.setattr(source_sync.store, "source_revisions", revisions) + monkeypatch.setattr(decision_extract, "extract_document", down) + + result, ctx = asyncio.run(_supervised()) + + assert result.failed == 3 + assert ctx.failures == _noted("mining", "not_run", "3 of 3") + + +def test_the_only_document_mined_in_a_pass_failing_is_not_the_workers_failure( + world: _World, monkeypatch: pytest.MonkeyPatch +) -> None: + """One changed document of a deployment's only source fails to mine: one try tells + nothing of the model, so it stays the document's own.""" + from server.memory.app.decision_extract import ExtractReport + + _sources(world, "a") + _turns(monkeypatch, set()) + _documents(monkeypatch, 1) + world.mine_answer = lambda uri: ExtractReport(uri, False, error="no chunks") + + result, ctx = asyncio.run(_supervised()) + + assert len(world.mined) == 1 and result.failed == 1 + assert ctx.failures == [] + + +def test_orgs_the_document_bound_left_waiting_have_not_failed( + world: _World, monkeypatch: pytest.MonkeyPatch +) -> None: + """One org's backlog takes every try of the pass while the model is down: the orgs the + bound left waiting have not failed, so one org's failing backlog never fails the + worker, and the outage is not noted (each source's `extract_error` shows it).""" + from server.memory.app.decision_extract import ExtractReport + + world.sources = [ + _source("a"), + dataclasses.replace(_source("b"), org="o2"), + dataclasses.replace(_source("c"), org="o3"), + ] + _turns(monkeypatch, set()) + + async def revisions(at: str, ns: str, tag: str, **kw: Any) -> list[dict[str, str]]: + return [ + {"source_uri": f"https://docs.example.com/{at}/{i}", "source_revision": "r1"} + for i in range(100 if at == ORG else 5) + ] + + monkeypatch.setattr(source_sync.store, "source_revisions", revisions) + world.mine_answer = lambda uri: ExtractReport(uri, False, error="model down") + + result, ctx = asyncio.run(_supervised()) + + assert world.mined and all(f"/{ORG}/" in uri for uri, _, _ in world.mined) + assert result.extract_deferred == 3 # the rest of a's backlog, and b's and c's documents + assert ctx.failures == [] + + +@pytest.mark.parametrize("failing", ["b", "abc"]) +def test_a_removed_sources_failed_retirement_is_its_own_unless_most_fail( + world: _World, monkeypatch: pytest.MonkeyPatch, failing: str +) -> None: + world.sources = [ + dataclasses.replace(_source(name), active=False, pending_delete=True) for name in "abc" + ] + + async def retire(src: KnowledgeSource, run: Any, result: Any) -> None: + if src.name in failing: + raise ConnectionError("store down") + + monkeypatch.setattr(source_sync, "_retire_all", retire) + + result, ctx = asyncio.run(_supervised()) + + assert result.failed == len(failing) + assert ctx.failures == (_noted("retirement", "ConnectionError") if failing == "abc" else []) + + +@pytest.mark.parametrize("other_retires", [False, True], ids=["alone", "beside_another"]) +def test_a_failed_retirement_is_judged_against_the_orgs_it_ran_for( + world: _World, monkeypatch: pytest.MonkeyPatch, other_retires: bool +) -> None: + """Nothing a tenant does fails a retirement: it deletes Loom's own copies, with no + credential. An org with no removed source does not dilute it, so one org's retirement + failing is the worker's failure when it fails for most of the orgs it retired for.""" + world.sources = [ + dataclasses.replace(_source("gone"), active=False, pending_delete=True), + dataclasses.replace( + _source("c"), org="other", active=not other_retires, pending_delete=other_retires + ), + ] + _turns(monkeypatch, set()) + + async def retire(src: KnowledgeSource, run: Any, result: Any) -> None: + if src.org == ORG: + raise ConnectionError("store down") + + monkeypatch.setattr(source_sync, "_retire_all", retire) + + result, ctx = asyncio.run(_supervised()) + + assert result.errors[:1] == [f"{ORG}/{NS}/gone: ConnectionError"] + assert ctx.failures == ([] if other_retires else _noted("retirement", "ConnectionError")) + + +def test_a_note_names_the_kind_most_common_among_the_orgs_that_failed() -> None: + """One org's few rate-limited sources, not most of its own, name no outage of the + two orgs whose only source failed.""" + tally = source_sync.SourceTally() + for i in range(7): + tally.handled(_source(f"a{i}"), kind="rate_limited" if i < 3 else "") + for org in ("b", "c"): + tally.handled(dataclasses.replace(_source("x"), org=org), kind="failed") + ctx = pass_context.begin(source_sync.WORKER) + try: + tally.note("sync", set()) + finally: + pass_context.clear() + + assert ctx.failures == _noted("sync", "failed", "2 of 3") + + +def test_a_mining_note_names_the_kind_of_most_failed_documents() -> None: + """A kind weighs the documents that failed of it, not the sources: 40 documents of + one source failing outweigh two sources whose record write raised.""" + tally = source_sync.SourceTally() + tally.handled(_source("big"), 40, kind="not_run") + for name in ("s1", "s2"): + tally.handled(_source(name), kind="ConnectionError", failed_whole=True) + ctx = pass_context.begin(source_sync.WORKER) + try: + tally.note("mining", set(), unit="documents", least=2) + finally: + pass_context.clear() + + assert ctx.failures == _noted("mining", "not_run") diff --git a/tests/unit/test_ops_incidents.py b/tests/unit/test_ops_incidents.py index 5eef00f721..14c1a1cd3b 100644 --- a/tests/unit/test_ops_incidents.py +++ b/tests/unit/test_ops_incidents.py @@ -1,5 +1,5 @@ """ops.incidents: the current incidents from readiness, provider health, worker streaks -and the org's request failures; an unread source is named in `degraded`, never a 500.""" +and the org's request failures; a failed read is named in `degraded`, never a 500.""" from __future__ import annotations @@ -11,10 +11,12 @@ import pytest +from server.auth import sharing from server.auth.context import set_current_auth from server.auth.jwt import AuthInfo, TokenError from server.core import readiness from server.core.errors import BackendUnavailableError, WrongCellError +from server.core.principals import personal_name from server.insights.api.models_ops import OpsIncidentsInput, OpsIncidentsOutput from server.insights.app import incidents from server.insights.app.incidents import handle_ops_incidents @@ -23,16 +25,18 @@ from server.operations.registry import OPERATIONS_BY_NAME from server.settings import settings from tests.unit.ch_fake import RecordingCH, server_error +from tests.unit.clock_fake import ManualClock def _token( org: str = "acme", namespaces: tuple[str, ...] = ("*",), roles: tuple[Role, ...] = (Role.VIEWER,), + subject: str = "viewer", **kw: Any, ) -> AuthInfo: return AuthInfo( - subject="viewer", + subject=subject, org=org, namespaces=namespaces, roles=roles, @@ -41,6 +45,9 @@ def _token( ) +# The collections a caller reads, before the fixture stands in for it. +_READABLE = sharing.readable + # reads the org whole, as the org-wide rollups' rule has it (`reads_every_namespace`) ORG_WIDE = _token(roles=(Role.ORG_ADMIN,)) @@ -55,14 +62,20 @@ def _clean(monkeypatch: pytest.MonkeyPatch): monkeypatch.setattr( "server.auth.context.restricted_hidden", AsyncMock(return_value=([], False)) ) + monkeypatch.setattr("server.auth.sharing.readable", AsyncMock(return_value=[])) provider_health.reset() degradations.begin() yield provider_health.reset() -def _ch(monkeypatch: pytest.MonkeyPatch, *, workers=(), sli=()) -> RecordingCH: - ch = RecordingCH().on("loom.worker_status", list(workers)).on("sli_minute", list(sli)) +def _ch(monkeypatch: pytest.MonkeyPatch, *, workers=(), sli=(), sources=()) -> RecordingCH: + ch = ( + RecordingCH() + .on("loom.worker_status", list(workers)) + .on("sli_minute", list(sli)) + .on("loom.code_index_state", list(sources)) + ) return ch.install(monkeypatch) @@ -207,21 +220,24 @@ async def test_a_provider_failure_older_than_the_window_is_not_current(monkeypat @pytest.mark.asyncio -async def test_an_unread_source_is_named_in_degraded_and_the_others_answer(monkeypatch) -> None: +async def test_a_failed_read_is_named_in_degraded_and_the_others_answer(monkeypatch) -> None: def _down(sql, params): raise server_error("Connection refused", code=210) readiness.register("migrations", lambda: readiness.result(False, "pending: 200_x.sql")) - RecordingCH().on("loom.worker_status", _down).on("sli_minute", _down).install(monkeypatch) + down = RecordingCH().on("loom.worker_status", _down).on("sli_minute", _down) + down.on("loom.code_index_state", _down).install(monkeypatch) out = await _incidents() assert [(i.kind, i.subject) for i in out.incidents] == [("readiness", "migrations")] assert out.requests == "unread" # `ok` would not have covered the org's calls + assert (out.sources.read, out.sources.failing, out.sources.sample) == ("unread", 0, []) notes = degradations.current() assert [n.split(" (")[0] for n in notes] == [ "ops.incidents: workers_unread", "ops.incidents: requests_unread", + "ops.incidents: sources_unread", ] assert "Connection refused" not in " ".join(notes) # the kind, never the driver's text assert provider_health.status()["providers"] == {} # Loom's own reads, not a provider @@ -234,7 +250,8 @@ async def test_polls_within_the_ttl_share_one_read_and_a_cached_failure_is_still def _down(sql, params): raise server_error("Connection refused", code=210) - ch = RecordingCH().on("loom.worker_status", _down).on("sli_minute", []).install(monkeypatch) + ch = RecordingCH().on("loom.worker_status", _down).on("sli_minute", []) + ch.on("loom.code_index_state", []).install(monkeypatch) await _incidents() degradations.begin() # the next poll is another request @@ -248,20 +265,22 @@ def _down(sql, params): @pytest.mark.asyncio async def test_polls_that_arrive_while_a_read_is_in_flight_wait_for_it(monkeypatch) -> None: - """A stalled store: concurrent polls share the one read in flight per source, so they + """A stalled store: concurrent polls share each read in flight, so they do not multiply the reads while ClickHouse is slow.""" from server.insights.store import ops as ops_store + from server.knowledge.store import sources as sources_store from server.workers import status_store calls: list[str] = [] - async def _slow(source: str) -> list[dict[str, Any]]: + async def _slow(source: str) -> Any: calls.append(source) await asyncio.sleep(0.05) - return [] + return (0, []) if source == "sources" else [] monkeypatch.setattr(status_store, "failing_streaks", lambda *a, **k: _slow("workers")) monkeypatch.setattr(ops_store, "request_errors_by_class", lambda *a, **k: _slow("requests")) + monkeypatch.setattr(sources_store, "failing_sources", lambda *a, **k: _slow("sources")) set_current_auth(ORG_WIDE) try: polls = [handle_ops_incidents(OpsIncidentsInput(org="acme")) for _ in range(8)] @@ -269,7 +288,7 @@ async def _slow(source: str) -> list[dict[str, Any]]: finally: set_current_auth(None) - assert sorted(calls) == ["requests", "workers"] + assert sorted(calls) == ["requests", "sources", "workers"] assert [o.status for o in outs] == ["ok"] * 8 @@ -324,11 +343,13 @@ async def test_only_a_caller_that_reads_the_org_whole_reads_its_request_counts( await _incidents(auth=None), ] - assert ch.statements("sli_minute") == [] + assert ch.statements("sli_minute") == ch.statements("loom.code_index_state") == [] assert [(o.incidents, o.requests) for o in outs] == [([], "not_permitted")] * len(outs) + assert [o.sources.read for o in outs] == ["not_permitted"] * len(outs) assert degradations.current() == [] whole = await _incidents() assert [i.subject for i in whole.incidents] == ["code"] and whole.requests == "read" + assert whole.sources.read == "read" @pytest.mark.asyncio @@ -343,17 +364,20 @@ async def test_an_org_admin_with_a_restricted_namespace_hidden_reads_no_counts( monkeypatch.setattr("server.auth.context.restricted_hidden", hidden) out = await _incidents() - assert (out.incidents, out.requests) == ([], "not_permitted") + assert (out.incidents, out.requests, out.sources.read) == ([], "not_permitted", "not_permitted") assert degradations.current() == [] hidden.return_value = (["*"], False) out = await _incidents() - assert (out.incidents, out.requests) == ([], "unread") - assert degradations.current() == ["ops.incidents: requests_unread (ClassificationUnavailable)"] + assert (out.incidents, out.requests, out.sources.read) == ([], "unread", "unread") + assert degradations.current() == [ + "ops.incidents: requests_unread (ClassificationUnavailable)", + "ops.incidents: sources_unread (ClassificationUnavailable)", + ] degradations.begin() hidden.return_value = (["code-secret"], True) # its grant could not be read out = await _incidents() - assert (out.incidents, out.requests) == ([], "unread") + assert (out.incidents, out.requests, out.sources.read) == ([], "unread", "unread") # A platform administrator's repository read checks the org's tenancy: a cell that # cannot tell, or another cell's org, reads no counts and the other sources answer. @@ -364,10 +388,246 @@ async def test_an_org_admin_with_a_restricted_namespace_hidden_reads_no_counts( degradations.begin() hidden.side_effect = refused out = await _incidents() - assert (out.incidents, out.requests) == ([], "unread") - assert degradations.current() == [f"ops.incidents: requests_unread ({kind})"] + assert (out.incidents, out.requests, out.sources.read) == ([], "unread", "unread") + assert degradations.current() == [ + f"ops.incidents: requests_unread ({kind})", + f"ops.incidents: sources_unread ({kind})", + ] hidden.side_effect = None - assert ch.statements("sli_minute") == [] + assert ch.statements("sli_minute") == ch.statements("loom.code_index_state") == [] + + +# What the sources statement answers: the sample, each row with the total. +_FAILING = [ + {"namespace": "team", "source_name": "decks", "status": "credential_invalid", "failing": 7}, + {"namespace": "ops", "source_name": "runbooks", "status": "rate_limited", "failing": 7}, +] + + +@pytest.mark.asyncio +async def test_the_callers_org_failing_sources_are_listed_and_never_degrade_status( + monkeypatch, +) -> None: + """A tenant's revoked credential is the tenant's to fix: `sources` names the org's + failing sources and `status` stays Loom's own health.""" + ch = _ch(monkeypatch, sources=_FAILING) + + out = await _incidents() + + assert (out.status, out.incidents) == ("ok", []) + assert out.sources.read == "read" and out.sources.failing == 7 + assert [(s.namespace, s.name, s.status) for s in out.sources.sample] == [ + ("team", "decks", "credential_invalid"), + ("ops", "runbooks", "rate_limited"), + ] + (read,) = ch.statements("loom.code_index_state") + assert read.params["org"] == "acme" # the caller's org, never another + assert read.params["limit"] == incidents.MAX_SOURCE_SAMPLE == 5 + assert degradations.current() == [] + + +@pytest.mark.asyncio +async def test_no_failing_source_reads_zero(monkeypatch) -> None: + _ch(monkeypatch) + + out = await _incidents() + + assert (out.sources.read, out.sources.failing, out.sources.sample) == ("read", 0, []) + + +@pytest.mark.asyncio +async def test_each_org_reads_its_own_sources_once_per_ttl(monkeypatch) -> None: + ch = _ch(monkeypatch, sources=_FAILING) + + await _incidents() + await _incidents() + other = await _incidents(org="other", auth=_token(org="other", roles=(Role.ORG_ADMIN,))) + + assert [s.params["org"] for s in ch.statements("loom.code_index_state")] == ["acme", "other"] + assert other.sources.failing == 7 # the route answers every org alike here + + +@pytest.mark.asyncio +async def test_each_read_carries_the_readiness_bound_to_clickhouse(monkeypatch) -> None: + """A read past the bound stops on the server too, so a poll after its cached + failure never runs beside the statement the last one left.""" + from server.core.ch import statement_timeout_var + + seen: dict[str, float] = {} + + def _at(name: str, rows: list[dict[str, Any]]): + def answer(sql, params): + seen[name] = statement_timeout_var.get() + return rows + + return answer + + ch = ( + RecordingCH() + .on("loom.worker_status", _at("workers", [])) + .on("sli_minute", _at("requests", [])) + ) + ch.on("loom.code_index_state", _at("sources", _FAILING)).install(monkeypatch) + + await _incidents() + + bound = settings.readiness_check_timeout_s + assert seen == {"workers": bound, "requests": bound, "sources": bound} + + +@pytest.mark.asyncio +async def test_a_sources_read_serves_a_minute_whether_it_answered_or_failed( + monkeypatch, +) -> None: + """A source's sync state changes once a pass, and each read parses every one of the + org's states: a read serves a minute, a failed one too, so a read slower than the + bound is not started again every few seconds.""" + clock = ManualClock(t=1000.0) + monkeypatch.setattr(incidents, "time", clock) # not time.monotonic: asyncio.timeout reads that + reads: list[float] = [] + + def _sources(sql, params): + reads.append(clock.t) + if len(reads) == 1: + raise server_error("Connection refused", code=210) + return _FAILING + + ch = RecordingCH().on("loom.worker_status", []).on("sli_minute", []) + ch.on("loom.code_index_state", _sources).install(monkeypatch) + + for step in (0, 6, 50, 11, 6, 53, 1): + clock.advance(step) + await _incidents() + + assert reads == [1000.0, 1067.0, 1127.0] + + +@pytest.mark.asyncio +async def test_a_collection_the_caller_holds_no_grant_for_is_left_out(monkeypatch) -> None: + """An org admin reaches a collection only through a grant, so the sources of the + others are neither counted nor named; a platform admin reads every collection. A + caller is never served the read of a wider reach: one with the same reach shares it.""" + monkeypatch.setattr("server.auth.sharing.readable", AsyncMock(return_value=["col-board"])) + ch = _ch(monkeypatch, sources=_FAILING) + + await _incidents() + # The same subject as a platform admin reaches every collection: its own read. + await _incidents(auth=_token(roles=(Role.PLATFORM_ADMIN,))) + # Another org admin with the same reach shares the first read. + await _incidents(auth=_token(roles=(Role.ORG_ADMIN,), subject="other-admin")) + + admin, platform = ch.statements("loom.code_index_state") + assert (admin.params["col_prefix"], admin.params["col_readable"]) == ("col-", ["col-board"]) + assert "startsWith(namespace, {col_prefix:String})" in admin.sql + assert "col_prefix" not in platform.params and "col_prefix" not in platform.sql + + +@pytest.mark.asyncio +async def test_the_analyzer_corpus_runs_the_sources_scope_the_builder_makes(monkeypatch) -> None: + """The analyzer corpus EXPLAINs the sources statement with a copied org admin scope; + it must be the fragment `collection_clause` builds.""" + from server.auth.context import collection_clause + from tests.analyzer.cases.workers import SOURCES_SCOPE, SOURCES_SCOPE_PARAMS + + monkeypatch.setattr("server.auth.sharing.readable", AsyncMock(return_value=["col-board"])) + set_current_auth(ORG_WIDE) + try: + assert await collection_clause("acme") == (SOURCES_SCOPE, SOURCES_SCOPE_PARAMS) + finally: + set_current_auth(None) + + +@pytest.mark.asyncio +async def test_org_admins_with_the_same_grants_share_a_read_whatever_their_own_collection( + monkeypatch, +) -> None: + """A person's own collection holds no source (`_source_refusal`), so it neither keys + the read nor joins the statement: each admin reaching it does not add a read.""" + + async def readable(auth, org): + return sorted(["col-board", personal_name(org, auth.subject)]) + + monkeypatch.setattr("server.auth.sharing.readable", readable) + ch = _ch(monkeypatch, sources=_FAILING) + + await _incidents() + await _incidents(auth=_token(roles=(Role.ORG_ADMIN,), subject="other-admin")) + + (read,) = ch.statements("loom.code_index_state") + assert read.params["col_readable"] == ["col-board"] + + +@pytest.mark.asyncio +@pytest.mark.parametrize( + "down", + [RuntimeError("tree unread"), BackendUnavailableError("tree unread")], + ids=["unread", "backend"], +) +async def test_an_unread_collection_reach_answers_unread(monkeypatch, down) -> None: + """The collection tree or a grant cannot be read: `sharing.readable` answers no shared + collection, or the outage, and the sources are unread rather than a narrower count.""" + from server.auth import sharing + + monkeypatch.setattr(sharing, "readable", _READABLE) + monkeypatch.setattr(sharing, "tree", AsyncMock(side_effect=down)) + ch = _ch(monkeypatch, sources=_FAILING) + + out = await _incidents() + + assert (out.sources.read, out.sources.failing, out.sources.sample) == ("unread", 0, []) + assert ch.statements("loom.code_index_state") == [] + assert [n.split(" (")[0] for n in degradations.current()] == ["ops.incidents: sources_unread"] + + +@pytest.mark.asyncio +async def test_a_collection_reach_slower_than_a_readiness_check_answers_unread( + monkeypatch, +) -> None: + """The reach is read before the sources, through the grant cache: it is cut at the + same bound as the reads, so a slow grant store never holds the answer.""" + + async def slow(auth: Any, org: str) -> list[str]: + await asyncio.sleep(5) + return [] + + monkeypatch.setattr(sharing, "readable", slow) + monkeypatch.setattr(settings, "readiness_check_timeout_s", 0.05) + ch = _ch(monkeypatch, sources=_FAILING) + + out = await _incidents() + + assert (out.sources.read, out.sources.failing, out.sources.sample) == ("unread", 0, []) + assert ch.statements("loom.code_index_state") == [] + assert [n.split(" (")[0] for n in degradations.current()] == ["ops.incidents: sources_unread"] + + +@pytest.mark.asyncio +async def test_a_member_reads_no_sources(monkeypatch) -> None: + """A member's `*` token could hold no grant on a restricted namespace whose source + fails: only a caller that reads the org whole reads them, as for `requests`.""" + ch = _ch(monkeypatch, sources=_FAILING) + + out = await _incidents(auth=_token()) + + assert (out.sources.read, out.sources.failing, out.sources.sample) == ("not_permitted", 0, []) + assert ch.statements("loom.code_index_state") == [] + + +@pytest.mark.asyncio +async def test_an_unread_sources_read_answers_unread_and_is_named_in_degraded( + monkeypatch, +) -> None: + def _down(sql, params): + raise server_error("Connection refused", code=210) + + ch = RecordingCH().on("loom.worker_status", []).on("sli_minute", []) + ch.on("loom.code_index_state", _down).install(monkeypatch) + + out = await _incidents() + + assert (out.status, out.requests) == ("ok", "read") + assert (out.sources.read, out.sources.failing, out.sources.sample) == ("unread", 0, []) + assert [n.split(" (")[0] for n in degradations.current()] == ["ops.incidents: sources_unread"] def test_any_viewer_polls_it_and_it_reads_no_namespace() -> None: diff --git a/tests/unit/test_ops_incidents_sql.py b/tests/unit/test_ops_incidents_sql.py index 2087361ab9..94f9edad40 100644 --- a/tests/unit/test_ops_incidents_sql.py +++ b/tests/unit/test_ops_incidents_sql.py @@ -1,9 +1,11 @@ -"""The two statements ops.incidents reads, on clickhouse-local over the production tables: -the failure streaks of this deployment's enabled workers, and the org's calls per SLO -class that failed on the server.""" +"""The statements ops.incidents reads, on clickhouse-local over the production tables: +the failure streaks of this deployment's enabled workers, the org's calls per SLO class +that failed on the server, and the org's document sources whose last turn failed.""" from __future__ import annotations +from typing import Any + import pytest from server.insights.store import ops as ops_store @@ -111,3 +113,137 @@ async def read(org: str) -> list[tuple[str, int, int]]: assert await read("o2") == [("interactive", 50, 0)] assert await read("o3") == [("read", 10, 10)] assert await read("o4") == [] + + +_MIRROR = "acl-" + "a" * 24 + +# (org, namespace, source, access, credential mode, source kind, active, version) +_REGISTRY = [ + ("o1", "team", "decks", "namespace", "shared", "gdrive", 1, 1), + ("o1", "ops", "runbooks", "namespace", "shared", "notion", 1, 1), + ("o1", "team", "notes", "namespace", "shared", "gdrive", 1, 1), + ("o1", "team", "fixed", "namespace", "shared", "gdrive", 1, 1), + ("o1", "team", "broke", "namespace", "shared", "gdrive", 1, 1), + ("o1", "team", "drive", "mirrored", "shared", "gdrive", 1, 1), # a mirrored source + ("o1", "team", "mine", "mirrored", "connected", "notion", 1, 1), # a person's own + ("o1", "team", "linked", "namespace", "connected", "gdrive", 1, 1), # a connected one + ("o1", _MIRROR, "drive-id", "namespace", "shared", "gdrive", 1, 1), # in a mirror + ("o1", "team", "gone", "namespace", "shared", "gdrive", 1, 1), + ("o1", "team", "gone", "namespace", "shared", "gdrive", 0, 2), # removed since + ("o1", "team", "agent", "namespace", "shared", "mcp", 1, 1), # a worker source + ("o1", "team", "meet", "namespace", "shared", "recording", 1, 1), + ("o1", "team", "fresh", "namespace", "shared", "gdrive", 1, 1), + ("o1", "paused", "old", "namespace", "shared", "gdrive", 1, 1), # an inactive namespace + ("o2", "team", "decks", "namespace", "shared", "gdrive", 1, 1), # another org's + ("o1", "col-board", "minutes", "namespace", "shared", "gdrive", 1, 1), # a collection's +] + +# (org, namespace, state key, status, last turn, version) +_STATES = [ + ("o1", "team", "knowledge_source:decks", "credential_invalid", "2026-03-02T00:00:00+00:00", 1), + ("o1", "ops", "knowledge_source:runbooks", "rate_limited", "2026-03-03T00:00:00+00:00", 1), + ("o1", "team", "knowledge_source:notes", "ok", "2026-03-04T00:00:00+00:00", 1), + ("o1", "team", "knowledge_source:fixed", "failed", "2026-03-01T00:00:00+00:00", 1), + ("o1", "team", "knowledge_source:fixed", "ok", "2026-03-05T00:00:00+00:00", 2), # recovered + ("o1", "team", "knowledge_source:broke", "ok", "2026-02-01T00:00:00+00:00", 1), + ("o1", "team", "knowledge_source:broke", "failed", "2026-03-01T00:00:00+00:00", 2), + ("o1", "team", "knowledge_source:drive", "failed", "2026-03-09T00:00:00+00:00", 1), + ("o1", "team", "knowledge_source:mine", "credential_invalid", "2026-03-09T00:00:00+00:00", 1), + ("o1", "team", "knowledge_source:linked", "failed", "2026-03-09T00:00:00+00:00", 1), + ("o1", _MIRROR, "knowledge_source:drive-id", "failed", "2026-03-09T00:00:00+00:00", 1), + ("o1", "team", "knowledge_source:gone", "failed", "2026-03-09T00:00:00+00:00", 1), + ("o1", "team", "knowledge_source:agent", "failed", "2026-03-09T00:00:00+00:00", 1), + # A meet recording source, whose turn the sync does not count as failed. + ("o1", "team", "knowledge_source:meet", "provider_removed", "2026-03-09T00:00:00+00:00", 1), + ("o1", "team", "knowledge_source:fresh", "", "", 1), # asked for, never run + ("o1", "paused", "knowledge_source:old", "failed", "2026-03-09T00:00:00+00:00", 1), + ("o1", "team", "code_cursor:main", "failed", "2026-03-09T00:00:00+00:00", 1), # no source's + ("o2", "team", "knowledge_source:decks", "failed", "2026-03-09T00:00:00+00:00", 1), + ("o1", "col-board", "knowledge_source:minutes", "failed", "2026-03-08T00:00:00+00:00", 1), +] + + +def _source_rows() -> list[str]: + registry = ", ".join( + f"('{o}', '{ns}', '{name}', '{access}', '{mode}', '{kind}', {active}, {v})" + for o, ns, name, access, mode, kind, active, v in _REGISTRY + ) + states = ", ".join( + f"('{o}', '{ns}', '{key}', '" + + (f'{{"status": "{status}", "last_synced_at": "{at}"}}' if status else "{}") + + f"', {v})" + for o, ns, key, status, at, v in _STATES + ) + return [ + 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 o, ns, n, generateUUIDv4(), a, m, k, act, v FROM values(" + "'o String, ns String, n String, a String, m String, k String, act Bool, v UInt64', " + f"{registry})", + f"INSERT INTO loom.code_index_state (org, namespace, state_key, detail, version) " + f"VALUES {states}", + "INSERT INTO loom.namespaces (org, namespace, owner_email, active) VALUES " + "('o1', 'team', '', true), ('o1', 'paused', '', false)", + ] + + +async def test_the_sources_read_counts_and_samples_the_orgs_own_failing_sources() -> None: + from server.knowledge.store import sources + + ch: Any = LocalCH(*_source_rows()) + + # No collection clause: a platform admin, or auth off, reads every collection. + failing, sample = await sources.failing_sources( + "o1", sample=5, scope="", scope_params={}, ch=ch + ) + + assert failing == 4 + assert sample == [ + {"namespace": "col-board", "name": "minutes", "status": "failed"}, + {"namespace": "ops", "name": "runbooks", "status": "rate_limited"}, + {"namespace": "team", "name": "decks", "status": "credential_invalid"}, + {"namespace": "team", "name": "broke", "status": "failed"}, + ] + failing, sample = await sources.failing_sources( + "o1", sample=2, scope="", scope_params={}, ch=ch + ) + assert failing == 4 and [s["name"] for s in sample] == ["minutes", "runbooks"] + assert await sources.failing_sources("o2", sample=5, scope="", scope_params={}, ch=ch) == ( + 1, + [{"namespace": "team", "name": "decks", "status": "failed"}], + ) + assert await sources.failing_sources("o3", sample=5, scope="", scope_params={}, ch=ch) == ( + 0, + [], + ) + + +@pytest.mark.parametrize("readable", [[], ["col-board"]], ids=["no-grant", "granted"]) +async def test_the_sources_read_leaves_out_the_collections_the_caller_cannot_read( + monkeypatch: pytest.MonkeyPatch, readable: list[str] +) -> None: + """The fragment `collection_clause` gives an org admin, run on the statement.""" + from types import SimpleNamespace + from unittest.mock import AsyncMock + + from server.auth import context + from server.knowledge.store import sources + + admin = SimpleNamespace(has_role=lambda role: False) + monkeypatch.setattr(context, "current_auth", lambda: admin) + monkeypatch.setattr("server.auth.sharing.readable", AsyncMock(return_value=readable)) + where, params = await context.collection_clause("o1") + ch: Any = LocalCH(*_source_rows()) + + failing, sample = await sources.failing_sources( + "o1", sample=5, scope=where, scope_params=params, ch=ch + ) + + names = [s["name"] for s in sample] + if readable: + assert (failing, names) == (4, ["minutes", "runbooks", "decks", "broke"]) + else: + assert (failing, names) == (3, ["runbooks", "decks", "broke"])