Skip to content

A definition declares the team or product it applies to, and declared differences read as alternatives - #2378

Merged
zlareb1 merged 6 commits into
mainfrom
feat/definition-applies-to
Dec 6, 2026
Merged

zlareb1 merged 6 commits into
mainfrom
feat/definition-applies-to

Conversation

@zlareb1

@zlareb1 zlareb1 commented Dec 6, 2026 •

Copy link
Copy Markdown
Member

Related: #1765
Related: #1232

Changelog category (leave one):

  • New Feature

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

A definition can say which team or product it is for (applies_to in its value), and memory.definitions.disputes reports a name whose differing definitions each declare another team or product as alternatives instead of a dispute to correct. The Review queue's Definitions tab shows what each definition applies to, lists the names that need review first, and lets a writer declare the team and product.

Why

Two teams can each define one name differently on purpose. memory.definitions.disputes compares text only, so every such pair read as a dispute, and the only ways out of the list were to make the texts equal or delete one. A declared scope lets the definitions stay different and tells a reader which case they are looking at.

Scope and risk

Design in brief:

  • The scope. applies_to is a key of the definition's stored value: an object of team, product or both, each a string of at most 64 characters. There is no table, column, migration or setting. Anything else under applies_to (another key, a value that is no string or is longer) declares nothing, so a misspelled key separates no definitions. A blank value declares nothing for its key only, and the other key still counts.
  • The rule. Two claims are separated when both declare team, or both declare product, with different values. Values are compared with the helper that folds a definition's names (fold_name: format characters dropped, NFKC, trimmed, runs of whitespace made one space, case-folded), so Finance and FINANCE are one team. A scope on one side only, and team on one side against product on the other, separate nothing. A dispute is alternatives when every two claims whose texts differ are separated; two claims with the same text need no separation from each other. Everything else is suspected, which is what every dispute was.
  • The bound. Each pair of claims looked at costs 16 characters of the request's existing work bound (256 KiB, shared with the names and the text read), so the whole bound pays for 16,384 pair checks, and the loop gets a turn before each dispute. A dispute whose pairs the bound does not pay for is suspected: the answer never says alternatives for pairs it did not check.
  • Belief revision. Declaring a scope is a Revise of the definition: memory.set on its key with the claim's content_sha256 as if_match_sha256. A governed definition lapses as changed until an admin promotes the edited text, as for any edit. A name keeps one shared definition: promoting a second, scoped or not, is refused with 409 DEFINITION_NAME_TAKEN, which is unchanged behaviour that the new integration test pins.

What it touches:

  • server/memory/domain/definition_disputes.py (claim_of reads the scope; separated, dispute_state), server/memory/app/definition_disputes.py (the bounded state pass), server/memory/api/models_lifecycle.py (the two fields). The locate statement and every other statement are unchanged.
  • Dashboard: frontend/src/views/admin/Definitions.tsx (the Applies to line and dialog, the badges, the order), frontend/src/api/definitions.ts (declareAppliesTo), frontend/src/api/memory.ts (rowFields: the fields of a row that a write of a new version sends back, which pinMemory and the dialog share), and one rule in frontend/src/components/MemoryInspector.tsx: Save refuses text that does not parse as JSON over a stored object, with a field error and no write. Saved as typed, such text replaced the object with a string.

Left alone: comparing definitions across namespaces, a state that allows both definitions without a scope, validation of applies_to at write time (a value the read does not accept is stored and reads as not declared; the dialog refuses a name over 64 characters), the drawer's handling of text that parses as JSON, and the drawer's Save, tag and expiry writes, which send the row's type, tags and character limit only.

What could break:

  • A definition that already holds an applies_to object of that shape starts to be read as a scope. Only a dispute's state changes; no row, search result or promotion rule does.
  • memory.set builds the whole new version from its input, so the dialog sends the row's other fields back with the value, as a pin does: type, tags, entities, confidence, sensitivity label, source trace, source resource, a source class a caller may declare, the validity window and the character limit. Declaring a scope changes the scope only: a definition with an end date keeps it. A copy rule's mark on the source trace is left out, since memory.set refuses it from a caller and the edited value is no longer the text the rule's run wrote. The concepts page names the same fields for a caller of memory.set, with the two values the op refuses from a caller: a source class the server decides and a copy rule's mark.
  • A definition edited between the list read and Save is refused by the hash and the dialog says so; nothing is written over another person's edit. The dialog is drawn outside the states of the list read, so it stays open, with its reason and the names typed, when the read after a refusal fails.
  • The dashboard's index chunk stays at 112.4 kB of its 120 kB budget: the dialog is in the Review queue's own chunk and the memory client in its own lazily loaded one.

Compatibility, rollout and rollback

  • Wire: memory.definitions.disputes takes the same input. Each entry of disputes gains state (suspected or alternatives, default suspected), and each claim gains applies_to (an object of string values, empty when the definition declares none). Both are additive. No op, error code, migration or setting is added: the registry holds 426 operations (312 experimental), as before.
  • MCP: the op's description gains one sentence on alternatives; its first line, which the help row shows, is unchanged. SDKs: the Python, TypeScript, Go and Rust wire models are regenerated; the Ruby SDK, the Python client and the reference pages did not change. CLI: loom call memory.definitions.disputes; a scope is declared with loom call memory.set.
  • Rolling upgrade: nothing stored or cached changes shape, so there is no rolling-upgrade rule. A dashboard of the previous build ignores state and applies_to and draws every dispute as before. A server of the previous build sends neither, which this dashboard reads as a name that needs review whose definitions declare nothing (a frontend test covers it). A scope written through this build is an ordinary key of the value to the previous one.
  • Operator steps: none.
  • Rollback: reverting removes the two fields, the dialog and the Save rule. An applies_to already written stays in its definition's value as an inert key.

Tests

Run on a ClickHouse and a server started for this change.

  • tests/unit/test_definition_disputes.py (48 tests, 13 added): 47 passed, 1 skipped (it runs SQL through the clickhouse binary, which the machine lacks). The added tests were written before the rules, and their first run failed on the missing dispute_state. Each rule was then broken in turn to see which test fails:
    • test_a_key_both_declare_with_different_values_reads_as_alternatives fails when no pair is ever separated, when values are compared as written instead of folded, and when a blank value beside a declared key voids the whole scope instead of its own key.
    • test_a_scope_on_one_side_only_is_suspected fails when a declared scope against an undeclared one separates.
    • test_disjoint_or_unknown_scope_keys_are_suspected (8 cases: team against product, an unknown key, an unknown key beside a known one, a number, a 65-character value, a blank value, a text and a list in place of the object) fails when an unknown key is dropped instead of voiding the scope, and when any two different scopes separate.
    • test_alternatives_needs_every_differing_pair_separated fails when claims that say the same must also be separated, and when one unseparated pair is let through.
    • test_a_pair_past_the_work_bound_stays_suspected fails when the pair checks are not charged to the bound: one character short of the fourth check leaves the second dispute suspected.
    • test_another_task_runs_before_each_disputes_pairs_are_checked: the loop gets a turn before each dispute.
  • tests/integration/test_definition_disputes.py (5 tests, 1 added) with tests/analyzer: 17 passed. test_declaring_a_scope_lapses_the_governed_copy_as_changed promotes a definition, declares its team through memory.set under the claim's hash and reads lapsed / changed from memory.definitions.list; a write under the hash of the text before the edit is refused with PRECONDITION_FAILED and leaves the version; the dispute is suspected with one side declared and alternatives with both; promoting the second definition is refused with DEFINITION_NAME_TAKEN; promoting the edited text governs the first again.
  • Dashboard, npx vitest run --maxWorkers=2 --testTimeout=30000, on the final tree:
    • src/views/admin/Definitions.test.tsx (42 tests, 12 added), src/api/definitions.test.ts (6, new), src/api.memory.test.ts, src/views/admin/ReviewQueue.test.tsx, src/components/MemoryInspector.pin.test.tsx, src/views/Recent.lists.test.tsx: 6 files, 191 passed.
    • src/components/MemoryInspector.rename.test.tsx (12, 2 added), src/lib/callReason.test.ts, src/lib/canCall.test.ts, src/callBudget.test.tsx, src/views/copy.rules.test.ts: 5 files, 56 passed.
    • The ten files of the memory drawer: 121 passed, on the tree before the dialog's write changed; that change does not touch the drawer.
    • "refuses to save unparseable text over an object value" failed before the rule existed (no field error, and the text was written). "draws the names that need review first, each with its badge" fails without the sort, and "reads an answer with no state and no scope as names that need review" fails when a missing state reads as alternatives: that test is the previous server's answer.
    • The dialog's tests: it opens on what the definition declares and saves both names under the claim it opened on, then both lists are read again; a governed definition gets the line before Save, an unshared one none, and a writer who reads no shared list the conditional line; a definition that changed keeps the dialog open with the reason and reads the list again; another failure keeps it open with the server's words; a name over 64 characters is a field error with no write; a viewer sees the control unavailable with the role it needs; no axe violation with the dialog open.
    • "stays open with its reason and the names typed when the read after a refusal fails" failed while the dialog was drawn inside the answered state of the list read: the failed read removed it.
    • The write's tests in src/api/definitions.test.ts: the body carries the row's type, tags, entities, confidence, sensitivity label, source trace, source resource, source class, validity window and character limit back with the new value, and leaves out a class the server decides, a copy rule's mark and an end date the row does not have. Both failed while the write sent the type, tags and character limit only. The body of the first parses as the op's input model, which refuses the copy rule's mark.
    • With the default 5 s test timeout two existing rename tests of the drawer timed out on the busy machine; they pass with the longer one.
  • npm --prefix frontend run build: built. npm --prefix frontend run budget: OK, the index chunk at 112.4 kB of 120 kB. Biome 2.5.14 on the changed files: clean.
  • Repository scans and the neighbouring definition tests (test_package_contracts, test_op_transport_contract, test_mcp_listing_budget, test_sdk_surface_contract, test_go_sdk_contract, test_docs_reference, test_op_reach_census, test_tunable_constants, test_store_names_refused, test_degraded_unnoted, test_public_copy, test_doc_links, test_agent_instructions, test_definitions_list, test_promote_definition, test_definition_write_rules, test_definition_term_match): 1024 passed, 15 skipped. Then test_definition_disputes, test_session_content_senders, test_i18n, test_doc_links, test_public_copy and test_read_scope_admission: 1571 passed, 1 skipped. Both were run before the review fixes.
  • On the tree before the concepts page's list of fields was completed, test_definition_disputes with the scans test_package_contracts, test_op_transport_contract, test_tunable_constants, test_store_names_refused, test_degraded_unnoted, test_public_copy, test_doc_links, test_agent_instructions and tests/analyzer: 662 passed, 13 skipped, 1 failed. The failure is test_degraded_unnoted, which names a handler in server/code/app/index/review_brief_build.py. This change touches neither that file, the scan nor its list.
  • On the final tree, which differs from that one in that page only, the same scans without test_definition_disputes: 616 passed, 12 skipped, 1 failed, on the same handler. main has changed the handler since, so the scan passes there; this branch does not hold that commit, and git merge-tree reports no conflict with main. make typecheck: 0 errors. Prettier 3.9.9 and the prose checker on the page: clean.
  • make typecheck: 0 errors. ruff format --check and ruff check on the changed files: clean. The function-length gate is at its baseline. Prettier 3.9.9 on the four changed pages: clean.
  • main was merged three times. The third merge conflicted on the Review queue row of docs/features/dashboard.md; the row keeps both sides' sentences, and on that tree test_doc_links and test_public_copy (310 passed), src/views/emptyStates.rules.test.ts (2 passed) and Prettier on the page pass. The first two merged without a conflict. On the tree of the second merge every generator's --check exits 0 (sdk_py_gen, sdk_py_client_gen, sdk_py_admin_gen, sdk_ts_gen, sdk_rb_gen, sdk_rust_gen, sdk_rust_gen --fixtures, sdk_go_gen, docs_reference, op_reach_census, plugin_eval_tools), the registry holds 426 operations (312 experimental), and test_session_content_senders, test_definition_disputes, test_docs_reference, test_sdk_surface_contract, test_go_sdk_contract, test_op_reach_census, test_mcp_listing_budget and test_op_transport_contract pass (320 passed, 1 skipped).
  • sdk/rust/src/wire_models.rs is 2,401,641 bytes on the merged tree, under the 4,194,304 byte bound on a tracked SDK source file. The Go and Rust wire models were formatted with gofmt from the Go 1.27.4 image and rustfmt from the Rust 1.85.1 image; neither tool is installed on the machine that ran the generators.

Not run: the full unit suite, the full integration suite and the Playwright run (CI runs them; frontend/e2e/definitions.spec.ts serves the new fields and asserts the badge and the Applies to lines), and no benchmark or load run.

AI assistance in the code (leave one; writing this description with AI is fine):

  • AI-generated (an agent wrote most of the diff): Claude Code. Checked by writing the server tests and the drawer's Save test before their rules, by breaking each server rule and two dashboard rules in turn and reading which test failed, by running the tests above against a ClickHouse and a server started for this change, and by reading the whole diff against the area rules.

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

Checklist

  • Local format, lint, type checks and focused tests pass. The full make test-unit and applicable integration results are reported by CI; a full local run is not required before pushing.
  • Generated files are regenerated in this PR, not by hand: the SDK op tables, docs/reference/configuration.md and the docs/reference/ tables (python scripts/codegen/docs_reference.py), the reach manifest, schemas/schema.sql (make schema-dump), the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.py) and the standalone skill bundles (python3 scripts/codegen/standalone_skills.py).
  • A new migration is additive and numbered after the latest on main; no merged migration is edited.
  • A behaviour change to any file a plugin ships (hooks/, lib/, bin/, skills/, .mcp.json, the Codex plugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version.
  • The frontend builds (npm --prefix frontend run build) and its tests pass, if frontend/ changed.
  • Docs under docs/ describe the system as it now is, and this description names any operator steps and wire changes.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers; the history goes in this description (tests/unit/test_public_copy.py).
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.
  • I signed the Contributor License Agreement (CLA) if CLA assistant requested a signature.

🤖 Generated with Claude Code

zlareb1 and others added 3 commits December 6, 2026 09:08
… differences read as alternatives

Two teams can each define one name differently on purpose. Without a declared
scope every such pair reads as a dispute to correct.

A definition's value may hold applies_to, an object of team, product or both,
each a string of at most 64 characters. A claim of memory.definitions.disputes
serves it as applies_to, and a dispute carries state: alternatives when every
two claims whose texts differ both declare team, or both product, with values
that differ once folded as names are; suspected otherwise. A scope on one side
only, team against product, and an applies_to with any other key or value
shape separate nothing. Each pair check is charged 16 characters to the
request's work bound, and a dispute whose pairs the bound does not pay for
stays suspected.

Declaring a scope is an edit of the definition through memory.set under the
claim's hash, so a governed definition lapses as changed until its edited text
is promoted, and a name keeps one shared definition.

The Review queue's Definitions tab shows what each differing definition
applies to, draws the names that need review before the alternatives, and
lets a writer declare the team and product in a dialog that says before Save
when the definition stops being governed. The memory drawer's Save refuses
text that is no JSON over a stored object: saved as typed, it would replace
the object with a string.

Signed-off-by: Mohammad Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The generated SDK wire models merge without a conflict; every generator's
check passes on the merged tree.

Signed-off-by: Mohammad Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The generated SDK wire models merge without a conflict; every generator's
check passes on the merged tree.

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

vercel Bot commented Dec 6, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
loom-docs Ready Ready Preview Dec 6, 2026 10:34am UTC
loom-telemetry Ready Ready Preview Dec 6, 2026 10:34am UTC

Request Review

zlareb1 and others added 3 commits December 6, 2026 10:06
memory.set builds the whole new version from its input, so a write that
sends the value, type, tags and character limit resets the rest: a
definition lost its validity window, confidence, entities, source and
sensitivity label when a writer named its team. The dialog's write sends
the row's fields back as a pin does, from one builder both share
(rowFields). A copy rule's mark on the source trace is left out:
memory.set refuses it from a caller, and the edited value is no longer
the text the rule's run wrote. setMemory loses the hash option only the
dialog used.

The Applies to dialog is drawn outside the states of the list read. It
was drawn inside the answered state, so a read that failed after a
refusal removed it with its reason and the names typed, and Retry opened
a new one on the stale claim.

The concepts page says a blank scope value declares nothing for its key
only, as the code does, and tells a caller of memory.set to send the
definition's other fields back. A unit case pins the blank value beside a
declared key, and the wire model's comment says the served value is
trimmed.

Signed-off-by: Mohammad Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
docs/features/dashboard.md conflicted on the Review queue row: it keeps
main's sentence on a correction request in a stewardship review and this
branch's on the names that need review first and the team or product a
definition applies to.

Signed-off-by: Mohammad Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ates

memory.set builds the whole new version from its input, so a field the
call leaves out is reset: confidence to 1.0, the sensitivity label to
what detection gives for the value, the character limit to none. The
sentence on declaring a scope named the type, tags, entities, validity
and source. It names the confidence, sensitivity label, source trace,
source resource and character limit too, as the dashboard's dialog sends
them, and the two values memory.set refuses from a caller with 422: a
source_class other than derived, external or imported, and a
source_trace that starts with copy_rule:.

Signed-off-by: Mohammad Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@zlareb1
zlareb1 merged commit ac1dffe into main Dec 6, 2026
86 of 97 checks passed
@zlareb1
zlareb1 deleted the feat/definition-applies-to branch December 6, 2026 10:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant