Repository navigation
The pre-edit block shows each decision and constraint whole - #228
Merged
Merged
Conversation
zlareb1
force-pushed
the
feat/for-file-whole-decisions
branch
6 times, most recently
from
November 3, 2026 22:54
c4479e4 to
c0eaae2
Compare
memory.for_file prints a decision or constraint row whole (statement, every rejected option, source) instead of cutting it at 220 characters, and reads it up to the block's ceiling rather than 600 bytes. Those rows no longer count against token_budget, which keeps applying to the other rows; they share one ceiling, the new LIVE setting memory_for_file_whole_tokens (1500), which keeps the block under the hosts' hook-output caps. Rows past it are left out and named on a closing line with how to read them. 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]>
…whole The decision statement no longer clips its parts: the record's field limits bound each one, and the embedding already reads only its own excerpt. The pre-edit block reads a decision or constraint up to six stored bytes per character of its ceiling, so escaped non-ASCII text is judged by its printed length. A row left out with the row that supersedes it is counted on the "… more" line, never named as one to read, and the left-out line names at most five keys. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…its more line The record cuts an alternative over 300 characters at a space and ends it in "…", so the record, the statement and file detection see whole tokens only and re-extraction tells a cut alternative by its mark. The pre-edit block reads a decision or constraint at twelve stored bytes a character (an escaped surrogate pair) and skips its no-reserve shortcut whenever a row will be left out. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…erves less is_cut also takes an alternative that fills ALTERNATIVE_CHARS, as a stored one cut there with no mark does, so re-extraction matches its reason as a prefix. Alternatives are deduplicated on their cut form. The pre-edit block reserves room for a "… more" line only when a budgeted row may be left out or a decision or constraint left out at the ceiling supersedes older rows. The precedents test gains a distractor that shares the target's excerpt. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
clean_alternatives always deduplicates, and counts toward MAX_ALTERNATIVES, on the cut form, so the extractor's uncut list holds as many alternatives as the record will and an unchanged document re-extracts as unchanged. render_block reads its ceiling from the setting only. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
The row's excerpt is cut from the stored JSON, where a non-ASCII character is a six-character escape, but chunking compared the decoded text with the excerpt limit. A Cyrillic or CJK value of a few hundred characters was embedded by its first part only and got no chunks, so its tail could not be found. Chunking now compares the text the excerpt is cut from. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…te retires its passages The excerpt keeps room for its " (#<key>)" suffix, so the chunk threshold now takes the memory key and compares the stored JSON with what is left; every caller passes the key it has. memory.delete_version retires every chunk the removed version's passages can hold, not only those the current rule plans, so a chunk written under another rule no longer outlives the version under shared-scope search. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…serves A key's memory.set chunk rows are the user's, shared by every agent and session holding the key, so the restore after memory.delete_version now reads each of that user's live rows of the key (user_key_rows) and puts back the chunks any of them cuts, not only the deleting identity's newer value. The restore always runs; it is idempotent. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…l cuts A key's memory.set chunk rows carry no user: every user, agent and session holding the key shares them. The restore after memory.delete_version now reads every row of the key in the namespace that search serves (served_key_rows: live, not expired, inside its validity, of a served status), projecting only what it needs and computing each distinct value's chunks once. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…ing row served_key_rows excludes the deleting identity in SQL and returns each distinct (memory_type, sensitivity, value) once, so the restore computes one chunk set per value. The chunk-row fixtures share one base row, and the restore test covers an ended and a high row. 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]>
served_key_rows leaves out high rows and unsearchable types in SQL and returns each distinct (memory_type, value) once. The docs name the key suffix the excerpt reserves. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…t line caps each key An alternative with no space before the limit is cut between two wide characters (Hangul pairs excepted), so unspaced CJK keeps its text and two options that differ early stay two; a single long token such as a path or unspaced Thai still leaves the mark alone. The for_file closing line cuts each named key and namespace at 120 characters. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
cut_alternative drops the punctuation or dash a cut leaves before the mark, and its scan for a wide pair stops before comparing the last character with the first. 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/for-file-whole-decisions
branch
from
November 3, 2026 22:57
c0eaae2 to
14d5e69
Compare
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.recordnow stores a decision's statement whole: scenario, outcome, reason and every rejected option. The pre-edit block (memory.for_file) prints every decision and constraint whole with its source, outsidetoken_budget, up to a new ceilingmemory_for_file_whole_tokens(1,500); it names any it leaves out. A long statement is embedded by its first 1,200 characters and found past them through its chunks. A rejected option over 300 characters is now cut at a word and ends in…. A non-ASCII memory value of a few hundred characters is now chunked, so its tail is found. A decision recorded before this release keeps its shortened statement until it is recorded again.Why
A decision cut short loses its reason and the options it rejected, which are the parts an agent needs before an edit. Two cuts did this.
decision.recordclipped each part of the stored statement (scenario 80 characters, outcome 200, reasoning 360, rejected options 240 joined, realized outcome 170). Thenmemory.for_filecut every line to 220 characters and counted decisions against its 300-token budget, which could drop a long decision outright.The stored statement (
server/memory/domain/decision_statement.py). The per-part clips and their helpers for cutting wide text are removed. The record's own limits bound each part: scenario 2,000, outcome 1,000, reasoning 4,000, realized outcome 2,000, up to ten alternatives of 300. A statement can therefore run to about 12,000 characters. Every write path (decision.record,decision.outcome,loom decisions extract) goes throughDecisionRecordInputor the stored record, so no part is unbounded. The clips existed so the statement fit the 1,200-character embedding excerpt.build_excerptalready cuts the embedding input to that length and keeps the key suffix. A statement whose stored form runs past the excerpt is also written toloom.memory_chunks, as any longmemory.setvalue is, so search still reaches its tail: a new integration test showsdecision.precedentsfinding a decision by its outcome and reasoning when the scenario alone fills the excerpt.Alternatives (
server/memory/app/decisions.py). The record used to cut an alternative at exactly 300 characters. Now that the statement carries alternatives whole, such a cut can leave half a path, which file detection reads as a file the decision never names (src/cache/LruCache.cofLruCache.cpp). An alternative over the limit is now cut at the last space before it, or later between two wide (CJK) characters (two Hangul syllables excepted, since Korean spaces its words), and ends in…. So unspaced Chinese or Japanese keeps its text, and two options that differ early stay two. A first token longer than the limit with neither a space nor a wide pair, such as a path, unspaced Thai or unspaced Korean, leaves…alone. So the record, the statement and file detection see whole tokens only, and_without_cut_tokenis deleted. Alternatives are always deduplicated, and counted toward the ten, on their cut form, including the extractor's uncut list, so a candidate holds as many alternatives as the record will. Re-extraction (_same_reasons) treats an alternative as cut (is_cut) when it ends in…or when it is 300 characters long, as an alternative stored by an earlier build and cut there with no mark is. A cut alternative's reason matches a candidate's as a prefix.Chunking non-ASCII values (
server/memory/app/set_chunks.py). The excerpt a row is embedded by is cut from the stored JSON, where every non-ASCII character is a six-character\uXXXXescape. Chunking compared the decoded text with the 1,200-character limit instead. So a Cyrillic or CJK value of about 200 to 1,200 characters was embedded by its first part only (about 190 characters) and got no chunks, and its tail could not be found. A decision with a Cyrillic scenario could not be found by its outcome._chunked_textnow compares the text the excerpt is cut from (the stored JSON, or a procedure's text), against the room the excerpt leaves after its key suffix, and still chunks the human text. This is a fix for every memory value of that kind, not only decisions:(#<key>)suffixbuild_excerptreserves, somemory_keynow reachesplan_set_chunksandset_chunk_identitiesfrom every caller (the write, the private-scope fold, delete_version). This changes which values are chunked in three ways.decision:<16 hex>key.memory.delete_versionused to retire a version's chunks by the identities the current rule plans for it. That would miss chunks written under a different rule: an old dict chunked by its indented length, or a short non-ASCII value whose chunks an N-1 delete left. Shared-scope search (fold_shared_set_chunks) reads no row and serves any live chunk of the key, so such a chunk would keep lifting a deleted version.passage_identities: every chunk row the version's passages can hold, whatever the excerpt rule. These are the only rows whose index and text match this value._restore_newer_chunkstakes the same set and puts back every chunk a value search still serves cuts. A key's chunk rows carry no user: they are shared by every user, agent and session holding the key, and stamped by the last writer. So the restore reads every row of the key in the namespace that search serves, through a new sequentially consistent store read,served_key_rows: live, not expired, inside its validity, of a served status, and notsensitivity: high. It restores the union of their chunks and the deleting identity's own newer value's. Before this, only the deleting identity's newer value counted, so another session's or user's passages of the key went dark.served_key_rowsselects two columns (memory_type,value), one row per distinct value. It applies every filter in SQL: the deleting identity left out, live, not expired, inside its validity, of a served status, notsensitivity: high, and of a searchable type. The primary key prunes it to the namespace, and thememory_keybloom filter skips the granules without the key. It is one FINAL read per version delete of a searchable value, plus a second only when chunks were put back. A value of no searchable type returns before any read.memory.delete, a move and erasure retire all of a key's chunks, so they were never affected.memory_embeddings.content_excerpt, which is the same 1,200-character stored excerpt. Past the excerpt, only the chunk plane reaches the text, which is why the chunk threshold must follow the excerpt.The pre-edit block (
server/memory/app/for_file.py).memory_type = 'decision', or taggeddecisionorconstraint) is read up towhole_bytes=memory_for_file_whole_tokens× 4 × 12, which is 72,000 bytes at the default. Twelve bytes is the stored length of one escaped character outside the Basic Multilingual Plane (an emoji is a surrogate pair, two\uXXXXescapes). The rendered line then decides whether the row fits. Every other row is still read up to 600 bytes.token_budget, which keeps applying to the other rows.- … <n> more decisions or constraints left out to keep this block short; memory.get on the key reads each, or loom_search: <key>, <key> (namespace "<ns>") and <m> more. It names at most five keys.… moreline and never named as rows to read.… moreline only when a budgeted row may be left out, or when a decision or constraint left out at the ceiling supersedes older rows.Ceiling: 1,500 tokens (about 6,000 characters), a LIVE setting allowed from 50 to 4,000.
additionalContextwhole only up to 10,000 characters; past that it saves the text to a file and shows a 2,000-character preview.Scope and risk
decision.recordstores a decision's row value as the whole statement, which is embedded by its 1,200-character excerpt and chunked intoloom.memory_chunkspast it. The record cuts a long alternative at a word with a…mark, and re-extraction matches reasons against those cuts.memory.for_file's select, renderer, wire comments and op description.top_k, tenant scoping (row_in_scopeon extra namespaces), sensitivity and expiry filters are unchanged.memory.getreturns it whole andmemory.searchserves it in the body mode asked for, and a statement over the 1,200-character excerpt also writesloom.memory_chunksrows. The blacklist, sensitivity and attribute checks already read every field, so nothing new is let through.whole_bytes(72,000 bytes at the default).memory.setvalue taggedconstraintordecisionhas no value limit, so such a row can read the full 72,000 bytes.limrows (top_k, default 8, max 50). The links match reads up tolimmore per slice of linked ids, and a slice holds about 1,600 ids. So a namespace reads at mostlim× (1 + slices) ×whole_bytes. For a file with fewer than 1,600 linked memories at the defaulttop_k, that is 8 × 2 × 72 KB, about 1.2 MB, and attop_k50 about 7.2 MB, for each of up to three namespaces read.loom-file-contexthooks passrenderedthrough as it is and have no character cap of their own. They sendtoken_budgetfromLOOM_FILE_CONTEXT_TOKENS(300), which now covers only the other rows. The Cursor integration does not callmemory.for_file. No hook code changed, only the env-knob comment and the README row, so the plugin manifests are not bumped.decision_extract's prompt still asks for an outcome short enough that "Decided because ." fits 220 characters. That is a quality target for extraction, not a render cap, and this PR leaves it alone.Compatibility, rollout and rollback
memory.setvalue whose stored JSON runs past the excerpt now writes chunks (chunks_written), including short non-ASCII values that wrote none before.token_budgetnow covers only non-decision, non-constraint rows.valueup to the read limit rather than 600 bytes.truncatedis also set when the ceiling left rows out.…at a word boundary rather than being cut at exactly 300.is_cuttakes the 300-character length).…-marked cuts, which are at most 300 characters, as uncut unless one is exactly 300. So an N-1 extraction pass over a document N recorded may re-record its decisions once, in N-1's form, and N rewrites them whole on its next pass.memory.delete_versionof such a version during the window retires by N-1's rule, so it leaves N's chunks of that version live. Shared-scope search would serve them until N retires them: N's nextdelete_versionof the key retires by passages, a whole-key delete or erasure retires them all, and a later write of the key long enough to chunk replaces them. That residue is limited to deletes N-1 serves while the window lasts.decision.recordwith the same category and scenario rewrites the row whole.decision.outcomealso rewrites the row whole from the record. For a record whose alternative an earlier build cut at exactly 300 characters, the statement then carries that cut as stored, which can end in half a token with no…. Files are unaffected: the row's files are kept or detected from the record's fields as before.LOOM_MEMORY_FOR_FILE_WHOLE_TOKENS(default 1500, LIVE) is optional.…-marked alternatives written by this build stay in place, and the reverted build prints those statements cut. No migrations are involved.Tests
tests/unit/test_memory_for_file.py:… moreline added by a left-out constraint still fits the budget, and notes that fill the budget exactly all print beside a constraint left out at the ceiling that supersedes nothing.whole_bytes, and the setting driving both; the render tests set the ceiling through the setting.test_decision_statement.py,test_decision_ops.py,test_decision_extract.py:src/cache/LruCache.cpp is slow, whose raw cut would end insrc/cache/LruCache.c, is cut at the space, so neither the record's files nor the statement name a file.…. Unspaced CJK is cut between characters, and two options alike for the first 299 characters are one while two that differ early are two. Unspaced Thai leaves….slow,,option —or a full-width,ends in the word and…. Unspaced Korean over the limit leaves…alone.部署失败怎么办?keeps its?, and使用ClickHouse。ends in..test_memory_for_file_decisions.py(a decision whose outcome, reasoning and rejected options are each past the old clips, the options over 240 characters joined, is served whole, with no...and no…),test_decision_record_source.py(4 tests: the row's files, source and class; alike decisions, two of which now share their whole excerpt, each keep a live row;decision.precedentsranks a Latin decision and a Cyrillic decision first by their outcome and reasoning past the excerpt, each with a distractor that has the same scenario, and so the same excerpt, found below it),test_decision_extract_repo.py,test_memory_code_links.py,test_knowledge_chunking.py: 209 passed.test_memory_set_from_messages.py,test_raw_evidence_sensitivity.py,test_vector_retire_race.py,test_memory_delete_list.py: together with the files above, 227 passed and 35 skipped. After the restore change,test_decision_record_source.py,test_memory_for_file_decisions.py,test_memory_delete_list.py,test_search_statements_pass_analyzer.pyandtest_vector_retire_race.pywere run again: 54 passed, 32 skipped.test_memory_set_chunks.py: a 300-character Cyrillic value is chunked, and an ASCII value of the same length is not. A decision statement stored in 1,180 characters under adecision:<16 hex>key is chunked, and without a key it is not. An ASCII string whose escapes push it past the excerpt is chunked.test_delete_version_sql.py:user_idis empty, with the shared chunk stamped-. An expired, superseded, ended (valid_topassed) orsensitivity: highrow does not keep it. The other-session case fails with the cross-identity read stubbed out.make format lint typecheck,agent_plugin_sync --check, the plugin'sfile-rules-teamtest,test_public_copy.py,test_doc_links.py,test_test_inventory.pypass. Regenerated: settings reference, schema and example;docs_reference; SDK generators (no change); the LIVE and defaults snapshots.pytest tests/unit -q -p no:randomly) on this head: 26,226 passed, 20 skipped, 1 xfailed, 0 failed.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: the read limit, render pools, statement and alternative cuts against the tests and a live server.
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.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