Repository navigation
A decision record carries the files it governs, its source and its class, and its memory row reads as a statement - #163
Merged
Conversation
zlareb1
force-pushed
the
feat/decision-record-files-source
branch
from
November 1, 2026 20:19
42fdcde to
d808b9c
Compare
…ass, and its memory row reads as a statement decision.record takes files, source_resource_id and source_class and writes them on the decision's memory row; decision.outcome keeps the row's files. The decision's memory row holds one statement instead of a JSON object. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
The outcome keeps the live row's files, source and caller tags from the row it already reads under the writer's identity; a decision with no live row answers not-found, so the no-row fallback goes. The clickhouse-local decision tests create the blacklist tables the record path now reads. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
A decision's conflict check answers only conflict or clear, so memory.set never merges its row into another key nor refuses it for a pinned peer. decision.record and decision.outcome drop the merge answers and the DecisionOutcomeOutput.next field that carried one; a PINNED_CONFLICT is always the writer's own pinned row. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
A re-record that keeps the decision's text leaves the row's hash as it was, so decision.outcome reads the writer's record again after its row write and answers 409 when it moved. The second blacklist pass over the stored statement goes: memory.set runs it before anything is written. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
The second check before the row write leaves nothing written when a same-text re-record lands first; the one before the record write stays for a re-record inside the row write. One helper answers both 409s, and the decisions page names what each leaves behind. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
The outcome's record check answers not-found when the writer's row is gone, as the read at its start does, instead of the changed-decision 409. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
zlareb1
force-pushed
the
feat/decision-record-files-source
branch
from
November 1, 2026 23:23
2631f5f to
4e974aa
Compare
…e Sensitivity alias Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
8 of 9 tasks
zlareb1
added a commit
that referenced
this pull request
Nov 2, 2026
… pass Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
zlareb1
added a commit
that referenced
this pull request
Nov 2, 2026
… pass Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
zlareb1
added a commit
that referenced
this pull request
Nov 2, 2026
… pass Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
zlareb1
added a commit
that referenced
this pull request
Nov 2, 2026
… pass Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changelog category (leave one):
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.recordtakesfiles,source_resource_idandsource_classand writes them on the decision's memory row, asmemory.setdoes, so a decision can name the files it governs and amemory.searchhit cites its source (the decision rows ofdecision.precedents,decision.chainandcontext.packdo not carry it yet);decision.outcomekeeps the row's files instead of re-detecting them from the realized outcome. The decision's memory row now holds one statement (Category: <category>. Scenario: <scenario>. Decided <outcome> because <reasoning>. Rejected: …) instead of a JSON object, so search embeds and excerpts the decision rather than field names.Why
The three fields.
decision.recordtook no files, source or declared class: the row's files were only those detected from its JSON value, a hit cited nothing, anddecision.outcomere-detected files from a value that included the realized outcome, so an outcome naming another file swapped the row's files.DecisionRecordInputnow declares them (filessharesMemorySetInput'sFileRefsalias: 32 paths of at most 1024 characters;source_classis hidden from the MCP listing and typedLiteral["derived", "external", "imported"], so the transport refuses any other value,""included, wherememory.set'sstrfield reads""as unset; leave it out instead), and_write_decisionpasses them toMemorySetInput. Whenfilesis unset, they are detected from the stored fields (category, scenario, outcome and reasoning in full, each alternative as the record keeps it, without a token cut at 300 characters) (a subset of what the blacklist reads, never the realized outcome); none found passesNone, so a re-record keeps the row's files.The statement. The row's value was a JSON dict of every record field, embedded as is, so precedent similarity compared field names as much as content and
memory.for_fileprinted the start of the JSON.memory_valuenow returns a statement: category, scenario, outcome and reason, rejected alternatives, thenRealized: …oncedecision.outcomehas recorded one. Each part is clipped to a cap counted JSON-encoded, asmemory.setstores it (category 40, scenario 80, outcome 200, reasoning 360, joined alternatives 240, realized outcome 170), so the longest statement fits the embedded excerpt (EXCERPT_LIMIT1200 less the 29-character key suffix) andmemory.for_file's 220-character line, which prints the stored value, shows at least 60 characters of the outcome. A cut falls on whitespace (the category also on:,/or-, not_, which the file detector reads as part of a word), so a path is kept whole or dropped and spaced text in any script, Korean included (never cut between two Hangul syllables), is cut at a space. Unspaced CJK text may instead be cut between two wide characters when that is later, so it keeps its head even after a spaced ASCII term. A part that is one token past its cap, with no cut point before it (unspaced Thai, a long path), becomes...; a cut part drops trailing spaces and separators (.,;,:,,,-,—,/) before the ellipsis. An uncut part drops its own trailing full stop, comma, semicolon or colon (ASCII or full-width), so the statement's punctuation is never doubled; a caller's trailing ellipsis (…or...) stays, with nothing after it, and?,!,?,!and…end a sentence themselves. A reason that starts with the word "Because" loses it (the statement says "because" itself), matched on a word boundary. So no half token reads as a file. The typed record keeps every field in full except the alternatives, each kept to its first 300 characters as before.Putting the scenario first, cut to 80 characters, is a reasoned choice, not a measured one: precedent queries are scenarios, the outcome and reasons that follow describe the same situation, and the old value interleaved the same content with field names and nulls shared by every decision row. Measuring recall needs a paid embedder run, which was not done.
Checks read the full text. The statement is clipped, so
_checked_statement(run by_write_decisionfordecision.recordanddecision.outcome) reads every stored field in full before anything is written: the blacklist on those fields as plain text (so a non-ASCII pattern matches; a refusal counts asblacklistedinloom.memory.writes, asmemory.set's does, and a failed blacklist read aserror;memory.setthen checks the stored statement itself, before its row and so before the record), the sensitivity detector on the fields the statement is built from and the statement itself, and the attribute labels on those fields (notdecision_makerorrun_id, which the row never holds), read field by field (the attribute detector reads only a text's first 4,000 characters). A decision counts every attribute label it adds in the attribute-tag metric once its row is written (count_attribute_tags, shared withmemory.set);memory.setcounts labels only alongside a sensitivity tier, and aligning the two is out of scope. The decision's own checks read each field on its own, asmemory.setreads the scalars of a JSON value;memory.set's pass over the statement afterwards can only add labels, never lower them. A refused decision leaves no record; a credential past a cut still makes the rowhigh, which keeps it out of the embeddings.Distinct decisions keep distinct rows (a memory-plane behaviour change).
memory.set's write-time conflict check merges a write into a peer with the same canonical text, files it as aduplicateof one with the same content words, lets a close pinned peer refuse it, and undernewest_winslets a templated substitution supersede the peer. Two keys can hold one free-text fact, so that is right for facts. A decision is identified by its key (category and scenario), and the content-word test drops short words, stop words and plural endings and accepts a subset:ci/db,deploy/deploys, or scenarios differing by a stop word or past the clip read as duplicates. The old JSON value avoided that only because it carriedmade_atandrun_id. ForKEY_IDENTIFIED_TYPES(decision),check_on_commitanswersconflictfor every close peer, flagged and cross-linked for the conflict resolver, never merge, duplicate, refinement or pinned refusal, and skips the out-of-scope pinned-peer read. The peer reads exclude the decision's own key; a same-key re-record is a last-write-wins rewrite.A word-for-word re-record is a restatement (a memory-plane behaviour change). The old JSON value carried
made_atandrun_id, so no two records of one decision had the same value. The statement carries neither, so recording the same category, scenario, outcome, reasoning and alternatives again writes a byte-identical value, whichmemory.settakes asrestated: the row'sreinforcement_countrises (so it ranks higher in precedents), and a pinned decision accepts the restatement instead of answering 409. Re-deciding the same thing reinforcing it is the intended reading; the decisions page says so and a unit test pins the identical value. A restatement that changes onlyfiles,source_resource_idorsource_class(the normal way to attach them to a decision) now counts as a change, not a pure reinforcement, somemory.setannouncesmemory.revisedfor it; before,memory.setcompared status, type, tags, expiry, confidence, validity and sensitivity, and not those three, which no decision reached while its value carriedmade_at. It still does not comparepinned,entitiesor the expiry fields' reasons; that is left to its own change. This applies to everymemory.set(_only_reinforcesinserver/memory/app/set_commit.py), with a webhook test per column.decision.outcomerewrites the memory row from the record, which holds neither the files nor the source. It already reads the writer's live row (fresh,strong, under the record writer's exact identity, the row its write is conditional on) and now carries that row's files,source_resource_id, declaredsource_classand the caller's tags. It rebuilds onlydecision, the decision's owndecision:category:<category>,decision:outcome-known,decision:success,decision:failureand the server'ssensitivity:/attribute:labels, whichmemory.setworks out again (asprocedure.addtreats them). A decision with no live writer row answers not-found, so there is no fallback for one. A token bound to one user or session cannot call it: the transport refuses everydecision.*op for a narrowed token.On top of the record retirement. With the conflict rule above,
memory.setnever merges a decision's row into another key and never refuses it for a pinned peer. So the merge answersdecision.recordanddecision.outcomegave (the peer's key with an emptyrecord_id,updated=false) can no longer happen and are removed, withDecisionOutcomeOutput.next, which only carried that answer; aPINNED_CONFLICTa decision gets is always its writer's own pinned row, whichdecision.recordrewords to namememory.unpin.Readers. Nothing parses the value:
decision.precedents,decision.chainandcontext.pack's decisions section read the typed record.context.packfalls back to the hit excerpt when the record read fails and always for a narrowed token, which now shows "Category: … Scenario: … Decided … because …" in the scenario slot. The SDKs, the dashboard and the plugins readDecisionRowor context-pack sections.The outcome and a same-text re-record. The statement carries neither
made_atnorrun_id, so a re-record by the same writer that keeps the text (another run, a new confidence or decision maker) leaves the row's hash as it was, and the outcome'sif_match_sha256no longer notices it.decision.outcometherefore reads the writer's record twice more, before its row write and before its record write, and answers 409PRECONDITION_FAILED("call decision.outcome again") when it moved, instead of writing the older record over the re-record. What is left (named on the decisions page): a re-record caught at the second check finds the row already holding the outcome's statement, so until the call is made again the row reads it, with the outcome tags, while the record is the re-record's, and the retry restates the row (one reinforcement); and a re-record landing between the second check and the record write is still overwritten, one round trip wide, as the hash-only check allowed before (closing it needs a conditional record write).The statement's punctuation stays. A review asked to cut the trailing-ellipsis, full-width ending and leading-"Because" handling in
decision_statement.pydown to "strip and add one full stop". It is kept: the statement is what search embeds and what an agent reads inmemory.for_file, and "because Because …", "…." or "。." in every such line reads as a defect to that agent; it is 40 lines of a 147-line module, each case pinned by a test.Known limits, not changed here.
memory.setstores it, JSON-encoded, where each non-ASCII character is a six-character\uXXXXescape (twelve outside the Basic Multilingual Plane), so a Cyrillic or CJK part keeps about a sixth as many characters (a Cyrillic scenario at most 13, cut back to a word). The old JSON value was measured the same way but gave the scenario most of the excerpt. Storing values unescaped is amemory.set-wide change.memory_typeand keys. Undernewest_winsor the defaultauto_reinforceit can retire a decision row of another key it rules superseded, as it could with the JSON value; the retirement is recorded asmemory.auto_supersedeandmemory.restoreundoes it.memory.bulk_set's byte-identical dedup across keys and itsnewest_winsintra-batch supersession are type-agnostic.decision.recordnever reaches them, but a hand-writtendecisionentry sent throughmemory.bulk_setwhose value is byte-identical to a live row under another key still folds into that row.memory.for_file's_supersede_orderwill read two close decisions under different keys, now cross-linked as a conflict, as one superseding the other. The follow-up is to skipKEY_IDENTIFIED_TYPESrows there; it is left out of this change because that function is being rewritten in another open change.memory.set-wide fix retires a key's chunks when a short value replaces a long one.Scope and risk
server/memory/api/models_decision.py,models_common.py(FileRefs),models_crud.py: the three fields and the shared aliases (Sensitivitylives inserver/memory/domain/sensitivity.py,DeclaredSourceClassinserver/memory/domain/provenance.py).server/memory/domain/decision_statement.py(new): the statement and its clips.server/memory/app/decisions.py:statement_fields,blacklist_fields,decision_files(with_without_cut_tokenfor the 300-character alternative cut),clean_alternatives.server/memory/app/decision.py: the pass-through, the full-text checks, the outcome's carry-over.server/memory/domain/provenance.py:is_declarable, aTypeGuardoverCALLER_DECLARABLE.server/memory/domain/sensitivity.py: theSensitivityalias,is_level(aTypeGuardoverLEVELS), andSensitivityas the return type ofdetect_sensitivity,resolve_sensitivity,max_sensitivityandinherited_sensitivity.server/memory/api/models_bulk.py,models_import.py: the bulk and import entries'sensitivityuses theSensitivityalias (same wire schema).server/memory/app/conflicts.py: theKEY_IDENTIFIED_TYPESbranch (the set lives inserver/memory/domain/memory_types.py); every other memory type is judged as before.server/memory/app/set_commit.py,write.py:count_writeis public andcount_attribute_tagsis new, shared bymemory.set,memory.bulk_set(bulk_rows._with_attribute_tags) and the decision checks;_only_reinforcesalso comparesfiles,source_resource_idandsource_class, for everymemory.set(see "Why").sdk/python/loom/decision.py:record()takes the three fields (keyword-only; a bare string forfilesraisesTypeError).docs/features/tasks-and-decisions.md,docs/features/memory/conflicts-and-refusal.md,docs/features/memory/writing.md(thememory.revisedcolumns of a restatement, for everymemory.set),docs/architecture/memory-architecture.md,.claude/rules/memory-plane.md, and the regenerateddocs/reference/operations/decision.md.decision.record's role,CODE_MEMBER_WRITE_OPS, andmemory.set's ownsource_classfield and its 422.Compatibility, rollout and rollback
decision.recordgainsfiles(list[str] | null),source_resource_id(string) andsource_class(derived/external/imported, not in the MCP listing). All optional; no default changes.DecisionOutcomeOutput.nextis removed: it carried only the merge answer, which no decision write can now give (it was added by the record-retirement change and never released).decision.outcomeserved by N-1 rewrites the row from the payload alone: it drops the caller's tags (team:db,decision:owner:db), passes nofiles, somemory.setre-detects them from a JSON value that includes the realized outcome (the file swap this change fixes), and leaves an emptysource_resource_idand theassertedclass (aderivedrow can be raised toasserted). A later outcome on N carries the row as it then is, so only a re-record restores them. N-1 also does not run the decision conflict rule or the full-text checks.files/source_resource_id/source_classcolumns.Tests
tests/unit/test_decision_statement.py(new) andtests/unit/test_decision_ops.py:…,…;,...,...;,... ., a trailing comma); full-width sentence marks are not doubled; a leading "Because" is dropped on a word boundary ("Because.", "Because...", "Because, …", not "Becausewise").:,/,-and not_; unspaced CJK keeps its head, and a path run into CJK leaves no half name; a one-token part becomes...; the pre-edit line, rendered asmemory.for_filerenders it, shows 60 characters of a realistic outcome at full caps (it fails at the previous 60 / 120 caps)..mdxname at the 300-character alternative cut leaves no half name, a path past that cut is not attached); a part ending in.leaves no space before the full stop.high; an email indecision_makerleaves the row unlabelled; three numeric alternatives stay unlabelled; an attribute term past the cut, past 4,000 characters of the joined fields, or in an alternative is labelled; a refusal is counted asblacklisted. A blacklisted phrase past the cut, indecision_makeror in a realized outcome refuses the write with no record and no memory row.check_on_commitwith an identical-embedding peer):conflictforci/db,deploy/deploys, a stop-word and a word-superset scenario, differences past the clip, a pinned peer andnewest_wins. A foreign pinned decision with a below-threshold peer leaves the writeclearand marked for review.mark_peers_conflictedkeeps a pinned peer's pin.user_id/session_idincluded); keeps files, source, class and the caller's tags (decision:owner:dbincluded); keeps an empty files list. The clickhouse-local retirement tests (tests/unit/test_decision_retirement.py) run with the blacklist tables the record path now reads.decision.outcomedoes not honour a read scope (honours_read_scope), which is what makes the transport refuse a narrowed token. An undeclarable class is refused by the input model.tests/unit/test_sdk_procedure_decision_knowledge.py: the SDK sendsfilesas a list and refuses a bare string.tests/integration/test_decision_record_source.py(new), against a server from source on a private ClickHouse:loom.memoryand comparesvalue,files,source_resource_id,source_class,memory_type, the exacttags,sensitivity,confidenceand the identity.activeorconflicted, at least oneconflictedrow cross-linked (conflict_with) only to others of the seven.tests/integration/test_decision_record_source.py,tests/integration/test_read_scope_isolation.py,tests/integration/test_cross_principal_leakage.pybefore the rebase onto the record retirement, against a server from source on a private ClickHouse with the CI posture (fake embedder, workers off): 52 passed, 14 skipped. Not re-run since the rebase.make format lint typecheck: clean. Codegen regenerated (sdk_py_gen,sdk_py_client_gen,sdk_ts_gen,docs_reference,op_reach_census); the SDK surface snapshot is updated for the newrecord()parameters.main83e0eaee(addsmemory.import, which goes throughmemory.bulk_set; clean rebase, generated files current). Before that rebase, onmain8f7c7d88(the record retirement): fulltests/unitat427778a8: 24,350 passed, 20 skipped, 1 xfailed. At2631f5f9(one more test only):test_decision_retirement.py, 41 passed. At the rebased4e974aa4: fulltests/unit, 24,461 passed, 20 skipped, 1 xfailed, andtests/analyzer, 10 passed, 2 skipped. Atd7e63085, one test changed andmodels_import'ssensitivityto theSensitivityalias (same wire schema); the retirement, package-contract, import and copy tests pass there; the heade6e34e9fdrops one redundant assertion from that test, which passes. The retirement tests cover the outcome against a re-record that changes onlyrun_id, landing inside its row write (the record stays the re-record's and the row holds the outcome's statement) or before it (nothing written), and against a delete before its writes or after its row write (not-found, no row and no record; the second fails without the record check after the row write).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 reader of the decision memory value, the provenance rules for a declared class, the write-time conflict steps, and the rewrite path in
decision.outcome.I can explain every line of this diff and how it interacts with the rest of Loom.
Checklist
make format-check,make lint,make typecheckandmake test-unitpass; the integration suite passes if server behaviour changed. (Format, lint, typecheck and the full unit run pass at4e974aa4; the integration run predates the rebase, since Docker on the test host stopped creating containers.)docs/reference/configuration.mdand thedocs/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).main; no merged migration is edited.hooks/,lib/,bin/,skills/,.mcp.json, the Codexplugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version.npm --prefix frontend run build) and its tests pass, iffrontend/changed.docs/describe the system as it now is, and this description names any operator steps and wire changes.tests/unit/test_public_copy.py).git commit -s), as CONTRIBUTING.md asks.🤖 Generated with Claude Code