Skip to content

decision.record accepts a scenario written without Latin letters - #238

Merged
zlareb1 merged 7 commits into
mainfrom
fix/record-key-non-latin
Nov 4, 2026
Merged

zlareb1 merged 7 commits into
mainfrom
fix/record-key-non-latin

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in a release)

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

decision.record and memory.record.write accept an identity value written only in a non-Latin script (Cyrillic, CJK, Arabic) instead of answering 500, and a non-name identity value of punctuation, symbols or marks alone is refused with 400 MISSING_IDENTITY_FIELD.

Why

A record's derived key canonicalises each non-name identity value to its a-z0-9 characters after NFKD, mark stripping and casefold (server/memory/domain/record_identity.py::canonical_value). A scenario with no Latin letter or digit, such as Срок хранения журналов, canonicalises to "", canonical_record_key raises ValueError: identity field 'scenario' is empty, and nothing maps it: decision.record answered 500 INTERNAL_ERROR. memory.record.write failed the same way for any non-name identity field of that shape, and loom decisions extract dropped such candidates with "no letters or digits a-z, 0-9 to build a key from".

The fix: when that a-z0-9 form is empty, the value keys on every letter, digit and combining mark of the raw value, after NFKC and casefold. The fallback starts from the raw value, not the mark-stripped text, because in these scripts a mark tells words apart: Indic vowel signs and viramas (क्या / कया), Thai tone marks (ไม่ / ไม้), the Japanese voicing mark (かぎ / かき), Arabic and Hebrew points. So a word written with and without its Arabic vowel points gets two keys. Every key that exists today came from a non-empty a-z0-9 form, which still wins, so no stored key changes and nothing needs a backfill.

A value with no letter or digit in any script (?! …) still has no key, and is now a 4xx:

  • decision.record checks the category and scenario before any write and answers 400 MISSING_IDENTITY_FIELD with the empty fields, the code memory.record.write already uses for an identity field without a value.
  • memory.record.write counts an identity value that canonicalises to "" (whitespace, or a non-name identity value of punctuation, symbols or marks alone) as missing, so it gets the same 400 instead of the ValueError.

Name-like fields (name, title, label, *_name, *_title, *_label) keep their rule: it already keeps letters in any script, drops accents and the other combining marks (the Japanese voicing mark, the virama, Thai tone marks; Indic vowel signs stay), and is refused only when nothing is left once separators, combining marks, a leading article and a possessive are dropped.

Known limit, left as is because changing it would re-key stored records: a value with any a-z or 0-9 after compatibility decomposition (30 дней, 2024年度, №, ℃) keys on those characters alone, so two values that differ only in their other characters share one key (30 дней and 30 часов; a unit test pins this). A name-like field drops the Japanese voicing mark, so かぎ and かき share a name key. The typed-records section of docs/features/memory/writing.md now states the rule and this limit.

Scope and risk

  • Touches the canonical form of identity values that today have none (they failed), the 400 mapping in decision.record and memory.record.write, the extractor's drop reason, and three docs files (two pages plus the generated errors reference).
  • Stored data: no existing key changes; a unit test pins one existing key value (invoice:bef11f75f1b36a62) and one decision key was checked by hand before and after.
  • Rolling upgrade: build N-1 still fails on a non-Latin scenario and N records it. N-1 never wrote such a key, so no key is computed two ways. N-1's extractor drops those candidates, and its retire step keeps a row whose reasoning is still in the document, so it does not retire a decision N recorded.
  • Tenant isolation and auth: unchanged.

Compatibility, rollout and rollback

  • Wire: decision.record answers 400 MISSING_IDENTITY_FIELD (fields: the empty ones) where it answered 500; memory.record.write answers its existing 400 for a non-name identity value of punctuation, symbols or marks alone. A non-Latin identity value now records.
  • Operator steps: none.
  • Rollback: records written under a non-Latin key stay readable by key; a rolled-back build cannot re-derive that key from the scenario, so re-deciding the same non-Latin scenario fails again as before.

Tests

  • Reproduced first: against a server built from main, decision.record with a Cyrillic category and scenario answered 500 INTERNAL_ERROR; the new unit tests fail on main.
  • tests/unit/test_record_identity.py: Cyrillic, CJK, Arabic and Devanagari values get distinct keys, かぎ/かき, ไม่/ไม้, क्या/कया and pointed/unpointed Arabic differ, the same text twice gives the same key, case and punctuation do not count, the pinned ASCII key is unchanged, 30 дней and 30 часов share a key (the documented limit), punctuation, symbols (€$) or marks alone is empty; memory.record.write with an identity value of punctuation, symbols, whitespace or marks alone (a lone combining mark, a lone ा) is 400 MISSING_IDENTITY_FIELD, and ٣٤٥ and счёт record under two keys.
  • tests/unit/test_decision_ops.py: a Cyrillic decision records under one key for its record and memory row; a scenario with no letter or digit (?! …) is 400 before any write.
  • tests/unit/test_decision_extract.py: the drop case is now a scenario with no letter or digit (?! …), with the new reason.
  • tests/integration/test_decision_record_source.py (new test, against a local server): a Cyrillic decision records, a case and punctuation variant supersedes it, another scenario gets another key, and ?! … raises MISSING_IDENTITY_FIELD. That file, test_memory_for_file_decisions.py and test_memory_records_roundtrip.py pass.
  • make format lint typecheck, tests/unit/test_public_copy.py, tests/unit/test_doc_links.py, and the full unit suite on head 0ef5104, rebased on the latest main (26355 passed, 20 skipped, 1 xfailed). The diff since is a code comment and one added unit assertion; tests/unit/test_record_identity.py passes on the final head.

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: every caller of canonical_record_key, the pinned key value, the 500 reproduced on main and gone on this branch.

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

Checklist

  • make format-check, make lint, make typecheck and make test-unit pass; the integration suite passes if server behaviour changed.
  • 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) and the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.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.

🤖 Generated with Claude Code

@zlareb1
zlareb1 force-pushed the fix/record-key-non-latin branch 2 times, most recently from 894e21e to 0ef5104 Compare November 4, 2026 00:07
zlareb1 and others added 7 commits November 4, 2026 01:10
An identity value with no a-z, 0-9 characters (Cyrillic, CJK, Arabic)
canonicalised to "", so canonical_record_key raised and decision.record
answered 500. Such a value now keys on its letters, digits and marks in
any script after NFKC and casefold. A value with an a-z, 0-9 form keeps
it, so no stored key changes.

A value of punctuation alone still has no key and is now 400
MISSING_IDENTITY_FIELD in decision.record and memory.record.write.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
The fallback started from the mark-stripped text, so every combining
mark with a nonzero class was gone and words that differ only in one
collided: かぎ and かき, ไม่ and ไม้, क्या and कया. It now starts from the
raw value, NFKC and casefold, and keeps every letter, digit and
combining mark. The a-z, 0-9 path is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
The docs now say that any a-z or 0-9 after compatibility decomposition
wins, and that a name-like field drops combining marks. The record-write
test uses values that reach the non-Latin form, and a marks-only value is
a 400.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…imit

A name-like field drops accents and other combining marks and is refused
only for separators alone; any other field is refused for punctuation or
marks alone. A test pins that "30 дней" and "30 часов" share a key.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
No letter or digit means punctuation, symbols or marks alone; a name-like
value is refused only for separators or combining marks alone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 force-pushed the fix/record-key-non-latin branch from 76c2af1 to ccf23cf Compare November 4, 2026 01:16
@zlareb1
zlareb1 merged commit 27e9dbe into main Nov 4, 2026
21 of 22 checks passed
@zlareb1
zlareb1 deleted the fix/record-key-non-latin branch November 4, 2026 01:18
@pufit pufit mentioned this pull request Nov 4, 2026
9 tasks done
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