Skip to content

Commit 9ffd9a8

Browse files
zlareb1claude
andcommitted
Merge origin/main into fix/plugin-hooks-do-not-hold-the-session
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
2 parents 910d843 + 6fcd290 commit 9ffd9a8

24 files changed

Lines changed: 3700 additions & 781 deletions

‎docs/architecture/rolling-upgrades.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,15 @@ See the [participant lifecycle baseline](cells.md#participant-lifecycle-baseline
960960
the saga on those in `code_chunks` and `code_summaries`, and it is repeated. No gate
961961
holds the rollout.
962962

963+
66. **A definition renamed as it moves to another file or scope**
964+
(`server/code/domain/successor.py::elsewhere`): N's link recheck follows it; N-1's
965+
reads the link `missing`, as before. One host rechecks a repository at a time, so a
966+
range is read by one build. A `missing` link is never handed to a definition added
967+
since, so a link N-1 read `missing` during the rollout stays `missing` under N
968+
until its own name returns. The link rows are unchanged; `wide_ranges` is one more
969+
number in the `memory_code_links` pass outcome, which every build serves as stored. No gate holds the
970+
rollout.
971+
963972
## What checks them
964973

965974
`scripts/gates/mixed_version.py` (`make test-mixed-version`, the `mixed-version` CI job,

‎docs/concepts/memory.md‎

Lines changed: 77 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -465,12 +465,34 @@ A memory's detail in the dashboard lists these links with their state
465465
([clip](../assets/screenshots/clip-memory-linked-code.webm)).
466466

467467
A link follows its definition through file moves, renames (with an edit, when the new
468-
name is related to the old), and its class's rename within the file. A namesake in
469-
another class or namespace never inherits a link, and a `missing` link comes back only
470-
when its own name does. A definition moved to another file under its own name with an edit is followed
471-
there when its text is close to the one the link last read. A new definition left where
472-
it was stops that search only when it may be the old one under a new name: an export
473-
list or an unrelated function added beside it does not. A name gone from its file is
468+
name is related to the old), and its class's rename within the file. A definition
469+
renamed as it moves to another file, class or namespace is looked for among the
470+
definitions the changed files did not have before: the only one with its tokens under
471+
another name reads `moved`; failing that, the only one of its own name with a close text
472+
reads `changed`, unless a definition of that name that stayed in the changed files is
473+
close as well. A member reads `changed` there unless its class came with it unchanged. A
474+
definition under 30 tokens is told by neither its text nor its own name, which any class
475+
may define: it is followed there only under a name of the same words (`_read_rows` or
476+
`read_rows_v2` for `read_rows`) and with its scope, from module level to module level
477+
or, once no member of its class is left in its file, into the class that is that one
478+
renamed or keeps its members. Two definitions that may be it,
479+
or one that another removed definition may have become, leave the link `unresolved`. A
480+
range that changed more than 32 files under the entry's `path_prefixes` is not searched
481+
this way, and a warning in the server log names it; nor is a range whose diff cannot be
482+
read. Over such a range a live link is read as if nothing was renamed. An `unresolved`
483+
link is looked for from the commit its code was last read at, so its range grows with
484+
every commit. While that range is searched, the link is followed once one definition
485+
that may be it is left. Over a range that is not searched it stays `unresolved`, and no
486+
later commit narrows that range. The `memory_code_links` worker's pass outcome counts in
487+
`wide_ranges` the ranges its own pass followed, not those a `code.refresh` call followed
488+
first. A
489+
namesake that was already there never inherits a link, and a `missing` link comes back
490+
only when its own name does. A definition moved to another file under its own name with
491+
an edit is followed there when its text is close to the one the link last read. A new
492+
definition left where it was stops that search only when it may be the old one under a
493+
new name: an export list or an unrelated function added beside it does not. The search
494+
for a definition renamed as it moved is not made past a new definition left there,
495+
unless that one is another definition renamed alone. A name gone from its file is
474496
looked for in the files changed
475497
since its last check as the mirror holds them, beside the index, so a definition moved by
476498
a commit the index has not taken in whole (past `code_ingest_max_files_per_commit`) is
@@ -615,7 +637,8 @@ The links are read where the code is:
615637
the memories whose code moved, changed or went, with the same clause for a link now at
616638
another path or symbol.
617639
- `namespace.validate` lists memories whose code changed, was not found again or is
618-
gone, in the repositories the caller may read.
640+
gone, in the repositories the caller may read, and the edits that bring a memory's
641+
text up to a rename its link followed.
619642

620643
A memory with no link reads exactly as one whose code is current. `namespace.validate`
621644
counts the served memories that name code (a backticked or qualified name, a call, or
@@ -634,6 +657,53 @@ linked, is not counted. How far each repository's links trail its
634657
index is a gauge, and a health warning when it lasts
635658
([monitoring](../operations/monitoring.md#what-to-alert-on)).
636659

660+
A `moved` link is at its code, and the memory's text may still name the old definition or
661+
path. `namespace.validate` lists each memory whose text does under the `info` finding
662+
`code_rename_edits`, with either the `edits` its text allows (replace `old` with `new`
663+
from `start` to `end`, counted in Unicode code points of the text, where the text reads
664+
`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
665+
writes nothing: to apply an edit, read the sentence it changes, then call `memory.update`
666+
on the key with the revised text and `if_match_sha256` set to the listed hash. That is a
667+
revision by the caller, with its conflict check, and it is refused when the memory changed
668+
after the report read it. The link pass then links the revised memory where the code is.
669+
670+
An edit is offered only for a name written as code (a whole backticked identifier, an
671+
`A::b`, or a call written `a.b(` or `name()`) and for a whole repository path, in the
672+
spelling the text uses: `Reader.get` becomes `Reader.fetch`, a full dotted name becomes the
673+
full new one, and `self.get` keeps its receiver. The whole memory gets no edit for the
674+
first of these reasons that applies:
675+
676+
| Reason | The memory |
677+
| ------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
678+
| `not_text` | has a value that is not one string. |
679+
| `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. |
680+
| `incomplete` | names more code than the link caps keep. |
681+
| `overloaded` | is linked to a definition the index numbers among several of one name. |
682+
| `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. |
683+
| `prose_occurrence` | writes the old name as a bare word of the prose. |
684+
| `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. |
685+
| `names_several` | writes one name that two of its links were written against. |
686+
| `receiver_form` | writes the name as `self.name`, `cls.name` or `this.name`, and its `files` do not name the defining file. |
687+
| `old_name_still_defined` | spells the old name in a way that still names a definition on the indexed trunk. |
688+
| `new_name_present` | already holds the new name or path. |
689+
| `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. |
690+
| `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`. |
691+
| `named_in_key_or_tags` | holds the old name or path in its `memory_key` or a tag. |
692+
| `named_in_files` | lists the old path in `files`, which `memory.update` keeps. |
693+
| `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. |
694+
695+
A memory whose text names no old name or path is not listed, whatever its links, key, tags
696+
and `files` say: its bare name still holds after a move, or the link is back where the text
697+
says. A sentence ends after `.`, `!` or `?` and a space (not after a one-letter abbreviation
698+
such as `e.g.`), at a blank line and before a list item; a line break alone does not end
699+
one. The words that mark a sentence as
700+
being about the name are English, and `call` or `calls` is not one: it is read as calling
701+
the code. The finding reads the 2,000 memories whose `moved` link was last checked (all
702+
under `keys` when given), in the repositories the caller may read, and no high-sensitivity
703+
memory; a link whose code also changed is listed under `code_links_stale`. Neither the
704+
memory's key, tags, `files`, entities and concepts nor a line number written in its text
705+
is edited.
706+
637707
## Time
638708

639709
| Column | Axis | Meaning |

‎docs/use-cases/memory-linked-to-code.md‎

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@ reported commit](#check-a-lesson-after-a-code-edit).
3333
- **Links that follow refactors.** On every indexed commit, each link reads `fresh`,
3434
`moved`, `changed` (naming the commit that changed it), `unresolved` or `missing`. A link
3535
records the definition's tokens, so whitespace, comments and most formatter changes leave
36-
it `fresh`. A link to a file follows the lines that hold a name the memory cites, and
37-
is replaced by a link to a definition the memory names once the file defines it.
36+
it `fresh`. A definition renamed as it moves to another file or class is followed
37+
when one new definition there is it: `moved` with the same tokens, `changed` with an
38+
edit or outside its class. A link to a file follows the lines that hold a name the
39+
memory cites, and is replaced by a link to a definition the memory names once the
40+
file defines it.
3841
[Link states](../concepts/memory.md#memories-linked-to-code)
3942
- **The current name beside a memory written against the old one.** A rename leaves the
4043
memory's text as it was written. These reads name where the code is now:
@@ -86,6 +89,9 @@ reported commit](#check-a-lesson-after-a-code-edit).
8689
[`namespace.validate`](../reference/operations/namespace.md#namespacevalidate) lists the
8790
memories whose code changed, was not found again or is gone, and the dashboard shows each
8891
memory's links and their state.
92+
- **The edit a rename allows.** After a rename or a move the link follows, the same report
93+
lists the exact token edits that bring the memory's text up to date, or the reason it
94+
offers none. [Bring a lesson's text up to a rename](#bring-a-lessons-text-up-to-a-rename)
8995

9096
![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)
9197

@@ -150,6 +156,44 @@ tool selection are not tested.
150156
For removal, held-memory exceptions and model-backed revision, see the
151157
[link policies](../concepts/memory.md#memories-linked-to-code).
152158

159+
## Bring a lesson's text up to a rename
160+
161+
When a definition is renamed or moved with nothing else changed, its link follows it and
162+
reads `moved`. A lesson that wrote the old name, module or path still says it. Loom does
163+
not rewrite it; `namespace.validate` lists what a rewrite would be:
164+
165+
1. Call `namespace.validate` on the memory namespace (with `keys` to check the lessons
166+
one session wrote) and read the `code_rename_edits` finding. Each sample is one lesson
167+
with either `edits` and a `content_sha256`, or a `reason`.
168+
2. For a lesson with `edits`, `start` and `end` count Unicode code points of its text (a
169+
Python string index; not the UTF-16 units of a JavaScript string, nor bytes). Check
170+
that the text from `start` to `end` reads `old`, and apply nothing when it does not:
171+
the positions were counted in another unit. Then replace it with `new`, applying the
172+
last edit first so the earlier positions hold. Read the edited sentence: an edit is
173+
offered on the spelling and the index, and whether the claim survives the swap is
174+
yours to judge.
175+
3. Call `memory.update` on the key with the revised text and `if_match_sha256` set to the
176+
sample's `content_sha256`. A lesson that changed since the report returns `409`; run
177+
the report again.
178+
4. After the next link pass the lesson is linked at the new name and reads `fresh`, and
179+
the finding lists it no more.
180+
181+
A lesson with a `reason` gets no edit: the old name is a word of the prose, sits in a
182+
quoted snippet, still names another definition, or the sentence is about the name itself
183+
([every reason](../concepts/memory.md#memories-linked-to-code)). Check it against the code
184+
and rewrite it by hand.
185+
186+
The finding's `totals` count a namespace's lessons by `edits` and by reason: how often a
187+
mechanical edit is offered there, and what stops the rest. Applying the edits without a
188+
person reading them is worth considering only for a namespace whose `totals` come from its
189+
own lessons and where at least 100 listed edits were checked by hand against the lesson
190+
text with none wrong.
191+
192+
The `test_validate_lists_the_edit_a_followed_rename_allows_and_an_update_applies_it`
193+
[integration regression](https://github.com/ClickHouse/loom/blob/main/tests/integration/test_memory_code_links.py)
194+
renames a function, reads the listed edit, applies it with `memory.update` and checks the
195+
link at the new name.
196+
153197
## Compare a code-linked lesson across branches
154198

155199
When trunk and a maintained release branch diverge, a lesson can still apply to one of

‎sdk/python/loom/ops.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18189,6 +18189,7 @@ class NamespaceValidateFinding(TypedDict, total=False):
1818918189
count: Required[int]
1819018190
samples: NotRequired[list[dict[str, Any]]]
1819118191
detail: Required[str]
18192+
totals: NotRequired[dict[str, int]]
1819218193

1819318194

1819418195
class ObserveCrystallizeInput(TypedDict, total=False):

0 commit comments

Comments
 (0)