Skip to content

A decision record carries the files it governs, its source and its class, and its memory row reads as a statement - #163

Merged
zlareb1 merged 10 commits into
mainfrom
feat/decision-record-files-source
Nov 2, 2026
Merged

zlareb1 merged 10 commits into
mainfrom
feat/decision-record-files-source

Conversation

@zlareb1

@zlareb1 zlareb1 commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Improvement

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 takes files, source_resource_id and source_class and writes them on the decision's memory row, as memory.set does, so a decision can name the files it governs and a memory.search hit cites its source (the decision rows of decision.precedents, decision.chain and context.pack do not carry it yet); decision.outcome keeps 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.record took no files, source or declared class: the row's files were only those detected from its JSON value, a hit cited nothing, and decision.outcome re-detected files from a value that included the realized outcome, so an outcome naming another file swapped the row's files. DecisionRecordInput now declares them (files shares MemorySetInput's FileRefs alias: 32 paths of at most 1024 characters; source_class is hidden from the MCP listing and typed Literal["derived", "external", "imported"], so the transport refuses any other value, "" included, where memory.set's str field reads "" as unset; leave it out instead), and _write_decision passes them to MemorySetInput. When files is 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 passes None, 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_file printed the start of the JSON. memory_value now returns a statement: category, scenario, outcome and reason, rejected alternatives, then Realized: … once decision.outcome has recorded one. Each part is clipped to a cap counted JSON-encoded, as memory.set stores it (category 40, scenario 80, outcome 200, reasoning 360, joined alternatives 240, realized outcome 170), so the longest statement fits the embedded excerpt (EXCERPT_LIMIT 1200 less the 29-character key suffix) and memory.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_decision for decision.record and decision.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 as blacklisted in loom.memory.writes, as memory.set's does, and a failed blacklist read as error; memory.set then 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 (not decision_maker or run_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 with memory.set); memory.set counts 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, as memory.set reads 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 row high, 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 a duplicate of one with the same content words, lets a close pinned peer refuse it, and under newest_wins lets 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 carried made_at and run_id. For KEY_IDENTIFIED_TYPES (decision), check_on_commit answers conflict for 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_at and run_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, which memory.set takes as restated: the row's reinforcement_count rises (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 only files, source_resource_id or source_class (the normal way to attach them to a decision) now counts as a change, not a pure reinforcement, so memory.set announces memory.revised for it; before, memory.set compared status, type, tags, expiry, confidence, validity and sensitivity, and not those three, which no decision reached while its value carried made_at. It still does not compare pinned, entities or the expiry fields' reasons; that is left to its own change. This applies to every memory.set (_only_reinforces in server/memory/app/set_commit.py), with a webhook test per column.

decision.outcome rewrites 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, declared source_class and the caller's tags. It rebuilds only decision, the decision's own decision:category:<category>, decision:outcome-known, decision:success, decision:failure and the server's sensitivity: / attribute: labels, which memory.set works out again (as procedure.add treats 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 every decision.* op for a narrowed token.

On top of the record retirement. With the conflict rule above, memory.set never merges a decision's row into another key and never refuses it for a pinned peer. So the merge answers decision.record and decision.outcome gave (the peer's key with an empty record_id, updated=false) can no longer happen and are removed, with DecisionOutcomeOutput.next, which only carried that answer; a PINNED_CONFLICT a decision gets is always its writer's own pinned row, which decision.record rewords to name memory.unpin.

Readers. Nothing parses the value: decision.precedents, decision.chain and context.pack's decisions section read the typed record. context.pack falls 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 read DecisionRow or context-pack sections.

The outcome and a same-text re-record. The statement carries neither made_at nor run_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's if_match_sha256 no longer notices it. decision.outcome therefore reads the writer's record twice more, before its row write and before its record write, and answers 409 PRECONDITION_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.py down to "strip and add one full stop". It is kept: the statement is what search embeds and what an agent reads in memory.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.

  • Non-ASCII text: the caps count the value as memory.set stores it, JSON-encoded, where each non-ASCII character is a six-character \uXXXX escape (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 a memory.set-wide change.
  • The conflict resolver ignores memory_type and keys. Under newest_wins or the default auto_reinforce it can retire a decision row of another key it rules superseded, as it could with the JSON value; the retirement is recorded as memory.auto_supersede and memory.restore undoes it.
  • memory.bulk_set's byte-identical dedup across keys and its newest_wins intra-batch supersession are type-agnostic. decision.record never reaches them, but a hand-written decision entry sent through memory.bulk_set whose value is byte-identical to a live row under another key still folds into that row.
  • memory.for_file's _supersede_order will read two close decisions under different keys, now cross-linked as a conflict, as one superseding the other. The follow-up is to skip KEY_IDENTIFIED_TYPES rows there; it is left out of this change because that function is being rewritten in another open change.
  • Stale verbatim chunks: when a decision recorded before this change with a long JSON value is recorded again, its short statement writes no chunks and does not retire the old ones, so they stay findable until a 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 (Sensitivity lives in server/memory/domain/sensitivity.py, DeclaredSourceClass in server/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_token for 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, a TypeGuard over CALLER_DECLARABLE.
  • server/memory/domain/sensitivity.py: the Sensitivity alias, is_level (a TypeGuard over LEVELS), and Sensitivity as the return type of detect_sensitivity, resolve_sensitivity, max_sensitivity and inherited_sensitivity.
  • server/memory/api/models_bulk.py, models_import.py: the bulk and import entries' sensitivity uses the Sensitivity alias (same wire schema).
  • server/memory/app/conflicts.py: the KEY_IDENTIFIED_TYPES branch (the set lives in server/memory/domain/memory_types.py); every other memory type is judged as before.
  • server/memory/app/set_commit.py, write.py: count_write is public and count_attribute_tags is new, shared by memory.set, memory.bulk_set (bulk_rows._with_attribute_tags) and the decision checks; _only_reinforces also compares files, source_resource_id and source_class, for every memory.set (see "Why").
  • sdk/python/loom/decision.py: record() takes the three fields (keyword-only; a bare string for files raises TypeError).
  • Docs: docs/features/tasks-and-decisions.md, docs/features/memory/conflicts-and-refusal.md, docs/features/memory/writing.md (the memory.revised columns of a restatement, for every memory.set), docs/architecture/memory-architecture.md, .claude/rules/memory-plane.md, and the regenerated docs/reference/operations/decision.md.
  • Left alone: the record schema, decision.record's role, CODE_MEMBER_WRITE_OPS, and memory.set's own source_class field and its 422.

Compatibility, rollout and rollback

  • Wire: decision.record gains files (list[str] | null), source_resource_id (string) and source_class (derived / external / imported, not in the MCP listing). All optional; no default changes. DecisionOutcomeOutput.next is 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).
  • Stored data: decision rows written before this change keep their JSON value and embedding until the decision is recorded again or gets an outcome. Nothing reads the value as a dict, so no rewrite command.
  • Rolling upgrade: builds N-1 and N both read the record, not the value, so a JSON value written by N-1 beside N's statements is harmless. A decision.outcome served by N-1 rewrites the row from the payload alone: it drops the caller's tags (team:db, decision:owner:db), passes no files, so memory.set re-detects them from a JSON value that includes the realized outcome (the file swap this change fixes), and leaves an empty source_resource_id and the asserted class (a derived row can be raised to asserted). 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.
  • Operator steps: none.
  • Rollback: decision rows written meanwhile keep their statement values, which the old build serves as plain strings, and their files / source_resource_id / source_class columns.

Tests

  • tests/unit/test_decision_statement.py (new) and tests/unit/test_decision_ops.py:
    • Prose: the exact statement for full, sparse and failed-outcome payloads; casing kept; every part at its cap, ASCII or not, fits the excerpt less its key suffix.
    • Endings: a part keeps a trailing ellipsis and no other ending (…, …;, ..., ...;, ... ., a trailing comma); full-width sentence marks are not doubled; a leading "Because" is dropped on a word boundary ("Because.", "Because...", "Because, …", not "Becausewise").
    • Clips: whitespace cuts; slug cuts at :, /, - 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 as memory.for_file renders it, shows 60 characters of a realistic outcome at full caps (it fails at the previous 60 / 120 caps).
    • Files: detected from the stored fields (a path past a statement clip is attached, a .mdx name 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.
    • Full-text checks: a credential past the cut makes the row high; an email in decision_maker leaves 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 as blacklisted. A blacklisted phrase past the cut, in decision_maker or in a realized outcome refuses the write with no record and no memory row.
    • Conflict check (through check_on_commit with an identical-embedding peer): conflict for ci / db, deploy / deploys, a stop-word and a word-superset scenario, differences past the clip, a pinned peer and newest_wins. A foreign pinned decision with a below-threshold peer leaves the write clear and marked for review. mark_peers_conflicted keeps a pinned peer's pin.
    • Outcome: rewrites under the recording identity (a non-default user_id / session_id included); keeps files, source, class and the caller's tags (decision:owner:db included); 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.outcome does 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 sends files as a list and refuses a bare string.
  • tests/integration/test_decision_record_source.py (new), against a server from source on a private ClickHouse:
    • It records a decision with the three fields and caller tags, then records an outcome whose text names another file. Before and after, it reads the row from loom.memory and compares value, files, source_resource_id, source_class, memory_type, the exact tags, sensitivity, confidence and the identity.
    • It records seven decisions that read alike and reads seven live rows, each active or conflicted, at least one conflicted row cross-linked (conflict_with) only to others of the seven.
    • Before the conflict rule, four such records left two rows.
  • tests/integration/test_decision_record_source.py, tests/integration/test_read_scope_isolation.py, tests/integration/test_cross_principal_leakage.py before 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 new record() parameters.
  • Rebased onto main 83e0eaee (adds memory.import, which goes through memory.bulk_set; clean rebase, generated files current). Before that rebase, on main 8f7c7d88 (the record retirement): full tests/unit at 427778a8: 24,350 passed, 20 skipped, 1 xfailed. At 2631f5f9 (one more test only): test_decision_retirement.py, 41 passed. At the rebased 4e974aa4: full tests/unit, 24,461 passed, 20 skipped, 1 xfailed, and tests/analyzer, 10 passed, 2 skipped. At d7e63085, one test changed and models_import's sensitivity to the Sensitivity alias (same wire schema); the retirement, package-contract, import and copy tests pass there; the head e6e34e9f drops one redundant assertion from that test, which passes. The retirement tests cover the outcome against a re-record that changes only run_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 typecheck and make test-unit pass; the integration suite passes if server behaviour changed. (Format, lint, typecheck and the full unit run pass at 4e974aa4; the integration run predates the rebase, since Docker on the test host stopped creating containers.)
  • 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 feat/decision-record-files-source branch from 42fdcde to d808b9c Compare November 1, 2026 20:19
zlareb1 and others added 8 commits November 1, 2026 23:21
…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]>
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]>
@zlareb1
zlareb1 force-pushed the feat/decision-record-files-source branch from 2631f5f to 4e974aa Compare November 1, 2026 23:23
zlareb1 and others added 2 commits November 1, 2026 23:33
…e Sensitivity alias

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 merged commit d657945 into main Nov 2, 2026
21 of 22 checks passed
@zlareb1
zlareb1 deleted the feat/decision-record-files-source branch November 2, 2026 00:09
zlareb1 added a commit that referenced this pull request Nov 2, 2026
zlareb1 added a commit that referenced this pull request Nov 2, 2026
zlareb1 added a commit that referenced this pull request Nov 2, 2026
zlareb1 added a commit that referenced this pull request Nov 2, 2026
@pufit pufit mentioned this pull request Nov 2, 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