Skip to content

Decision extraction drops restated reasons, matches spans whitespace aside and skips captioned images - #176

Merged
zlareb1 merged 27 commits into
mainfrom
feat/decisions-extract-quality
Nov 2, 2026
Merged

zlareb1 merged 27 commits into
mainfrom
feat/decisions-extract-quality

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

Related: #174

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 drops a candidate whose reasoning only restates its outcome, accepts a span whose whitespace runs differ from the document's (and records the document's own text), and treats a section holding an image and a caption as image-only. The prompt now asks for the reason behind each choice and skips recap sections and superseded behaviour.

Why

The verbatim check accepts any span of the document, so a reasoning that is the decision in the document's own words ("We spill into sorted runs.") passes, and an agent reads "Decided X because X". Such rows are the main source of weak extracted decisions. The same check dropped good candidates whose span differed from the chunk only in line breaks or doubled spaces, which models drop when they copy. A recap section, or one that describes an old default as history, produced rows stated as current. And a diagram with a one-line caption had words, so it was sent to the model, which then built a rationale out of the caption.

Scope and risk

The rules live in server/memory/domain/decision_extract.py. server/memory/app/decision_extract.py changes in seven places: the section skip before the model call, the retire step's held key, the duplicate-pair key, _same_decision, the retire step's find_span, the document_spans/restates_outcome call in the candidate loop, and quote_section reading the document's span of the quote, so a dropped line names the right section:

  1. Restated reasoning (restates_outcome): a candidate is dropped when every content word of its reasoning is a word of its outcome. Words are compared lower case, without punctuation, as Snowball stems (server/memory/domain/lemmatize.py, the stemmer search already uses; stored meets store, running meets run), and a short list of filler words (we, the, will, decide, chose, use, instead, because, since, picked, opted, decision, ...) is skipped in any form, compared as stems. The prompt asks for the outcome without its reason: an outcome that carries the reason leaves the reasoning nothing to add, and such a candidate is dropped (a test pins this). The dropped line says reasoning only restates the outcome: it has no word the outcome lacks. I chose a subset test over containment or a similarity score: it explains itself in one line, needs no threshold, and errs towards keeping. A reasoning with even one word the outcome lacks stays. It runs after the verbatim check, on the document's spans.
  2. Whitespace (find_span): each span is matched with every whitespace run read as one space, through a regex built from the span's words joined by \s+. A candidate that passes is rewritten with the chunk's own spans (document_spans), so what decision.record stores is the document's text, line breaks included, and the quote's section is looked up from that text. The retire step uses the same find_span against the live text, so a re-wrapped line does not retire a row. Reconcile compares the stored reasoning with whitespace collapsed (collapse_ws), so a whitespace-only change is no change for every row: a confirmed row or one with a recorded outcome is not tagged source-changed, and an unconfirmed row keeps its stored span rather than being re-recorded. The retire step's map of decisions this run holds keys on the collapsed reasoning on both sides, so a re-wrapped reasoning under a reworded key still replaces the old row. Rejected options' reasons need no change: decision.record stores them collapsed already. Storing the document's span rather than the model's means the stored reasoning is still an exact substring for a build that tests with in, so N-1 agrees with N on every row N writes during a rolling upgrade. A row N keeps unchanged after a whitespace-only change in the document is, to an N-1 run, which compares exactly, a changed decision: N-1 may re-record it, delete it (an unconfirmed row its model does not emit again), or tag it source-changed (a confirmed row or one with a recorded outcome). N-1 already behaves this way on any whitespace change today. A later N run reads the row unchanged and clears that tag again. For an operator command this is harmless.
  3. Recaps and superseded text: prompt only. The model is told to emit nothing for a section that sums up other sections, and never to give as the outcome what the text marks as former, replaced or superseded.
  4. Captioned images: image_only now also holds for a body with an image and at most CAPTION_MAX_CHARS (80) characters of other text. The existing "no letters" rule is kept as no_words. Image markup inside a code span or a fenced block (![d](f.png) or <img> in code) is text: its markup characters are blanked, so the code still counts as text beside a real image. An image is also a reference-style Markdown image (![diagram][fig1]). A shortcut reference (![spill flow]) is not read, since it looks like a macro such as vec![0; n] in prose. The caption's characters are counted after images, HTML tags (a lower-case tag name on one line, so x < 10k and Option<A> stay text), link targets, reference labels, the empty brackets a link around an image leaves, and bare URLs are removed, so a badge wrapped in an HTML or Markdown link adds no text whatever form it takes; whether the body has an image at all is tested on the image forms alone. The image placeholder now matches [image], [Image 3], [image: ...], [image1], [image_1], [images] and [pictures], and no longer matches link text such as [image tiles](tiles.md), a reference link [image][1] or definition [image]: x.png, or a word such as [imagine ...]. Loom's own parsers emit no placeholder; these come from exported documents. The rule is judged on each section's own text (image_only_sections): a leaf, or a parent whose own text is a picture and its caption, while a heading alone over its subsections is not one. The text above the first heading, or a document with no heading, counts when it holds a picture and at most a caption; it is reported as (untitled). A chunk stored with an empty section path is skipped only when its own text is image-only too, so a document chunked without headings is not dropped whole. The chunks of those sections are the ones not sent, and the same list gives the report line, so a captioned diagram is reported with the image-only, rationale not extracted line rather than skipped silently, and a long section's last chunk holding an image and a short tail of text is still sent. A chunk with no words is not sent, as before. Text of that length with no image is still sent.

server/llm/fake.py: the fake model's answer to the extraction prompt used the first sentence as both outcome and reasoning, which the new check drops. It now takes the first sentence as the outcome, the second as the reasoning, and the span through both as the quote, and emits nothing for a section with one sentence.

server/cli/decisions.py: the help says the reasoning must say more than the outcome and that a heading over only an image and its caption is skipped; the CLI snapshots and docs/reference/cli.md are refreshed (help text only).

Left alone: reconcile, retire ownership, races and exit codes. Rows written before this change whose reasoning restates their outcome are not retired: retire still deletes only rows whose reasoning left the document or which this run recorded under another key. A re-run drops the restating candidate and leaves the old row as it is.

Compatibility, rollout and rollback

  • Wire: none. No op, field, setting, table or column.
  • Operator steps: none.
  • Rollback: reverting leaves rows written with the document's spans, which the old exact check reads as before.

Tests

  • tests/unit/test_decision_extract.py, fake model and stubbed planes: the restatement rule over pairs (restated, restated with inflection and filler, filler words in other forms such as were chosen and are choosing, store/stored, run/running, process/processes, a reason); a restating candidate dropped with its line and nothing recorded; a span with other whitespace passing, with find_span returning the document's text and rejecting a missing space; a candidate recorded with the chunk's line break in its reasoning; a row whose stored reasoning was re-wrapped not retired; a re-wrapped reasoning under a reworded key replacing the old row; a pinned row whose document only re-wrapped left untagged; a rejected reason the document re-wrapped read as no change; the prompt's new rules; image_only on a captioned image, a placeholder and caption, an image with real text, and short text with no image; a captioned diagram neither sent nor missed from the image-only list; a long section's last chunk with an image and a short tail still sent; the fake model resting its decision on the second sentence (replacing the earlier fake-model test, test_the_fake_model_returns_candidates_that_pass_the_check, which it covers). Two existing tests change where the new rules intend it: test_a_blank_reason_drops_the_alternative_and_a_reason_is_read_as_written is now test_a_blank_reason_drops_the_alternative_and_a_reason_is_read_stripped and expects the reason "costs random reads" where it expected " costs random reads" (spans are read stripped, since the verbatim check matches whitespace aside); and test_a_span_too_short_to_rest_a_decision_on_is_dropped gains three cases, a quote, a reasoning and a rejected reason of 12 or more characters as the model wrote them but under 12 once whitespace runs are collapsed, each dropped. Every other existing test passes unchanged.
  • End to end against a private ClickHouse (migrated, fake LLM and embedder, auth off): ingested a three-section document, dry run, --apply, re-run. A section with a reason was recorded and then unchanged; a section whose second sentence restated the first was dropped with the restatement line; a section with an image and a caption got the image-only line.
  • make format lint typecheck, test_doc_links, test_public_copy, test_llm_stage_registry, test_package_contracts and the fake model's tests pass.

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: each new rule with unit tests and an end-to-end run on the fake model.

  • 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 and typecheck pass locally, with the unit files of every touched module; the full unit suite runs in CI)
  • 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/decisions-extract-quality branch from 2854388 to c8bc450 Compare November 2, 2026 10:37
zlareb1 and others added 20 commits November 2, 2026 11:30
…kips captioned images

A candidate whose reasoning has no content word its outcome lacks is
dropped: it is the decision in the document's words, not its reason.
Spans match the chunk with whitespace runs read as one space, and the
chunk's own span is what gets recorded; retire reads the live text the
same way. A body holding an image and at most a caption's worth of
text is image-only. The prompt asks for the reason behind each choice
and skips recap sections and superseded behaviour.

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

A long section's last chunk holding an image and a short tail of text
is sent again: only the chunks of image-only sections are skipped, the
sections the image-only line reports. The restatement check drops a
final "e" and undoubles a final consonant after cutting an ending, so
stored meets store and running meets run.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
Reconcile compares the stored reasoning with whitespace runs collapsed,
so a confirmed row or one with a recorded outcome is not tagged
source-changed when the document only re-wrapped a line, and an
unconfirmed row keeps its stored span, which retire still finds. The
retire step's map of held decisions keys on the collapsed reasoning on
both sides, so a re-wrapped reasoning under a reworded key still
replaces the old row. Rejected options' reasons are stored collapsed
already.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
The 12-character floor is measured with whitespace runs collapsed, as
the span is matched and stored, so padding a short span with spaces no
longer lifts it over the floor.

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

A section whose own text is a picture and its caption is reported and
not sent, whether or not it has subsections; a heading alone over its
subsections is still not one. A link such as [image tiles](tiles.md)
is no image placeholder. Two candidates whose reasoning differs only
in whitespace are one decision.

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

[image1], [image_1], [images] and [pictures] are placeholders again;
link text and words such as [imagine ...] are not. The text above the
first heading, or a document with no heading, is image-only when it
holds a picture and at most a caption: it is not sent and is reported
as (untitled).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
Every form of a filler word is skipped by the restatement check
(deciding, choosing, were), since words are compared as stems against
the fillers' own stems. Spans are read stripped like the other fields:
the verbatim check matches whitespace aside, so stripping cannot make
a span match.

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]>
…e links as text

A chunk stored with an empty section path is skipped only when its own
text is image-only too, so a document chunked without headings is not
dropped whole because its preamble is a picture. [image][1] and
[image]: x.png are links, not placeholders.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
![diagram][fig1] is an image, and a linked image such as a build badge
is matched whole with its link, so its target is not counted as caption
text.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
A caption's length is counted after images, HTML tags, link targets,
reference labels and bare URLs are removed, so a badge wrapped in an
HTML or Markdown link adds no text, whatever form it takes. The help of
loom decisions extract says the reasoning must say more than the
outcome and that a captioned image is skipped.

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

A caption drops a lower-case tag on one line, so comparisons such as
x < 10k and y > 80% and generics such as Option<A> stay text, and a
decision beside a diagram is no longer read as a caption. The prompt
asks for the outcome without the reason, since an outcome that carries
its reason leaves the reasoning nothing to add.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
[the diagram][image] is a link: a placeholder never follows a closing
bracket. A heading-less document of one captioned picture is reported
as (untitled) and not sent.

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]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
… a re-wrapped quote's section

The restatement check compares Snowball stems, the stemmer search
already uses, in place of a hand-rolled one. A caption no longer counts
the empty brackets a link around an image leaves. A dropped candidate
whose quote is re-wrapped in the document names the quote's section.

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

"Because we spill into sorted runs." restates its outcome. ![spill flow]
is an image, so a caption under it is image-only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
vec![0; n] or ![a, b] in a code span or a fenced block is code, so a
short section holding a decision is no longer skipped as image-only;
the code still counts as text beside a real image.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 force-pushed the feat/decisions-extract-quality branch from 3d18314 to 790b975 Compare November 2, 2026 11:31
zlareb1 and others added 7 commits November 2, 2026 11:41
Image markup inside a code span or fence no longer makes a preamble or a parent heading image-only in the report.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
![spill flow] is no longer an image: in prose it is indistinguishable
from a macro such as vec![0; n], and telling them apart would need the
document's link definitions. image_only and image_only_sections share
has_image, which looks outside code.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
[image tiles] and [images and charts are in the appendix] are text: a placeholder is the word alone, with a number, or with a colon and its caption.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 merged commit 1a7c2e0 into main Nov 2, 2026
20 of 22 checks passed
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