From a2195aee54ded9dbd980e9422cbe7c4e7320ae13 Mon Sep 17 00:00:00 2001 From: Lareb Zafar Date: Sat, 28 Nov 2026 05:33:41 +0530 Subject: [PATCH 1/6] namespace.validate lists the token edits a followed rename allows in each memory, or why none is offered A link that follows its definition to another name or file reads `moved`, and the memory's text still names the old one. Nothing computed the replacement, and a blind replace is wrong often: the old bare name can be borne by another definition, the new one can be ambiguous, and a sentence about the name or a past state is right as it is. - `anchor.code_spans` reads the names a text writes as code (a whole backticked identifier, `A::b`, a call `a.b(` or `f()`) with their positions, and the spans that quote code: fenced blocks, URLs, quoted strings and longer backticked spans. A name joined to a path, a flag or a file suffix is neither. - `server.memory.domain.code_rename.plan` takes a memory's text and head, its links and the index's definitions at the head. It returns the edits (old and new token with character positions) and the hash memory.get serves for the text, or one reason from a closed list. Each name keeps its spelling: as many segments, the same separators, a full dotted name under the whole new module. One reason withholds the whole memory. - The `code_rename_edits` finding of namespace.validate lists, for the repositories the caller may read, each served memory with a `moved` link and its edits or reason. The finding's `totals` field counts the memories by `edits` and by reason. No high-sensitivity memory is read. - `stale_links` takes the link states to list. Loom writes nothing. The caller applies an edit with memory.update and `if_match_sha256`, a revision with its conflict check that is refused when the memory changed after the report read it. memory.update keeps `files`, so a memory whose `files` name a renamed path gets the reason `named_in_files`. Signed-off-by: Lareb Zafar Co-Authored-By: Claude Fable 5.2 --- docs/concepts/memory.md | 45 +- docs/use-cases/memory-linked-to-code.md | 38 + sdk/python/loom/ops.py | 1 + sdk/rust/src/wire_models.rs | 1479 +++++++++-------- sdk/typescript/src/generated/ops.ts | 1 + server/code/domain/anchor.py | 79 + .../identity/api/models_namespace_catalog.py | 3 + server/identity/app/namespace_validate.py | 57 +- server/memory/app/code_link_reads.py | 23 +- server/memory/app/code_renames.py | 117 ++ server/memory/domain/code_rename.py | 412 +++++ server/memory/store/code_links.py | 3 +- tests/analyzer/shapes.txt | 2 +- tests/integration/test_memory_code_links.py | 95 ++ tests/unit/test_code_anchor.py | 81 + tests/unit/test_memory_code_links.py | 3 + tests/unit/test_memory_code_rename_plan.py | 517 ++++++ tests/unit/test_namespace_validate.py | 108 +- 18 files changed, 2309 insertions(+), 755 deletions(-) create mode 100644 server/memory/app/code_renames.py create mode 100644 server/memory/domain/code_rename.py create mode 100644 tests/unit/test_memory_code_rename_plan.py diff --git a/docs/concepts/memory.md b/docs/concepts/memory.md index b4c396a93e..0fe2be47d8 100644 --- a/docs/concepts/memory.md +++ b/docs/concepts/memory.md @@ -584,7 +584,8 @@ The links are read where the code is: such a hit's line, with the same note as a `memory.for_file` line; `memory.ask` notes the memories whose code moved, changed or went. - `namespace.validate` lists memories whose code changed, was not found again or is - gone, in the repositories the caller may read. + gone, in the repositories the caller may read, and the edits that bring a memory's + text up to a rename its link followed. A memory with no link reads exactly as one whose code is current. `namespace.validate` counts the served memories that name code (a backticked or qualified name, a call, or @@ -603,6 +604,48 @@ linked, is not counted. How far each repository's links trail its index is a gauge, and a health warning when it lasts ([monitoring](../operations/monitoring.md#what-to-alert-on)). +A `moved` link is at its code, and the memory's text still names the old definition or +path. `namespace.validate` lists each such memory under the `info` finding +`code_rename_edits`, with either the `edits` its text allows (replace `old` with `new` at +characters `start` to `end`) and the `content_sha256` they are of, or the one `reason` no +edit is offered. The finding's `totals` count the memories by `edits` and by reason. Loom +writes nothing: to apply an edit, read the sentence it changes, then call `memory.update` +on the key with the revised text and `if_match_sha256` set to the listed hash. That is a +revision by the caller, with its conflict check, and it is refused when the memory changed +after the report read it. The link pass then links the revised memory where the code is. + +An edit is offered only for a name written as code (a whole backticked identifier, an +`A::b`, or a call written `a.b(` or `name()`) and for a whole repository path, in the +spelling the text uses: `Reader.get` becomes `Reader.fetch`, a full dotted name becomes the +full new one, and `self.get` keeps its receiver. The whole memory gets no edit for the +first of these reasons that applies: + +| Reason | The memory | +| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `not_text` | has a value that is not one string. | +| `link_not_settled` | has a link that is pending, `changed`, `unresolved` or `missing`, that its renamed class carried, or that is hashed under older fingerprint rules. | +| `incomplete` | names more code than the link caps keep. | +| `overloaded` | is linked to a definition the index numbers among several of one name. | +| `quoted_or_literal` | holds the old name or path in a fenced block, a URL, a quoted string or a backticked span that is more than one name. | +| `prose_occurrence` | writes the old name as a bare word of the prose. | +| `old_name_remains` | would still hold the old name or path where no edit reaches: a plain word, a part of a longer name, a path before a line number, or a path whose file still exists. | +| `names_several` | writes one name that two of its links were written against. | +| `receiver_form` | writes the name as `self.name`, `cls.name` or `this.name`, and its `files` do not name the defining file. | +| `old_name_still_defined` | spells the old name in a way that still names a definition on the indexed trunk. | +| `new_name_present` | already holds the new name or path. | +| `dated_claim` | is dated (`valid_to`, `invalid_at` or `temporal_anchor`), or the sentence to edit holds a commit hash, a version tag, a year, a month, or a pull request or issue number. | +| `about_naming` | would be edited in a sentence about the name or the place: it holds `rename`, `formerly`, `used to`, `was called`, `replaced`, `moved from`, `deprecated`, `legacy`, `before`, `previously` or `named`. | +| `named_in_key_or_tags` | holds the old name or path in its `memory_key` or a tag. | +| `named_in_files` | lists the old path in `files`, which `memory.update` keeps. | +| `would_unlink` | would lose a link once revised: the new name is not one definition on the indexed trunk, or the revised text no longer names a definition or file it is linked to. | +| `no_code_token` | names no old name or path: the bare name still holds after a move, or the link is back where the text says. | + +The words that mark a sentence as being about the name are English. The finding reads the +2,000 memories whose `moved` link was last checked (all under `keys` when given), in the +repositories the caller may read, and no high-sensitivity memory; a link whose code also +changed is listed under `code_links_stale`. Neither the memory's key, tags, `files`, +entities and concepts nor a line number written in its text is edited. + ## Time | Column | Axis | Meaning | diff --git a/docs/use-cases/memory-linked-to-code.md b/docs/use-cases/memory-linked-to-code.md index 205207f11c..f029d67463 100644 --- a/docs/use-cases/memory-linked-to-code.md +++ b/docs/use-cases/memory-linked-to-code.md @@ -76,6 +76,9 @@ reported commit](#check-a-lesson-after-a-code-edit). [`namespace.validate`](../reference/operations/namespace.md#namespacevalidate) lists the memories whose code changed, was not found again or is gone, and the dashboard shows each memory's links and their state. +- **The edit a rename allows.** After a rename or a move the link follows, the same report + lists the exact token edits that bring the memory's text up to date, or the reason it + offers none. [Bring a lesson's text up to a rename](#bring-a-lessons-text-up-to-a-rename) ![A memory's detail in the dashboard: its linked code, one definition current and one changed since a commit](../assets/screenshots/memory-linked-code.webp) @@ -134,6 +137,41 @@ tool selection are not tested. For removal, held-memory exceptions and model-backed revision, see the [link policies](../concepts/memory.md#memories-linked-to-code). +## Bring a lesson's text up to a rename + +When a definition is renamed or moved with nothing else changed, its link follows it and +reads `moved`. The lesson's text still says the old name. Loom does not rewrite it; +`namespace.validate` lists what a rewrite would be: + +1. Call `namespace.validate` on the memory namespace (with `keys` to check the lessons + one session wrote) and read the `code_rename_edits` finding. Each sample is one lesson + with either `edits` and a `content_sha256`, or a `reason`. +2. For a lesson with `edits`, replace `old` with `new` at characters `start` to `end` of + its text, applying the last edit first so the earlier positions hold. Read the edited + sentence: an edit is offered on the spelling and the index, and whether the claim + survives the swap is yours to judge. +3. Call `memory.update` on the key with the revised text and `if_match_sha256` set to the + sample's `content_sha256`. A lesson that changed since the report returns `409`; run + the report again. +4. After the next link pass the lesson is linked at the new name and reads `fresh`, and + the finding lists it no more. + +A lesson with a `reason` gets no edit: the old name is a word of the prose, sits in a +quoted snippet, still names another definition, or the sentence is about the name itself +([every reason](../concepts/memory.md#memories-linked-to-code)). Check it against the code +and rewrite it by hand. + +The finding's `totals` count a namespace's lessons by `edits` and by reason: how often a +mechanical edit is offered there, and what stops the rest. Applying the edits without a +person reading them is worth considering only for a namespace whose `totals` come from its +own lessons and where at least 100 listed edits were checked by hand against the lesson +text with none wrong. + +The `test_validate_lists_the_edit_a_followed_rename_allows_and_an_update_applies_it` +[integration regression](https://github.com/ClickHouse/loom/blob/main/tests/integration/test_memory_code_links.py) +renames a function, reads the listed edit, applies it with `memory.update` and checks the +link at the new name. + ## Compare a code-linked lesson across branches When trunk and a maintained release branch diverge, a lesson can still apply to one of diff --git a/sdk/python/loom/ops.py b/sdk/python/loom/ops.py index 922fb6a0c9..f3d6a3c764 100644 --- a/sdk/python/loom/ops.py +++ b/sdk/python/loom/ops.py @@ -18183,6 +18183,7 @@ class NamespaceValidateFinding(TypedDict, total=False): count: Required[int] samples: NotRequired[list[dict[str, Any]]] detail: Required[str] + totals: NotRequired[dict[str, int]] class ObserveCrystallizeInput(TypedDict, total=False): diff --git a/sdk/rust/src/wire_models.rs b/sdk/rust/src/wire_models.rs index c6ac9657a7..644bb88fc0 100644 --- a/sdk/rust/src/wire_models.rs +++ b/sdk/rust/src/wire_models.rs @@ -48924,6 +48924,8 @@ pub struct NamespaceValidateFinding { #[serde(default = "default_2161")] pub samples: Vec>, pub detail: String, + #[serde(default = "default_2162")] + pub totals: std::collections::HashMap, } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] @@ -48936,9 +48938,9 @@ pub struct NamespaceValidateOutput { pub warnings: Integer, pub infos: Integer, pub findings: Vec, - #[serde(default = "default_2162")] - pub skipped: Vec, #[serde(default = "default_2163")] + pub skipped: Vec, + #[serde(default = "default_2164")] pub keys_scoped: Integer, pub coverage: ReportCoverage, pub checked_at: String, @@ -49058,9 +49060,9 @@ impl NamespaceValidateInput { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[non_exhaustive] pub struct ObserveCrystallizeOutput { - #[serde(default = "default_2164")] - pub enqueued: Integer, #[serde(default = "default_2165")] + pub enqueued: Integer, + #[serde(default = "default_2166")] pub session_id: String, } @@ -49157,23 +49159,23 @@ impl ObserveCrystallizeInput { #[non_exhaustive] pub struct ObserveRecordOutput { pub memory_key: String, - #[serde(default = "default_2166")] - pub memory_id: String, #[serde(default = "default_2167")] - pub kind: String, + pub memory_id: String, #[serde(default = "default_2168")] - pub tags: Vec, + pub kind: String, #[serde(default = "default_2169")] - pub file_paths: Vec, + pub tags: Vec, #[serde(default = "default_2170")] - pub content_sha256: String, + pub file_paths: Vec, #[serde(default = "default_2171")] - pub tool_name: String, + pub content_sha256: String, #[serde(default = "default_2172")] - pub has_error: bool, + pub tool_name: String, #[serde(default = "default_2173")] - pub narrative_chars: Integer, + pub has_error: bool, #[serde(default = "default_2174")] + pub narrative_chars: Integer, + #[serde(default = "default_2175")] pub skipped_reason: String, } @@ -49372,26 +49374,26 @@ pub struct ProjectionFailureRow { pub failure_id: String, pub org: String, pub namespace: String, - #[serde(default = "default_2175")] + #[serde(default = "default_2176")] pub agent: String, pub projection: String, - #[serde(default = "default_2176")] - pub source_operation: String, #[serde(default = "default_2177")] - pub source_resource_id: String, + pub source_operation: String, #[serde(default = "default_2178")] - pub memory_keys: Vec, + pub source_resource_id: String, #[serde(default = "default_2179")] - pub error_type: String, + pub memory_keys: Vec, #[serde(default = "default_2180")] - pub error_message: String, + pub error_type: String, #[serde(default = "default_2181")] - pub payload: std::collections::HashMap, + pub error_message: String, #[serde(default = "default_2182")] - pub status: String, + pub payload: std::collections::HashMap, #[serde(default = "default_2183")] - pub created_at: Option, + pub status: String, #[serde(default = "default_2184")] + pub created_at: Option, + #[serde(default = "default_2185")] pub resolved_at: Option, } @@ -49545,22 +49547,22 @@ pub struct ProjectionFailureRetryRow { pub projection: String, pub retried: bool, pub resolved: bool, - #[serde(default = "default_2185")] - pub abandoned: bool, #[serde(default = "default_2186")] - pub reason: String, + pub abandoned: bool, #[serde(default = "default_2187")] + pub reason: String, + #[serde(default = "default_2188")] pub error: String, } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[non_exhaustive] pub struct ProjectionFailureRetryOutput { - #[serde(default = "default_2188")] + #[serde(default = "default_2189")] pub results: Vec, pub retried: Integer, pub resolved: Integer, - #[serde(default = "default_2189")] + #[serde(default = "default_2190")] pub abandoned: Integer, } @@ -49642,15 +49644,15 @@ impl ProjectionFailureRetryInput { pub struct OrgModelCallsOutput { pub org: String, pub enabled: bool, - #[serde(default = "default_2190")] - pub reason: String, #[serde(default = "default_2191")] - pub updated_by: String, + pub reason: String, #[serde(default = "default_2192")] - pub updated_at: Option, + pub updated_by: String, #[serde(default = "default_2193")] - pub locked: bool, + pub updated_at: Option, #[serde(default = "default_2194")] + pub locked: bool, + #[serde(default = "default_2195")] pub locked_by: String, } @@ -49989,7 +49991,7 @@ impl PolicyDecisionsInput { #[non_exhaustive] pub struct PolicyDeleteOutput { pub removed: bool, - #[serde(default = "default_2195")] + #[serde(default = "default_2196")] pub widening: bool, } @@ -50055,12 +50057,12 @@ pub struct PolicyRuleOut { pub condition: std::collections::HashMap, pub description: String, pub enabled: bool, - #[serde(default = "default_2196")] + #[serde(default = "default_2197")] pub mode: String, pub created_by: String, - #[serde(default = "default_2197")] - pub created_at: Option, #[serde(default = "default_2198")] + pub created_at: Option, + #[serde(default = "default_2199")] pub updated_at: Option, } @@ -50132,9 +50134,9 @@ impl PolicyListInput { pub struct PolicySetOutput { pub rule: PolicyRuleOut, pub leaf_count: Integer, - #[serde(default = "default_2199")] - pub widening: bool, #[serde(default = "default_2200")] + pub widening: bool, + #[serde(default = "default_2201")] pub change: Vec, } @@ -50404,37 +50406,37 @@ pub struct ProcedureEvolveOutput { pub revision: Integer, pub changed: bool, pub template: bool, - #[serde(default = "default_2201")] - pub folded_runs: Integer, #[serde(default = "default_2202")] - pub gate: ProcedureEvolveOutputGate, + pub folded_runs: Integer, #[serde(default = "default_2203")] - pub gate_mode: String, + pub gate: ProcedureEvolveOutputGate, #[serde(default = "default_2204")] - pub gate_llr: f64, + pub gate_mode: String, #[serde(default = "default_2205")] - pub gate_before: std::collections::HashMap, + pub gate_llr: f64, #[serde(default = "default_2206")] - pub gate_after: std::collections::HashMap, + pub gate_before: std::collections::HashMap, #[serde(default = "default_2207")] - pub gate_cost_before: std::collections::HashMap, + pub gate_after: std::collections::HashMap, #[serde(default = "default_2208")] - pub gate_cost_after: std::collections::HashMap, + pub gate_cost_before: std::collections::HashMap, #[serde(default = "default_2209")] - pub gate_reason: String, + pub gate_cost_after: std::collections::HashMap, #[serde(default = "default_2210")] - pub dead_end_steps: Vec, + pub gate_reason: String, #[serde(default = "default_2211")] - pub fail_prone_steps: Vec, + pub dead_end_steps: Vec, #[serde(default = "default_2212")] - pub fail_prone_transitions: Vec, + pub fail_prone_steps: Vec, #[serde(default = "default_2213")] - pub run_stats: std::collections::HashMap, + pub fail_prone_transitions: Vec, #[serde(default = "default_2214")] - pub strikes: Integer, + pub run_stats: std::collections::HashMap, #[serde(default = "default_2215")] - pub quarantined: bool, + pub strikes: Integer, #[serde(default = "default_2216")] + pub quarantined: bool, + #[serde(default = "default_2217")] pub retention: std::collections::HashMap, } @@ -50657,9 +50659,9 @@ pub struct ProcedureForkOutput { pub memory_key: String, pub version: Integer, pub name: String, - #[serde(default = "default_2217")] - pub steps: Vec, #[serde(default = "default_2218")] + pub steps: Vec, + #[serde(default = "default_2219")] pub forked_from: std::collections::HashMap, } @@ -50919,32 +50921,32 @@ pub enum ProcedureLocateOutputStatus { #[non_exhaustive] pub struct ProcedureLocateOutput { pub memory_key: String, - #[serde(default = "default_2219")] - pub name: String, #[serde(default = "default_2220")] + pub name: String, + #[serde(default = "default_2221")] pub status: ProcedureLocateOutputStatus, pub matched: bool, - #[serde(default = "default_2221")] - pub active: Option>, #[serde(default = "default_2222")] - pub hops: Vec>>, + pub active: Option>, #[serde(default = "default_2223")] - pub entry_nodes: Vec, + pub hops: Vec>>, #[serde(default = "default_2224")] - pub dominant_next: Vec, + pub entry_nodes: Vec, #[serde(default = "default_2225")] - pub revisits: std::collections::HashMap, + pub dominant_next: Vec, #[serde(default = "default_2226")] - pub looping: bool, + pub revisits: std::collections::HashMap, #[serde(default = "default_2227")] - pub exits: Vec, + pub looping: bool, #[serde(default = "default_2228")] - pub failure_notes: Vec>, + pub exits: Vec, #[serde(default = "default_2229")] - pub rendered: String, + pub failure_notes: Vec>, #[serde(default = "default_2230")] - pub run_stats: std::collections::HashMap, + pub rendered: String, #[serde(default = "default_2231")] + pub run_stats: std::collections::HashMap, + #[serde(default = "default_2232")] pub for_agent: std::collections::HashMap, } @@ -51099,43 +51101,43 @@ pub struct ProcedureMatch { pub name: String, pub situation: String, pub steps: Vec, - #[serde(default = "default_2232")] - pub tags: Vec, #[serde(default = "default_2233")] + pub tags: Vec, + #[serde(default = "default_2234")] pub metadata: std::collections::HashMap, pub similarity: f64, pub memory_key: String, pub namespace: String, - #[serde(default = "default_2234")] - pub graph: Option>, #[serde(default = "default_2235")] - pub template: bool, + pub graph: Option>, #[serde(default = "default_2236")] - pub run_stats: std::collections::HashMap, + pub template: bool, #[serde(default = "default_2237")] - pub status: ProcedureMatchStatus, + pub run_stats: std::collections::HashMap, #[serde(default = "default_2238")] - pub quarantined: Option>, + pub status: ProcedureMatchStatus, #[serde(default = "default_2239")] - pub fail_prone_steps: Vec, + pub quarantined: Option>, #[serde(default = "default_2240")] - pub revision: Integer, + pub fail_prone_steps: Vec, #[serde(default = "default_2241")] - pub rejected_revisions: Vec>, + pub revision: Integer, #[serde(default = "default_2242")] - pub tool_overlap: f64, + pub rejected_revisions: Vec>, #[serde(default = "default_2243")] - pub score: f64, + pub tool_overlap: f64, #[serde(default = "default_2244")] - pub utility: f64, + pub score: f64, #[serde(default = "default_2245")] - pub goal_similarity: Option, + pub utility: f64, #[serde(default = "default_2246")] - pub for_agent: std::collections::HashMap, + pub goal_similarity: Option, #[serde(default = "default_2247")] + pub for_agent: std::collections::HashMap, + #[serde(default = "default_2248")] pub run_stats_by_agent: std::collections::HashMap>, - #[serde(default = "default_2248")] + #[serde(default = "default_2249")] pub actor: String, } @@ -51143,11 +51145,11 @@ pub struct ProcedureMatch { #[non_exhaustive] pub struct ProcedureMatchOutput { pub matches: Vec, - #[serde(default = "default_2249")] - pub matched: Integer, #[serde(default = "default_2250")] - pub procedure_key: String, + pub matched: Integer, #[serde(default = "default_2251")] + pub procedure_key: String, + #[serde(default = "default_2252")] pub score: f64, } @@ -51528,7 +51530,7 @@ pub struct ProcedureReviseOutput { pub revision: Integer, pub prior_revision: Integer, pub digest: String, - #[serde(default = "default_2252")] + #[serde(default = "default_2253")] pub steps: Vec, } @@ -51640,14 +51642,14 @@ pub struct ProfileActivityEntry { pub agent: String, pub last_activated_at: String, pub event_count: Integer, - #[serde(default = "default_2253")] + #[serde(default = "default_2254")] pub operations: Vec, } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[non_exhaustive] pub struct ProfileActivityOutput { - #[serde(default = "default_2254")] + #[serde(default = "default_2255")] pub entries: Vec, } @@ -51755,17 +51757,17 @@ impl ProfileActivityInput { #[non_exhaustive] pub struct ProfileMutationOutput { pub version: Integer, - #[serde(default = "default_2255")] - pub memory_id: String, #[serde(default = "default_2256")] - pub content_sha256: String, + pub memory_id: String, #[serde(default = "default_2257")] - pub namespace: String, + pub content_sha256: String, #[serde(default = "default_2258")] - pub label: String, + pub namespace: String, #[serde(default = "default_2259")] - pub char_limit: Option, + pub label: String, #[serde(default = "default_2260")] + pub char_limit: Option, + #[serde(default = "default_2261")] pub value_length: Integer, } @@ -51874,7 +51876,7 @@ pub struct ProfileRenderOutput { pub rendered: String, pub section_count: Integer, pub total_chars: Integer, - #[serde(default = "default_2261")] + #[serde(default = "default_2262")] pub labels: Vec, } @@ -52259,17 +52261,17 @@ pub enum ProfileStructuredOutputStatus { #[non_exhaustive] pub struct ProfileStructuredOutput { pub status: ProfileStructuredOutputStatus, - #[serde(default = "default_2262")] - pub profile: std::collections::HashMap, #[serde(default = "default_2263")] - pub built_at: Option, + pub profile: std::collections::HashMap, #[serde(default = "default_2264")] - pub memory_id: String, + pub built_at: Option, #[serde(default = "default_2265")] - pub version: Integer, + pub memory_id: String, #[serde(default = "default_2266")] - pub version_text: String, + pub version: Integer, #[serde(default = "default_2267")] + pub version_text: String, + #[serde(default = "default_2268")] pub schema_sha256: String, } @@ -52386,13 +52388,13 @@ impl ProfileStructuredInput { #[non_exhaustive] pub struct ProfileSchemaOutput { pub found: bool, - #[serde(default = "default_2268")] - pub json_schema: std::collections::HashMap, #[serde(default = "default_2269")] - pub schema_sha256: String, + pub json_schema: std::collections::HashMap, #[serde(default = "default_2270")] - pub updated_by: String, + pub schema_sha256: String, #[serde(default = "default_2271")] + pub updated_by: String, + #[serde(default = "default_2272")] pub updated_at: Option, } @@ -52545,10 +52547,10 @@ pub enum RunBeginOutputStatus { #[non_exhaustive] pub struct RunBeginOutput { pub run_id: String, - #[serde(default = "default_2272")] + #[serde(default = "default_2273")] pub status: RunBeginOutputStatus, pub started_at: String, - #[serde(default = "default_2273")] + #[serde(default = "default_2274")] pub next: String, } @@ -52756,29 +52758,29 @@ pub struct RunCompleteOutput { pub run_id: String, pub status: RunCompleteOutputStatus, pub duration_ms: Integer, - #[serde(default = "default_2274")] - pub used_applied: Integer, #[serde(default = "default_2275")] - pub evidence_applied: Integer, + pub used_applied: Integer, #[serde(default = "default_2276")] - pub harm_applied: Integer, + pub evidence_applied: Integer, #[serde(default = "default_2277")] - pub memories_written: Vec, + pub harm_applied: Integer, #[serde(default = "default_2278")] - pub recalled: Integer, + pub memories_written: Vec, #[serde(default = "default_2279")] - pub observations: Integer, + pub recalled: Integer, #[serde(default = "default_2280")] - pub procedure_runs_recorded: Integer, + pub observations: Integer, #[serde(default = "default_2281")] - pub reflection_key: String, + pub procedure_runs_recorded: Integer, #[serde(default = "default_2282")] - pub retain: String, + pub reflection_key: String, #[serde(default = "default_2283")] - pub retained: Integer, + pub retain: String, #[serde(default = "default_2284")] - pub demoted: Integer, + pub retained: Integer, #[serde(default = "default_2285")] + pub demoted: Integer, + #[serde(default = "default_2286")] pub expiring: Integer, } @@ -53299,25 +53301,25 @@ pub enum RunGetOutputOverBudgetItem { #[non_exhaustive] pub struct RunGetOutput { pub found: bool, - #[serde(default = "default_2286")] - pub run: Option, #[serde(default = "default_2287")] - pub recalled: Integer, + pub run: Option, #[serde(default = "default_2288")] - pub recalled_keys: Vec, + pub recalled: Integer, #[serde(default = "default_2289")] - pub memories_written: Vec, + pub recalled_keys: Vec, #[serde(default = "default_2290")] - pub observations: Integer, + pub memories_written: Vec, #[serde(default = "default_2291")] - pub turns: Integer, + pub observations: Integer, #[serde(default = "default_2292")] - pub unpriced_turns: Integer, + pub turns: Integer, #[serde(default = "default_2293")] - pub cost_usd: f64, + pub unpriced_turns: Integer, #[serde(default = "default_2294")] - pub elapsed_seconds: Integer, + pub cost_usd: f64, #[serde(default = "default_2295")] + pub elapsed_seconds: Integer, + #[serde(default = "default_2296")] pub over_budget: Vec, } @@ -53384,17 +53386,17 @@ pub struct RunGradeProposal { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[non_exhaustive] pub struct RunGradeOutput { - #[serde(default = "default_2296")] - pub graded: Integer, #[serde(default = "default_2297")] - pub run_ids: Vec, + pub graded: Integer, #[serde(default = "default_2298")] - pub skipped_active: Integer, + pub run_ids: Vec, #[serde(default = "default_2299")] - pub unchanged: Integer, + pub skipped_active: Integer, #[serde(default = "default_2300")] - pub memories_counted: Integer, + pub unchanged: Integer, #[serde(default = "default_2301")] + pub memories_counted: Integer, + #[serde(default = "default_2302")] pub proposals_decided: Vec, } @@ -53509,7 +53511,7 @@ impl RunGradeInput { #[non_exhaustive] pub struct RunListOutput { pub runs: Vec, - #[serde(default = "default_2302")] + #[serde(default = "default_2303")] pub total: Option, } @@ -53786,39 +53788,39 @@ pub struct LiveSearchHit { pub title: String, pub url: String, pub provider: LiveSearchHitProvider, - #[serde(default = "default_2305")] - pub content: String, #[serde(default = "default_2306")] + pub content: String, + #[serde(default = "default_2307")] pub live: LiveSearchHitLive, } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[non_exhaustive] pub struct LiveSearchResults { - #[serde(default = "default_2304")] + #[serde(default = "default_2305")] pub live: LiveSearchResultsLive, - #[serde(default = "default_2307")] + #[serde(default = "default_2308")] pub results: Vec, } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[non_exhaustive] pub struct SearchOutput { - #[serde(default = "default_2303")] + #[serde(default = "default_2304")] pub tracker: Option>, - #[serde(default = "default_2308")] - pub live: Option, #[serde(default = "default_2309")] - pub memory: std::collections::HashMap, + pub live: Option, #[serde(default = "default_2310")] - pub knowledge: std::collections::HashMap, + pub memory: std::collections::HashMap, #[serde(default = "default_2311")] - pub profile: std::collections::HashMap, + pub knowledge: std::collections::HashMap, #[serde(default = "default_2312")] - pub conversations: std::collections::HashMap, + pub profile: std::collections::HashMap, #[serde(default = "default_2313")] - pub withheld: Option>, + pub conversations: std::collections::HashMap, #[serde(default = "default_2314")] + pub withheld: Option>, + #[serde(default = "default_2315")] pub namespaces_skipped: Vec, } @@ -54011,7 +54013,7 @@ impl SearchInput { pub struct SessionBriefDeleteOutput { pub deleted: bool, pub brief_key: String, - #[serde(default = "default_2315")] + #[serde(default = "default_2316")] pub revision: Integer, } @@ -54104,67 +54106,67 @@ impl SessionBriefDeleteInput { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[non_exhaustive] pub struct BriefDecision { - #[serde(default = "default_2324")] - pub what: String, #[serde(default = "default_2325")] + pub what: String, + #[serde(default = "default_2326")] pub why: String, } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[non_exhaustive] pub struct BriefDeadEnd { - #[serde(default = "default_2327")] - pub tried: String, #[serde(default = "default_2328")] + pub tried: String, + #[serde(default = "default_2329")] pub why_not: String, } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[non_exhaustive] pub struct BriefDone { - #[serde(default = "default_2330")] + #[serde(default = "default_2331")] pub what: String, - #[serde(rename = "ref", default = "default_2331")] + #[serde(rename = "ref", default = "default_2332")] pub r#ref: String, } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[non_exhaustive] pub struct BriefFile { - #[serde(default = "default_2335")] - pub path: String, #[serde(default = "default_2336")] + pub path: String, + #[serde(default = "default_2337")] pub role: String, } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[non_exhaustive] pub struct BriefSections { - #[serde(default = "default_2321")] - pub goal: String, #[serde(default = "default_2322")] - pub status: String, + pub goal: String, #[serde(default = "default_2323")] + pub status: String, + #[serde(default = "default_2324")] pub verification: String, - #[serde(default = "default_2326")] + #[serde(default = "default_2327")] pub decisions: Vec, - #[serde(default = "default_2329")] + #[serde(default = "default_2330")] pub dead_ends: Vec, - #[serde(default = "default_2332")] - pub done: Vec, #[serde(default = "default_2333")] - pub open_questions: Vec, + pub done: Vec, #[serde(default = "default_2334")] + pub open_questions: Vec, + #[serde(default = "default_2335")] pub next_steps: Vec, - #[serde(default = "default_2337")] - pub files: Vec, #[serde(default = "default_2338")] - pub constraints: Vec, + pub files: Vec, #[serde(default = "default_2339")] - pub pointers: Vec, + pub constraints: Vec, #[serde(default = "default_2340")] - pub client_summary: String, + pub pointers: Vec, #[serde(default = "default_2341")] + pub client_summary: String, + #[serde(default = "default_2342")] pub client_summary_at: String, } @@ -54172,45 +54174,45 @@ pub struct BriefSections { #[non_exhaustive] pub struct SessionBriefGetOutput { pub found: bool, - #[serde(default = "default_2316")] - pub brief_key: String, #[serde(default = "default_2317")] - pub revision: Integer, + pub brief_key: String, #[serde(default = "default_2318")] - pub snapshot_id: String, + pub revision: Integer, #[serde(default = "default_2319")] - pub snapshot_key: String, + pub snapshot_id: String, #[serde(default = "default_2320")] + pub snapshot_key: String, + #[serde(default = "default_2321")] pub rendered: String, - #[serde(default = "default_2342")] - pub sections: Option, #[serde(default = "default_2343")] - pub project: String, + pub sections: Option, #[serde(default = "default_2344")] - pub branch: String, + pub project: String, #[serde(default = "default_2345")] - pub head_sha: String, + pub branch: String, #[serde(default = "default_2346")] - pub author: String, + pub head_sha: String, #[serde(default = "default_2347")] - pub trigger: String, + pub author: String, #[serde(default = "default_2348")] - pub actor: String, + pub trigger: String, #[serde(default = "default_2349")] - pub source_sessions: Vec, + pub actor: String, #[serde(default = "default_2350")] - pub updated_at: Option, + pub source_sessions: Vec, #[serde(default = "default_2351")] - pub age_seconds: Integer, + pub updated_at: Option, #[serde(default = "default_2352")] - pub revisions: Integer, + pub age_seconds: Integer, #[serde(default = "default_2353")] - pub events_total: Integer, + pub revisions: Integer, #[serde(default = "default_2354")] - pub source_chars: Integer, + pub events_total: Integer, #[serde(default = "default_2355")] - pub brief_chars: Integer, + pub source_chars: Integer, #[serde(default = "default_2356")] + pub brief_chars: Integer, + #[serde(default = "default_2357")] pub deleted: bool, } @@ -54385,34 +54387,34 @@ impl SessionBriefGetInput { pub struct SessionBriefSummary { pub brief_key: String, pub revision: Integer, - #[serde(default = "default_2357")] - pub project: String, #[serde(default = "default_2358")] - pub branch: String, + pub project: String, #[serde(default = "default_2359")] - pub agent: String, + pub branch: String, #[serde(default = "default_2360")] - pub goal: String, + pub agent: String, #[serde(default = "default_2361")] - pub status: String, + pub goal: String, #[serde(default = "default_2362")] - pub author: String, + pub status: String, #[serde(default = "default_2363")] - pub actor: String, + pub author: String, #[serde(default = "default_2364")] - pub updated_at: Option, + pub actor: String, #[serde(default = "default_2365")] - pub age_seconds: Integer, + pub updated_at: Option, #[serde(default = "default_2366")] + pub age_seconds: Integer, + #[serde(default = "default_2367")] pub brief_chars: Integer, } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[non_exhaustive] pub struct SessionBriefListOutput { - #[serde(default = "default_2367")] - pub briefs: Vec, #[serde(default = "default_2368")] + pub briefs: Vec, + #[serde(default = "default_2369")] pub rendered: String, } @@ -54552,25 +54554,25 @@ impl SessionBriefListInput { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[non_exhaustive] pub struct SessionBriefStats { - #[serde(default = "default_2372")] - pub events_in: Integer, #[serde(default = "default_2373")] - pub windows: Integer, + pub events_in: Integer, #[serde(default = "default_2374")] - pub events_total: Integer, + pub windows: Integer, #[serde(default = "default_2375")] - pub source_chars: Integer, + pub events_total: Integer, #[serde(default = "default_2376")] - pub brief_chars: Integer, + pub source_chars: Integer, #[serde(default = "default_2377")] - pub compression_ratio: f64, + pub brief_chars: Integer, #[serde(default = "default_2378")] - pub dropped_ungrounded: Integer, + pub compression_ratio: f64, #[serde(default = "default_2379")] - pub tokens_in: Integer, + pub dropped_ungrounded: Integer, #[serde(default = "default_2380")] - pub tokens_out: Integer, + pub tokens_in: Integer, #[serde(default = "default_2381")] + pub tokens_out: Integer, + #[serde(default = "default_2382")] pub llm_model: String, } @@ -54580,13 +54582,13 @@ pub struct SessionBriefSaveOutput { pub brief_key: String, pub revision: Integer, pub changed: bool, - #[serde(default = "default_2369")] - pub author: String, #[serde(default = "default_2370")] - pub reason: String, + pub author: String, #[serde(default = "default_2371")] + pub reason: String, + #[serde(default = "default_2372")] pub rendered: String, - #[serde(default = "default_2382")] + #[serde(default = "default_2383")] pub stats: SessionBriefStats, } @@ -55331,39 +55333,39 @@ pub struct TaskPayload { pub priority: Integer, pub disclosure: TaskPayloadDisclosure, pub status: TaskPayloadStatus, - #[serde(default = "default_2383")] - pub reason: String, #[serde(default = "default_2384")] - pub blocked_on: String, + pub reason: String, #[serde(default = "default_2385")] - pub not_before: Option, + pub blocked_on: String, #[serde(default = "default_2386")] - pub resume_at: Option, + pub not_before: Option, #[serde(default = "default_2387")] - pub deadline: Option, + pub resume_at: Option, #[serde(default = "default_2388")] + pub deadline: Option, + #[serde(default = "default_2389")] pub defer_count: Integer, pub title: String, - #[serde(default = "default_2389")] + #[serde(default = "default_2390")] pub brief: std::collections::HashMap, pub from_agent: String, - #[serde(default = "default_2390")] - pub from_subject: String, #[serde(default = "default_2391")] - pub origin: String, + pub from_subject: String, #[serde(default = "default_2392")] - pub parent_task_id: Option, + pub origin: String, #[serde(default = "default_2393")] - pub owner: String, + pub parent_task_id: Option, #[serde(default = "default_2394")] - pub attempt: Integer, + pub owner: String, #[serde(default = "default_2395")] - pub fence: Integer, + pub attempt: Integer, #[serde(default = "default_2396")] - pub lease_until: Option, + pub fence: Integer, #[serde(default = "default_2397")] - pub outcome: std::collections::HashMap, + pub lease_until: Option, #[serde(default = "default_2398")] + pub outcome: std::collections::HashMap, + #[serde(default = "default_2399")] pub last_actor: String, pub created_at: String, pub updated_at: String, @@ -55374,7 +55376,7 @@ pub struct TaskPayload { #[non_exhaustive] pub struct TaskOutput { pub task: TaskPayload, - #[serde(default = "default_2399")] + #[serde(default = "default_2400")] pub seq: Integer, } @@ -55775,10 +55777,10 @@ impl TaskCompleteInput { pub struct InboxCount { pub inbox: String, pub status: String, - #[serde(default = "default_2400")] + #[serde(default = "default_2401")] pub blocked_on: String, pub n: Integer, - #[serde(default = "default_2401")] + #[serde(default = "default_2402")] pub oldest: Option, } @@ -55865,7 +55867,7 @@ pub struct TaskCreateOutput { pub task: TaskPayload, pub created: bool, pub seq: Integer, - #[serde(default = "default_2402")] + #[serde(default = "default_2403")] pub next: String, } @@ -56204,7 +56206,7 @@ impl TaskFailInput { #[non_exhaustive] pub struct TaskGetOutput { pub found: bool, - #[serde(default = "default_2403")] + #[serde(default = "default_2404")] pub task: Option, } @@ -56338,23 +56340,23 @@ pub struct TaskEventPayload { pub task_id: String, pub inbox: String, pub event: String, - #[serde(default = "default_2404")] - pub from_status: String, #[serde(default = "default_2405")] - pub to_status: String, + pub from_status: String, #[serde(default = "default_2406")] - pub actor: String, + pub to_status: String, #[serde(default = "default_2407")] - pub agent: String, + pub actor: String, #[serde(default = "default_2408")] - pub fence: Integer, + pub agent: String, #[serde(default = "default_2409")] - pub version: Integer, + pub fence: Integer, #[serde(default = "default_2410")] - pub reason: String, + pub version: Integer, #[serde(default = "default_2411")] - pub patch: std::collections::HashMap, + pub reason: String, #[serde(default = "default_2412")] + pub patch: std::collections::HashMap, + #[serde(default = "default_2413")] pub note: String, pub ts: String, } @@ -56694,7 +56696,7 @@ pub struct TaskPullOutput { pub tasks: Vec, pub waited_ms: Integer, pub backend: String, - #[serde(default = "default_2413")] + #[serde(default = "default_2414")] pub note: String, } @@ -57090,7 +57092,7 @@ impl TaskUnblockInput { pub struct TaskUpdateOutput { pub task: TaskPayload, pub seq: Integer, - #[serde(default = "default_2414")] + #[serde(default = "default_2415")] pub conflict: bool, } @@ -57453,19 +57455,19 @@ impl TaskReasonInput { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[non_exhaustive] pub struct TrackerAnswerOutput { - #[serde(default = "default_2415")] - pub intent: String, #[serde(default = "default_2416")] - pub anchors: std::collections::HashMap, + pub intent: String, #[serde(default = "default_2417")] - pub sections: Vec>, + pub anchors: std::collections::HashMap, #[serde(default = "default_2418")] - pub searched: Vec, + pub sections: Vec>, #[serde(default = "default_2419")] - pub lines: Vec, + pub searched: Vec, #[serde(default = "default_2420")] - pub restricted: bool, + pub lines: Vec, #[serde(default = "default_2421")] + pub restricted: bool, + #[serde(default = "default_2422")] pub verdict: String, } @@ -57561,17 +57563,17 @@ impl TrackerAnswerInput { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[non_exhaustive] pub struct TrackerBindingOutput { - #[serde(default = "default_2422")] - pub tracker_namespace: String, #[serde(default = "default_2423")] - pub tracker_namespaces: Vec, + pub tracker_namespace: String, #[serde(default = "default_2424")] - pub restricted: bool, + pub tracker_namespaces: Vec, #[serde(default = "default_2425")] - pub kind: String, + pub restricted: bool, #[serde(default = "default_2426")] - pub authorized: bool, + pub kind: String, #[serde(default = "default_2427")] + pub authorized: bool, + #[serde(default = "default_2428")] pub templates: Vec, } @@ -57624,13 +57626,13 @@ impl TrackerBindingInput { #[non_exhaustive] pub struct TrackerComponentOutput { pub component: String, - #[serde(default = "default_2428")] - pub risk: std::collections::HashMap, #[serde(default = "default_2429")] - pub open_issues: Vec>, + pub risk: std::collections::HashMap, #[serde(default = "default_2430")] - pub known: bool, + pub open_issues: Vec>, #[serde(default = "default_2431")] + pub known: bool, + #[serde(default = "default_2432")] pub tracker_unavailable: bool, } @@ -57691,9 +57693,9 @@ impl TrackerComponentInput { #[non_exhaustive] pub struct TrackerContractOutput { pub database: String, - #[serde(default = "default_2432")] - pub tables: Vec>, #[serde(default = "default_2433")] + pub tables: Vec>, + #[serde(default = "default_2434")] pub templates: std::collections::HashMap, } @@ -57746,66 +57748,66 @@ impl TrackerContractInput { #[non_exhaustive] pub struct TrackerLegStatus { pub name: String, - #[serde(default = "default_2444")] - pub status: String, #[serde(default = "default_2445")] - pub reason: String, + pub status: String, #[serde(default = "default_2446")] - pub message: String, + pub reason: String, #[serde(default = "default_2447")] - pub retried: bool, + pub message: String, #[serde(default = "default_2448")] - pub ms: Integer, + pub retried: bool, #[serde(default = "default_2449")] - pub cause: String, + pub ms: Integer, #[serde(default = "default_2450")] + pub cause: String, + #[serde(default = "default_2451")] pub namespace: String, } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[non_exhaustive] pub struct TrackerDuplicateCheckOutput { - #[serde(default = "default_2434")] - pub verdict: String, #[serde(default = "default_2435")] - pub items: Vec>, + pub verdict: String, #[serde(default = "default_2436")] - pub undecided: bool, + pub items: Vec>, #[serde(default = "default_2437")] - pub epistemic: String, + pub undecided: bool, #[serde(default = "default_2438")] - pub thresholds: std::collections::HashMap, + pub epistemic: String, #[serde(default = "default_2439")] - pub judge: std::collections::HashMap, + pub thresholds: std::collections::HashMap, #[serde(default = "default_2440")] - pub fit_at: String, + pub judge: std::collections::HashMap, #[serde(default = "default_2441")] - pub fit: std::collections::HashMap, + pub fit_at: String, #[serde(default = "default_2442")] - pub query: std::collections::HashMap, + pub fit: std::collections::HashMap, #[serde(default = "default_2443")] + pub query: std::collections::HashMap, + #[serde(default = "default_2444")] pub legs: std::collections::HashMap, - #[serde(default = "default_2451")] - pub leg_status: Vec, #[serde(default = "default_2452")] - pub tracker_unavailable: bool, + pub leg_status: Vec, #[serde(default = "default_2453")] - pub namespaces: Vec, + pub tracker_unavailable: bool, #[serde(default = "default_2454")] - pub by_namespace: std::collections::HashMap>, + pub namespaces: Vec, #[serde(default = "default_2455")] - pub closest: Vec>, + pub by_namespace: std::collections::HashMap>, #[serde(default = "default_2456")] - pub needs: Vec>, + pub closest: Vec>, #[serde(default = "default_2457")] - pub closest_note: String, + pub needs: Vec>, #[serde(default = "default_2458")] - pub nearest: Vec>, + pub closest_note: String, #[serde(default = "default_2459")] - pub rerank: std::collections::HashMap, + pub nearest: Vec>, #[serde(default = "default_2460")] - pub answer: String, + pub rerank: std::collections::HashMap, #[serde(default = "default_2461")] + pub answer: String, + #[serde(default = "default_2462")] pub related_prs: Vec>, } @@ -58012,17 +58014,17 @@ impl TrackerDuplicateCheckInput { #[non_exhaustive] pub struct TrackerFlakyOutput { pub test_name: String, - #[serde(default = "default_2462")] - pub known_flaky: bool, #[serde(default = "default_2463")] - pub open_issues: Integer, + pub known_flaky: bool, #[serde(default = "default_2464")] - pub issues: Vec>, + pub open_issues: Integer, #[serde(default = "default_2465")] - pub verdict: String, + pub issues: Vec>, #[serde(default = "default_2466")] - pub tracker_unavailable: bool, + pub verdict: String, #[serde(default = "default_2467")] + pub tracker_unavailable: bool, + #[serde(default = "default_2468")] pub signal: Option>, } @@ -58105,9 +58107,9 @@ impl TrackerFlakyInput { #[non_exhaustive] pub struct TrackerItemOutput { pub items: Vec>, - #[serde(default = "default_2468")] - pub unknown: Vec, #[serde(default = "default_2469")] + pub unknown: Vec, + #[serde(default = "default_2470")] pub tracker_unavailable: bool, } @@ -58156,19 +58158,19 @@ impl TrackerItemInput { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[non_exhaustive] pub struct TrackerLinksOutput { - #[serde(default = "default_2470")] - pub subject: std::collections::HashMap, #[serde(default = "default_2471")] - pub verdict: String, + pub subject: std::collections::HashMap, #[serde(default = "default_2472")] - pub items: Vec>, + pub verdict: String, #[serde(default = "default_2473")] - pub epistemic: String, + pub items: Vec>, #[serde(default = "default_2474")] - pub record: std::collections::HashMap, + pub epistemic: String, #[serde(default = "default_2475")] - pub computed_at: String, + pub record: std::collections::HashMap, #[serde(default = "default_2476")] + pub computed_at: String, + #[serde(default = "default_2477")] pub tracker_unavailable: bool, } @@ -58266,11 +58268,11 @@ impl TrackerLinksInput { pub struct TrackerReleaseOutput { pub version: String, pub blockers: Vec>, - #[serde(default = "default_2477")] - pub active_blockers: Integer, #[serde(default = "default_2478")] - pub health: std::collections::HashMap, + pub active_blockers: Integer, #[serde(default = "default_2479")] + pub health: std::collections::HashMap, + #[serde(default = "default_2480")] pub tracker_unavailable: bool, } @@ -58319,17 +58321,17 @@ impl TrackerReleaseInput { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[non_exhaustive] pub struct TrackerSimilarOutput { - #[serde(default = "default_2480")] - pub items: Vec>, #[serde(default = "default_2481")] - pub query: std::collections::HashMap, + pub items: Vec>, #[serde(default = "default_2482")] - pub legs: std::collections::HashMap, + pub query: std::collections::HashMap, #[serde(default = "default_2483")] - pub epistemic: String, + pub legs: std::collections::HashMap, #[serde(default = "default_2484")] - pub tracker_unavailable: bool, + pub epistemic: String, #[serde(default = "default_2485")] + pub tracker_unavailable: bool, + #[serde(default = "default_2486")] pub namespaces: Vec, } @@ -58450,19 +58452,19 @@ pub struct TrackerSourceAddOutput { pub name: String, pub host: String, pub database: String, - #[serde(default = "default_2486")] - pub namespaces: Vec>, #[serde(default = "default_2487")] - pub contract: std::collections::HashMap, + pub namespaces: Vec>, #[serde(default = "default_2488")] - pub roles: Vec, + pub contract: std::collections::HashMap, #[serde(default = "default_2489")] - pub my_role: String, + pub roles: Vec, #[serde(default = "default_2490")] - pub dry_run: bool, + pub my_role: String, #[serde(default = "default_2491")] - pub written: bool, + pub dry_run: bool, #[serde(default = "default_2492")] + pub written: bool, + #[serde(default = "default_2493")] pub view_templates: std::collections::HashMap, } @@ -58625,13 +58627,13 @@ impl TrackerSourceAddInput { #[non_exhaustive] pub struct TrackerSourceCheckOutput { pub name: String, - #[serde(default = "default_2493")] - pub database: String, #[serde(default = "default_2494")] - pub reachable: bool, + pub database: String, #[serde(default = "default_2495")] - pub contract: std::collections::HashMap, + pub reachable: bool, #[serde(default = "default_2496")] + pub contract: std::collections::HashMap, + #[serde(default = "default_2497")] pub view_templates: std::collections::HashMap, } @@ -58670,12 +58672,12 @@ impl TrackerSourceCheckInput { #[non_exhaustive] pub struct TrackerSourceInspectOutput { pub host: String, - pub database: String, - #[serde(default = "default_2497")] - pub tables: Vec>, + pub database: String, #[serde(default = "default_2498")] - pub roles: Vec, + pub tables: Vec>, #[serde(default = "default_2499")] + pub roles: Vec, + #[serde(default = "default_2500")] pub proposal: std::collections::HashMap, } @@ -58804,9 +58806,9 @@ impl TrackerSourceInspectInput { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[non_exhaustive] pub struct TrackerSourceListOutput { - #[serde(default = "default_2500")] - pub sources: Vec>, #[serde(default = "default_2501")] + pub sources: Vec>, + #[serde(default = "default_2502")] pub self_service: bool, } @@ -58859,9 +58861,9 @@ impl TrackerSourceListInput { #[non_exhaustive] pub struct TrackerSourceRemoveOutput { pub name: String, - #[serde(default = "default_2502")] - pub deactivated: bool, #[serde(default = "default_2503")] + pub deactivated: bool, + #[serde(default = "default_2504")] pub namespaces_retired: Vec, } @@ -58902,9 +58904,9 @@ impl TrackerSourceRemoveInput { #[non_exhaustive] pub struct TrackerSourceRotateOutput { pub name: String, - #[serde(default = "default_2504")] - pub contract: std::collections::HashMap, #[serde(default = "default_2505")] + pub contract: std::collections::HashMap, + #[serde(default = "default_2506")] pub rotated_at: String, } @@ -58951,11 +58953,11 @@ impl TrackerSourceRotateInput { #[non_exhaustive] pub struct TrackerSourceSetMappingOutput { pub name: String, - #[serde(default = "default_2506")] - pub contract: std::collections::HashMap, #[serde(default = "default_2507")] - pub dry_run: bool, + pub contract: std::collections::HashMap, #[serde(default = "default_2508")] + pub dry_run: bool, + #[serde(default = "default_2509")] pub written: bool, } @@ -59022,45 +59024,45 @@ impl TrackerSourceSetMappingInput { #[non_exhaustive] pub struct TrackerTestSignalOutput { pub test_name: String, - #[serde(default = "default_2509")] - pub verdict: String, #[serde(default = "default_2510")] - pub why: Vec, + pub verdict: String, #[serde(default = "default_2511")] - pub lower_bound: f64, + pub why: Vec, #[serde(default = "default_2512")] - pub window_days: Integer, + pub lower_bound: f64, #[serde(default = "default_2513")] - pub since: String, + pub window_days: Integer, #[serde(default = "default_2514")] - pub features: std::collections::HashMap, + pub since: String, #[serde(default = "default_2515")] - pub infra: std::collections::HashMap, + pub features: std::collections::HashMap, #[serde(default = "default_2516")] - pub churn: std::collections::HashMap, + pub infra: std::collections::HashMap, #[serde(default = "default_2517")] - pub thresholds: std::collections::HashMap, + pub churn: std::collections::HashMap, #[serde(default = "default_2518")] - pub source: String, + pub thresholds: std::collections::HashMap, #[serde(default = "default_2519")] - pub timings_ms: std::collections::HashMap, + pub source: String, #[serde(default = "default_2520")] - pub tracker_unavailable: bool, + pub timings_ms: std::collections::HashMap, #[serde(default = "default_2521")] - pub rollup: std::collections::HashMap, + pub tracker_unavailable: bool, #[serde(default = "default_2522")] - pub streak: std::collections::HashMap, + pub rollup: std::collections::HashMap, #[serde(default = "default_2523")] - pub smells: std::collections::HashMap, + pub streak: std::collections::HashMap, #[serde(default = "default_2524")] - pub prior: std::collections::HashMap, + pub smells: std::collections::HashMap, #[serde(default = "default_2525")] - pub unavailable_reason: String, + pub prior: std::collections::HashMap, #[serde(default = "default_2526")] - pub candidates: Vec>, + pub unavailable_reason: String, #[serde(default = "default_2527")] - pub candidate_matches: Integer, + pub candidates: Vec>, #[serde(default = "default_2528")] + pub candidate_matches: Integer, + #[serde(default = "default_2529")] pub resolved_from: String, } @@ -59164,9 +59166,9 @@ impl TrackerTestSignalInput { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[non_exhaustive] pub struct UiVitalsOutput { - #[serde(default = "default_2529")] - pub recorded: bool, #[serde(default = "default_2530")] + pub recorded: bool, + #[serde(default = "default_2531")] pub route: String, } @@ -59350,7 +59352,7 @@ pub struct WebhookDelivery { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[non_exhaustive] pub struct WebhookDeliveriesOutput { - #[serde(default = "default_2531")] + #[serde(default = "default_2532")] pub deliveries: Vec, } @@ -59472,14 +59474,14 @@ pub struct WebhookInfo { pub secret_ref: String, pub events: Vec, pub created_at: String, - #[serde(default = "default_2532")] + #[serde(default = "default_2533")] pub secret_present: bool, } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[non_exhaustive] pub struct WebhookListOutput { - #[serde(default = "default_2533")] + #[serde(default = "default_2534")] pub webhooks: Vec, } @@ -59661,7 +59663,7 @@ pub struct WorkingMemoryMutationOutput { pub version: Integer, pub char_limit: Integer, pub value_length: Integer, - #[serde(default = "default_2534")] + #[serde(default = "default_2535")] pub fill_ratio: f64, } @@ -59885,15 +59887,15 @@ impl WorkingMemoryDeleteInput { pub struct WorkingMemoryGetOutput { pub found: bool, pub block_key: String, - #[serde(default = "default_2535")] - pub content: String, #[serde(default = "default_2536")] - pub char_limit: Integer, + pub content: String, #[serde(default = "default_2537")] - pub version: Integer, + pub char_limit: Integer, #[serde(default = "default_2538")] - pub updated_at: Option, + pub version: Integer, #[serde(default = "default_2539")] + pub updated_at: Option, + #[serde(default = "default_2540")] pub fill_ratio: f64, } @@ -60004,7 +60006,7 @@ pub struct WorkingMemoryBlock { pub content: String, pub char_limit: Integer, pub version: Integer, - #[serde(default = "default_2540")] + #[serde(default = "default_2541")] pub updated_at: Option, } @@ -60012,7 +60014,7 @@ pub struct WorkingMemoryBlock { #[non_exhaustive] pub struct WorkingMemoryRenderOutput { pub rendered: String, - #[serde(default = "default_2541")] + #[serde(default = "default_2542")] pub blocks: Vec, pub block_count: Integer, pub total_chars: Integer, @@ -66881,17 +66883,17 @@ fn default_2160() -> String { fn default_2161() -> Vec> { serde_json::from_str("[]").expect("schema default") } -fn default_2162() -> Vec { - serde_json::from_str("[]").expect("schema default") +fn default_2162() -> std::collections::HashMap { + serde_json::from_str("{}").expect("schema default") } -fn default_2163() -> Integer { - serde_json::from_str("0").expect("schema default") +fn default_2163() -> Vec { + serde_json::from_str("[]").expect("schema default") } fn default_2164() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2165() -> String { - serde_json::from_str("\"\"").expect("schema default") +fn default_2165() -> Integer { + serde_json::from_str("0").expect("schema default") } fn default_2166() -> String { serde_json::from_str("\"\"").expect("schema default") @@ -66899,27 +66901,27 @@ fn default_2166() -> String { fn default_2167() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2168() -> Vec { - serde_json::from_str("[]").expect("schema default") +fn default_2168() -> String { + serde_json::from_str("\"\"").expect("schema default") } fn default_2169() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2170() -> String { - serde_json::from_str("\"\"").expect("schema default") +fn default_2170() -> Vec { + serde_json::from_str("[]").expect("schema default") } fn default_2171() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2172() -> bool { +fn default_2172() -> String { + serde_json::from_str("\"\"").expect("schema default") +} +fn default_2173() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2173() -> Integer { +fn default_2174() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2174() -> String { - serde_json::from_str("\"\"").expect("schema default") -} fn default_2175() -> String { serde_json::from_str("\"\"").expect("schema default") } @@ -66929,104 +66931,104 @@ fn default_2176() -> String { fn default_2177() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2178() -> Vec { +fn default_2178() -> String { + serde_json::from_str("\"\"").expect("schema default") +} +fn default_2179() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2179() -> String { +fn default_2180() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2180() -> String { +fn default_2181() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2181() -> std::collections::HashMap { +fn default_2182() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2182() -> String { +fn default_2183() -> String { serde_json::from_str("\"active\"").expect("schema default") } -fn default_2183() -> Option { +fn default_2184() -> Option { serde_json::from_str("null").expect("schema default") } -fn default_2184() -> Option { +fn default_2185() -> Option { serde_json::from_str("null").expect("schema default") } -fn default_2185() -> bool { +fn default_2186() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2186() -> String { +fn default_2187() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2187() -> String { +fn default_2188() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2188() -> Vec { +fn default_2189() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2189() -> Integer { +fn default_2190() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2190() -> String { +fn default_2191() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2191() -> String { +fn default_2192() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2192() -> Option { +fn default_2193() -> Option { serde_json::from_str("null").expect("schema default") } -fn default_2193() -> bool { +fn default_2194() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2194() -> String { +fn default_2195() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2195() -> bool { +fn default_2196() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2196() -> String { +fn default_2197() -> String { serde_json::from_str("\"inherit\"").expect("schema default") } -fn default_2197() -> Option { +fn default_2198() -> Option { serde_json::from_str("null").expect("schema default") } -fn default_2198() -> Option { +fn default_2199() -> Option { serde_json::from_str("null").expect("schema default") } -fn default_2199() -> bool { +fn default_2200() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2200() -> Vec { +fn default_2201() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2201() -> Integer { +fn default_2202() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2202() -> ProcedureEvolveOutputGate { +fn default_2203() -> ProcedureEvolveOutputGate { serde_json::from_str("\"none\"").expect("schema default") } -fn default_2203() -> String { +fn default_2204() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2204() -> f64 { +fn default_2205() -> f64 { serde_json::from_str("0.0").expect("schema default") } -fn default_2205() -> std::collections::HashMap { - serde_json::from_str("{}").expect("schema default") -} fn default_2206() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2207() -> std::collections::HashMap { +fn default_2207() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } fn default_2208() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2209() -> String { - serde_json::from_str("\"\"").expect("schema default") +fn default_2209() -> std::collections::HashMap { + serde_json::from_str("{}").expect("schema default") } -fn default_2210() -> Vec { - serde_json::from_str("[]").expect("schema default") +fn default_2210() -> String { + serde_json::from_str("\"\"").expect("schema default") } fn default_2211() -> Vec { serde_json::from_str("[]").expect("schema default") @@ -67034,134 +67036,134 @@ fn default_2211() -> Vec { fn default_2212() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2213() -> std::collections::HashMap { +fn default_2213() -> Vec { + serde_json::from_str("[]").expect("schema default") +} +fn default_2214() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2214() -> Integer { +fn default_2215() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2215() -> bool { +fn default_2216() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2216() -> std::collections::HashMap { +fn default_2217() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2217() -> Vec { +fn default_2218() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2218() -> std::collections::HashMap { +fn default_2219() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2219() -> String { +fn default_2220() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2220() -> ProcedureLocateOutputStatus { +fn default_2221() -> ProcedureLocateOutputStatus { serde_json::from_str("\"authored\"").expect("schema default") } -fn default_2221() -> Option> { +fn default_2222() -> Option> { serde_json::from_str("null").expect("schema default") } -fn default_2222() -> Vec>> { +fn default_2223() -> Vec>> { serde_json::from_str("[]").expect("schema default") } -fn default_2223() -> Vec { +fn default_2224() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2224() -> Vec { +fn default_2225() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2225() -> std::collections::HashMap { +fn default_2226() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2226() -> bool { +fn default_2227() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2227() -> Vec { +fn default_2228() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2228() -> Vec> { +fn default_2229() -> Vec> { serde_json::from_str("[]").expect("schema default") } -fn default_2229() -> String { +fn default_2230() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2230() -> std::collections::HashMap { +fn default_2231() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2231() -> std::collections::HashMap { +fn default_2232() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2232() -> Vec { +fn default_2233() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2233() -> std::collections::HashMap { +fn default_2234() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2234() -> Option> { +fn default_2235() -> Option> { serde_json::from_str("null").expect("schema default") } -fn default_2235() -> bool { +fn default_2236() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2236() -> std::collections::HashMap { +fn default_2237() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2237() -> ProcedureMatchStatus { +fn default_2238() -> ProcedureMatchStatus { serde_json::from_str("\"authored\"").expect("schema default") } -fn default_2238() -> Option> { +fn default_2239() -> Option> { serde_json::from_str("null").expect("schema default") } -fn default_2239() -> Vec { +fn default_2240() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2240() -> Integer { +fn default_2241() -> Integer { serde_json::from_str("1").expect("schema default") } -fn default_2241() -> Vec> { +fn default_2242() -> Vec> { serde_json::from_str("[]").expect("schema default") } -fn default_2242() -> f64 { - serde_json::from_str("0.0").expect("schema default") -} fn default_2243() -> f64 { serde_json::from_str("0.0").expect("schema default") } fn default_2244() -> f64 { serde_json::from_str("0.0").expect("schema default") } -fn default_2245() -> Option { +fn default_2245() -> f64 { + serde_json::from_str("0.0").expect("schema default") +} +fn default_2246() -> Option { serde_json::from_str("null").expect("schema default") } -fn default_2246() -> std::collections::HashMap { +fn default_2247() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2247() -> std::collections::HashMap> { +fn default_2248() -> std::collections::HashMap> { serde_json::from_str("{}").expect("schema default") } -fn default_2248() -> String { +fn default_2249() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2249() -> Integer { +fn default_2250() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2250() -> String { +fn default_2251() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2251() -> f64 { +fn default_2252() -> f64 { serde_json::from_str("0.0").expect("schema default") } -fn default_2252() -> Vec { - serde_json::from_str("[]").expect("schema default") -} fn default_2253() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2254() -> Vec { +fn default_2254() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2255() -> String { - serde_json::from_str("\"\"").expect("schema default") +fn default_2255() -> Vec { + serde_json::from_str("[]").expect("schema default") } fn default_2256() -> String { serde_json::from_str("\"\"").expect("schema default") @@ -67172,101 +67174,101 @@ fn default_2257() -> String { fn default_2258() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2259() -> Option { +fn default_2259() -> String { + serde_json::from_str("\"\"").expect("schema default") +} +fn default_2260() -> Option { serde_json::from_str("null").expect("schema default") } -fn default_2260() -> Integer { +fn default_2261() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2261() -> Vec { +fn default_2262() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2262() -> std::collections::HashMap { +fn default_2263() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2263() -> Option { +fn default_2264() -> Option { serde_json::from_str("null").expect("schema default") } -fn default_2264() -> String { +fn default_2265() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2265() -> Integer { +fn default_2266() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2266() -> String { +fn default_2267() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2267() -> String { +fn default_2268() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2268() -> std::collections::HashMap { +fn default_2269() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2269() -> String { +fn default_2270() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2270() -> String { +fn default_2271() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2271() -> Option { +fn default_2272() -> Option { serde_json::from_str("null").expect("schema default") } -fn default_2272() -> RunBeginOutputStatus { +fn default_2273() -> RunBeginOutputStatus { serde_json::from_str("\"active\"").expect("schema default") } -fn default_2273() -> String { +fn default_2274() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2274() -> Integer { - serde_json::from_str("0").expect("schema default") -} fn default_2275() -> Integer { serde_json::from_str("0").expect("schema default") } fn default_2276() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2277() -> Vec { +fn default_2277() -> Integer { + serde_json::from_str("0").expect("schema default") +} +fn default_2278() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2278() -> Integer { +fn default_2279() -> Integer { serde_json::from_str("-1").expect("schema default") } -fn default_2279() -> Integer { +fn default_2280() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2280() -> Integer { +fn default_2281() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2281() -> String { +fn default_2282() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2282() -> String { +fn default_2283() -> String { serde_json::from_str("\"keep\"").expect("schema default") } -fn default_2283() -> Integer { - serde_json::from_str("0").expect("schema default") -} fn default_2284() -> Integer { serde_json::from_str("0").expect("schema default") } fn default_2285() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2286() -> Option { +fn default_2286() -> Integer { + serde_json::from_str("0").expect("schema default") +} +fn default_2287() -> Option { serde_json::from_str("null").expect("schema default") } -fn default_2287() -> Integer { +fn default_2288() -> Integer { serde_json::from_str("-1").expect("schema default") } -fn default_2288() -> Vec { - serde_json::from_str("[]").expect("schema default") -} fn default_2289() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2290() -> Integer { - serde_json::from_str("0").expect("schema default") +fn default_2290() -> Vec { + serde_json::from_str("[]").expect("schema default") } fn default_2291() -> Integer { serde_json::from_str("0").expect("schema default") @@ -67274,57 +67276,57 @@ fn default_2291() -> Integer { fn default_2292() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2293() -> f64 { +fn default_2293() -> Integer { + serde_json::from_str("0").expect("schema default") +} +fn default_2294() -> f64 { serde_json::from_str("0.0").expect("schema default") } -fn default_2294() -> Integer { +fn default_2295() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2295() -> Vec { +fn default_2296() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2296() -> Integer { +fn default_2297() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2297() -> Vec { +fn default_2298() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2298() -> Integer { - serde_json::from_str("0").expect("schema default") -} fn default_2299() -> Integer { serde_json::from_str("0").expect("schema default") } fn default_2300() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2301() -> Vec { +fn default_2301() -> Integer { + serde_json::from_str("0").expect("schema default") +} +fn default_2302() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2302() -> Option { +fn default_2303() -> Option { serde_json::from_str("null").expect("schema default") } -fn default_2303() -> Option> { +fn default_2304() -> Option> { serde_json::from_str("null").expect("schema default") } -fn default_2304() -> LiveSearchResultsLive { +fn default_2305() -> LiveSearchResultsLive { serde_json::from_str("true").expect("schema default") } -fn default_2305() -> String { +fn default_2306() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2306() -> LiveSearchHitLive { +fn default_2307() -> LiveSearchHitLive { serde_json::from_str("true").expect("schema default") } -fn default_2307() -> Vec { +fn default_2308() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2308() -> Option { +fn default_2309() -> Option { serde_json::from_str("null").expect("schema default") } -fn default_2309() -> std::collections::HashMap { - serde_json::from_str("{}").expect("schema default") -} fn default_2310() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } @@ -67334,24 +67336,24 @@ fn default_2311() -> std::collections::HashMap { fn default_2312() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2313() -> Option> { +fn default_2313() -> std::collections::HashMap { + serde_json::from_str("{}").expect("schema default") +} +fn default_2314() -> Option> { serde_json::from_str("null").expect("schema default") } -fn default_2314() -> Vec { +fn default_2315() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2315() -> Integer { +fn default_2316() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2316() -> String { +fn default_2317() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2317() -> Integer { +fn default_2318() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2318() -> String { - serde_json::from_str("\"\"").expect("schema default") -} fn default_2319() -> String { serde_json::from_str("\"\"").expect("schema default") } @@ -67373,60 +67375,60 @@ fn default_2324() -> String { fn default_2325() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2326() -> Vec { +fn default_2326() -> String { + serde_json::from_str("\"\"").expect("schema default") +} +fn default_2327() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2327() -> String { +fn default_2328() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2328() -> String { +fn default_2329() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2329() -> Vec { +fn default_2330() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2330() -> String { +fn default_2331() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2331() -> String { +fn default_2332() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2332() -> Vec { +fn default_2333() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2333() -> Vec { +fn default_2334() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2334() -> Vec { +fn default_2335() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2335() -> String { +fn default_2336() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2336() -> String { +fn default_2337() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2337() -> Vec { +fn default_2338() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2338() -> Vec { +fn default_2339() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2339() -> Vec { +fn default_2340() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2340() -> String { +fn default_2341() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2341() -> String { +fn default_2342() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2342() -> Option { +fn default_2343() -> Option { serde_json::from_str("null").expect("schema default") } -fn default_2343() -> String { - serde_json::from_str("\"\"").expect("schema default") -} fn default_2344() -> String { serde_json::from_str("\"\"").expect("schema default") } @@ -67442,15 +67444,15 @@ fn default_2347() -> String { fn default_2348() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2349() -> Vec { +fn default_2349() -> String { + serde_json::from_str("\"\"").expect("schema default") +} +fn default_2350() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2350() -> Option { +fn default_2351() -> Option { serde_json::from_str("null").expect("schema default") } -fn default_2351() -> Integer { - serde_json::from_str("0").expect("schema default") -} fn default_2352() -> Integer { serde_json::from_str("0").expect("schema default") } @@ -67463,11 +67465,11 @@ fn default_2354() -> Integer { fn default_2355() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2356() -> bool { - serde_json::from_str("false").expect("schema default") +fn default_2356() -> Integer { + serde_json::from_str("0").expect("schema default") } -fn default_2357() -> String { - serde_json::from_str("\"\"").expect("schema default") +fn default_2357() -> bool { + serde_json::from_str("false").expect("schema default") } fn default_2358() -> String { serde_json::from_str("\"\"").expect("schema default") @@ -67487,21 +67489,21 @@ fn default_2362() -> String { fn default_2363() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2364() -> Option { +fn default_2364() -> String { + serde_json::from_str("\"\"").expect("schema default") +} +fn default_2365() -> Option { serde_json::from_str("null").expect("schema default") } -fn default_2365() -> Integer { +fn default_2366() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2366() -> Integer { +fn default_2367() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2367() -> Vec { +fn default_2368() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2368() -> String { - serde_json::from_str("\"\"").expect("schema default") -} fn default_2369() -> String { serde_json::from_str("\"\"").expect("schema default") } @@ -67511,8 +67513,8 @@ fn default_2370() -> String { fn default_2371() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2372() -> Integer { - serde_json::from_str("0").expect("schema default") +fn default_2372() -> String { + serde_json::from_str("\"\"").expect("schema default") } fn default_2373() -> Integer { serde_json::from_str("0").expect("schema default") @@ -67526,32 +67528,32 @@ fn default_2375() -> Integer { fn default_2376() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2377() -> f64 { - serde_json::from_str("0.0").expect("schema default") -} -fn default_2378() -> Integer { +fn default_2377() -> Integer { serde_json::from_str("0").expect("schema default") } +fn default_2378() -> f64 { + serde_json::from_str("0.0").expect("schema default") +} fn default_2379() -> Integer { serde_json::from_str("0").expect("schema default") } fn default_2380() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2381() -> String { +fn default_2381() -> Integer { + serde_json::from_str("0").expect("schema default") +} +fn default_2382() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2382() -> SessionBriefStats { +fn default_2383() -> 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_2383() -> String { - serde_json::from_str("\"\"").expect("schema default") -} fn default_2384() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2385() -> Option { - serde_json::from_str("null").expect("schema default") +fn default_2385() -> String { + serde_json::from_str("\"\"").expect("schema default") } fn default_2386() -> Option { serde_json::from_str("null").expect("schema default") @@ -67559,57 +67561,57 @@ fn default_2386() -> Option { fn default_2387() -> Option { serde_json::from_str("null").expect("schema default") } -fn default_2388() -> Integer { +fn default_2388() -> Option { + serde_json::from_str("null").expect("schema default") +} +fn default_2389() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2389() -> std::collections::HashMap { +fn default_2390() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2390() -> String { +fn default_2391() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2391() -> String { +fn default_2392() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2392() -> Option { +fn default_2393() -> Option { serde_json::from_str("null").expect("schema default") } -fn default_2393() -> String { +fn default_2394() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2394() -> Integer { +fn default_2395() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2395() -> Integer { +fn default_2396() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2396() -> Option { +fn default_2397() -> Option { serde_json::from_str("null").expect("schema default") } -fn default_2397() -> std::collections::HashMap { +fn default_2398() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2398() -> String { +fn default_2399() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2399() -> Integer { +fn default_2400() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2400() -> String { +fn default_2401() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2401() -> Option { +fn default_2402() -> Option { serde_json::from_str("null").expect("schema default") } -fn default_2402() -> String { +fn default_2403() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2403() -> Option { +fn default_2404() -> Option { serde_json::from_str("null").expect("schema default") } -fn default_2404() -> String { - serde_json::from_str("\"\"").expect("schema default") -} fn default_2405() -> String { serde_json::from_str("\"\"").expect("schema default") } @@ -67619,327 +67621,327 @@ fn default_2406() -> String { fn default_2407() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2408() -> Integer { - serde_json::from_str("0").expect("schema default") +fn default_2408() -> String { + serde_json::from_str("\"\"").expect("schema default") } fn default_2409() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2410() -> String { +fn default_2410() -> Integer { + serde_json::from_str("0").expect("schema default") +} +fn default_2411() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2411() -> std::collections::HashMap { +fn default_2412() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2412() -> String { +fn default_2413() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2413() -> String { +fn default_2414() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2414() -> bool { +fn default_2415() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2415() -> String { +fn default_2416() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2416() -> std::collections::HashMap { +fn default_2417() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2417() -> Vec> { +fn default_2418() -> Vec> { serde_json::from_str("[]").expect("schema default") } -fn default_2418() -> Vec { +fn default_2419() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2419() -> Vec { +fn default_2420() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2420() -> bool { +fn default_2421() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2421() -> String { +fn default_2422() -> String { serde_json::from_str("\"unknown\"").expect("schema default") } -fn default_2422() -> String { +fn default_2423() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2423() -> Vec { +fn default_2424() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2424() -> bool { +fn default_2425() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2425() -> String { +fn default_2426() -> String { serde_json::from_str("\"none\"").expect("schema default") } -fn default_2426() -> bool { +fn default_2427() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2427() -> Vec { +fn default_2428() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2428() -> std::collections::HashMap { +fn default_2429() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2429() -> Vec> { +fn default_2430() -> Vec> { serde_json::from_str("[]").expect("schema default") } -fn default_2430() -> bool { +fn default_2431() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2431() -> bool { +fn default_2432() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2432() -> Vec> { +fn default_2433() -> Vec> { serde_json::from_str("[]").expect("schema default") } -fn default_2433() -> std::collections::HashMap { +fn default_2434() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2434() -> String { +fn default_2435() -> String { serde_json::from_str("\"none\"").expect("schema default") } -fn default_2435() -> Vec> { +fn default_2436() -> Vec> { serde_json::from_str("[]").expect("schema default") } -fn default_2436() -> bool { +fn default_2437() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2437() -> String { +fn default_2438() -> String { serde_json::from_str("\"calibrated\"").expect("schema default") } -fn default_2438() -> std::collections::HashMap { +fn default_2439() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2439() -> std::collections::HashMap { +fn default_2440() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2440() -> String { +fn default_2441() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2441() -> std::collections::HashMap { +fn default_2442() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2442() -> std::collections::HashMap { +fn default_2443() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2443() -> std::collections::HashMap { +fn default_2444() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2444() -> String { +fn default_2445() -> String { serde_json::from_str("\"ok\"").expect("schema default") } -fn default_2445() -> String { +fn default_2446() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2446() -> String { +fn default_2447() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2447() -> bool { +fn default_2448() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2448() -> Integer { +fn default_2449() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2449() -> String { +fn default_2450() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2450() -> String { +fn default_2451() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2451() -> Vec { +fn default_2452() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2452() -> bool { +fn default_2453() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2453() -> Vec { +fn default_2454() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2454() -> std::collections::HashMap> { +fn default_2455() -> std::collections::HashMap> { serde_json::from_str("{}").expect("schema default") } -fn default_2455() -> Vec> { +fn default_2456() -> Vec> { serde_json::from_str("[]").expect("schema default") } -fn default_2456() -> Vec> { +fn default_2457() -> Vec> { serde_json::from_str("[]").expect("schema default") } -fn default_2457() -> String { +fn default_2458() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2458() -> Vec> { +fn default_2459() -> Vec> { serde_json::from_str("[]").expect("schema default") } -fn default_2459() -> std::collections::HashMap { +fn default_2460() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2460() -> String { +fn default_2461() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2461() -> Vec> { +fn default_2462() -> Vec> { serde_json::from_str("[]").expect("schema default") } -fn default_2462() -> bool { +fn default_2463() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2463() -> Integer { +fn default_2464() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2464() -> Vec> { +fn default_2465() -> Vec> { serde_json::from_str("[]").expect("schema default") } -fn default_2465() -> String { +fn default_2466() -> String { serde_json::from_str("\"no_flaky_signal\"").expect("schema default") } -fn default_2466() -> bool { +fn default_2467() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2467() -> Option> { +fn default_2468() -> Option> { serde_json::from_str("null").expect("schema default") } -fn default_2468() -> Vec { +fn default_2469() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2469() -> bool { +fn default_2470() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2470() -> std::collections::HashMap { +fn default_2471() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2471() -> String { +fn default_2472() -> String { serde_json::from_str("\"not_computed\"").expect("schema default") } -fn default_2472() -> Vec> { +fn default_2473() -> Vec> { serde_json::from_str("[]").expect("schema default") } -fn default_2473() -> String { +fn default_2474() -> String { serde_json::from_str("\"candidate\"").expect("schema default") } -fn default_2474() -> std::collections::HashMap { +fn default_2475() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2475() -> String { +fn default_2476() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2476() -> bool { +fn default_2477() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2477() -> Integer { +fn default_2478() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2478() -> std::collections::HashMap { +fn default_2479() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2479() -> bool { +fn default_2480() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2480() -> Vec> { +fn default_2481() -> Vec> { serde_json::from_str("[]").expect("schema default") } -fn default_2481() -> std::collections::HashMap { +fn default_2482() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2482() -> std::collections::HashMap { +fn default_2483() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2483() -> String { +fn default_2484() -> String { serde_json::from_str("\"lower_bound\"").expect("schema default") } -fn default_2484() -> bool { +fn default_2485() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2485() -> Vec { +fn default_2486() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2486() -> Vec> { +fn default_2487() -> Vec> { serde_json::from_str("[]").expect("schema default") } -fn default_2487() -> std::collections::HashMap { +fn default_2488() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2488() -> Vec { +fn default_2489() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2489() -> String { +fn default_2490() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2490() -> bool { +fn default_2491() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2491() -> bool { +fn default_2492() -> bool { serde_json::from_str("true").expect("schema default") } -fn default_2492() -> std::collections::HashMap { +fn default_2493() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2493() -> String { +fn default_2494() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2494() -> bool { +fn default_2495() -> bool { serde_json::from_str("true").expect("schema default") } -fn default_2495() -> std::collections::HashMap { +fn default_2496() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2496() -> std::collections::HashMap { +fn default_2497() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2497() -> Vec> { +fn default_2498() -> Vec> { serde_json::from_str("[]").expect("schema default") } -fn default_2498() -> Vec { +fn default_2499() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2499() -> std::collections::HashMap { +fn default_2500() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2500() -> Vec> { +fn default_2501() -> Vec> { serde_json::from_str("[]").expect("schema default") } -fn default_2501() -> bool { +fn default_2502() -> bool { serde_json::from_str("true").expect("schema default") } -fn default_2502() -> bool { +fn default_2503() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2503() -> Vec { +fn default_2504() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2504() -> std::collections::HashMap { +fn default_2505() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2505() -> String { +fn default_2506() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2506() -> std::collections::HashMap { +fn default_2507() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2507() -> bool { +fn default_2508() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2508() -> bool { +fn default_2509() -> bool { serde_json::from_str("true").expect("schema default") } -fn default_2509() -> String { +fn default_2510() -> String { serde_json::from_str("\"no_signal\"").expect("schema default") } -fn default_2510() -> Vec { +fn default_2511() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2511() -> f64 { +fn default_2512() -> f64 { serde_json::from_str("0.0").expect("schema default") } -fn default_2512() -> Integer { +fn default_2513() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2513() -> String { +fn default_2514() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2514() -> std::collections::HashMap { - serde_json::from_str("{}").expect("schema default") -} fn default_2515() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } @@ -67949,18 +67951,18 @@ fn default_2516() -> std::collections::HashMap { fn default_2517() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2518() -> String { +fn default_2518() -> std::collections::HashMap { + serde_json::from_str("{}").expect("schema default") +} +fn default_2519() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2519() -> std::collections::HashMap { +fn default_2520() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2520() -> bool { +fn default_2521() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2521() -> std::collections::HashMap { - serde_json::from_str("{}").expect("schema default") -} fn default_2522() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } @@ -67970,54 +67972,57 @@ fn default_2523() -> std::collections::HashMap { fn default_2524() -> std::collections::HashMap { serde_json::from_str("{}").expect("schema default") } -fn default_2525() -> String { +fn default_2525() -> std::collections::HashMap { + serde_json::from_str("{}").expect("schema default") +} +fn default_2526() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2526() -> Vec> { +fn default_2527() -> Vec> { serde_json::from_str("[]").expect("schema default") } -fn default_2527() -> Integer { +fn default_2528() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2528() -> String { +fn default_2529() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2529() -> bool { +fn default_2530() -> bool { serde_json::from_str("true").expect("schema default") } -fn default_2530() -> String { +fn default_2531() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2531() -> Vec { +fn default_2532() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2532() -> bool { +fn default_2533() -> bool { serde_json::from_str("false").expect("schema default") } -fn default_2533() -> Vec { +fn default_2534() -> Vec { serde_json::from_str("[]").expect("schema default") } -fn default_2534() -> f64 { +fn default_2535() -> f64 { serde_json::from_str("0.0").expect("schema default") } -fn default_2535() -> String { +fn default_2536() -> String { serde_json::from_str("\"\"").expect("schema default") } -fn default_2536() -> Integer { +fn default_2537() -> Integer { serde_json::from_str("4096").expect("schema default") } -fn default_2537() -> Integer { +fn default_2538() -> Integer { serde_json::from_str("0").expect("schema default") } -fn default_2538() -> Option { +fn default_2539() -> Option { serde_json::from_str("null").expect("schema default") } -fn default_2539() -> f64 { +fn default_2540() -> f64 { serde_json::from_str("0.0").expect("schema default") } -fn default_2540() -> Option { +fn default_2541() -> Option { serde_json::from_str("null").expect("schema default") } -fn default_2541() -> Vec { +fn default_2542() -> Vec { serde_json::from_str("[]").expect("schema default") } diff --git a/sdk/typescript/src/generated/ops.ts b/sdk/typescript/src/generated/ops.ts index 033554a5a3..a618652c26 100644 --- a/sdk/typescript/src/generated/ops.ts +++ b/sdk/typescript/src/generated/ops.ts @@ -8699,6 +8699,7 @@ export interface NamespaceValidateFinding { count: number; samples?: Array>; detail: string; + totals?: Record; } export interface NamespaceValidateOutput { diff --git a/server/code/domain/anchor.py b/server/code/domain/anchor.py index e183637530..3e5e6f52dc 100644 --- a/server/code/domain/anchor.py +++ b/server/code/domain/anchor.py @@ -205,6 +205,85 @@ def mentions(text: str, *, cap: int = 16) -> list[Mention]: return [Mention(name, in_prose) for name, in_prose in list(out.items())[:cap]] +class Span(NamedTuple): + """A name written as code: where it is in the text and how it is spelled, without + the `self.`, `cls.` or `this.` before it (`receiver`, '' when it has none).""" + + start: int + end: int + name: str + receiver: str = "" + + +# what quotes code and names none: a fenced block (an unclosed one runs to the end), a +# URL, a quoted string (an apostrophe inside a word opens none) +_FENCED = re.compile(r"^[ \t]*(```|~~~)[^\n]*\n.*?(?:^[ \t]*\1[^\n]*$|\Z)", re.M | re.S) +_URL = re.compile(r"(? bool: + """What is written from `start` to `end` is a part of something longer: a path, a + flag, a URL fragment, an assignment, a file name.""" + before = text[start - 1] if start else " " + after = text[end] if end < len(text) else " " + return before in _JOINS_BEFORE or after in _JOINS_AFTER or bool(_FILE_SUFFIX.match(text, end)) + + +def code_spans(text: str) -> tuple[list[Span], list[tuple[int, int]]]: + """The names `text` writes as code, in text order, and the spans that quote code + without naming any. A name is a whole backticked identifier (`` `Reader.get` ``, + `` `load_rows()` ``), an `A::b`, or a call written `a.b(` or `f()`; never a word + of the prose, which `mentions` reads and a rewrite may not. Quoted are a fenced + block, a URL, a quoted string and a backticked span that is more than one name. A + name joined to something longer (`--load_rows`, `load_rows.py`, `x=Reader::get`) + is neither.""" + quoted: list[tuple[int, int]] = [] + found: list[Span] = [] + + def blank(m: re.Match[str]) -> str: + quoted.append(m.span()) + return re.sub(r"[^\n]", " ", m[0]) + + def ticked(m: re.Match[str]) -> str: + name = _TICKED_NAME.fullmatch(m[1]) + if name is None: + return blank(m) + if not _joined(m.string, m.start(), m.end()): + found.append(_span(m.start(1) + name.start(1), name[1])) + return " " * len(m[0]) + + masked = _mask_pytest_nodes(text or "") + for rx in (_FENCED, _URL, _QUOTED): + masked = rx.sub(blank, masked) + masked = _TICKED.sub(ticked, masked) + for rx in (_QUALIFIED, _DOTTED_CALL, _EMPTY_CALL): + found.extend( + _span(m.start(), m[0]) for m in rx.finditer(masked) if not _joined(masked, *m.span()) + ) + return sorted(found), sorted(quoted) + + +def _span(start: int, spelled: str) -> Span: + """The span of a name spelled `spelled` at `start`, its receiver apart.""" + name = _RECEIVER.sub("", spelled) + receiver = spelled[: len(spelled) - len(name)] + return Span(start + len(receiver), start + len(spelled), name, receiver) + + +def code_shaped(word: str) -> bool: + """`word` alone is a name `mentions` reads in prose: camelCase, PascalCase or + snake_case.""" + return bool(_CAMEL.fullmatch(word) or _SNAKE.fullmatch(word)) + + def names_symbol(mention: str, qualified_name: str, path: str) -> bool: """`mention` is the qualified name or a `::`- / `.`-separated suffix of it.""" m, q = mention.replace("::", "."), qualified_name.replace("::", ".") diff --git a/server/identity/api/models_namespace_catalog.py b/server/identity/api/models_namespace_catalog.py index 249fc84df5..89a51d48e4 100644 --- a/server/identity/api/models_namespace_catalog.py +++ b/server/identity/api/models_namespace_catalog.py @@ -284,6 +284,9 @@ class _NamespaceValidateFinding(FindingContract): samples: list[dict[str, Any]] = Field(default_factory=list) # One sentence: what the check means and what to do about a hit. detail: str + # `count` by the check's own classes, for a check that names them in its `detail` + # (`code_rename_edits`: `edits`, or the reason no edit is offered); empty otherwise. + totals: dict[str, int] = Field(default_factory=dict) class NamespaceValidateOutput(BaseModel): diff --git a/server/identity/app/namespace_validate.py b/server/identity/app/namespace_validate.py index 3ae5a0883a..bc6f2a3275 100644 --- a/server/identity/app/namespace_validate.py +++ b/server/identity/app/namespace_validate.py @@ -6,7 +6,7 @@ handler is that call: the same class of invariants, scoped to one (org, namespace), returned with samples the caller can act on. -Eighteen checks, each a read over existing tables (the four `code_unlinked_*` share +Nineteen checks, each a read over existing tables (the four `code_unlinked_*` share one). No mutation, no new storage. A check that fails to run is reported in `skipped` and the rest still return — the report closes a task, it must never fail one. Under Postgres the checks start once ClickHouse holds what the namespace committed @@ -33,6 +33,7 @@ import asyncio import functools import logging +from collections import Counter from collections.abc import Awaitable, Callable from typing import Any @@ -401,6 +402,23 @@ "A memory that still holds after its code changed is counted until someone checks it." ), ), + # Its predicate is the planner's (`code_rename.plan`) and the names the link pass + # reads as code (`anchor.code_spans`): a change to either raises this version. + "code_rename_edits": RuleContract( + "usage_heuristic", + 1, + exceptions=( + f"Only the {code_unlinked.SCANNED} memories whose `moved` link was last checked " + "are read (all under `keys` when given), only in repositories the caller may " + "read, and no high-sensitivity memory. A link whose code also changed is " + "`code_links_stale`'s." + ), + uncertainty=( + "An edit is offered on the spelling and the index alone: whether the sentence " + "still holds once the name is swapped is for whoever applies it to read. The " + "words that mark a sentence as being about the name are English." + ), + ), "code_unlinked_no_repository": RuleContract( "usage_heuristic", 1, @@ -482,6 +500,39 @@ async def _code_links_stale(params: dict[str, Any]) -> list[dict[str, Any]]: ] +# Planned by the code links rather than with SQL: the same links, and the index, decide +# which name may be swapped. +_CODE_RENAME_EDITS = ( + "info", + "A memory whose linked code was renamed or moved and followed there: the link is at " + "the new name or path and the memory's text still says the old one. Each sample " + "carries either `edits` (replace `old` with `new` at `start`..`end` of the text) " + "with the `content_sha256` they are of, or the `reason` no edit is offered; `totals` " + "counts the memories by `edits` and by reason. Nothing is written: to apply, read " + "the edited sentence, then memory.update the key with the revised text and " + "`if_match_sha256` set to the sample's `content_sha256`. Only repositories you may " + "read are counted.", +) + + +class _RenameEdits: + """`code_rename_edits`'s rows in the shape the SQL checks give, and their totals by + outcome once they are read.""" + + def __init__(self, params: dict[str, Any]) -> None: + self.params = params + self.totals: dict[str, int] = {} + + async def rows(self) -> list[dict[str, Any]]: + from server.memory.app import code_renames + + params = self.params + found = await code_renames.planned(params["org"], params["ns"], params["keys"] or None) + counts = Counter(str(m.get("reason") or code_renames.OFFERED) for m in found) + self.totals = dict(sorted(counts.items())) + return [{"total": len(found), **m} for m in found[: params["lim"]]] + + # A served memory that names code and holds no link, by cause: a read shows it exactly # as one whose code is current. One read (`code_unlinked.unlinked`) answers the four. _CODE_UNLINKED: dict[str, tuple[str, str]] = { @@ -568,6 +619,7 @@ async def run( severity: str, detail: str, query: Callable[[], Awaitable[list[dict[str, Any]]]], + totals: Callable[[], dict[str, int]] = dict, ) -> None: try: rows = await query() @@ -592,6 +644,7 @@ async def run( samples_complete=total <= len(samples), exceptions=rule.exceptions, uncertainty=rule.uncertainty, + totals=totals(), ) ) @@ -599,6 +652,8 @@ async def run( for name, (severity, detail, sql) in _CHECKS.items(): await run(name, severity, detail, functools.partial(ch.query_all, sql, params=params)) await run("code_links_stale", *_CODE_LINKS_STALE, functools.partial(_code_links_stale, params)) + renames = _RenameEdits(params) + await run("code_rename_edits", *_CODE_RENAME_EDITS, renames.rows, lambda: renames.totals) unlinked = _code_unlinked(params) for name, (cause, detail) in _CODE_UNLINKED.items(): await run(name, "info", detail, functools.partial(unlinked, cause)) diff --git a/server/memory/app/code_link_reads.py b/server/memory/app/code_link_reads.py index 00cc31f83b..f10e7523b5 100644 --- a/server/memory/app/code_link_reads.py +++ b/server/memory/app/code_link_reads.py @@ -80,14 +80,23 @@ async def current_links(org: str, links: list[LinkRow]) -> list[LinkRow]: return [a for h in heads for a in current(org, h, by_mid.get(str(h["mid"]), []))] +# the states of a link whose code is not what its memory was written against +STALE = ("changed", "unresolved", "missing") + + async def stale_links( - org: str, namespace: str, keys: Sequence[str] | None = None, *, limit: int + org: str, + namespace: str, + keys: Sequence[str] | None = None, + *, + limit: int, + states: Sequence[str] = STALE, ) -> list[dict[str, Any]]: - """Up to `limit` of the namespace's changed, unresolved and missing links into - repositories the caller may read, of its served memories (those under `keys` when - given) as they are now, one per memory, newest check first; each with its memory_key, - memory_id, code_namespace, path, qualified_name, state, changed_since, checked_at and - `total`, the number of memories they are of.""" + """Up to `limit` of the namespace's links in `states` (changed, unresolved and + missing unless given) into repositories the caller may read, of its served memories + (those under `keys` when given) as they are now, one per memory, newest check first; + each with its memory_key, memory_id, code_namespace, path, qualified_name, state, + changed_since, checked_at and `total`, the number of memories they are of.""" trunk = code.trunk_namespace(org, namespace) tagged = [] if trunk else _tag_namespaces(org) seen = await readable_namespaces(org, {trunk, *(cns for _, cns in tagged)} - {""}) @@ -96,7 +105,7 @@ async def stale_links( return await store.stale_of_served( org, namespace, - ["changed", "unresolved", "missing"], + list(states), memory_keys=keys, trunk=trunk, tag_namespaces=tagged, diff --git a/server/memory/app/code_renames.py b/server/memory/app/code_renames.py new file mode 100644 index 0000000000..1bda83003d --- /dev/null +++ b/server/memory/app/code_renames.py @@ -0,0 +1,117 @@ +"""The edits that bring a namespace's memories up to renames their links followed, for +namespace.validate. + +A link in state `moved` is at its code, and its memory's text still names the old +definition or path. This reads each such memory, its links and the index at the head, +and plans its edits (`server.memory.domain.code_rename`): the old and new token with +their positions and the hash to apply them against, or the one reason none is offered. +Nothing is written: a principal applies an edit with memory.update and +`if_match_sha256`. +""" + +from __future__ import annotations + +import asyncio +from collections import defaultdict +from collections.abc import Sequence +from typing import Any + +from server.code.app import memory_links as code +from server.code.domain.anchor import Definition, bare_name, mentions +from server.code.domain.declaration import fingerprint_version +from server.memory.app import code_link_pass as link_pass +from server.memory.app import code_link_reads +from server.memory.app.code_unlinked import SCANNED +from server.memory.domain import code_rename +from server.memory.store import code_links as store +from server.memory.store.code_links import LinkRow + +# What `planned` counts a memory under when it offers edits; else under its reason. +OFFERED = "edits" + +# A memory to plan: its head and the links made from it as it is now. +_Linked = tuple[dict[str, Any], list[LinkRow]] +# What the index says of one repository: its definitions under their bare names, and +# the old paths its head no longer has. +_Index = tuple[dict[str, list[Definition]], set[str]] + + +async def planned( + org: str, namespace: str, keys: Sequence[str] | None = None +) -> list[dict[str, Any]]: + """One row per served memory of the namespace (under `keys` when given) that holds + a `moved` link into a repository the caller may read, the newest checked first, of + the `SCANNED` newest: its memory_key and memory_id, and either its `edits` (each a + `start`, `end`, `old` and `new` over the text) with the `content_sha256` they are + of, or the `reason` it gets none (`code_rename.REASONS`). A high-sensitivity memory + is not read: an edit quotes its text.""" + moved = await code_link_reads.stale_links( + org, namespace, keys, limit=SCANNED, states=("moved",) + ) + if not moved: + return [] + ids = [str(a["memory_id"]) for a in moved] + readable = {str(a["code_namespace"]) for a in moved} + heads, rows = await asyncio.gather(store.memory_heads(org, ids), store.for_memories(org, ids)) + by_memory: dict[str, list[LinkRow]] = defaultdict(list) + for a in rows: + if a["code_namespace"] in readable: + by_memory[a["memory_id"]].append(a) + read = {str(h["mid"]): h for h in heads if _quotable(h)} + memories: list[_Linked] = [] + for mid in ids: + links = code_link_reads.current(org, read[mid], by_memory[mid]) if mid in read else [] + if any(a["state"] == "moved" for a in links): + memories.append((read[mid], links)) + # reading names and planning are CPU work: off the loop + wanted = await asyncio.to_thread(_wanted, memories) + index: dict[str, _Index] = {} + for cns, (names, paths) in wanted.items(): + by_name: dict[str, list[Definition]] = defaultdict(list) + for d in await code.candidates(org, cns, names=sorted(names)): + by_name[d.name].append(d) + live = await code.live_paths(org, cns, sorted(paths)) + index[cns] = by_name, {p for p in paths if live.get(p) != p} + return await asyncio.to_thread(_rows, memories, index) + + +def _quotable(head: dict[str, Any]) -> bool: + """A served memory whose text a report may quote.""" + return ( + head["status"] in code_link_reads.SERVED + and head.get("tombstoned_at") is None + and head.get("sensitivity") != "high" + ) + + +def _wanted(memories: Sequence[_Linked]) -> dict[str, tuple[set[str], set[str]]]: + """Code namespace -> what a plan reads of its index: the bare names its memories + mention or are linked to, and the paths their links were written against.""" + out: dict[str, tuple[set[str], set[str]]] = defaultdict(lambda: (set(), set())) + for head, links in memories: + names, paths = out[links[0]["code_namespace"]] + text = link_pass.claim_of(head["value"]) or "" + names.update(bare_name(m.name) for m in mentions(text, cap=len(text))) + for a in links: + was_path, was_name = code_rename.written_as(a) + names.update(bare_name(n) for n in (was_name, a["qualified_name"]) if n) + paths.add(was_path) + return out + + +def _rows(memories: Sequence[_Linked], index: dict[str, _Index]) -> list[dict[str, Any]]: + rules = fingerprint_version() + out: list[dict[str, Any]] = [] + for head, links in memories: + by_name, gone = index[links[0]["code_namespace"]] + plan = code_rename.plan( + link_pass.claim_of(head["value"]), head, links, by_name, gone=gone, rules=rules + ) + row: dict[str, Any] = {"memory_key": str(head["memory_key"]), "memory_id": str(head["mid"])} + if plan.reason: + row["reason"] = plan.reason + else: + row["edits"] = [e._asdict() for e in plan.edits] + row["content_sha256"] = plan.sha256 + out.append(row) + return out diff --git a/server/memory/domain/code_rename.py b/server/memory/domain/code_rename.py new file mode 100644 index 0000000000..a56b8e1354 --- /dev/null +++ b/server/memory/domain/code_rename.py @@ -0,0 +1,412 @@ +"""The edits that bring a memory's text up to a rename its link followed, or why none +is offered. + +A link that followed its definition to another name or file leaves the memory's text +naming the old one. Whether the name can be swapped in the text depends on how it is +spelled and on the sentence around it, not on the link: the same rename is unambiguous +as a full dotted name, ambiguous as a bare word another definition also bears, and +wrong in any spelling when the sentence is about the name, the place or a past state. +`plan` offers an edit only for a name written as code (`anchor.code_spans`) or a whole +path, and withholds the whole memory for the first of `REASONS` that applies. Nothing +here writes: a principal applies the edits with memory.update and `if_match_sha256`. +""" + +from __future__ import annotations + +import re +from collections.abc import Collection, Mapping, Sequence +from dataclasses import dataclass +from typing import Any, NamedTuple + +from server.code.domain.anchor import ( + Definition, + Span, + bare_name, + code_shaped, + code_spans, + local_name, + mentions, + names_symbol, + path_matches, + resolve, +) +from server.code.domain.python_names import import_forms +from server.core.hashing import served_content_sha256 + +# Why a memory gets no edit, in the order `plan` reports them: the first that applies. +REASONS = ( + "not_text", # its value is not one string + "link_not_settled", # a link is pending, changed, lost, or not on its baseline + "incomplete", # the caps cut its links: not all of its code is known + "overloaded", # an old or new name is one of several definitions under its name + "quoted_or_literal", # an old name or path sits in a fenced block, a URL, a quoted + # string or a longer backticked span + "prose_occurrence", # an old name is written as a word of the prose + "old_name_remains", # an old name or path stays where no edit reaches it + "names_several", # one written name is the old name of more than one link + "receiver_form", # `self.name`, and the memory's files do not name its file + "old_name_still_defined", # the name as written names a definition at the head + "new_name_present", # the text already holds the new name or path + "dated_claim", # the memory, or the sentence, is about a point in time + "about_naming", # the sentence is about the name or the place itself + "named_in_key_or_tags", # the memory_key or a tag holds an old name or path + "named_in_files", # `files` names the old path, which memory.update keeps + "would_unlink", # the revised memory would not link to all the code it links to now + "no_code_token", # the text names no old name or path: nothing to edit +) + +# what makes a sentence a statement about a point in time: a commit, a version tag, a +# year, a month, a pull request or issue +_DATED = re.compile( + r"\b(?=[0-9a-f]*\d)(?=[0-9a-f]*[a-f])[0-9a-f]{7,40}\b" + r"|\bv\d+(?:\.\d+)*\b|\b\d+\.\d+\.\d+\b" + r"|\b(?:19|20)\d\d\b" + r"|\b(?:january|february|march|april|june|july|august|september|october|november" + r"|december)\b" + r"|#\d+\b|\b(?:pr|mr|gh)[- ]?\d+\b|\b(?:issue|pull request)s? \d+", + re.IGNORECASE, +) +# what makes a sentence a statement about the name or the place (English only) +_NAMING = re.compile( + r"\b(?:renam\w+|formerly|used to|was called|replaced|moved from|deprecated|legacy" + r"|before|previously|named)\b", + re.IGNORECASE, +) +_SENTENCE_END = re.compile(r"(?<=[.!?])\s+|\n") +_JOIN = re.compile(r"::|\.") +# the ordinal the index gives the second and later definitions of one name in a scope +_ORDINAL = re.compile(r"(?<=[^:.])#\d+(?=$|::|\.)") +# the columns that date a memory: its validity ended, or it is about an event +_DATES = ("valid_to", "invalid_at", "temporal_anchor") + + +class Edit(NamedTuple): + """Replace `text[start:end]`, which reads `old`, with `new`.""" + + start: int + end: int + old: str + new: str + + +@dataclass(frozen=True) +class Plan: + """The edits of one memory's text, all or none, or the reason it gets none.""" + + edits: tuple[Edit, ...] = () + reason: str = "" + # the hash memory.get serves for the text the edits are of: memory.update's + # `if_match_sha256` + sha256: str = "" + + +class _Move(NamedTuple): + """A link that sits elsewhere than its memory's text says: from, to.""" + + was_path: str + was_name: str + path: str + name: str + + +def written_as(link: Mapping[str, Any]) -> tuple[str, str]: + """(path, qualified name) the memory's text was written against: the oldest + identity the link keeps, else its anchor. A definition link that replaced a file + link was never that file: only an identity of the link's own kind counts.""" + of_symbol = bool(link.get("qualified_name")) + former = [f for f in link.get("former") or [] if bool(f["name"]) == of_symbol] + if former: + return str(former[0]["path"]), str(former[0]["name"]) + return str(link.get("anchored_path") or ""), str(link.get("anchored_name") or "") + + +def revised(text: str, edits: Sequence[Edit]) -> str: + """`text` with `edits` applied.""" + out, at = [], 0 + for e in sorted(edits): + out += [text[at : e.start], e.new] + at = e.end + return "".join(out) + text[at:] + + +def plan( + text: str | None, + memory: Mapping[str, Any], + links: Sequence[Mapping[str, Any]], + by_name: Mapping[str, Sequence[Definition]], + *, + gone: Collection[str] = (), + rules: str, +) -> Plan: + """The edits that make `text` (a memory's value; None when it is not a string) name + its code where the code is now, or the reason none is offered. + + `memory` is its head (`files`, `memory_key`, `tags`, the columns that date it) and + `links` the links made from it as it is now. `by_name` holds the index's definitions + at the head under every bare name the text mentions and every new name; `gone` the + old paths the head no longer has; `rules` the fingerprint rules in force. Only a link + in state `moved` on its baseline is revised, and only when every link is settled: + applying an edit makes the link pass link the memory again from its new text.""" + if text is None: + return Plan(reason="not_text") + why: set[str] = set() + if not all(_settled(a, rules) for a in links): + why.add("link_not_settled") + if not all(a["complete"] for a in links): + why.add("incomplete") + files = [str(f) for f in memory.get("files") or []] + spans, quoted = code_spans(text) + edits: dict[tuple[int, int], Edit] = {} + for m in (_move(a) for a in links if a["state"] == "moved"): + if m is None: + continue + alive = m.was_path not in gone + why |= _in_labels(memory, m, alive) + if m.name: + why |= _renamed(text, m, spans, quoted, by_name, files, edits) + if m.was_path != m.path: + why |= _repathed(text, m, quoted, files, alive, edits) + if edits: + why |= _about(text, memory, edits.values()) + why |= _unlinked(revised(text, list(edits.values())), links, by_name, files) + for reason in REASONS: + if reason in why: + return Plan(reason=reason) + if not edits: + return Plan(reason="no_code_token") + return Plan(edits=tuple(sorted(edits.values())), sha256=served_content_sha256(text)) + + +def _settled(link: Mapping[str, Any], rules: str) -> bool: + """The link is at its code, on the text its memory was written against, hashed + under the rules in force.""" + return ( + link["state"] in ("fresh", "moved") + and not link["carried"] + and link["body_hash"] == link["checked_hash"] + and link["fingerprint_version"] == rules + ) + + +def _move(link: Mapping[str, Any]) -> _Move | None: + """Where `link` was written and where it is; None for one back where it was.""" + was, now = written_as(link), (str(link["path"]), str(link["qualified_name"])) + return _Move(*was, *now) if was[0] and was != now else None + + +def _forms(path: str, qualified_name: str) -> tuple[str, ...]: + """The dotted names a text may spell the definition by, the qualified name first.""" + dotted = qualified_name.replace("::", ".") + return tuple(dict.fromkeys((dotted, *import_forms(path, qualified_name.split("::"))))) + + +def _respelled(written: str, m: _Move) -> str: + """`written`, a spelling of the old name, as the same spelling of the new one, joined + as `written` joins it. A name written inside its module (`get`, `Reader.get`) keeps + as many segments. One written with its module names the whole new name inside the + new module, under as many module segments, and under the whole module when it wrote + the whole old one: a full dotted name stays one.""" + dotted = written.replace("::", ".") + old, new = _forms(m.was_path, m.was_name), _forms(m.path, m.name) + at = next((i for i, f in enumerate(old) if f == dotted or f.endswith("." + dotted)), 0) + was_local = local_name(m.was_name, m.was_path).split(".") + local = local_name(m.name, m.path).split(".") + joins = _JOIN.findall(written) + over = len(joins) + 1 - len(was_local) # the module segments it wrote + if over <= 0: + parts = local[-(len(joins) + 1) :] + else: + module = new[min(at, len(new) - 1)].split(".")[: -len(local)] + whole = over >= len(old[at].split(".")) - len(was_local) + parts = (module if whole else module[-over:]) + local + # its own joins, from the right; a longer name repeats its first + joins = joins[:1] * (len(parts) - 1 - len(joins)) + joins + joins = joins[len(joins) - (len(parts) - 1) :] + return parts[0] + "".join(j + p for j, p in zip(joins, parts[1:], strict=True)) + + +def _renamed( + text: str, + m: _Move, + spans: Sequence[Span], + quoted: Sequence[tuple[int, int]], + by_name: Mapping[str, Sequence[Definition]], + files: Sequence[str], + edits: dict[tuple[int, int], Edit], +) -> set[str]: + """Add to `edits` the names in `text` that spell the old definition of `m` and not + the new one, each as the same spelling of the new one; the reasons they withhold.""" + if _plain(m.was_name) != m.was_name or _plain(m.name) != m.name: + return {"overloaded"} + why: set[str] = set() + old, new = bare_name(m.was_name), bare_name(m.name) + mine = [ + s + for s in spans + if names_symbol(s.name, m.was_name, m.was_path) and not names_symbol(s.name, m.name, m.path) + ] + for s in mine: + to = _respelled(s.name, m) + if s.receiver and not any(path_matches(p, f) for f in files for p in (m.was_path, m.path)): + why.add("receiver_form") + if any( + names_symbol(s.name, _plain(d.qualified_name), d.path) + for d in by_name.get(bare_name(s.name), ()) + if (d.path, d.qualified_name) != (m.path, m.name) + ): + why.add("old_name_still_defined") + at = resolve(to, by_name.get(new, ()), files) + if at is None or (at.path, at.qualified_name) != (m.path, m.name): + why.add("would_unlink") + if edits.setdefault((s.start, s.end), Edit(s.start, s.end, s.name, to)).new != to: + why.add("names_several") + # a move keeps the bare name valid: only the spellings it replaces may be left over + olds = [old] if old != new else sorted({s.name for s in mine}) + news = [new] if old != new else sorted({_respelled(s.name, m) for s in mine}) + why |= _left_over(text, olds, mine, spans, quoted) + if mine and any(_word(t).search(text) for t in news): + why.add("new_name_present") + return why + + +def _plain(qualified_name: str) -> str: + """`qualified_name` without the index's ordinals: `Reader#2::get` is a `Reader::get`.""" + return _ORDINAL.sub("", qualified_name) + + +def _word(spelling: str) -> re.Pattern[str]: + return re.compile(rf"(? tuple[int, int] | None: + """The first of `regions` that holds start..end.""" + return next(((a, b) for a, b in regions if a <= start and end <= b), None) + + +def _left_over( + text: str, + olds: Sequence[str], + mine: Sequence[Span], + spans: Sequence[Span], + quoted: Sequence[tuple[int, int]], +) -> set[str]: + """Why an old spelling that no edit of `mine` covers withholds the memory. A name + written as code that ends in it and is not edited names another definition.""" + why: set[str] = set() + for spelling in olds: + for o in _word(spelling).finditer(text): + if any(s.start <= o.start() and o.end() == s.end for s in mine): + continue + theirs = next((s for s in spans if s.start <= o.start() and o.end() <= s.end), None) + if _inside(quoted, *o.span()): + why.add("quoted_or_literal") + elif theirs is None: + why.add("prose_occurrence" if code_shaped(spelling) else "old_name_remains") + elif o.end() != theirs.end: + why.add("old_name_remains") # `Reader.get` still holds the old `Reader` + return why + + +def _repathed( + text: str, + m: _Move, + quoted: Sequence[tuple[int, int]], + files: Sequence[str], + alive: bool, + edits: dict[tuple[int, int], Edit], +) -> set[str]: + """Add to `edits` the whole old path of `m` wherever `text` writes it, when the head + no longer has that file (`alive` False); the reasons its path withholds. A path in + a longer one, before a line number or in a test id, and the old file's bare name, + are left over; so is every one while the old file is still there, where the text + may be about the file.""" + why: set[str] = set() + whole = re.compile(rf"(? set[str]: + """`named_in_key_or_tags` when the memory's key or a tag (stored lowercased) holds + the old bare name of `m`, or its old path once the head no longer has that file + (`alive` False): an edit of the text leaves them.""" + labels = [str(memory.get("memory_key") or ""), *(str(t) for t in memory.get("tags") or [])] + old, new = bare_name(m.was_name), bare_name(m.name) + held = [] + if old and old != new: + held.append(re.compile(rf"(? str: + """The sentence, or line, of `text` that holds position `at`.""" + start = max((b.end() for b in _SENTENCE_END.finditer(text, 0, at)), default=0) + end = _SENTENCE_END.search(text, at) + return text[start : end.start() if end else len(text)] + + +def _about(text: str, memory: Mapping[str, Any], edits: Collection[Edit]) -> set[str]: + """The reasons the sentences `edits` change, or the memory's own dates, withhold + them: a claim about a point in time, or about the name itself, is right as it is.""" + why: set[str] = set() + if any(memory.get(column) for column in _DATES): + why.add("dated_claim") + # without the names themselves: a path under `v2/` dates nothing + rest = revised(text, [e._replace(new=" " * (e.end - e.start)) for e in edits]) + for sentence in {_sentence(rest, e.start) for e in edits}: + if _DATED.search(sentence): + why.add("dated_claim") + if _NAMING.search(sentence): + why.add("about_naming") + return why + + +def _unlinked( + text: str, + links: Sequence[Mapping[str, Any]], + by_name: Mapping[str, Sequence[Definition]], + files: Sequence[str], +) -> set[str]: + """`would_unlink` when `text` (the revised one) would not be linked to every + definition and file `links` are at: each name resolved as the link pass resolves it + (`anchor.resolve`), each file link named by `files`.""" + named = set() + for mention in mentions(text, cap=len(text)): + d = resolve( + mention.name, by_name.get(bare_name(mention.name), ()), files, in_prose=mention.in_prose + ) + if d is not None: + named.add((d.path, d.qualified_name)) + for a in links: + if a["qualified_name"]: + kept = (a["path"], a["qualified_name"]) in named + else: + kept = any(path_matches(a["path"], f) for f in files) + if not kept: + return {"would_unlink"} + return set() diff --git a/server/memory/store/code_links.py b/server/memory/store/code_links.py index fdae938c20..0f38b12fac 100644 --- a/server/memory/store/code_links.py +++ b/server/memory/store/code_links.py @@ -579,7 +579,8 @@ async def code_namespaces( toString(memory_id) AS mid, value, tags, files, toString(content_sha256) AS sha, CAST(status AS String) AS status, tombstoned_at, - pinned, lock_mode, lock_until, verified_by, verified_sha256, sensitivity + pinned, lock_mode, lock_until, verified_by, verified_sha256, sensitivity, + valid_to, invalid_at, temporal_anchor FROM loom.memory FINAL """ diff --git a/tests/analyzer/shapes.txt b/tests/analyzer/shapes.txt index 92faacb59f..60ba8ebfec 100644 --- a/tests/analyzer/shapes.txt +++ b/tests/analyzer/shapes.txt @@ -2,7 +2,6 @@ # \t; sorted. Regenerate with # python -m tests.analyzer.corpus --write # and review the diff: a new line is a new statement shape. -001824490f23 SELECT org, namespace, agent, user_id, session_id, memory_key, actor, toString(memory_id) AS mid, value, tags, files, toString(content_sha256) AS sha, CAST(status AS String) AS status, tombstoned_at, 001eb6c5587e SELECT DISTINCT canonical_text FROM loom.entity_canonical_map FINAL WHERE org = {org:String} AND namespace IN {namespaces:Array(String)} AND mention_text IN {mentions:Array(String)} AND tombstoned_at 0028ff84bbed SELECT agent, user_id, session_id, memory_key FROM loom.memory FINAL WHERE org = {org:String} AND namespace = {ns:String} AND tombstoned_at IS NULL AND has(tags, {tag:String}) ORDER BY updated_at DESC 004f2544bc01 SELECT e.memory_key AS memory_key, e.memory_type AS memory_type, e.content_excerpt AS content_excerpt, e.status AS status, e.version AS version, -- Multi-vector axis: min(value_dist, key_dist). CH?t g @@ -2244,6 +2243,7 @@ f7c04f2fe996 SELECT count() AS n FROM loom.document_blobs WHERE org = {org:Strin f8081de4841b 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 f833c025305d SELECT e.memory_key AS memory_key, e.memory_type AS memory_type, e.content_excerpt AS content_excerpt, e.status AS status, e.version AS version, -- Multi-vector axis: min(value_dist, key_dist). CH?t g f83401bb2bae SELECT * FROM loom.service_accounts FINAL WHERE org = {org:String} AND name = {name:String} AND (created_by IN {subs:Array(String)} OR hasAny(lineage, {subs:Array(String)})) AND revoked_at IS NULL AND +f83f4bc3fef2 SELECT org, namespace, agent, user_id, session_id, memory_key, actor, toString(memory_id) AS mid, value, tags, files, toString(content_sha256) AS sha, CAST(status AS String) AS status, tombstoned_at, f8544e732b91 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 f86ba4e3e00f SELECT conflict_threshold, duplicate_threshold, default_conflict_policy FROM loom.namespaces FINAL WHERE org = {org:String} AND namespace = {ns:String} LIMIT ? f86df7b89de1 SELECT chunk_id, path, cosineDistance(embedding, {q:Array(Float32)}) AS distance FROM loom.code_chunks FINAL WHERE org = {org:String} AND namespace = {ns:String} AND embedding_model = {model:String} A diff --git a/tests/integration/test_memory_code_links.py b/tests/integration/test_memory_code_links.py index 5ccdf87156..b078c0f2a8 100644 --- a/tests/integration/test_memory_code_links.py +++ b/tests/integration/test_memory_code_links.py @@ -1461,6 +1461,101 @@ async def stale_for(namespaces: tuple[str, ...]) -> Any: assert (memory_only.count, memory_only.samples) == (0, []) +async def test_validate_lists_the_edit_a_followed_rename_allows_and_an_update_applies_it( + env, +) -> None: + """After a rename the link follows, the memory's text still says the old name. The + report lists the edit its spelling allows, or why none is offered, and writes + nothing; memory.update with the listed hash applies it, the link pass links the + revised memory where the code is, and a caller who may not read the repository is + told nothing.""" + from fastapi import HTTPException + + from server.auth.context import set_current_auth + from server.auth.jwt import AuthInfo + from server.identity.api.models_namespace_catalog import NamespaceValidateInput + from server.identity.app.namespace_validate import handle_namespace_validate + from server.memory.api.models_crud import MemoryUpdateInput + from server.memory.app.update import handle_memory_update + from server.operations.base import Role + + repo = env + path = "src/widgets/io.py" + src = "def fetch_rows(conn, n):\n rows = conn.read(n)\n return [r for r in rows if r]\n" + c1 = repo.commit({path: src}) + await _index(TRUNK, repo, c1, [path]) + text = "`fetch_rows` drops empty rows" + mid = await _remember(MEM, "fetch-rows", text) + # a word of the prose links inside the memory's files, and is never edited + await _remember(MEM, "fetch-rows-prose", "fetch_rows drops empty rows", files=[path]) + await _pass() + c2 = repo.commit({path: src.replace("fetch_rows", "load_rows")}) + await _index(TRUNK, repo, c2, [path]) + await _pass() + + async def renames_for(namespaces: tuple[str, ...]) -> Any: + set_current_auth( + AuthInfo( + subject="it@example.com", + org=ORG, + namespaces=namespaces, + roles=(Role.VIEWER,), + is_service_account=False, + ) + ) + try: + report = await handle_namespace_validate(NamespaceValidateInput(org=ORG, namespace=MEM)) + finally: + set_current_auth(None) + return next(f for f in report.findings if f.check == "code_rename_edits") + + listed = await renames_for((MEM, TRUNK)) + assert listed.count == 2 and listed.totals == {"edits": 1, "prose_occurrence": 1} + by_key = {s["memory_key"]: s for s in listed.samples} + assert by_key["fetch-rows-prose"]["reason"] == "prose_occurrence" + offered = by_key["fetch-rows"] + assert offered["memory_id"] == mid + assert offered["edits"] == [{"start": 1, "end": 11, "old": "fetch_rows", "new": "load_rows"}] + # the listed hash is the one memory.get serves: the report cites the same revision + cited = {e.memory_key: e.content_sha256 for e in listed.evidence} + assert offered["content_sha256"] == cited["fetch-rows"] + # nothing was written + assert (await _row(mid)).value == text + hidden = await renames_for((MEM,)) + assert (hidden.count, hidden.samples, hidden.totals) == (0, [], {}) + + (edit,) = offered["edits"] + revised = text[: edit["start"]] + edit["new"] + text[edit["end"] :] + applied = await handle_memory_update( + MemoryUpdateInput( + org=ORG, + namespace=MEM, + memory_key="fetch-rows", + value=revised, + if_match_sha256=offered["content_sha256"], + ) + ) + assert applied.updated and (await _row(mid)).value == "`load_rows` drops empty rows" + # the same edit against the value it was planned from is refused once that is gone + with pytest.raises(HTTPException) as refused: + await handle_memory_update( + MemoryUpdateInput( + org=ORG, + namespace=MEM, + memory_key="fetch-rows", + value=revised, + if_match_sha256=offered["content_sha256"], + ) + ) + assert refused.value.status_code == 409 + await _pass() + (link,) = await _links(mid) + assert (link["symbol"].rsplit("::", 1)[-1], link["state"]) == ("load_rows", "fresh") + after = await renames_for((MEM, TRUNK)) + assert after.totals == {"prose_occurrence": 1} + assert [s["memory_key"] for s in after.samples] == ["fetch-rows-prose"] + + async def test_validate_counts_unlinked_code_memories_by_cause(env) -> None: """A memory that names code and holds no link reads as one whose code is current; the report counts each under why it has none, from the rows the pass stored and the diff --git a/tests/unit/test_code_anchor.py b/tests/unit/test_code_anchor.py index e973c50b19..228f610443 100644 --- a/tests/unit/test_code_anchor.py +++ b/tests/unit/test_code_anchor.py @@ -11,6 +11,7 @@ cited_fingerprint, cited_lines, cited_names, + code_spans, local_name, mentions, recheck, @@ -499,3 +500,83 @@ def test_a_go_package_renamed_in_place_keeps_the_link() -> None: here = [_d("pkg/x.go", "pkg.rows::B::Read", "h2")] after = recheck(link, path_now="pkg/x.go", here=here, head="c2") assert (after.state, after.qualified_name) == ("changed", "pkg.rows::B::Read") + + +def _spans(text: str) -> list[str]: + """Each name `text` writes as code, as the text spells it there.""" + return [text[s.start - len(s.receiver) : s.end] for s in code_spans(text)[0]] + + +def test_code_spans_are_the_names_written_as_code_where_they_are() -> None: + text = "`Reader.get` calls ns::load_rows, then cfg.read_rows() and flush_all(); `load()` too" + spans, quoted = code_spans(text) + assert [(s.name, text[s.start : s.end]) for s in spans] == [ + ("Reader.get", "Reader.get"), + ("ns::load_rows", "ns::load_rows"), + ("cfg.read_rows", "cfg.read_rows"), + ("flush_all", "flush_all"), + ("load", "load"), + ] + assert quoted == [] + + +def test_a_word_of_the_prose_is_no_code_span() -> None: + # `mentions` reads these inside a memory's files; a rewrite may not + assert _spans("read_rows retries and fetchRows does not; Reader.get is hot") == [] + + +def test_a_receiver_is_kept_apart_from_the_name_it_precedes() -> None: + text = "`self.read_rows` and this.fetchRows() leak" + spans, _ = code_spans(text) + assert [(s.receiver, s.name) for s in spans] == [("self.", "read_rows"), ("this.", "fetchRows")] + assert [text[s.start : s.end] for s in spans] == ["read_rows", "fetchRows"] + + +def test_quoted_code_names_nothing() -> None: + fenced = "run:\n```python\nload_rows()\n```\nthen `load_rows`" + spans, quoted = code_spans(fenced) + assert [s.name for s in spans] == ["load_rows"] and fenced[spans[0].start :].startswith("load") + assert [fenced[a:b] for a, b in quoted] == ["```python\nload_rows()\n```"] + for text, held in ( + ("see https://example.org/api/load_rows() for it", "https://example.org/api/load_rows()"), + ('the "ns::load_rows" key', '"ns::load_rows"'), + ("the 'load_rows()' key", "'load_rows()'"), + ("`rows = load_rows(conn)`", "`rows = load_rows(conn)`"), + ("`python tools/load_rows.py`", "`python tools/load_rows.py`"), + ): + spans, quoted = code_spans(text) + assert spans == [] and [text[a:b] for a, b in quoted] == [held], text + # an unclosed fence quotes the rest; an apostrophe inside a word opens no quote + assert code_spans("```\nload_rows()")[0] == [] + assert _spans("it doesn't call `load_rows` when the reader isn't ready") == ["load_rows"] + + +def test_a_name_joined_to_something_longer_is_no_code_span() -> None: + for text in ( + "pass --load_rows() to enable", + "pass --mode=`fast_path`", + "in tools/load_rows() and tools/`load_rows`", + "ping @`load_rows` or #load_rows()", + "the file `load_rows`.py and ns::load_rows.py", + "x.ns::load_rows and ns::load_rows.attr()", + "`load_rows`'s rows", + ): + assert _spans(text) == [], text + # the end of a sentence joins nothing + assert _spans("It calls `load_rows`. Then ns::load_rows.") == ["load_rows", "ns::load_rows"] + + +def test_a_pytest_node_id_holds_no_code_span() -> None: + assert _spans("tests/test_io.py::TestReader::test_read fails; `TestReader` is slow") == [ + "TestReader" + ] + + +def test_reading_code_spans_is_linear_in_the_text() -> None: + from tests.unit.step_count import steps + + def work(n: int) -> int: + text = " ".join(f'`read_rows_{i}` a.b.c{i}-d "q{i}" A::b{i} http://x/{i}' for i in range(n)) + return steps(lambda: code_spans(text)) + + assert work(1600) / work(200) < 12 diff --git a/tests/unit/test_memory_code_links.py b/tests/unit/test_memory_code_links.py index c04c7e9520..8a6c895dac 100644 --- a/tests/unit/test_memory_code_links.py +++ b/tests/unit/test_memory_code_links.py @@ -1751,6 +1751,9 @@ async def readable(org, nss): assert asked["states"] == ["changed", "unresolved", "missing"] and asked["keys"] == ["k"] assert asked["trunk"] == "" and asked["readable"] == ["code-a"] and asked["limit"] == 3 assert asked["tag_namespaces"] == [("repo:acme/a", "code-a"), ("repo:acme/s", "code-secret")] + # the states asked for, under the same scope + await code_link_reads.stale_links("o", "ns", limit=3, states=("moved",)) + assert asked["states"] == ["moved"] and asked["readable"] == ["code-a"] monkeypatch.setattr(code_link_reads, "readable_namespaces", lambda org, nss: _async(set())) assert await code_link_reads.stale_links("o", "ns", limit=3) == [] # nothing readable diff --git a/tests/unit/test_memory_code_rename_plan.py b/tests/unit/test_memory_code_rename_plan.py new file mode 100644 index 0000000000..0a830702b7 --- /dev/null +++ b/tests/unit/test_memory_code_rename_plan.py @@ -0,0 +1,517 @@ +"""The edits that bring a memory's text up to a rename its link followed: which +spellings are edited, which withhold the whole memory and why, and what the listing +namespace.validate reads returns.""" + +from __future__ import annotations + +import json +from collections import defaultdict +from typing import Any + +import pytest + +from server.code.domain.anchor import Definition +from server.core.hashing import served_content_sha256 +from server.memory.app import code_link_reads, code_renames +from server.memory.domain.code_rename import REASONS, Plan, plan, revised, written_as + +RULES = "rules-1" +PATH = "src/io/reader.py" +OLD = "src.io.reader::Reader::read_rows" +NEW = "src.io.reader::Reader::fetch_rows" + + +def _d(path: str, qn: str) -> Definition: + return Definition(path=path, qualified_name=qn, name=qn.replace("::", ".").split(".")[-1]) + + +def _link(path: str, qn: str, *, was: tuple[str, str] | None = None, **fields: Any) -> dict: + """A link at (path, qn), written against `was`: `moved` when that is elsewhere.""" + was_path, was_name = was or (path, qn) + row = { + "path": path, + "qualified_name": qn, + "state": "moved" if (was_path, was_name) != (path, qn) else "fresh", + "complete": 1, + "carried": 0, + "body_hash": "h1", + "checked_hash": "h1", + "fingerprint_version": RULES, + "anchored_path": was_path, + "anchored_name": was_name, + "former": [], + "code_namespace": "code", + "suggestion": "", + } + return row | fields + + +RENAMED = _link(PATH, NEW, was=(PATH, OLD)) + + +def _plan( + text: Any, + *, + links: list[dict] | None = None, + defs: list[Definition] | None = None, + gone: tuple[str, ...] = (), + **memory: Any, +) -> Plan: + by_name: dict[str, list[Definition]] = defaultdict(list) + for d in [_d(PATH, NEW)] if defs is None else defs: + by_name[d.name].append(d) + return plan( + text, memory, [RENAMED] if links is None else links, by_name, gone=gone, rules=RULES + ) + + +def _revised(text: str, **kw: Any) -> str: + """`text` with its planned edits applied; the plan offers some.""" + planned = _plan(text, **kw) + assert planned.reason == "" and planned.edits, planned + return revised(text, planned.edits) + + +@pytest.mark.parametrize( + ("text", "want"), + [ + ("`read_rows` retries twice.", "`fetch_rows` retries twice."), + ("`read_rows()` retries twice.", "`fetch_rows()` retries twice."), + ("`Reader.read_rows` retries.", "`Reader.fetch_rows` retries."), + ("`Reader::read_rows` retries.", "`Reader::fetch_rows` retries."), + ("Reader::read_rows retries.", "Reader::fetch_rows retries."), + ("Reader.read_rows() retries.", "Reader.fetch_rows() retries."), + ("Call read_rows() once.", "Call fetch_rows() once."), + ( + "`src.io.reader.Reader.read_rows` retries.", + "`src.io.reader.Reader.fetch_rows` retries.", + ), + ( + "`read_rows` retries; so does Reader.read_rows().", + "`fetch_rows` retries; so does Reader.fetch_rows().", + ), + ], +) +def test_every_explicit_spelling_is_edited_at_its_own_depth_and_separator( + text: str, want: str +) -> None: + planned = _plan(text) + assert revised(text, planned.edits) == want + assert planned.sha256 == served_content_sha256(text) + for e in planned.edits: + assert text[e.start : e.end] == e.old + + +def test_text_outside_the_edits_is_byte_identical() -> None: + text = "Ünïcode — get_read_rows_fast and read_rowsx stay;\n\t`read_rows` goes.\r\n" + planned = _plan(text) + (edit,) = planned.edits + assert (edit.old, edit.new) == ("read_rows", "fetch_rows") + assert text[: edit.start] + edit.new + text[edit.end :] == revised(text, planned.edits) + assert revised(text, planned.edits) == text.replace("`read_rows`", "`fetch_rows`") + + +def test_planning_the_revised_text_again_offers_no_edit() -> None: + text = "`Reader.read_rows` retries; `read_rows` backs off." + after = _revised(text) + # with the links not yet made again, and once the link pass has made them from it + assert _plan(after).edits == () + assert _plan(after, links=[_link(PATH, NEW)]) == Plan(reason="no_code_token") + + +@pytest.mark.parametrize( + ("text", "reason"), + [ + # a word of the prose, which the link pass reads inside the memory's files + ("read_rows retries twice.", "prose_occurrence"), + ("`read_rows` retries; read_rows backs off.", "prose_occurrence"), + ("pass --read_rows to `read_rows`", "prose_occurrence"), + ("read_rows.py holds `read_rows`", "prose_occurrence"), + # quoted code + ("see https://example.org/api/read_rows for `read_rows`", "quoted_or_literal"), + ('the "read_rows" key feeds `read_rows`', "quoted_or_literal"), + ("```\nread_rows(conn)\n```\n`read_rows` is hot", "quoted_or_literal"), + ("`rows = read_rows(conn)` then `read_rows`", "quoted_or_literal"), + # the sentence is about the name, or about a point in time + ("We should rename `read_rows` to something shorter.", "about_naming"), + ("`read_rows`, formerly the slow path, retries.", "about_naming"), + ("`read_rows` was called from the loader before the split.", "about_naming"), + ("`read_rows` regressed in a1b2c3d4e5.", "dated_claim"), + ("`read_rows` retries since v2.3.", "dated_claim"), + ("`read_rows` retries, see #1234.", "dated_claim"), + ("In March `read_rows` retried twice.", "dated_claim"), + # the new name is there already + ("`read_rows` calls `fetch_rows`.", "new_name_present"), + ("`read_rows` and the fetch_rows helper.", "new_name_present"), + # written through its receiver, with no file that says whose + ("`self.read_rows()` leaks.", "receiver_form"), + ], +) +def test_a_spelling_or_sentence_that_cannot_be_swapped_withholds_the_memory( + text: str, reason: str +) -> None: + assert _plan(text) == Plan(reason=reason) + + +def test_a_cue_in_another_sentence_does_not_withhold() -> None: + text = "The loader was renamed in 2019. `read_rows` retries twice.\nSee #12 for the loader." + assert _revised(text) == text.replace("read_rows", "fetch_rows") + + +def test_a_cue_inside_the_edited_name_itself_does_not_withhold() -> None: + was, now = "src/v2/reader2019.py", "src/v2/read2019.py" + link = _link(now, "", was=(was, "")) + text = "`src/v2/reader2019.py` holds the retry loop." + planned = _plan(text, links=[link], defs=[], gone=(was,), files=["read2019.py"]) + assert revised(text, planned.edits) == "`src/v2/read2019.py` holds the retry loop." + + +def test_a_plain_word_or_a_part_of_a_longer_name_is_not_an_occurrence() -> None: + # `close` renamed: the prose word stays and withholds; a longer name is another name + link = _link(PATH, "src.io.reader::Reader::shut", was=(PATH, "src.io.reader::Reader::close")) + defs = [_d(PATH, "src.io.reader::Reader::shut")] + assert _plan("`close` runs when files close.", links=[link], defs=defs).reason == ( + "old_name_remains" + ) + text = "`close` runs; close_all and unclose do not." + assert _revised(text, links=[link], defs=defs) == "`shut` runs; close_all and unclose do not." + + +def test_a_receiver_form_is_edited_when_the_files_name_its_file() -> None: + assert _revised("`self.read_rows()` leaks.", files=[PATH]) == "`self.fetch_rows()` leaks." + assert _revised("cls.read_rows() leaks.", files=["reader.py"]) == "cls.fetch_rows() leaks." + + +def test_an_old_name_another_definition_still_bears_withholds() -> None: + homonym = _d("src/io/writer.py", "src.io.writer::Writer::read_rows") + defs = [_d(PATH, NEW), homonym] + assert _plan("`read_rows` retries.", defs=defs).reason == "old_name_still_defined" + # the spelling decides: `Reader.read_rows` names no other definition + assert _revised("`Reader.read_rows` retries.", defs=defs) == "`Reader.fetch_rows` retries." + # a definition in a scope the index numbers (a second `impl`) is still that name + numbered = [_d(PATH, NEW), _d(PATH, "src.io.reader::Reader#2::read_rows")] + assert _plan("`Reader.read_rows` retries.", defs=numbered).reason == "old_name_still_defined" + + +def test_a_name_another_definition_is_written_by_is_left_alone() -> None: + other = _d("src/io/writer.py", "src.io.writer::Writer::read_rows") + text = "`Writer.read_rows` buffers; `Reader.read_rows` retries." + links = [RENAMED, _link("src/io/writer.py", other.qualified_name)] + assert _revised(text, links=links, defs=[_d(PATH, NEW), other]) == ( + "`Writer.read_rows` buffers; `Reader.fetch_rows` retries." + ) + + +def test_a_new_name_that_does_not_resolve_to_the_link_withholds() -> None: + homonym = _d("src/io/writer.py", "src.io.writer::Writer::fetch_rows") + assert _plan("`read_rows` retries.", defs=[_d(PATH, NEW), homonym]).reason == "would_unlink" + # inside the memory's files it is one definition + assert _plan("`read_rows` retries.", defs=[_d(PATH, NEW), homonym], files=[PATH]).edits + # the index does not have the new definition yet + assert _plan("`read_rows` retries.", defs=[]).reason == "would_unlink" + + +def test_an_edit_that_would_drop_another_link_withholds() -> None: + # the update relinks the memory from its text: a link no name of it resolves to goes + other = _link("src/io/writer.py", "src.io.writer::Writer::flush") + assert _plan("`read_rows` retries.", links=[RENAMED, other]).reason == "would_unlink" + defs = [_d(PATH, NEW), _d("src/io/writer.py", "src.io.writer::Writer::flush")] + text = "`read_rows` retries before `Writer.flush`." + assert _plan(text, links=[RENAMED, other], defs=defs).reason == "about_naming" # "before" + text = "`read_rows` retries and `Writer.flush` runs." + assert _revised(text, links=[RENAMED, other], defs=defs).startswith("`fetch_rows`") + + +@pytest.mark.parametrize( + ("fields", "reason"), + [ + ({"state": "pending", "path": "", "qualified_name": "pkg.later"}, "link_not_settled"), + ({"state": "changed"}, "link_not_settled"), + ({"state": "unresolved"}, "link_not_settled"), + ({"state": "missing"}, "link_not_settled"), + ({"carried": 1}, "link_not_settled"), + ({"checked_hash": "h2"}, "link_not_settled"), + ({"fingerprint_version": "rules-0"}, "link_not_settled"), + ({"complete": 0}, "incomplete"), + ], +) +def test_a_link_that_is_not_settled_or_was_cut_withholds(fields: dict, reason: str) -> None: + other = _link("src/io/writer.py", "src.io.writer::Writer::flush") | fields + assert _plan("`read_rows` retries.", links=[RENAMED, other]).reason == reason + + +def test_an_ordinal_name_withholds() -> None: + numbered = "src.io.reader::Reader#2::fetch_rows" + for was, now in ((OLD + "#2", NEW), (OLD, NEW + "#2"), (OLD, numbered)): + link = _link(PATH, now, was=(PATH, was)) + assert _plan("`Reader.read_rows` retries.", links=[link]).reason == "overloaded" + + +def test_a_value_that_is_not_one_string_is_not_text() -> None: + assert _plan(None) == Plan(reason="not_text") + # what the listing passes for a stored object, list or number + for value in ({"claim": "`read_rows` retries."}, ["`read_rows`"], 7): + assert code_renames.link_pass.claim_of(json.dumps(value)) is None + + +def test_the_old_name_in_the_key_or_a_tag_withholds() -> None: + text = "`read_rows` retries." + assert _plan(text, memory_key="repo/lesson/read_rows-retry").reason == "named_in_key_or_tags" + assert _plan(text, tags=["repo:x", "Read_Rows"]).reason == "named_in_key_or_tags" + assert _plan(text, memory_key="repo/lesson/read_rows_twice", tags=["thread_rows"]).edits + + +def test_a_dated_memory_withholds() -> None: + for column in ("valid_to", "invalid_at", "temporal_anchor"): + assert _plan("`read_rows` retries.", **{column: "2031-01-01 00:00:00"}).reason == ( + "dated_claim" + ) + + +def test_one_name_two_links_wrote_withholds() -> None: + # two definitions moved apart under one written name + a = _link("src/a.py", "src.a::load_all", was=("src/a.py", "src.a::load")) + b = _link("src/b.py", "src.b::load_some", was=("src/b.py", "src.b::load")) + defs = [_d("src/a.py", "src.a::load_all"), _d("src/b.py", "src.b::load_some")] + assert _plan("`load` is slow.", links=[a, b], defs=defs).reason == "names_several" + + +def test_a_scope_change_edits_only_the_spellings_that_name_the_old_scope() -> None: + # the class was renamed and its own link followed it: the bare name still holds + link = _link(PATH, "src.io.reader::Loader", was=(PATH, "src.io.reader::Reader")) + defs = [_d(PATH, "src.io.reader::Loader")] + assert _revised("`Reader` wraps the socket.", links=[link], defs=defs) == ( + "`Loader` wraps the socket." + ) + # a member written through the old class is not this link's to rename + assert _plan("`Reader` wraps; `Reader.get` reads.", links=[link], defs=defs).reason == ( + "old_name_remains" + ) + # moved to another module under its own name: only a qualified spelling changes + moved = _link( + "src/net/util.py", "src.net.util::backoff", was=("src/io/util.py", "src.io.util::backoff") + ) + defs = [_d("src/net/util.py", "src.net.util::backoff")] + assert _plan("`backoff` doubles.", links=[moved], defs=defs) == Plan(reason="no_code_token") + assert _revised("`io.util.backoff` doubles.", links=[moved], defs=defs) == ( + "`net.util.backoff` doubles." + ) + text = "`io.util.backoff` doubles; io.util.backoff is shared." + assert _plan(text, links=[moved], defs=defs).reason == "old_name_remains" + + +def test_a_renamed_file_edits_its_whole_path_once_the_old_one_is_gone() -> None: + was, now = "src/io/reader.py", "src/io/read.py" + link = _link(now, "src.io.read::Reader::get", was=(was, "src.io.reader::Reader::get")) + defs = [_d(now, "src.io.read::Reader::get")] + kw: dict[str, Any] = {"links": [link], "defs": defs, "gone": (was,)} + text = "`Reader.get` in `src/io/reader.py` retries (see src/io/reader.py)." + assert _revised(text, **kw) == "`Reader.get` in `src/io/read.py` retries (see src/io/read.py)." + assert _revised("`reader.Reader.get` retries.", **kw) == "`read.Reader.get` retries." + for text, reason in ( + # the old file is still there: the text may be about the file + ("`Reader.get` in `src/io/reader.py` retries.", "old_name_remains"), + ): + assert _plan(text, links=[link], defs=defs).reason == reason + for text, reason in ( + ("`Reader.get` at src/io/reader.py:120 retries.", "old_name_remains"), + ("`Reader.get` in reader.py retries.", "old_name_remains"), + ("`Reader.get` in lib/src/io/reader.py retries.", "old_name_remains"), + ("`python src/io/reader.py` runs `Reader.get`.", "quoted_or_literal"), + ("see https://example.org/src/io/reader.py for `Reader.get`", "quoted_or_literal"), + ("`src/io/reader.py` became `src/io/read.py`.", "new_name_present"), + ): + assert _plan(text, **kw).reason == reason, text + + +def test_files_and_labels_that_name_the_old_path_withhold() -> None: + was, now = "src/io/reader.py", "src/io/read.py" + link = _link(now, "", was=(was, "")) + text = "`src/io/reader.py` holds the retry loop." + kw: dict[str, Any] = {"links": [link], "defs": [], "gone": (was,)} + # memory.update keeps `files`: the old entry would stay, and the file link with it + assert _plan(text, files=[was], **kw).reason == "named_in_files" + assert _plan(text, files=[now], memory_key="repo/file/src/io/reader.py", **kw).reason == ( + "named_in_key_or_tags" + ) + # a file moved under its own bare name is still what `files` names + moved = _link("lib/reader.py", "", was=("src/reader.py", "")) + kw = {"links": [moved], "defs": [], "gone": ("src/reader.py",)} + assert _revised("`src/reader.py` holds it.", files=["reader.py"], **kw) == ( + "`lib/reader.py` holds it." + ) + # no file of the memory names the file link's path any more + assert _plan("`src/reader.py` holds it.", files=[], **kw).reason == "would_unlink" + + +def test_a_link_back_where_it_was_written_or_reanchored_gets_no_edit() -> None: + # renamed and renamed back: the text names it + back = _link(PATH, OLD, state="moved", anchored_name=NEW, former=[_former(PATH, OLD)]) + assert _plan("`read_rows` retries.", links=[back], defs=[_d(PATH, OLD)]) == ( + Plan(reason="no_code_token") + ) + # re-anchored where the code is by a `holds` verdict: no move is planned from it + held = _link(PATH, NEW, former=[_former(PATH, OLD)]) + assert held["state"] == "fresh" + assert _plan("`read_rows` retries.", links=[held]) == Plan(reason="no_code_token") + # beside a renamed link, the update would drop it: its old name resolves nowhere + other = _link("src/a.py", "src.a::load_all", was=("src/a.py", "src.a::load")) + defs = [_d(PATH, NEW), _d("src/a.py", "src.a::load_all")] + text = "`read_rows` retries and `load` is slow." + assert _plan(text, links=[held, other], defs=defs).reason == "would_unlink" + + +def _former(path: str, name: str) -> dict[str, str]: + return {"path": path, "name": name, "hash": "h1"} + + +def test_written_as_is_the_oldest_identity_of_the_links_own_kind() -> None: + link = _link(PATH, NEW, was=(PATH, "src.io.reader::Reader::load")) + assert written_as(link) == (PATH, "src.io.reader::Reader::load") + link["former"] = [_former(PATH, OLD), _former(PATH, "src.io.reader::Reader::load")] + assert written_as(link) == (PATH, OLD) + # a definition link that replaced a file link was never that file + link["former"] = [_former(PATH, "")] + assert written_as(link) == (PATH, "src.io.reader::Reader::load") + + +def test_every_reason_is_one_the_plan_can_give() -> None: + assert len(set(REASONS)) == len(REASONS) + assert REASONS[0] == "not_text" and REASONS[-1] == "no_code_token" + + +# ---- the listing namespace.validate reads ---------------------------------------------- + + +def _head(mid: str, text: Any, **fields: Any) -> dict[str, Any]: + head = { + "mid": mid, + "namespace": "ns", + "memory_key": f"k/{mid}", + "user_id": "-", + "value": json.dumps(text), + "tags": ["repo:x"], + "files": [], + "sha": "s", + "status": "active", + "tombstoned_at": None, + "sensitivity": "normal", + } + return head | fields + + +@pytest.fixture +def listing(monkeypatch: pytest.MonkeyPatch) -> dict[str, Any]: + """A store of heads and links, an index and one readable repository.""" + world: dict[str, Any] = {"heads": [], "links": [], "defs": [_d(PATH, NEW)], "live": {}} + monkeypatch.setattr(code_renames, "fingerprint_version", lambda: RULES) + monkeypatch.setattr(code_link_reads, "inputs_now", lambda org, memory: "inputs") + + async def stale_links(org: str, ns: str, keys: Any = None, *, limit: int, states: Any) -> Any: + world["asked"] = (keys, limit, tuple(states)) + moved = [ + a for a in world["links"] if a["state"] == "moved" and a["code_namespace"] == "code" + ] + return [{"memory_id": a["memory_id"], "code_namespace": "code"} for a in moved] + + async def memory_heads(org: str, ids: list[str]) -> list[dict[str, Any]]: + return [h for h in world["heads"] if h["mid"] in ids] + + async def for_memories(org: str, ids: list[str]) -> list[dict[str, Any]]: + return [a for a in world["links"] if a["memory_id"] in ids] + + async def candidates(org: str, cns: str, *, names: list[str]) -> list[Definition]: + world["names"] = names + return [d for d in world["defs"] if d.name in names] + + async def live_paths(org: str, cns: str, refs: list[str]) -> dict[str, str]: + return {r: world["live"].get(r, r) for r in refs if r not in world.get("gone", ())} + + monkeypatch.setattr(code_link_reads, "stale_links", stale_links) + monkeypatch.setattr(code_renames.store, "memory_heads", memory_heads) + monkeypatch.setattr(code_renames.store, "for_memories", for_memories) + monkeypatch.setattr(code_renames.code, "candidates", candidates) + monkeypatch.setattr(code_renames.code, "live_paths", live_paths) + return world + + +def _stored( + world: dict[str, Any], mid: str, text: Any, link: dict | None = None, **head: Any +) -> None: + world["heads"].append(_head(mid, text, **head)) + world["links"].append((link or RENAMED) | {"memory_id": mid, "inputs_hash": "inputs"}) + + +@pytest.mark.asyncio +async def test_the_listing_gives_each_memory_its_edits_or_its_reason(listing: dict) -> None: + _stored(listing, "m1", "`read_rows` retries twice.") + _stored(listing, "m2", "read_rows retries twice.") + _stored(listing, "m3", {"claim": "`read_rows` retries twice."}) + rows = await code_renames.planned("o", "ns", ["k"]) + assert rows == [ + { + "memory_key": "k/m1", + "memory_id": "m1", + "edits": [{"start": 1, "end": 10, "old": "read_rows", "new": "fetch_rows"}], + "content_sha256": served_content_sha256("`read_rows` retries twice."), + }, + {"memory_key": "k/m2", "memory_id": "m2", "reason": "prose_occurrence"}, + {"memory_key": "k/m3", "memory_id": "m3", "reason": "not_text"}, + ] + assert listing["asked"] == (["k"], code_renames.SCANNED, ("moved",)) + # the index is asked for the old and new bare names and what the text mentions + assert {"read_rows", "fetch_rows"} <= set(listing["names"]) + + +@pytest.mark.asyncio +async def test_the_listing_reads_no_memory_it_may_not_quote_or_serve(listing: dict) -> None: + _stored(listing, "m1", "`read_rows` retries.", sensitivity="high") + _stored(listing, "m2", "`read_rows` retries.", status="superseded") + _stored(listing, "m3", "`read_rows` retries.", tombstoned_at="2031-01-01 00:00:00") + # its links were made from an earlier value: the link pass has not read this one + _stored(listing, "m4", "`read_rows` retries.") + listing["links"][-1]["inputs_hash"] = "older" + assert await code_renames.planned("o", "ns") == [] + + +@pytest.mark.asyncio +async def test_the_listing_gives_no_row_for_a_repository_the_caller_may_not_read( + listing: dict, monkeypatch: pytest.MonkeyPatch +) -> None: + _stored(listing, "m1", "`read_rows` retries.", link=RENAMED | {"code_namespace": "secret"}) + assert await code_renames.planned("o", "ns") == [] + # through the real read: nothing is read of a namespace with no readable repository + monkeypatch.setattr(code_link_reads, "stale_links", _REAL_STALE_LINKS) + monkeypatch.setattr(code_link_reads.code, "trunk_namespace", lambda org, ns: "secret") + + async def none_readable(org: str, namespaces: set[str]) -> set[str]: + return set() + + async def unread(*a: Any, **kw: Any) -> Any: + raise AssertionError("no link, memory or index is read") + + monkeypatch.setattr(code_link_reads, "readable_namespaces", none_readable) + for name in ("stale_of_served", "memory_heads", "for_memories"): + monkeypatch.setattr(code_renames.store, name, unread) + monkeypatch.setattr(code_renames.code, "candidates", unread) + assert await code_renames.planned("o", "ns") == [] + + +_REAL_STALE_LINKS = code_link_reads.stale_links + + +@pytest.mark.asyncio +async def test_the_listing_asks_the_index_which_old_paths_are_gone(listing: dict) -> None: + was, now = "src/io/reader.py", "src/io/read.py" + link = _link(now, "src.io.read::Reader::get", was=(was, "src.io.reader::Reader::get")) + listing["defs"] = [_d(now, "src.io.read::Reader::get")] + _stored(listing, "m1", "`Reader.get` in `src/io/reader.py` retries.", link=link) + (row,) = await code_renames.planned("o", "ns") + assert row["reason"] == "old_name_remains" # the index still has the old file + listing["gone"] = (was,) + (row,) = await code_renames.planned("o", "ns") + assert [(e["old"], e["new"]) for e in row["edits"]] == [(was, now)] + # a bare name the index resolves to another file is not the old path + listing["gone"], listing["live"] = (), {was: "other/src/io/reader.py"} + (row,) = await code_renames.planned("o", "ns") + assert [(e["old"], e["new"]) for e in row["edits"]] == [(was, now)] diff --git a/tests/unit/test_namespace_validate.py b/tests/unit/test_namespace_validate.py index 839671205b..cf11e3aab3 100644 --- a/tests/unit/test_namespace_validate.py +++ b/tests/unit/test_namespace_validate.py @@ -19,6 +19,8 @@ from server.transport import mcp_descriptions _STALE_LINKS = code_link_reads.stale_links # the real read, before `_no_code_links` +# the checks read from the code links rather than with SQL of their own +_CODE_LINK_CHECKS = ("code_links_stale", "code_rename_edits") class _CH: @@ -69,7 +71,7 @@ async def test_clean_namespace_is_healthy_and_lists_every_check( assert out.healthy is True assert (out.errors, out.warnings, out.infos) == (0, 0, 0) names = [f.check for f in out.findings] - assert set(names) == {*nv._CHECKS, "code_links_stale", *nv._CODE_UNLINKED} + assert set(names) == {*nv._CHECKS, *_CODE_LINK_CHECKS, *nv._CODE_UNLINKED} assert "unresolved_evidence" in names assert all(f.count == 0 and f.samples == [] for f in out.findings) assert out.skipped == [] @@ -137,8 +139,9 @@ async def test_one_failing_check_is_skipped_not_raised(monkeypatch: pytest.Monke out = await nv.handle_namespace_validate(_inp()) assert out.skipped == ["orphan_vectors: RuntimeError"] assert "orphan_vectors" not in [f.check for f in out.findings] - # every other check, the stale code links and the unlinked memories by cause - assert len(out.findings) == len(nv._CHECKS) + len(nv._CODE_UNLINKED) + # every other check, the two read from the code links and the unlinked memories by cause + others = len(nv._CHECKS) - 1 + assert len(out.findings) == others + len(_CODE_LINK_CHECKS) + len(nv._CODE_UNLINKED) assert out.healthy is True @@ -290,7 +293,11 @@ def link(key: str) -> dict[str, Any]: asked: list[Any] = [] - async def stale_links(org: str, namespace: str, keys: Any = None, *, limit: int) -> Any: + async def stale_links( + org: str, namespace: str, keys: Any = None, *, limit: int, states: Any = () + ) -> Any: + if "moved" in states: + return [] # the rename check's read asked.append((keys, limit)) return [link("new")] @@ -304,7 +311,7 @@ async def stale_links(org: str, namespace: str, keys: Any = None, *, limit: int) def test_every_check_declares_its_kind_version_and_uncertainty() -> None: - assert set(nv._CONTRACT) == {*nv._CHECKS, "code_links_stale", *nv._CODE_UNLINKED} + assert set(nv._CONTRACT) == {*nv._CHECKS, *_CODE_LINK_CHECKS, *nv._CODE_UNLINKED} assert {r.kind for r in nv._CONTRACT.values()} == { "contract_violation", "usage_heuristic", @@ -419,7 +426,7 @@ async def test_stale_code_links_are_named_skipped_while_the_code_registry_is_unr out = await nv.handle_namespace_validate(_inp()) # every check that reads which repositories are configured assert out.skipped == [ - f"{check}: RegistryUnread" for check in ("code_links_stale", *nv._CODE_UNLINKED) + f"{check}: RegistryUnread" for check in (*_CODE_LINK_CHECKS, *nv._CODE_UNLINKED) ] assert out.coverage.complete is False @@ -487,4 +494,91 @@ async def unlinked(org: str, namespace: str, keys: Any = None) -> dict[str, list monkeypatch.setattr(nv, "get_client", lambda: _CH({})) out = await nv.handle_namespace_validate(_inp()) assert out.skipped == [f"{check}: TimeoutError" for check in nv._CODE_UNLINKED] - assert reads == 1 and {f.check for f in out.findings} == {*nv._CHECKS, "code_links_stale"} + assert reads == 1 and {f.check for f in out.findings} == {*nv._CHECKS, *_CODE_LINK_CHECKS} + + +@pytest.mark.asyncio +async def test_rename_edits_are_listed_with_their_totals_by_outcome( + monkeypatch: pytest.MonkeyPatch, +) -> None: + """A memory whose link followed a rename is listed with the edits its text allows, + or the reason it gets none; the totals count every memory read, not only the + samples. Information: it never makes a namespace unhealthy, even under `strict`.""" + from server.memory.app import code_renames + + asked: list[Any] = [] + edit = {"start": 1, "end": 10, "old": "read_rows", "new": "fetch_rows"} + + def memory(n: int, **more: Any) -> dict[str, Any]: + return {"memory_key": f"k{n}", "memory_id": f"00000000-0000-0000-0000-{n:012d}", **more} + + found = [ + memory(1, edits=[edit], content_sha256="a" * 64), + memory(2, reason="prose_occurrence"), + memory(3, reason="old_name_still_defined"), + memory(4, reason="prose_occurrence"), + ] + + async def planned(org: str, namespace: str, keys: Any = None) -> list[dict[str, Any]]: + asked.append((org, namespace, keys)) + return found + + monkeypatch.setattr(code_renames, "planned", planned) + monkeypatch.setattr(nv, "get_client", lambda: _CH({})) + out = await nv.handle_namespace_validate(_inp(keys=["k1"], sample_limit=2, strict=True)) + renames = next(f for f in out.findings if f.check == "code_rename_edits") + assert renames.count == 4 and renames.samples == found[:2] + assert renames.samples_complete is False and renames.severity == "info" + assert renames.totals == {"edits": 1, "old_name_still_defined": 1, "prose_occurrence": 2} + assert (out.infos, out.warnings, out.errors, out.healthy) == (4, 0, 0, True) + assert "memory.update" in renames.detail and "if_match_sha256" in renames.detail + assert asked == [("o", "ns", ["k1"])] + # no sample asked for: every memory is still counted, by outcome + out = await nv.handle_namespace_validate(_inp(sample_limit=0)) + renames = next(f for f in out.findings if f.check == "code_rename_edits") + assert (renames.count, renames.samples) == (4, []) and sum(renames.totals.values()) == 4 + assert asked[-1] == ("o", "ns", None) + # a check with no classes of its own carries no totals + assert all(f.totals == {} for f in out.findings if f.check != "code_rename_edits") + + +@pytest.mark.asyncio +async def test_a_failed_rename_read_skips_its_check_and_no_other( + monkeypatch: pytest.MonkeyPatch, +) -> None: + from server.memory.app import code_renames + + async def planned(org: str, namespace: str, keys: Any = None) -> list[dict[str, Any]]: + raise TimeoutError("read timed out") + + monkeypatch.setattr(code_renames, "planned", planned) + monkeypatch.setattr(nv, "get_client", lambda: _CH({})) + out = await nv.handle_namespace_validate(_inp()) + assert out.skipped == ["code_rename_edits: TimeoutError"] + assert "code_rename_edits" not in {f.check for f in out.findings} + + +@pytest.mark.asyncio +async def test_rename_edits_list_nothing_of_a_repository_the_caller_may_not_read( + monkeypatch: pytest.MonkeyPatch, +) -> None: + """The listing starts from the links into repositories the caller may read: with + none readable, no memory, link or index row is read and nothing is listed.""" + from server.memory.app import code_renames + + async def none_readable(org: str, namespaces: set[str]) -> set[str]: + return set() + + async def unread(*args: Any, **kw: Any) -> Any: + raise AssertionError("nothing is read of an unreadable repository") + + monkeypatch.setattr(code_link_reads, "stale_links", _STALE_LINKS) + monkeypatch.setattr(code_link_reads.code, "trunk_namespace", lambda org, ns: "secret-code") + monkeypatch.setattr(code_link_reads, "readable_namespaces", none_readable) + for name in ("stale_of_served", "memory_heads", "for_memories"): + monkeypatch.setattr(code_renames.store, name, unread) + monkeypatch.setattr(code_renames.code, "candidates", unread) + monkeypatch.setattr(nv, "get_client", lambda: _CH({})) + out = await nv.handle_namespace_validate(_inp()) + renames = next(f for f in out.findings if f.check == "code_rename_edits") + assert (renames.count, renames.samples, renames.totals) == (0, [], {}) From 1abb2a99b254e11ab0b814a29684e53ff423d715 Mon Sep 17 00:00:00 2001 From: Lareb Zafar Date: Sat, 28 Nov 2026 06:00:00 +0530 Subject: [PATCH 2/6] code_rename_edits lists only memories that write an old name, and asks the index for every old path - `code.live_paths` reads its paths in slices of 500, the most the file table's reads answer for in one call. A report with more old paths than that read the rest as gone and offered a whole-path edit for a file the head still has. The link pass resolves a batch's `files` through the same call. - A sentence that says `name`, `names`, `naming`, `called` or a word that starts with `alias` is about the name and gets `about_naming`. `call` and `calls` are left out: they say the code is called. - The dotted module a definition left, written over two segments or more outside the edits (an import, a sentence about the place), withholds the memory as `old_name_remains`, or `quoted_or_literal` inside quoted code. - A memory whose text names no old name or path is left out of the finding: its count, samples and `totals` are the memories whose text says an old name. Signed-off-by: Lareb Zafar Co-Authored-By: Claude Fable 5.2 --- docs/concepts/memory.md | 56 +++++++-------- docs/use-cases/memory-linked-to-code.md | 4 +- server/code/app/memory_links.py | 14 ++-- server/memory/app/code_renames.py | 16 +++-- server/memory/domain/code_rename.py | 50 ++++++++++++-- tests/unit/test_memory_code_rename_plan.py | 79 +++++++++++++++++++++- tests/unit/test_namespace_validate.py | 2 +- 7 files changed, 172 insertions(+), 49 deletions(-) diff --git a/docs/concepts/memory.md b/docs/concepts/memory.md index 0fe2be47d8..fd6fff90ea 100644 --- a/docs/concepts/memory.md +++ b/docs/concepts/memory.md @@ -604,8 +604,8 @@ linked, is not counted. How far each repository's links trail its index is a gauge, and a health warning when it lasts ([monitoring](../operations/monitoring.md#what-to-alert-on)). -A `moved` link is at its code, and the memory's text still names the old definition or -path. `namespace.validate` lists each such memory under the `info` finding +A `moved` link is at its code, and the memory's text may still name the old definition or +path. `namespace.validate` lists each memory whose text does under the `info` finding `code_rename_edits`, with either the `edits` its text allows (replace `old` with `new` at characters `start` to `end`) and the `content_sha256` they are of, or the one `reason` no edit is offered. The finding's `totals` count the memories by `edits` and by reason. Loom @@ -620,31 +620,33 @@ spelling the text uses: `Reader.get` becomes `Reader.fetch`, a full dotted name full new one, and `self.get` keeps its receiver. The whole memory gets no edit for the first of these reasons that applies: -| Reason | The memory | -| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `not_text` | has a value that is not one string. | -| `link_not_settled` | has a link that is pending, `changed`, `unresolved` or `missing`, that its renamed class carried, or that is hashed under older fingerprint rules. | -| `incomplete` | names more code than the link caps keep. | -| `overloaded` | is linked to a definition the index numbers among several of one name. | -| `quoted_or_literal` | holds the old name or path in a fenced block, a URL, a quoted string or a backticked span that is more than one name. | -| `prose_occurrence` | writes the old name as a bare word of the prose. | -| `old_name_remains` | would still hold the old name or path where no edit reaches: a plain word, a part of a longer name, a path before a line number, or a path whose file still exists. | -| `names_several` | writes one name that two of its links were written against. | -| `receiver_form` | writes the name as `self.name`, `cls.name` or `this.name`, and its `files` do not name the defining file. | -| `old_name_still_defined` | spells the old name in a way that still names a definition on the indexed trunk. | -| `new_name_present` | already holds the new name or path. | -| `dated_claim` | is dated (`valid_to`, `invalid_at` or `temporal_anchor`), or the sentence to edit holds a commit hash, a version tag, a year, a month, or a pull request or issue number. | -| `about_naming` | would be edited in a sentence about the name or the place: it holds `rename`, `formerly`, `used to`, `was called`, `replaced`, `moved from`, `deprecated`, `legacy`, `before`, `previously` or `named`. | -| `named_in_key_or_tags` | holds the old name or path in its `memory_key` or a tag. | -| `named_in_files` | lists the old path in `files`, which `memory.update` keeps. | -| `would_unlink` | would lose a link once revised: the new name is not one definition on the indexed trunk, or the revised text no longer names a definition or file it is linked to. | -| `no_code_token` | names no old name or path: the bare name still holds after a move, or the link is back where the text says. | - -The words that mark a sentence as being about the name are English. The finding reads the -2,000 memories whose `moved` link was last checked (all under `keys` when given), in the -repositories the caller may read, and no high-sensitivity memory; a link whose code also -changed is listed under `code_links_stale`. Neither the memory's key, tags, `files`, -entities and concepts nor a line number written in its text is edited. +| Reason | The memory | +| ------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `not_text` | has a value that is not one string. | +| `link_not_settled` | has a link that is pending, `changed`, `unresolved` or `missing`, that its renamed class carried, or that is hashed under older fingerprint rules. | +| `incomplete` | names more code than the link caps keep. | +| `overloaded` | is linked to a definition the index numbers among several of one name. | +| `quoted_or_literal` | holds the old name or path in a fenced block, a URL, a quoted string or a backticked span that is more than one name. | +| `prose_occurrence` | writes the old name as a bare word of the prose. | +| `old_name_remains` | would still hold the old name or path where no edit reaches: a plain word, a part of a longer name, the dotted module the definition left (two segments or more), a path before a line number, or a path whose file still exists. | +| `names_several` | writes one name that two of its links were written against. | +| `receiver_form` | writes the name as `self.name`, `cls.name` or `this.name`, and its `files` do not name the defining file. | +| `old_name_still_defined` | spells the old name in a way that still names a definition on the indexed trunk. | +| `new_name_present` | already holds the new name or path. | +| `dated_claim` | is dated (`valid_to`, `invalid_at` or `temporal_anchor`), or the sentence to edit holds a commit hash, a version tag, a year, a month, or a pull request or issue number. | +| `about_naming` | would be edited in a sentence about the name or the place: it holds `name`, `names`, `named`, `naming`, a word that starts with `renam` or `alias`, `called`, `formerly`, `used to`, `replaced`, `moved from`, `deprecated`, `legacy`, `before` or `previously`. | +| `named_in_key_or_tags` | holds the old name or path in its `memory_key` or a tag. | +| `named_in_files` | lists the old path in `files`, which `memory.update` keeps. | +| `would_unlink` | would lose a link once revised: the new name is not one definition on the indexed trunk, or the revised text no longer names a definition or file it is linked to. | + +A memory whose text names no old name or path is not listed: its bare name still holds +after a move, or the link is back where the text says. The words that mark a sentence as +being about the name are English, and `call` or `calls` is not one: it is read as calling +the code. The finding reads the 2,000 memories whose `moved` link was last checked (all +under `keys` when given), in the repositories the caller may read, and no high-sensitivity +memory; a link whose code also changed is listed under `code_links_stale`. Neither the +memory's key, tags, `files`, entities and concepts nor a line number written in its text +is edited. ## Time diff --git a/docs/use-cases/memory-linked-to-code.md b/docs/use-cases/memory-linked-to-code.md index f029d67463..972a9f67f4 100644 --- a/docs/use-cases/memory-linked-to-code.md +++ b/docs/use-cases/memory-linked-to-code.md @@ -140,8 +140,8 @@ For removal, held-memory exceptions and model-backed revision, see the ## Bring a lesson's text up to a rename When a definition is renamed or moved with nothing else changed, its link follows it and -reads `moved`. The lesson's text still says the old name. Loom does not rewrite it; -`namespace.validate` lists what a rewrite would be: +reads `moved`. A lesson that wrote the old name, module or path still says it. Loom does +not rewrite it; `namespace.validate` lists what a rewrite would be: 1. Call `namespace.validate` on the memory namespace (with `keys` to check the lessons one session wrote) and read the `code_rename_edits` finding. Each sample is one lesson diff --git a/server/code/app/memory_links.py b/server/code/app/memory_links.py index 853c0c47b5..8d242b45a9 100644 --- a/server/code/app/memory_links.py +++ b/server/code/app/memory_links.py @@ -10,6 +10,7 @@ import logging from collections.abc import Sequence from dataclasses import dataclass +from itertools import batched from typing import Any from server.code.app.index import gitrepo, mirrors @@ -409,11 +410,14 @@ async def live_paths(org: str, namespace: str, refs: list[str]) -> dict[str, str """ref -> the live path it names: itself when indexed, else the one live path whose basename it is. Unresolved or ambiguous refs are absent.""" repo = CodeRepo() - present = await repo.live_paths_present(org, namespace, refs) - out = {r: r for r in refs if r in present} - bare = [r for r in refs if r not in out and "/" not in r] - named = await repo.live_paths_by_basename(org, namespace, bare) if bare else {} - out.update((r, paths[0]) for r, paths in named.items() if len(paths) == 1) + out: dict[str, str] = {} + # the store answers for at most 500 paths of one read + for some in batched(sorted(set(refs)), 500): + present = await repo.live_paths_present(org, namespace, list(some)) + out.update((r, r) for r in some if r in present) + bare = [r for r in some if r not in present and "/" not in r] + named = await repo.live_paths_by_basename(org, namespace, bare) if bare else {} + out.update((r, paths[0]) for r, paths in named.items() if len(paths) == 1) return out diff --git a/server/memory/app/code_renames.py b/server/memory/app/code_renames.py index 1bda83003d..701b564c5d 100644 --- a/server/memory/app/code_renames.py +++ b/server/memory/app/code_renames.py @@ -1,10 +1,11 @@ """The edits that bring a namespace's memories up to renames their links followed, for namespace.validate. -A link in state `moved` is at its code, and its memory's text still names the old +A link in state `moved` is at its code, and its memory's text may still name the old definition or path. This reads each such memory, its links and the index at the head, and plans its edits (`server.memory.domain.code_rename`): the old and new token with their positions and the hash to apply them against, or the one reason none is offered. +A memory whose text names nothing old is not listed. Nothing is written: a principal applies an edit with memory.update and `if_match_sha256`. """ @@ -40,11 +41,12 @@ async def planned( org: str, namespace: str, keys: Sequence[str] | None = None ) -> list[dict[str, Any]]: """One row per served memory of the namespace (under `keys` when given) that holds - a `moved` link into a repository the caller may read, the newest checked first, of - the `SCANNED` newest: its memory_key and memory_id, and either its `edits` (each a - `start`, `end`, `old` and `new` over the text) with the `content_sha256` they are - of, or the `reason` it gets none (`code_rename.REASONS`). A high-sensitivity memory - is not read: an edit quotes its text.""" + a `moved` link into a repository the caller may read and whose text names an old + name or path, the newest checked first, of the `SCANNED` newest: its memory_key and + memory_id, and either its `edits` (each a `start`, `end`, `old` and `new` over the + text) with the `content_sha256` they are of, or the `reason` it gets none + (`code_rename.REASONS` but `UNNAMED`). A high-sensitivity memory is not read: an + edit quotes its text.""" moved = await code_link_reads.stale_links( org, namespace, keys, limit=SCANNED, states=("moved",) ) @@ -107,6 +109,8 @@ def _rows(memories: Sequence[_Linked], index: dict[str, _Index]) -> list[dict[st plan = code_rename.plan( link_pass.claim_of(head["value"]), head, links, by_name, gone=gone, rules=rules ) + if plan.reason == code_rename.UNNAMED: + continue # its text holds as it is row: dict[str, Any] = {"memory_key": str(head["memory_key"]), "memory_id": str(head["mid"])} if plan.reason: row["reason"] = plan.reason diff --git a/server/memory/domain/code_rename.py b/server/memory/domain/code_rename.py index a56b8e1354..baddbf5990 100644 --- a/server/memory/domain/code_rename.py +++ b/server/memory/domain/code_rename.py @@ -54,6 +54,8 @@ "would_unlink", # the revised memory would not link to all the code it links to now "no_code_token", # the text names no old name or path: nothing to edit ) +# the reason of a memory whose text holds as it is +UNNAMED = REASONS[-1] # what makes a sentence a statement about a point in time: a commit, a version tag, a # year, a month, a pull request or issue @@ -66,10 +68,11 @@ r"|#\d+\b|\b(?:pr|mr|gh)[- ]?\d+\b|\b(?:issue|pull request)s? \d+", re.IGNORECASE, ) -# what makes a sentence a statement about the name or the place (English only) +# what makes a sentence a statement about the name or the place (English only). Not +# `call` or `calls`: far more often the code is called than named. _NAMING = re.compile( - r"\b(?:renam\w+|formerly|used to|was called|replaced|moved from|deprecated|legacy" - r"|before|previously|named)\b", + r"\b(?:nam(?:e|es|ed|ing)|renam\w+|called|alias\w*|formerly|used to|replaced" + r"|moved from|deprecated|legacy|before|previously)\b", re.IGNORECASE, ) _SENTENCE_END = re.compile(r"(?<=[.!?])\s+|\n") @@ -157,15 +160,15 @@ def plan( files = [str(f) for f in memory.get("files") or []] spans, quoted = code_spans(text) edits: dict[tuple[int, int], Edit] = {} - for m in (_move(a) for a in links if a["state"] == "moved"): - if m is None: - continue + moves = [m for a in links if a["state"] == "moved" and (m := _move(a))] + for m in moves: alive = m.was_path not in gone why |= _in_labels(memory, m, alive) if m.name: why |= _renamed(text, m, spans, quoted, by_name, files, edits) if m.was_path != m.path: why |= _repathed(text, m, quoted, files, alive, edits) + why |= _old_modules(text, moves, list(edits), quoted) if edits: why |= _about(text, memory, edits.values()) why |= _unlinked(revised(text, list(edits.values())), links, by_name, files) @@ -173,7 +176,7 @@ def plan( if reason in why: return Plan(reason=reason) if not edits: - return Plan(reason="no_code_token") + return Plan(reason=UNNAMED) return Plan(edits=tuple(sorted(edits.values())), sha256=served_content_sha256(text)) @@ -307,6 +310,39 @@ def _left_over( return why +def _modules(path: str, qualified_name: str) -> set[str]: + """The dotted spellings of the module a definition is in: whole, and from each of + its segments on.""" + local = "." + local_name(qualified_name, path) + out: set[str] = set() + for form in _forms(path, qualified_name): + parts = form.removesuffix(local).split(".") if form.endswith(local) else [] + out.update(".".join(parts[i:]) for i in range(len(parts))) + return out + + +def _old_modules( + text: str, + moves: Sequence[_Move], + edited: Sequence[tuple[int, int]], + quoted: Sequence[tuple[int, int]], +) -> set[str]: + """Why a module a definition of `moves` left withholds the memory: `text` writes it, + over more than one segment, outside the `edited` spans (an import, a sentence about + the place), so the revised text would name both places. One segment is as often a + word of the prose.""" + why: set[str] = set() + for m in moves: + left = _modules(m.was_path, m.was_name) - _modules(m.path, m.name) if m.name else set() + for module in (x for x in left if "." in x): + spelled = re.escape(module).replace(r"\.", r"(?:\.|::)") + for o in re.finditer(rf"(? None: # the sentence is about the name, or about a point in time ("We should rename `read_rows` to something shorter.", "about_naming"), ("`read_rows`, formerly the slow path, retries.", "about_naming"), - ("`read_rows` was called from the loader before the split.", "about_naming"), + ("`read_rows` was called from the loader.", "about_naming"), + ("`read_rows` is a bad name for this.", "about_naming"), + ("Never name a helper `read_rows`: it collides with the fixture.", "about_naming"), + ("The loader names it `read_rows`.", "about_naming"), + ("The naming of `read_rows` follows the loader.", "about_naming"), + ("The helper is called `read_rows`.", "about_naming"), + ("`read_rows` is an alias of the loader.", "about_naming"), ("`read_rows` regressed in a1b2c3d4e5.", "dated_claim"), ("`read_rows` retries since v2.3.", "dated_claim"), ("`read_rows` retries, see #1234.", "dated_claim"), @@ -158,6 +164,14 @@ def test_a_cue_in_another_sentence_does_not_withhold() -> None: assert _revised(text) == text.replace("read_rows", "fetch_rows") +def test_a_longer_word_that_holds_a_cue_or_a_call_of_the_code_does_not_withhold() -> None: + for text in ( + "`read_rows` reads the filename, the hostname and the namespace.", + "The worker calls `read_rows` twice.", + ): + assert _revised(text) == text.replace("read_rows", "fetch_rows") + + def test_a_cue_inside_the_edited_name_itself_does_not_withhold() -> None: was, now = "src/v2/reader2019.py", "src/v2/read2019.py" link = _link(now, "", was=(was, "")) @@ -300,6 +314,29 @@ def test_a_scope_change_edits_only_the_spellings_that_name_the_old_scope() -> No assert _plan(text, links=[moved], defs=defs).reason == "old_name_remains" +def test_the_module_a_definition_left_withholds_where_no_edit_reaches_it() -> None: + was, now = "src/io/util.py", "src/net/util.py" + moved = _link(now, "src.net.util::backoff", was=(was, "src.io.util::backoff")) + defs = [_d(now, "src.net.util::backoff")] + for text, reason in ( + ("`io.util.backoff` doubles; `from src.io.util import backoff`.", "quoted_or_literal"), + ("`io.util.backoff` doubles; it lives in the io.util module.", "old_name_remains"), + ("`io.util.backoff` doubles; see `src.io.util`.", "old_name_remains"), + ("`backoff` doubles; it lives in src::io::util.", "old_name_remains"), + ): + assert _plan(text, links=[moved], defs=defs).reason == reason, text + # the part both modules end in is not the old one, and one segment may be a word + text = "`io.util.backoff` doubles; util and io hold the rest." + assert _revised(text, links=[moved], defs=defs).startswith("`net.util.backoff`") + # two definitions that left one module are both edited: each covers its own module + jitter = _link(now, "src.net.util::jitter", was=(was, "src.io.util::jitter")) + text = "`src.io.util.backoff` and `src.io.util.jitter` double." + both = [*defs, _d(now, "src.net.util::jitter")] + assert _revised(text, links=[moved, jitter], defs=both) == ( + "`src.net.util.backoff` and `src.net.util.jitter` double." + ) + + def test_a_renamed_file_edits_its_whole_path_once_the_old_one_is_gone() -> None: was, now = "src/io/reader.py", "src/io/read.py" link = _link(now, "src.io.read::Reader::get", was=(was, "src.io.reader::Reader::get")) @@ -447,6 +484,8 @@ async def test_the_listing_gives_each_memory_its_edits_or_its_reason(listing: di _stored(listing, "m1", "`read_rows` retries twice.") _stored(listing, "m2", "read_rows retries twice.") _stored(listing, "m3", {"claim": "`read_rows` retries twice."}) + # names nothing old: its text holds as it is, and it is not listed + _stored(listing, "m4", "`Reader` wraps the socket.") rows = await code_renames.planned("o", "ns", ["k"]) assert rows == [ { @@ -498,6 +537,7 @@ async def unread(*a: Any, **kw: Any) -> Any: _REAL_STALE_LINKS = code_link_reads.stale_links +_REAL_LIVE_PATHS = code_renames.code.live_paths @pytest.mark.asyncio @@ -515,3 +555,40 @@ async def test_the_listing_asks_the_index_which_old_paths_are_gone(listing: dict listing["gone"], listing["live"] = (), {was: "other/src/io/reader.py"} (row,) = await code_renames.planned("o", "ns") assert [(e["old"], e["new"]) for e in row["edits"]] == [(was, now)] + + +class _Files: + """The file table of an index, answering as the store's reads ask it.""" + + def __init__(self, live: set[str]) -> None: + self.live = live + self.asked: list[int] = [] + + async def query_all(self, sql: str, params: dict[str, Any]) -> list[dict[str, Any]]: + self.asked.append(len(params["paths"])) + return [{"path": p} for p in params["paths"] if p in self.live] + + +@pytest.mark.asyncio +async def test_an_old_path_past_the_store_reads_cap_is_still_asked_for( + listing: dict, monkeypatch: pytest.MonkeyPatch +) -> None: + """The store answers for 500 paths of one read: a report with more old paths than + that asks in slices, so the last path, which the head still has, is not read as gone.""" + from server.code.store.index import CodeRepo + + last = 500 + for i in range(last + 1): + was, now = f"src/old/f{i:03}.py", f"src/new/f{i:03}.py" + link = _link(now, "", was=(was, "")) + _stored(listing, f"m{i:03}", f"`{was}` holds it.", link=link, files=[f"f{i:03}.py"]) + files = _Files({f"src/old/f{last}.py"}) + monkeypatch.setattr(code_renames.code, "live_paths", _REAL_LIVE_PATHS) + monkeypatch.setattr(code_renames.code, "CodeRepo", lambda: CodeRepo(files)) + rows = {r["memory_id"]: r for r in await code_renames.planned("o", "ns")} + assert files.asked == [500, 1] + assert rows[f"m{last}"]["reason"] == "old_name_remains" + assert [(e["old"], e["new"]) for e in rows["m000"]["edits"]] == [ + ("src/old/f000.py", "src/new/f000.py") + ] + assert sum("edits" in r for r in rows.values()) == last diff --git a/tests/unit/test_namespace_validate.py b/tests/unit/test_namespace_validate.py index cf11e3aab3..c17ad5a9de 100644 --- a/tests/unit/test_namespace_validate.py +++ b/tests/unit/test_namespace_validate.py @@ -502,7 +502,7 @@ async def test_rename_edits_are_listed_with_their_totals_by_outcome( monkeypatch: pytest.MonkeyPatch, ) -> None: """A memory whose link followed a rename is listed with the edits its text allows, - or the reason it gets none; the totals count every memory read, not only the + or the reason it gets none; the totals count every memory listed, not only the samples. Information: it never makes a namespace unhealthy, even under `strict`.""" from server.memory.app import code_renames From 225295e669ad3fee302057c8aa36ff6f0b639f50 Mon Sep 17 00:00:00 2001 From: Lareb Zafar Date: Sat, 28 Nov 2026 06:16:34 +0530 Subject: [PATCH 3/6] code_rename_edits offers no edit while another code name keeps the old one, and reads a wrapped sentence whole A name written as code that ends in the old name and is not edited was taken to name another definition without asking the index. With `Reader::read_rows` renamed, "`Reader.read_rows` retries; wrap `conn.read_rows()` in a try." got one edit and kept `conn.read_rows()`, a call the head no longer has. Such a name is now left alone only when it names a definition at the head, or the old definition of another followed link, which that link edits; otherwise the memory gets `old_name_remains`. The same holds for `~Reader` beside an edited `Reader`. The naming and date cues were searched in the line. A sentence now ends after `.`, `!` or `?` and a space (not after a one-letter abbreviation such as `e.g.`), at a blank line and before a list item, so "formerly named" on the line above the name withholds the edit. `May` capitalised after another word of the sentence counts as a month: "In May `read_rows` retried twice." is a dated claim, and "`read_rows` may retry" is still edited. Co-Authored-By: Claude Fable 5.2 Signed-off-by: Lareb Zafar --- docs/concepts/memory.md | 40 +++++++-------- server/memory/domain/code_rename.py | 57 ++++++++++++++-------- tests/unit/test_memory_code_rename_plan.py | 31 ++++++++++-- 3 files changed, 85 insertions(+), 43 deletions(-) diff --git a/docs/concepts/memory.md b/docs/concepts/memory.md index fd6fff90ea..169c72e75e 100644 --- a/docs/concepts/memory.md +++ b/docs/concepts/memory.md @@ -620,27 +620,29 @@ spelling the text uses: `Reader.get` becomes `Reader.fetch`, a full dotted name full new one, and `self.get` keeps its receiver. The whole memory gets no edit for the first of these reasons that applies: -| Reason | The memory | -| ------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `not_text` | has a value that is not one string. | -| `link_not_settled` | has a link that is pending, `changed`, `unresolved` or `missing`, that its renamed class carried, or that is hashed under older fingerprint rules. | -| `incomplete` | names more code than the link caps keep. | -| `overloaded` | is linked to a definition the index numbers among several of one name. | -| `quoted_or_literal` | holds the old name or path in a fenced block, a URL, a quoted string or a backticked span that is more than one name. | -| `prose_occurrence` | writes the old name as a bare word of the prose. | -| `old_name_remains` | would still hold the old name or path where no edit reaches: a plain word, a part of a longer name, the dotted module the definition left (two segments or more), a path before a line number, or a path whose file still exists. | -| `names_several` | writes one name that two of its links were written against. | -| `receiver_form` | writes the name as `self.name`, `cls.name` or `this.name`, and its `files` do not name the defining file. | -| `old_name_still_defined` | spells the old name in a way that still names a definition on the indexed trunk. | -| `new_name_present` | already holds the new name or path. | -| `dated_claim` | is dated (`valid_to`, `invalid_at` or `temporal_anchor`), or the sentence to edit holds a commit hash, a version tag, a year, a month, or a pull request or issue number. | -| `about_naming` | would be edited in a sentence about the name or the place: it holds `name`, `names`, `named`, `naming`, a word that starts with `renam` or `alias`, `called`, `formerly`, `used to`, `replaced`, `moved from`, `deprecated`, `legacy`, `before` or `previously`. | -| `named_in_key_or_tags` | holds the old name or path in its `memory_key` or a tag. | -| `named_in_files` | lists the old path in `files`, which `memory.update` keeps. | -| `would_unlink` | would lose a link once revised: the new name is not one definition on the indexed trunk, or the revised text no longer names a definition or file it is linked to. | +| Reason | The memory | +| ------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `not_text` | has a value that is not one string. | +| `link_not_settled` | has a link that is pending, `changed`, `unresolved` or `missing`, that its renamed class carried, or that is hashed under older fingerprint rules. | +| `incomplete` | names more code than the link caps keep. | +| `overloaded` | is linked to a definition the index numbers among several of one name. | +| `quoted_or_literal` | holds the old name or path in a fenced block, a URL, a quoted string or a backticked span that is more than one name. | +| `prose_occurrence` | writes the old name as a bare word of the prose. | +| `old_name_remains` | would still hold the old name or path where no edit reaches: a plain word, a part of a longer name, a longer name written as code that names no definition on the indexed trunk (`conn.read_rows()`), the dotted module the definition left (two segments or more), a path before a line number, or a path whose file still exists. | +| `names_several` | writes one name that two of its links were written against. | +| `receiver_form` | writes the name as `self.name`, `cls.name` or `this.name`, and its `files` do not name the defining file. | +| `old_name_still_defined` | spells the old name in a way that still names a definition on the indexed trunk. | +| `new_name_present` | already holds the new name or path. | +| `dated_claim` | is dated (`valid_to`, `invalid_at` or `temporal_anchor`), or the sentence to edit holds a commit hash, a version tag, a year, a month (`May` only capitalised after another word), or a pull request or issue number. | +| `about_naming` | would be edited in a sentence about the name or the place: it holds `name`, `names`, `named`, `naming`, a word that starts with `renam` or `alias`, `called`, `formerly`, `used to`, `replaced`, `moved from`, `deprecated`, `legacy`, `before` or `previously`. | +| `named_in_key_or_tags` | holds the old name or path in its `memory_key` or a tag. | +| `named_in_files` | lists the old path in `files`, which `memory.update` keeps. | +| `would_unlink` | would lose a link once revised: the new name is not one definition on the indexed trunk, or the revised text no longer names a definition or file it is linked to. | A memory whose text names no old name or path is not listed: its bare name still holds -after a move, or the link is back where the text says. The words that mark a sentence as +after a move, or the link is back where the text says. A sentence ends after `.`, `!` or +`?` and a space (not after a one-letter abbreviation such as `e.g.`), at a blank line and +before a list item; a line break alone does not end one. The words that mark a sentence as being about the name are English, and `call` or `calls` is not one: it is read as calling the code. The finding reads the 2,000 memories whose `moved` link was last checked (all under `keys` when given), in the repositories the caller may read, and no high-sensitivity diff --git a/server/memory/domain/code_rename.py b/server/memory/domain/code_rename.py index baddbf5990..b153e702b1 100644 --- a/server/memory/domain/code_rename.py +++ b/server/memory/domain/code_rename.py @@ -58,13 +58,14 @@ UNNAMED = REASONS[-1] # what makes a sentence a statement about a point in time: a commit, a version tag, a -# year, a month, a pull request or issue +# year, a month, a pull request or issue. `May` is the month only capitalised after +# another word: elsewhere it is the verb. _DATED = re.compile( r"\b(?=[0-9a-f]*\d)(?=[0-9a-f]*[a-f])[0-9a-f]{7,40}\b" r"|\bv\d+(?:\.\d+)*\b|\b\d+\.\d+\.\d+\b" r"|\b(?:19|20)\d\d\b" r"|\b(?:january|february|march|april|june|july|august|september|october|november" - r"|december)\b" + r"|december)\b|(?<=\w\s)(?-i:May)\b" r"|#\d+\b|\b(?:pr|mr|gh)[- ]?\d+\b|\b(?:issue|pull request)s? \d+", re.IGNORECASE, ) @@ -75,7 +76,11 @@ r"|moved from|deprecated|legacy|before|previously)\b", re.IGNORECASE, ) -_SENTENCE_END = re.compile(r"(?<=[.!?])\s+|\n") +# a sentence ends after `.`, `!` or `?` and a space (not after a one-letter abbreviation: +# `e.g.`, `i.e.`), at a blank line and before a list item; a wrapped line goes on +_SENTENCE_END = re.compile( + r"(? str: def _renamed( text: str, m: _Move, + moves: Sequence[_Move], spans: Sequence[Span], quoted: Sequence[tuple[int, int]], by_name: Mapping[str, Sequence[Definition]], @@ -252,11 +258,7 @@ def _renamed( to = _respelled(s.name, m) if s.receiver and not any(path_matches(p, f) for f in files for p in (m.was_path, m.path)): why.add("receiver_form") - if any( - names_symbol(s.name, _plain(d.qualified_name), d.path) - for d in by_name.get(bare_name(s.name), ()) - if (d.path, d.qualified_name) != (m.path, m.name) - ): + if _names_another(s.name, m, by_name): why.add("old_name_still_defined") at = resolve(to, by_name.get(new, ()), files) if at is None or (at.path, at.qualified_name) != (m.path, m.name): @@ -266,12 +268,29 @@ def _renamed( # a move keeps the bare name valid: only the spellings it replaces may be left over olds = [old] if old != new else sorted({s.name for s in mine}) news = [new] if old != new else sorted({_respelled(s.name, m) for s in mine}) - why |= _left_over(text, olds, mine, spans, quoted) + # a name that ends in an old spelling holds as it is when it names another + # definition at the head, and is edited by the link whose old definition it names + others = [ + s + for s in spans + if _names_another(s.name, m, by_name) + or any(x != m and x.name and names_symbol(s.name, x.was_name, x.was_path) for x in moves) + ] + why |= _left_over(text, olds, [*mine, *others], spans, quoted) if mine and any(_word(t).search(text) for t in news): why.add("new_name_present") return why +def _names_another(name: str, m: _Move, by_name: Mapping[str, Sequence[Definition]]) -> bool: + """`name` as written names a definition at the head other than the one `m` is at.""" + return any( + names_symbol(name, _plain(d.qualified_name), d.path) + for d in by_name.get(bare_name(name), ()) + if (d.path, d.qualified_name) != (m.path, m.name) + ) + + def _plain(qualified_name: str) -> str: """`qualified_name` without the index's ordinals: `Reader#2::get` is a `Reader::get`.""" return _ORDINAL.sub("", qualified_name) @@ -289,24 +308,24 @@ def _inside(regions: Sequence[tuple[int, int]], start: int, end: int) -> tuple[i def _left_over( text: str, olds: Sequence[str], - mine: Sequence[Span], + covered: Sequence[Span], spans: Sequence[Span], quoted: Sequence[tuple[int, int]], ) -> set[str]: - """Why an old spelling that no edit of `mine` covers withholds the memory. A name - written as code that ends in it and is not edited names another definition.""" + """Why an old spelling withholds the memory, unless it ends one of the `covered` + names: those an edit replaces and those that name other code.""" why: set[str] = set() for spelling in olds: for o in _word(spelling).finditer(text): - if any(s.start <= o.start() and o.end() == s.end for s in mine): + if any(s.start <= o.start() and o.end() == s.end for s in covered): continue - theirs = next((s for s in spans if s.start <= o.start() and o.end() <= s.end), None) if _inside(quoted, *o.span()): why.add("quoted_or_literal") - elif theirs is None: + elif any(s.start <= o.start() and o.end() <= s.end for s in spans): + # `Reader.get` still holds the old `Reader`; `cfg.read_rows()` names nothing + why.add("old_name_remains") + else: why.add("prose_occurrence" if code_shaped(spelling) else "old_name_remains") - elif o.end() != theirs.end: - why.add("old_name_remains") # `Reader.get` still holds the old `Reader` return why @@ -400,7 +419,7 @@ def _in_labels(memory: Mapping[str, Any], m: _Move, alive: bool) -> set[str]: def _sentence(text: str, at: int) -> str: - """The sentence, or line, of `text` that holds position `at`.""" + """The sentence of `text` that holds position `at`.""" start = max((b.end() for b in _SENTENCE_END.finditer(text, 0, at)), default=0) end = _SENTENCE_END.search(text, at) return text[start : end.start() if end else len(text)] diff --git a/tests/unit/test_memory_code_rename_plan.py b/tests/unit/test_memory_code_rename_plan.py index 4354211d09..66a1f05ad3 100644 --- a/tests/unit/test_memory_code_rename_plan.py +++ b/tests/unit/test_memory_code_rename_plan.py @@ -132,6 +132,9 @@ def test_planning_the_revised_text_again_offers_no_edit() -> None: ('the "read_rows" key feeds `read_rows`', "quoted_or_literal"), ("```\nread_rows(conn)\n```\n`read_rows` is hot", "quoted_or_literal"), ("`rows = read_rows(conn)` then `read_rows`", "quoted_or_literal"), + # written as code through something the index does not define + ("`read_rows` retries; call cfg.read_rows() once.", "old_name_remains"), + ("`Reader.read_rows` retries; wrap `conn.read_rows()` in a try.", "old_name_remains"), # the sentence is about the name, or about a point in time ("We should rename `read_rows` to something shorter.", "about_naming"), ("`read_rows`, formerly the slow path, retries.", "about_naming"), @@ -142,10 +145,14 @@ def test_planning_the_revised_text_again_offers_no_edit() -> None: ("The naming of `read_rows` follows the loader.", "about_naming"), ("The helper is called `read_rows`.", "about_naming"), ("`read_rows` is an alias of the loader.", "about_naming"), + # a wrapped line and a one-letter abbreviation do not end the sentence + ("The loader was formerly named\n`read_rows`.", "about_naming"), + ("It was renamed, e.g. `read_rows` retries.", "about_naming"), ("`read_rows` regressed in a1b2c3d4e5.", "dated_claim"), ("`read_rows` retries since v2.3.", "dated_claim"), ("`read_rows` retries, see #1234.", "dated_claim"), ("In March `read_rows` retried twice.", "dated_claim"), + ("In May `read_rows` retried twice.", "dated_claim"), # the new name is there already ("`read_rows` calls `fetch_rows`.", "new_name_present"), ("`read_rows` and the fetch_rows helper.", "new_name_present"), @@ -160,14 +167,21 @@ def test_a_spelling_or_sentence_that_cannot_be_swapped_withholds_the_memory( def test_a_cue_in_another_sentence_does_not_withhold() -> None: - text = "The loader was renamed in 2019. `read_rows` retries twice.\nSee #12 for the loader." - assert _revised(text) == text.replace("read_rows", "fetch_rows") + for text in ( + "The loader was renamed in 2019. `read_rows` retries twice.\nSee #12 for the loader.", + # a blank line and a list item end a sentence that has no full stop + "The loader was renamed\n\n`read_rows` retries twice", + "- the loader was renamed\n- `read_rows` retries twice\n3. see #12", + ): + assert _revised(text) == text.replace("read_rows", "fetch_rows") def test_a_longer_word_that_holds_a_cue_or_a_call_of_the_code_does_not_withhold() -> None: for text in ( "`read_rows` reads the filename, the hostname and the namespace.", "The worker calls `read_rows` twice.", + "`read_rows` may retry twice.", + "May `read_rows` retry twice?", ): assert _revised(text) == text.replace("read_rows", "fetch_rows") @@ -214,6 +228,14 @@ def test_a_name_another_definition_is_written_by_is_left_alone() -> None: assert _revised(text, links=links, defs=[_d(PATH, NEW), other]) == ( "`Writer.read_rows` buffers; `Reader.fetch_rows` retries." ) + # renamed as well, under its own link: each link edits its own name + now = _d("src/io/writer.py", "src.io.writer::Writer::fetch_rows") + links = [RENAMED, _link(now.path, now.qualified_name, was=(other.path, other.qualified_name))] + assert _revised(text, links=links, defs=[_d(PATH, NEW), now]) == ( + "`Writer.fetch_rows` buffers; `Reader.fetch_rows` retries." + ) + # the head no longer defines it and no link follows it + assert _plan(text).reason == "old_name_remains" def test_a_new_name_that_does_not_resolve_to_the_link_withholds() -> None: @@ -298,9 +320,8 @@ def test_a_scope_change_edits_only_the_spellings_that_name_the_old_scope() -> No "`Loader` wraps the socket." ) # a member written through the old class is not this link's to rename - assert _plan("`Reader` wraps; `Reader.get` reads.", links=[link], defs=defs).reason == ( - "old_name_remains" - ) + for text in ("`Reader` wraps; `Reader.get` reads.", "`Reader` wraps; `~Reader` closes."): + assert _plan(text, links=[link], defs=defs).reason == "old_name_remains" # moved to another module under its own name: only a qualified spelling changes moved = _link( "src/net/util.py", "src.net.util::backoff", was=("src/io/util.py", "src.io.util::backoff") From 33a308d09dfe876ef3f753f2adde0cc315b352cd Mon Sep 17 00:00:00 2001 From: Lareb Zafar Date: Sat, 28 Nov 2026 06:33:01 +0530 Subject: [PATCH 4/6] code_rename_edits says an edit's positions count Unicode code points and that the slice must read `old` The planner positions an edit by Python string index, which counts Unicode code points. The guide, the concept page and the finding's `detail` said only "characters", and no step checked the slice. A caller that indexes UTF-16 units or bytes read another slice once the text held a character outside the Basic Multilingual Plane before the edit: for the text " `read_rows` retries" the edit is at 3..12, and a UTF-16 slice of 3..12 is "`read_row". `if_match_sha256` matches the unrevised memory, so memory.update accepted the corrupted text. The guide's step, the concept page, the finding's `detail` and the `Edit` docstring now name the unit, and the step applies nothing unless the text from `start` to `end` reads `old`. The planner's output is unchanged. A unit case plans a text with such a character before the edit. Co-Authored-By: Claude Fable 5.2 Signed-off-by: Lareb Zafar --- docs/concepts/memory.md | 6 +++--- docs/use-cases/memory-linked-to-code.md | 11 +++++++---- server/identity/app/namespace_validate.py | 3 ++- server/memory/domain/code_rename.py | 4 +++- tests/unit/test_memory_code_rename_plan.py | 12 ++++++++++++ 5 files changed, 27 insertions(+), 9 deletions(-) diff --git a/docs/concepts/memory.md b/docs/concepts/memory.md index 169c72e75e..529807aa6d 100644 --- a/docs/concepts/memory.md +++ b/docs/concepts/memory.md @@ -606,9 +606,9 @@ index is a gauge, and a health warning when it lasts A `moved` link is at its code, and the memory's text may still name the old definition or path. `namespace.validate` lists each memory whose text does under the `info` finding -`code_rename_edits`, with either the `edits` its text allows (replace `old` with `new` at -characters `start` to `end`) and the `content_sha256` they are of, or the one `reason` no -edit is offered. The finding's `totals` count the memories by `edits` and by reason. Loom +`code_rename_edits`, with either the `edits` its text allows (replace `old` with `new` +from `start` to `end`, counted in Unicode code points of the text, where the text reads +`old`) and the `content_sha256` they are of, or the one `reason` no edit is offered. The finding's `totals` count the memories by `edits` and by reason. Loom writes nothing: to apply an edit, read the sentence it changes, then call `memory.update` on the key with the revised text and `if_match_sha256` set to the listed hash. That is a revision by the caller, with its conflict check, and it is refused when the memory changed diff --git a/docs/use-cases/memory-linked-to-code.md b/docs/use-cases/memory-linked-to-code.md index 972a9f67f4..25f279cfee 100644 --- a/docs/use-cases/memory-linked-to-code.md +++ b/docs/use-cases/memory-linked-to-code.md @@ -146,10 +146,13 @@ not rewrite it; `namespace.validate` lists what a rewrite would be: 1. Call `namespace.validate` on the memory namespace (with `keys` to check the lessons one session wrote) and read the `code_rename_edits` finding. Each sample is one lesson with either `edits` and a `content_sha256`, or a `reason`. -2. For a lesson with `edits`, replace `old` with `new` at characters `start` to `end` of - its text, applying the last edit first so the earlier positions hold. Read the edited - sentence: an edit is offered on the spelling and the index, and whether the claim - survives the swap is yours to judge. +2. For a lesson with `edits`, `start` and `end` count Unicode code points of its text (a + Python string index; not the UTF-16 units of a JavaScript string, nor bytes). Check + that the text from `start` to `end` reads `old`, and apply nothing when it does not: + the positions were counted in another unit. Then replace it with `new`, applying the + last edit first so the earlier positions hold. Read the edited sentence: an edit is + offered on the spelling and the index, and whether the claim survives the swap is + yours to judge. 3. Call `memory.update` on the key with the revised text and `if_match_sha256` set to the sample's `content_sha256`. A lesson that changed since the report returns `409`; run the report again. diff --git a/server/identity/app/namespace_validate.py b/server/identity/app/namespace_validate.py index bc6f2a3275..312ecb6b08 100644 --- a/server/identity/app/namespace_validate.py +++ b/server/identity/app/namespace_validate.py @@ -506,7 +506,8 @@ async def _code_links_stale(params: dict[str, Any]) -> list[dict[str, Any]]: "info", "A memory whose linked code was renamed or moved and followed there: the link is at " "the new name or path and the memory's text still says the old one. Each sample " - "carries either `edits` (replace `old` with `new` at `start`..`end` of the text) " + "carries either `edits` (replace `old` with `new` at `start`..`end` of the text, " + "counted in Unicode code points; apply none unless that slice reads `old`) " "with the `content_sha256` they are of, or the `reason` no edit is offered; `totals` " "counts the memories by `edits` and by reason. Nothing is written: to apply, read " "the edited sentence, then memory.update the key with the revised text and " diff --git a/server/memory/domain/code_rename.py b/server/memory/domain/code_rename.py index b153e702b1..16a0ea194c 100644 --- a/server/memory/domain/code_rename.py +++ b/server/memory/domain/code_rename.py @@ -89,7 +89,9 @@ class Edit(NamedTuple): - """Replace `text[start:end]`, which reads `old`, with `new`.""" + """Replace `text[start:end]`, which reads `old`, with `new`. The positions count + Unicode code points, as a Python string index does: a caller that indexes UTF-16 + units or bytes converts them, and checks the slice against `old`.""" start: int end: int diff --git a/tests/unit/test_memory_code_rename_plan.py b/tests/unit/test_memory_code_rename_plan.py index 66a1f05ad3..3f1f907816 100644 --- a/tests/unit/test_memory_code_rename_plan.py +++ b/tests/unit/test_memory_code_rename_plan.py @@ -111,6 +111,18 @@ def test_text_outside_the_edits_is_byte_identical() -> None: assert revised(text, planned.edits) == text.replace("`read_rows`", "`fetch_rows`") +def test_an_edit_is_positioned_in_unicode_code_points() -> None: + """A character outside the Basic Multilingual Plane before the edit is one position, + not the two UTF-16 units or four bytes it takes elsewhere.""" + text = "\U0001f680 `read_rows` retries." + (edit,) = _plan(text).edits + assert (edit.start, edit.end, edit.old) == (3, 12, "read_rows") + assert text[edit.start : edit.end] == edit.old + utf16 = text.encode("utf-16-le") + assert utf16[2 * edit.start : 2 * edit.end].decode("utf-16-le") == "`read_row" + assert revised(text, [edit]) == "\U0001f680 `fetch_rows` retries." + + def test_planning_the_revised_text_again_offers_no_edit() -> None: text = "`Reader.read_rows` retries; `read_rows` backs off." after = _revised(text) From 14efe188dd1db7738b8691fab15655eba7ca9c7b Mon Sep 17 00:00:00 2001 From: Lareb Zafar Date: Sat, 28 Nov 2026 07:11:34 +0530 Subject: [PATCH 5/6] A rename plan lists only a memory whose text names something old A reason the links, the key, a tag or `files` give (`link_not_settled`, `incomplete`, `named_in_key_or_tags`, `named_in_files`, and `overloaded` for a numbered definition) was returned before the text was found to write an old name, so `code_rename_edits` listed and counted memories whose text holds as it is. Such a plan is `no_code_token`, which the listing skips. Two cases withheld an edit the text allows: - the module a definition left, written as the start of a name that names another definition at the head (`io.util.helper` after `backoff` moved to `net.util`), read as `old_name_remains`; - a blank line written `\r\n\r\n`, which did not end a sentence, so a naming or dating cue in the paragraph before withheld the edit. Co-Authored-By: Claude Fable 5.2 Signed-off-by: Lareb Zafar --- docs/concepts/memory.md | 47 +++++++++++----------- server/memory/domain/code_rename.py | 41 +++++++++++++------ tests/unit/test_memory_code_rename_plan.py | 30 ++++++++++++++ 3 files changed, 83 insertions(+), 35 deletions(-) diff --git a/docs/concepts/memory.md b/docs/concepts/memory.md index 003266a5d6..586bd1058f 100644 --- a/docs/concepts/memory.md +++ b/docs/concepts/memory.md @@ -651,29 +651,30 @@ spelling the text uses: `Reader.get` becomes `Reader.fetch`, a full dotted name full new one, and `self.get` keeps its receiver. The whole memory gets no edit for the first of these reasons that applies: -| Reason | The memory | -| ------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `not_text` | has a value that is not one string. | -| `link_not_settled` | has a link that is pending, `changed`, `unresolved` or `missing`, that its renamed class carried, or that is hashed under older fingerprint rules. | -| `incomplete` | names more code than the link caps keep. | -| `overloaded` | is linked to a definition the index numbers among several of one name. | -| `quoted_or_literal` | holds the old name or path in a fenced block, a URL, a quoted string or a backticked span that is more than one name. | -| `prose_occurrence` | writes the old name as a bare word of the prose. | -| `old_name_remains` | would still hold the old name or path where no edit reaches: a plain word, a part of a longer name, a longer name written as code that names no definition on the indexed trunk (`conn.read_rows()`), the dotted module the definition left (two segments or more), a path before a line number, or a path whose file still exists. | -| `names_several` | writes one name that two of its links were written against. | -| `receiver_form` | writes the name as `self.name`, `cls.name` or `this.name`, and its `files` do not name the defining file. | -| `old_name_still_defined` | spells the old name in a way that still names a definition on the indexed trunk. | -| `new_name_present` | already holds the new name or path. | -| `dated_claim` | is dated (`valid_to`, `invalid_at` or `temporal_anchor`), or the sentence to edit holds a commit hash, a version tag, a year, a month (`May` only capitalised after another word), or a pull request or issue number. | -| `about_naming` | would be edited in a sentence about the name or the place: it holds `name`, `names`, `named`, `naming`, a word that starts with `renam` or `alias`, `called`, `formerly`, `used to`, `replaced`, `moved from`, `deprecated`, `legacy`, `before` or `previously`. | -| `named_in_key_or_tags` | holds the old name or path in its `memory_key` or a tag. | -| `named_in_files` | lists the old path in `files`, which `memory.update` keeps. | -| `would_unlink` | would lose a link once revised: the new name is not one definition on the indexed trunk, or the revised text no longer names a definition or file it is linked to. | - -A memory whose text names no old name or path is not listed: its bare name still holds -after a move, or the link is back where the text says. A sentence ends after `.`, `!` or -`?` and a space (not after a one-letter abbreviation such as `e.g.`), at a blank line and -before a list item; a line break alone does not end one. The words that mark a sentence as +| Reason | The memory | +| ------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `not_text` | has a value that is not one string. | +| `link_not_settled` | has a link that is pending, `changed`, `unresolved` or `missing`, that its renamed class carried, or that is hashed under older fingerprint rules. | +| `incomplete` | names more code than the link caps keep. | +| `overloaded` | is linked to a definition the index numbers among several of one name. | +| `quoted_or_literal` | holds the old name or path in a fenced block, a URL, a quoted string or a backticked span that is more than one name. | +| `prose_occurrence` | writes the old name as a bare word of the prose. | +| `old_name_remains` | would still hold the old name or path where no edit reaches: a plain word, a part of a longer name, a longer name written as code that names no definition on the indexed trunk (`conn.read_rows()`), the dotted module the definition left (two segments or more) outside a name written as code that names a definition on the indexed trunk, a path before a line number, or a path whose file still exists. | +| `names_several` | writes one name that two of its links were written against. | +| `receiver_form` | writes the name as `self.name`, `cls.name` or `this.name`, and its `files` do not name the defining file. | +| `old_name_still_defined` | spells the old name in a way that still names a definition on the indexed trunk. | +| `new_name_present` | already holds the new name or path. | +| `dated_claim` | is dated (`valid_to`, `invalid_at` or `temporal_anchor`), or the sentence to edit holds a commit hash, a version tag, a year, a month (`May` only capitalised after another word), or a pull request or issue number. | +| `about_naming` | would be edited in a sentence about the name or the place: it holds `name`, `names`, `named`, `naming`, a word that starts with `renam` or `alias`, `called`, `formerly`, `used to`, `replaced`, `moved from`, `deprecated`, `legacy`, `before` or `previously`. | +| `named_in_key_or_tags` | holds the old name or path in its `memory_key` or a tag. | +| `named_in_files` | lists the old path in `files`, which `memory.update` keeps. | +| `would_unlink` | would lose a link once revised: the new name is not one definition on the indexed trunk, or the revised text no longer names a definition or file it is linked to. | + +A memory whose text names no old name or path is not listed, whatever its links, key, tags +and `files` say: its bare name still holds after a move, or the link is back where the text +says. A sentence ends after `.`, `!` or `?` and a space (not after a one-letter abbreviation +such as `e.g.`), at a blank line and before a list item; a line break alone does not end +one. The words that mark a sentence as being about the name are English, and `call` or `calls` is not one: it is read as calling the code. The finding reads the 2,000 memories whose `moved` link was last checked (all under `keys` when given), in the repositories the caller may read, and no high-sensitivity diff --git a/server/memory/domain/code_rename.py b/server/memory/domain/code_rename.py index 16a0ea194c..16fa60add8 100644 --- a/server/memory/domain/code_rename.py +++ b/server/memory/domain/code_rename.py @@ -56,6 +56,9 @@ ) # the reason of a memory whose text holds as it is UNNAMED = REASONS[-1] +# the reasons the links, the labels and `files` give whatever the text says: they +# withhold only a text that names something old +_UNWRITTEN = frozenset({"link_not_settled", "incomplete", "named_in_key_or_tags", "named_in_files"}) # what makes a sentence a statement about a point in time: a commit, a version tag, a # year, a month, a pull request or issue. `May` is the month only capitalised after @@ -77,9 +80,10 @@ re.IGNORECASE, ) # a sentence ends after `.`, `!` or `?` and a space (not after a one-letter abbreviation: -# `e.g.`, `i.e.`), at a blank line and before a list item; a wrapped line goes on +# `e.g.`, `i.e.`), at a blank line (`\r\n` ends a line too) and before a list item; a +# wrapped line goes on _SENTENCE_END = re.compile( - r"(? set[str]: """Add to `edits` the names in `text` that spell the old definition of `m` and not the new one, each as the same spelling of the new one; the reasons they withhold.""" - if _plain(m.was_name) != m.was_name or _plain(m.name) != m.name: - return {"overloaded"} - why: set[str] = set() - old, new = bare_name(m.was_name), bare_name(m.name) + was, now = _plain(m.was_name), _plain(m.name) + old, new = bare_name(was), bare_name(now) mine = [ s for s in spans - if names_symbol(s.name, m.was_name, m.was_path) and not names_symbol(s.name, m.name, m.path) + if names_symbol(s.name, was, m.was_path) and not names_symbol(s.name, now, m.path) ] + if (was, now) != (m.was_name, m.name): + # one of several under its name: withheld where the text writes the old one + return {"overloaded"} if mine or (old != new and _word(old).search(text)) else set() + why: set[str] = set() for s in mine: to = _respelled(s.name, m) if s.receiver and not any(path_matches(p, f) for f in files for p in (m.was_path, m.path)): @@ -346,19 +352,30 @@ def _old_modules( text: str, moves: Sequence[_Move], edited: Sequence[tuple[int, int]], + spans: Sequence[Span], quoted: Sequence[tuple[int, int]], + by_name: Mapping[str, Sequence[Definition]], ) -> set[str]: """Why a module a definition of `moves` left withholds the memory: `text` writes it, over more than one segment, outside the `edited` spans (an import, a sentence about the place), so the revised text would name both places. One segment is as often a - word of the prose.""" + word of the prose, and a name written as code that names a definition at the head + (another one still in that module) holds as it is.""" why: set[str] = set() + held = [ + (s.start, s.end) + for s in spans + if any( + names_symbol(s.name, _plain(d.qualified_name), d.path) + for d in by_name.get(bare_name(s.name), ()) + ) + ] for m in moves: left = _modules(m.was_path, m.was_name) - _modules(m.path, m.name) if m.name else set() for module in (x for x in left if "." in x): spelled = re.escape(module).replace(r"\.", r"(?:\.|::)") for o in re.finditer(rf"(? None: "The loader was renamed in 2019. `read_rows` retries twice.\nSee #12 for the loader.", # a blank line and a list item end a sentence that has no full stop "The loader was renamed\n\n`read_rows` retries twice", + "The loader was renamed\r\n\r\n`read_rows` retries twice", "- the loader was renamed\n- `read_rows` retries twice\n3. see #12", ): assert _revised(text) == text.replace("read_rows", "fetch_rows") @@ -368,6 +369,14 @@ def test_the_module_a_definition_left_withholds_where_no_edit_reaches_it() -> No assert _revised(text, links=[moved, jitter], defs=both) == ( "`src.net.util.backoff` and `src.net.util.jitter` double." ) + # a name written as code that the old module still defines holds as it is + text = "`io.util.backoff` doubles; `io.util.helper` and src::io::util::helper() do not." + stays = [*defs, _d(was, "src.io.util::helper")] + assert _revised(text, links=[moved], defs=stays) == text.replace( + "io.util.backoff", "net.util.backoff" + ) + # the index defines no such name: the text may be about the place + assert _plan(text, links=[moved], defs=defs).reason == "old_name_remains" def test_a_renamed_file_edits_its_whole_path_once_the_old_one_is_gone() -> None: @@ -414,6 +423,27 @@ def test_files_and_labels_that_name_the_old_path_withhold() -> None: assert _plan("`src/reader.py` holds it.", files=[], **kw).reason == "would_unlink" +def test_a_text_that_names_nothing_old_holds_whatever_its_links_and_labels_say() -> None: + """A reason the links, the key, a tag or `files` give withholds an edit: a text with + no old name or path in it has none, and its memory is not listed.""" + holds = Plan(reason="no_code_token") + text = "`Reader` wraps the socket." + other = _link("src/io/writer.py", "src.io.writer::Writer::flush") + for fields in ({"state": "changed"}, {"complete": 0}): + assert _plan(text, links=[RENAMED, other | fields]) == holds + assert _plan(text, memory_key="repo/lesson/read_rows-retry", tags=["read_rows"]) == holds + numbered = _link(PATH, NEW, was=(PATH, OLD + "#2")) + assert _plan(text, links=[numbered]) == holds + was = "src/io/reader.py" + kw: dict[str, Any] = {"links": [_link("src/io/read.py", "", was=(was, ""))], "defs": []} + assert _plan("The retry loop is hot.", files=[was], gone=(was,), **kw) == holds + # the old name where no edit reaches it is something old: the reason is given + assert _plan("read_rows retries.", links=[numbered]).reason == "overloaded" + assert _plan("read_rows retries.", links=[RENAMED, other | {"complete": 0}]).reason == ( + "incomplete" + ) + + def test_a_link_back_where_it_was_written_or_reanchored_gets_no_edit() -> None: # renamed and renamed back: the text names it back = _link(PATH, OLD, state="moved", anchored_name=NEW, former=[_former(PATH, OLD)]) From 64d0e4c860678f79aa7616ccb400d66b6e4ff647 Mon Sep 17 00:00:00 2001 From: Lareb Zafar Date: Sat, 28 Nov 2026 07:14:29 +0530 Subject: [PATCH 6/6] A rename edit keeps a whole C++ name whole and reads the new path only as a path of its own A C or C++ name carries no module part, so the whole old name was respelled with as many segments as it wrote: `ns::Reader::get` became `io::Reader::get` when the definition moved to `ns::io::Reader::get`. The whole old name is the whole new one in every language. `new_name_present` was a substring test on the new path, so `test/src/util.py` or `src/util.pyc` withheld the edit to `src/util.py`. The new path counts where it is written as a path of its own, a line number after it included. Co-Authored-By: Claude Fable 5.2 Signed-off-by: Lareb Zafar --- server/memory/domain/code_rename.py | 11 ++++++++--- tests/unit/test_memory_code_rename_plan.py | 22 ++++++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/server/memory/domain/code_rename.py b/server/memory/domain/code_rename.py index 16fa60add8..a42d390ba4 100644 --- a/server/memory/domain/code_rename.py +++ b/server/memory/domain/code_rename.py @@ -219,7 +219,8 @@ def _respelled(written: str, m: _Move) -> str: as `written` joins it. A name written inside its module (`get`, `Reader.get`) keeps as many segments. One written with its module names the whole new name inside the new module, under as many module segments, and under the whole module when it wrote - the whole old one: a full dotted name stays one.""" + the whole old one: a full dotted name stays one, also where no part of it is the + module (C and C++).""" dotted = written.replace("::", ".") old, new = _forms(m.was_path, m.was_name), _forms(m.path, m.name) at = next((i for i, f in enumerate(old) if f == dotted or f.endswith("." + dotted)), 0) @@ -227,7 +228,9 @@ def _respelled(written: str, m: _Move) -> str: local = local_name(m.name, m.path).split(".") joins = _JOIN.findall(written) over = len(joins) + 1 - len(was_local) # the module segments it wrote - if over <= 0: + if dotted == old[0]: + parts = new[0].split(".") + elif over <= 0: parts = local[-(len(joins) + 1) :] else: module = new[min(at, len(new) - 1)].split(".")[: -len(local)] @@ -414,7 +417,9 @@ def _repathed( continue literal = not alive and _inside(quoted, *o.span()) why.add("quoted_or_literal" if literal else "old_name_remains") - if mine and m.path in text: + # the new path inside a longer one (`test/src/util.py`, `src/util.pyc`) is another file + present = rf"(? No assert _plan(text, links=[moved], defs=defs).reason == "old_name_remains" +def test_a_whole_name_with_no_module_part_becomes_the_whole_new_name() -> None: + # C++ names carry no path: the whole old name gains the namespace the new one has + path = "src/reader.cpp" + link = _link(path, "ns::io::Reader::get", was=(path, "ns::Reader::get")) + kw: dict[str, Any] = {"links": [link], "defs": [_d(path, "ns::io::Reader::get")]} + assert _revised("`ns::Reader::get` retries.", **kw) == "`ns::io::Reader::get` retries." + assert _revised("ns.Reader.get() retries.", **kw) == "ns.io.Reader.get() retries." + # a shorter spelling still names the new one: nothing to edit + assert _plan("`Reader::get` retries.", **kw) == Plan(reason="no_code_token") + back = _link(path, "ns::Reader::get", was=(path, "ns::io::Reader::get")) + kw = {"links": [back], "defs": [_d(path, "ns::Reader::get")]} + assert _revised("`ns::io::Reader::get` retries.", **kw) == "`ns::Reader::get` retries." + assert _revised("`io::Reader::get` retries.", **kw) == "`ns::Reader::get` retries." + + def test_the_module_a_definition_left_withholds_where_no_edit_reaches_it() -> None: was, now = "src/io/util.py", "src/net/util.py" moved = _link(now, "src.net.util::backoff", was=(was, "src.io.util::backoff")) @@ -421,6 +436,13 @@ def test_files_and_labels_that_name_the_old_path_withhold() -> None: ) # no file of the memory names the file link's path any more assert _plan("`src/reader.py` holds it.", files=[], **kw).reason == "would_unlink" + # the new path as a path of its own is there already; inside a longer one it is not + for also in ("lib/reader.py:12", "`lib/reader.py`", "./lib/reader.py", "/lib/reader.py."): + text = f"`src/reader.py` holds it; see {also}" + assert _plan(text, files=["reader.py"], **kw).reason == "new_name_present", text + for also in ("test/lib/reader.py", "lib/reader.pyc", "https://example.org/lib/reader.py"): + text = f"`src/reader.py` holds it; see {also}" + assert _revised(text, files=["reader.py"], **kw) == text.replace("`src/", "`lib/"), text def test_a_text_that_names_nothing_old_holds_whatever_its_links_and_labels_say() -> None: