Skip to content

The verbatim check reads a span across interleaved label lines and letter case, and stores the document's words without the labels - #182

Merged
zlareb1 merged 15 commits into
mainfrom
feat/decision-extract-span-labels
Nov 3, 2026
Merged

zlareb1 merged 15 commits into
mainfrom
feat/decision-extract-span-labels

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 2, 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):

loom decisions extract now accepts a quoted span whose letter case differs from the document or that skips up to three short label lines a converted slide or diagram puts inside a sentence, and records the document's own words and case on one line, without the labels.

Why

Slides and diagrams converted to Markdown put short label lines (box titles, arrow labels) on lines of their own between a sentence's two halves, and a model copying a span skips them and often capitalises a sentence's first word. The verbatim check read both as "not in the document text" and dropped decisions the document states.

Scope and risk

server/memory/domain/decision_extract.py:

  • find_span matches with re.IGNORECASE and, between two words, either a whitespace run or a line break, one to three label lines and the next word on its own line. A label line is one to three words on a line of their own (blank lines around it allowed) that is title-like (its first letter or digit, after any markup, is an upper-case letter or a digit: a lower-case line of narrow-wrapped prose, "We keep the / old / index", continues its sentence, and a line of a script without case is never read across), does not start as a list item (-, *, +, 1. or 1) followed by a space, so **Proxy** and +3 nodes are labels), a fence or code, a rule (---, ***, ___), a table row, a heading or a heading's underline (===, ---), an HTML tag, a quote or a definition; does not end in ., !, ? or ; (or their full-width forms, closing brackets, quotes and emphasis after the mark aside), as the last line of a wrapped paragraph does; and holds no ban word (states_a_ban's list), no contrast word (inverted_options' list), no hedge (rarely, unless, but, however and the like, a list used only here) and no word ending in n't. A bullet (•, ◦, ▪, ‣, ·, ‧) and a line starting with = (an AsciiDoc heading) are structure too. The trade-off, stated once in the docs and the docstring: a label is recognised by its shape and these word lists, so a short line of another kind that the sentence needs can still be read across; the stored span is the document's words, so a reader can check it against the source. So "Retries are / not / safe" never reads as "Retries are safe", and a paragraph break never reads as a label. A fourth label line, a four-word line, a line that is no label, or a label inside a line ends the match, and no label is read after a word ending in sentence punctuation (closing brackets, quotes and emphasis after the mark aside): a label sits inside a sentence, and a join across a sentence end (a heading between two paragraphs) is the stitched quote the check refuses. Between two words the fewest label lines that reach the next word are read, so a later line reading as that word is not swallowed as a label. One chunk only, the first chunk wins, as before.
  • Each gap plus its next word is an atomic group ((?>...), Python 3.11+), so once the next word is found the gap is not re-read another way: a failed match costs time linear in the span's words at each start position. Each word but the last must end where a document word ends ((?=\s)), so so never takes the start of a label Something and then fails. The plain whitespace reading is tried before labels, and labels are as few as reach the next word. A stored span is label-free (see document_spans below), and find_span re-finds its document text across the same labels, so the retire step keeps a row on an unchanged document. A second limit, stated in the docstring and the docs and pinned by a test: a last word that would end inside a document word is tried after the label reading of its gap, so a rejected label reading there leaves that start unmatched ("cache plan" over "cache / plans / not / plan"); a retry at the same start without the label alternative was not added, as it would need a second pattern per span for a shape this rare. The main limit: a label line whose first word reads as the next word ("The proxy" over "the nearest replica") is taken as that word and the span is not found, which the docs and the docstring state and a test pins. The last word prefers a word end, then the label reading, then a partial end as before (a CJK span has no spaces to end at). Whether the lines read across are labels is checked on the match's groups, not inside the pattern, where the word lists would be tried at every character of every line read as a label; a rejected match retries from the next start.
  • Chunk texts hold a section's body without its heading line (detect_sections splits on headings and chunk_document windows inside each body); a # line inside a chunk is a fenced or HTML block's text. The retire step also searches the whole document text, which holds heading lines: an ATX heading (#), a Setext underline (===, ---) and an HTML tag line (<h2>…) are all lines that are no label, so a span never reads across a heading there either.
  • MIN_SPAN_CHARS is still measured on the span as the model gave it (unchanged).
  • _drop_inverted reads the inverted-option check on unlabelled_span of the quote (the stored reasons already have the same words, which is all their match reads): the document's match with its label lines (and the blank lines around them) left out and its other line breaks kept. A list item or blank line still ends a sentence there, and a label naming a rejected option ("Shard by tenant" inside "We shard by time / so joins stay local") states nothing. Removing a label's blank lines with it is deliberate: a label sits inside one sentence, and a blank line left in its place would end that sentence. Chunk breadcrumbs are detect_sections paths (chunk_document sets each chunk's section_path from the section it windows), so quote_section names sections as the image-only filter does.

Every find_span caller, checked against the wider match:

  • verbatim_failure, unfound_reason: only ask whether a span is found; a case-differing or label-split span now passes, which is the change.
  • document_spans now stores stored_span: the document's own span with the label lines it read across left out and whitespace collapsed onto one line, its words and case. The same match find_span makes, with the label lines removed through the pattern's groups. Quote, reasoning, every rejected reason and a reason-less ban's outcome are stored this way, so the label lines the match read across are left out of the record and a re-run writes the same text. Rows written before this change kept line breaks; _same_decision compares with whitespace collapsed, so a re-run leaves them unchanged.
  • _check_window: unchanged order: document_spans first, then reasonless_ban, restates_outcome and without_reason on the stored spans. stored_span gives the model's words up to case (a label the model copied stays in both, one it skipped leaves both), and these checks ignore case in their word comparisons, so they judge the same words the model gave; a reason-less ban's outcome is the stored reasoning on one line.
  • quote_section(w, find_span(quote) or quote): find_span returns the raw text with labels, a substring of its chunk, so quote in c.text names its section; a stored label-free quote is passed through find_span first at both call sites.
  • _repairs also compares the failed outcomes with letter case aside, as the held keys and pairs do, so a repair whose outcome differs in case is not dropped as a repeat (test added).
  • _repairs: compared the model's raw reasoning, whitespace collapsed, with the kept candidates' document spans. A repeat copied in another case would have slipped past and been written under a reworded scenario and outcome; it now compares the stored span (stored_span) (test added, fails without the fix).
  • _retire_one: find_span(stored reasoning, live_texts). The stored reasoning holds the document's words in order; find_span reads across the same labels again, so an unchanged document keeps the row and a changed one retires it (tests for both). A document whose only change is letter case no longer retires the row. The held map and the retire lookup key the outcome and the reasoning with whitespace and case aside (_held_key, a casefold; find_span uses re.IGNORECASE, which differs only for one-to-many folds such as ß/ss), so a case-only change under a reworded scenario replaces the old row, for a reason-less ban too.
  • _same_decision and _same_reasons (Reconcile) compare the stored reasoning and rejected reasons with letter case aside, as the verbatim check, the retire step and the held keys do, so a case-only change in the document leaves a pinned or attested row unchanged instead of tagging it source-changed depending on the model's reply (test added).
  • _states_as_chosen builds its own pattern from a reason over the quote, both unlabelled_span (_drop_inverted); it now ignores case too, so a reason the quote holds in another case is still the sentence that rejects it.
  • Statement and pre-edit block: memory_value reads the stored parts, which leave out the label lines the match read across; states_reason compares the reasoning and outcome case-folded, and a reason-less ban's outcome is its stored reasoning, so it still reads as no stated reason.

Left alone: the cross-chunk rule (no joins across chunks), the window and prompt, and the recap rule (a heading that names a recap, summary or background).

Compatibility, rollout and rollback

  • Wire: none. No op, field or default changes.
  • Operator steps: none. A re-run of loom decisions extract over a converted deck may now record decisions it dropped before.
  • Rollback: reverting leaves recorded rows as they are; a later run under the old check would retire a row whose reasoning only the wider match finds.
  • Rolling upgrade: the extractor is an operator command run in-process; builds N-1 and N share no state through it beyond the rows decision.record writes.

Tests

  • New unit tests in tests/unit/test_decision_extract.py (fake LLM): a span split by 1, 2 and 3 label lines is found and returned as the text's own; 4 label lines, a 4-word label line, and labels inside a line are not found; a case-differing span is found as written; a span across two chunks is not found; 200,000 lines that all read as span words or labels, and 200,000 where every match is rejected, each cost under 60x the time of a tenth of the input, both the best of three runs (quadratic time would be about 100x); twice the span's words against one text costs under 20x (about 1.5x here; with the atomic groups removed, about 190x); labels starting like the next word (Something/so, API/a, Index/a) are read across; not, don't, never twice, a list item, a numbered item, a fence, a table row, a heading and a quote are not skipped; a label line whose first word reads as the next word is not found (pinned, two cases); the fewest label lines reaching the next word are read; a wrapped paragraph's last line is no label; every documented non-label prefix and sentence end is parametrized; a reasonless ban whose document span holds a label is stored without it, whole-quote and fragment cases; a lower-case line (wrapped prose, shard a) is no label; a case-only outcome difference across overlapping windows is one decision; a stored label-free span retires nothing on an unchanged document and retires on a changed one; a found span with labels finds itself; a case-only change under a reworded scenario replaces the old row; a ban copied in another case is still its whole quote; a reason in another case keeps its option rejected; a run stores a case-differing, label-split reasoning as the document's text and the retire step keeps that row while retiring one whose reasoning left; label words do not save a restating reasoning; a repeat copied in another case on the second read is dropped as a repeat; a run leaves out a rejected option that a list item of the quote states as chosen; a label naming a rejected option keeps it rejected; the blank lines around a label are dropped with it in the inverted check; a CJK line between two CJK halves is not read across; Only, Always, Instead, Rather, Rarely, Unless, • Shard A, Costs.) and **Done.** are no labels; each no-label fixture fails with only its own rule removed: the structure, sentence-end and word-list fixtures pass the title-like check, while ***, ___, ---, -, -- and 代理 pin the title-like rule itself (=== is caught by both the title-like rule and the = prefix, and Not and Never twice are in both word lists, so each of these fails only with both of its rules removed); a heading between two paragraphs is not read across, after ., .), ." or .*; a ___ rule is no label and 2.5 GB, a dotted version number and 3 replicas are labels.
  • Existing tests changed by design: test_a_span_differing_only_in_whitespace_is_the_documents and test_a_span_with_other_line_breaks_is_recorded_on_one_line (renamed) now expect the stored span on one line. The _World fixture gained a content attribute so a test can set the document text the retire step reads.
  • make format lint typecheck: pass. tests/unit/test_doc_links.py tests/unit/test_public_copy.py: pass.
  • Full unit suite (pytest tests/unit -q -p no:randomly) on the branch rebased onto main: 25281 passed, 20 skipped, 1 xfailed, and 1 failed, test_profile_redaction.py::test_a_retried_redact_scrubs_the_profile_rows_a_failed_one_left, which passes run alone (9 passed) and does not reach the extractor.
  • No integration test covers the extractor; it runs against stubbed planes in the unit suite.

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; every find_span caller listed above and the regex's backtracking bound were checked by reading the code and by the tests named above.

  • 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 (none affected).
  • A new migration is additive and numbered after the latest on main; no merged migration is edited (none).
  • A behaviour change to any file a plugin ships bumps both plugin manifests' version (none).
  • The frontend builds, if frontend/ changed (not changed).
  • Docs under docs/ describe the system as it now is: docs/features/tasks-and-decisions.md, the verbatim check, reason-less bans and the retire step.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers.
  • Commits are signed off (git commit -s).

🤖 Generated with Claude Code

@zlareb1 zlareb1 changed the title The verbatim check reads a span across interleaved label lines and letter case, and a recap divider covers the sections after it The verbatim check reads a span across interleaved label lines and letter case, and stores the document's words without the labels Nov 2, 2026
zlareb1 and others added 15 commits November 3, 2026 03:51
…tter case

find_span now matches a span with letter case ignored and with up to three
short label lines (one to three words, each on a line of its own) between two
of its words, as slides and diagrams converted to text put box labels between
a sentence's two halves. The returned span is still the chunk's own text,
labels included, so it stays a substring of the live document. Each gap is an
atomic group, so a failed match costs linear time.

The restatement check reads the model's spans, so label words in the
document's span add no reason, and the second read's repeat check compares
the document's span of a reasoning.

A short section (at most a caption of text, no subsections) whose heading
names a recap, summary or background now opens a recap span over the
sections after it, until the next short section or a heading above its level.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…where the text's does

find_span reads a line across only when it is a label: not a list item, fence,
table row, heading, quote or definition, and holding no ban, contrast or n't
word, checked on the match's groups. Each word but the last must end where a
document word ends, so a short word never takes the start of a label. The
retire step's reasoning key and the reason-less ban's whole-quote check ignore
case as find_span does, the inverted-option check finds its reason in any
case, and a breadcrumb that also names a section outside a recap span is not
covered.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…bel, and the fewest labels are read

The last line of a wrapped paragraph ends in sentence punctuation, so a span
no longer reads across a paragraph break. Setext underlines and HTML tag
lines, which the retire step meets in the whole document text, are no labels
either. A gap reads the fewest label lines that reach the next word, so a later
line reading as that word is not swallowed as a label.

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

A kept candidate's quote, reasoning, rejected reasons and a reason-less ban's
outcome are stored as the document's words and case on one line, the label
lines the match read across left out (stored_span). The retire step reads the
stored span across the same labels again. The ban checks run on the model's
spans before the document's replace them, and the retire step's held key
ignores case in the outcome too.

A recap divider's body only titles what follows: image-only, or a short line
with no sentence punctuation and no link, so a one-line summary section no
longer drops the sections after it.

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

A line starting lower case continues a narrow-wrapped sentence and is no
label. A recap divider's span ends at the first section longer than a slide
(600 characters), so a design document's lone diagram or empty Background
heading covers nothing. Candidates differing only in the case of their
outcome across windows are one decision.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…e document's lines

The recap divider span is removed: a rule that can drop a design document's
decisions must fail toward keeping them, and the heading-named recap rule
stays as it was. The inverted-option check reads the document's raw match of
the quote and its reasons, so a list item or a blank line still ends a
sentence although the stored quote is on one line.

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

The inverted-option check reads the document's match with its label lines left
out and its other line breaks kept (unlabelled_span), so a label naming a
rejected option no longer reads as the quote choosing it. A label gap is
refused after a word ending in sentence punctuation: a label sits inside a
sentence, and a heading between two paragraphs is no label.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…e is told apart

The restatement and reason-less ban checks run after document_spans, as on
main: the stored span is the model's words up to case. A label gap is refused
after a sentence mark followed by closing brackets, quotes or emphasis; a
`___` rule is no label, and a number such as 2.5 GB is no list marker.

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

A line starting `-`, `*` or `+` is a list item only with a space after the
marker, and `---`, `***` and `___` are rules, so emphasised box titles and
signed numbers are labels. The structure cases use lines of at most three
tokens, so each fails without its prefix rule, and a test doubles the span's
words against one text, which an exponential matcher fails.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
The chunker reads any run of `-` under a line as a Setext underline, so a
one- or two-dash line is structure too, and a numbered marker alone (`3)`)
stays one. The text-length timing test's comment says what it pins.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…tence end is no label

A label line's first letter or digit, after any markup, must be upper case or
a digit, so a line of a script without case is never read across. A line
ending in a sentence mark followed by closing brackets, quotes or emphasis is
no label. Tests pin each word list, the blank lines removed around a label in
the inverted check, and the partial last-word limit is documented.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
The no-label fixtures pass the title-like check, so each fails with only its
own rule removed. The underline and rule branches are dropped: a line with no
letter or digit is never a label. The partial last-word limit is documented
and pinned.

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

A line holding rarely, unless, but, however and similar hedges is no label,
nor is a line starting with a Unicode bullet. The docs and the find_span
docstring state the trade-off: a label is recognised by its shape and word
lists, and the stored span is the document's words, checkable against it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
_same_decision and _same_reasons compare the reasoning and the rejected
reasons with letter case aside, as the verbatim check, the retire step and
the held keys already do, so a pinned row is not tagged source-changed for
a capitalised word. The wrapped-paragraph test now pins the sentence-end rule.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
_repairs compares the failed outcomes with case aside, as the held keys and
pairs do. _drop_inverted remaps only the quote through unlabelled_span: the
stored reasons have the same words. The docs drop a stray sentence and say
duplicate candidates are compared with whitespace and case aside.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 force-pushed the feat/decision-extract-span-labels branch from 3ba9176 to 6915d23 Compare November 3, 2026 03:52
@zlareb1
zlareb1 merged commit 10840a9 into main Nov 3, 2026
20 of 22 checks passed
@zlareb1
zlareb1 deleted the feat/decision-extract-span-labels branch November 3, 2026 04:17
@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