Skip to content

Decision extraction keeps stated bans, reads an empty or stitched reply again, and drops recaps and inverted alternatives - #177

Merged
zlareb1 merged 16 commits into
mainfrom
feat/decisions-extract-rules
Nov 2, 2026
Merged

zlareb1 merged 16 commits into
mainfrom
feat/decisions-extract-rules

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

Related: #174
Related: #176

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 keeps a ban the document states without a reason, reads a window again when its reply holds no decision or a reason joined from two places, drops decisions quoted from recap, summary or background sections, and leaves out a rejected option the document states as part of the choice. A decision whose reasoning is its outcome now reads Decided X. with no "because".

Why

Six ways the extractor loses or misstates a document's decisions:

  1. The prompt told the model to emit nothing for a heading, an image or an image with its caption. A document that states a decision in a one-line caption over a diagram, beside more text, got nothing back, though the code-level image-only filter had sent the section on purpose. The filter already makes that call, so the prompt should not make it a second time.
  2. A small document fits one window, so one empty reply ({"decisions": []}) loses the whole document.
  3. The restatement filter drops a ban stated with no reason ("Client-side retries only; no server retry setting."): its reasoning and outcome are the same line. That is a constraint an agent needs before an edit.
  4. A recap section restates decisions made elsewhere, and its candidates were recorded as decisions.
  5. The model sometimes lists part of the chosen design as a rejected option ("Sharding by tenant is deferred to v2." recorded as the rejected "Defer sharding by tenant").
  6. A reason the model joins from two non-adjacent fragments fails the verbatim check, and the decision is lost although the quote is the document's.

Scope and risk

The rules live in server/memory/domain/decision_extract.py; server/memory/app/decision_extract.py applies them in the window loop, which is split into _candidates (the calls), _check_window (one reply's candidates), _duplicate_or_unfit (the existing key, pair, fit and per-section checks, unchanged) and _drop_inverted.

  1. Prompt: the caption clause is removed. The recap/summary and superseded rules stay. For rule 3, the line that said a decision with no stated reason is not emitted now makes one exception: a ban or an invariant the text states without a reason may be emitted with is_constraint true and its own sentence as the reasoning; every other decision still needs a stated reason.
  2. Empty reply: when a window's reply parses and holds no candidate, and the window's text is more than a caption (more_than_a_caption, the same 80-character measure image_only uses, now shared), the window is read once more with the same prompt and the second reply is the window's. An unreadable or failed first call is not retried: it is lost as before. The no-window-read and partial-read exit rules read the final outcome, so a second call that fails loses the window (exit 2, or exit 1 when no window was read).
  3. Bans with no reason: a candidate is kept as a ban with no reason (reasonless_ban) when is_constraint is true, its reasoning, the span that is stored, holds only, no, never, must, not, always, at most or at least as a word (states_a_ban), and that reasoning restates its outcome or is its whole quote (an outcome shorter than the ban sentence would otherwise store "Decided because "), and that reasoning fits decision.record's 1000-character outcome limit; a longer one is judged as any other candidate. Its outcome is set to its reasoning, the document's span on one line (without_reason); a reasoning with fewer words than the outcome (a fragment such as "no server retry setting") gives way to the quote when the quote holds a ban word too, so the stored ban is whole. Representation: decision.record requires a non-empty reasoning, and the retire step must find the reasoning in the document, so the reasoning stays the document's span. The marker is the record itself: a reasoning equal to the outcome, case, whitespace and closing punctuation aside, states no reason. memory_value (server/memory/domain/decision_statement.py, states_reason) then writes Decided <outcome>. without "because", the outcome clipped to the outcome and reasoning budgets together so a long ban keeps its end, and context.pack's decision line drops its (because …). I chose this over a tag because the statement is rebuilt from the record alone (by decision.record and again by decision.outcome), so a tag on the row would not reach it without a schema or wire change, and because decision.precedents and memory.get show the record as it is. This is also a change for any other decision.record caller whose reasoning equals its outcome: such a statement used to read "Decided X because X.", which said nothing more. Every other restating candidate is still dropped; is_constraint alone is not enough, since models mark plain descriptions as constraints.
  4. Recaps: a candidate whose quote's section breadcrumb has recap, summary or background as a word at any level (case-insensitive; not recall, a normal heading word in a search system) is dropped with the line the quote is in a recap, summary or background section. The section stays in the window and the prompt, so its text can still give another decision's reason (a test covers this).
  5. Inverted alternatives: an option is left out (the decision kept, a dropped line reported, exit code unchanged) when all its content words, compared as the restatement check compares them (Snowball stems, filler words aside), are in one sentence of the candidate's own quote, the span of the chosen design (a sentence ends at ., ! or ? before whitespace, except after vs., e.g. or i.e., at a blank line or before a list item; a single line break joins, so a hard-wrapped negation stays with its sentence) and that sentence has none of not no never cannot can't instead rather without fail* reject* than avoid* slow, nor over against versus vs unlike replace* favor*/favour* prefer* outperform* beat beats compar* drop*, so "We chose sorted runs over a plain set on disk." and "We prefer sorted runs to a plain set on disk." keep their alternative. The list leans wide on purpose: a missed contrast word drops a true alternative's Rejected: part, while an inverted option kept would mislead an agent about the chosen design. Deviation from the rule as first stated: the sentence that holds the option's own rejection reason is not read. Without that, the canonical case "A plain set on disk costs random reads." (option "a plain set on disk", reason "costs random reads") has no marker and would lose a correct alternative, which breaks existing behaviour and tests. The cost: if the model gives as an inverted option's reason a span of the very sentence that states it, the option is kept. Only the quote is read: a document often names an option in one sentence and rejects it in the next ("We looked at a plain set on disk. Each lookup costs a random read.", a list of options, "benchmarked … against …"), and reading the whole window dropped such correct alternatives. The dropped line says the quote states it as part of the choice.
  6. Stitched reasons: when a candidate's quote is in the text but its reasoning or a rejected option's reason is not, and no span is under the 12-character floor a second read cannot fix (unfound_reason), the window is read once more with a note before the text naming each such decision's outcome and span and asking for those decisions again with one contiguous span, or none (stitched_note). The first reply's other candidates stand; the failed ones are reported as dropped as before. Of the second reply, only a candidate with a failed decision's outcome, or with a reasoning none of the window's kept decisions has, goes through the checks: a kept decision given again under a reworded scenario would otherwise be written twice, and is reported as the second read repeats a decision the first reply gave. A candidate in a recap section does not trigger it. The window is answered already, so a second read that fails or comes back unreadable is a read again line, not a refused drop: the first reply's decisions are recorded and the exit code is unchanged.

A window gets at most one extra call in total: a window already read again for an empty reply is not read a third time for a stitched reason. Each extra call is reported in a new retried list, printed as - read again [<section>] <why>; it does not change the exit code.

Left alone: reconcile, retire, ownership, races, the verbatim check itself, and the fake model.

Compatibility, rollout and rollback

  • Wire: no op, field, setting, table or column. The statement decision.record writes for a record whose reasoning equals its outcome changes from "Decided X because X." to "Decided X.". loom decisions extract's help text and report gain the second-read lines.
  • Rolling upgrade: an N-1 extractor drops a reason-less ban as a restatement and never writes one; its retire step leaves an N row whose reasoning is still in the document. An N-1 decision.outcome on such a row rebuilds the statement with "because X", which an N write restores.
  • Operator steps: none.
  • Rollback: rows written as reason-less bans stay, with reasoning equal to outcome; an older build reads and renders them with a "because".

Tests

  • tests/unit/test_decision_extract.py (fake model, stubbed planes; the test model can now serve a sequence of replies or raise): an empty reply read again and its second reply recorded; an empty reply over a caption of text not read again; a failed second read losing the window (exit 1); a stitched reasoning asked for again with the span named and the second reply recorded; at most one extra call per window; an unquoted failure not read again; states_a_ban over bans, plain constraints, cannot/nothing, and a ban not flagged as a constraint; a reason-less ban recorded with reasoning equal to outcome, the constraint tag and the statement Decided <ban>.; a restating candidate that is no ban still dropped; in_recap at each breadcrumb level, SUMMARY, and Recalling, Improving recall in hybrid search and Current design not matching; a recap candidate with a missing reasoning not read again; a ban word only in the quote, not the stored reasoning, still dropped; a recap quote dropped while the recap's text gives the next decision its reason; inverted_options on the deferred-sharding, cannot-evict, rejection-sentence, than and filler-only cases; an inverted alternative left out with the decision kept; a hard-wrapped negation on the next line keeping the alternative; a list item read as its own sentence; a short quote or reasoning not read again; a stitched re-read that raises or returns an unreadable reply keeping the first reply's decision, exit 0; a ban over 200 characters keeping its end in the statement.
  • Existing tests changed where a rule intends it: the eight that unpack one prompt from a window answered [] now expect the second, identical call; test_a_dropped_candidate_with_a_rewrapped_quote_names_the_quotes_section now sees the window read again for its missing reasoning and the drop reported once per reply; test_the_prompt_asks_for_the_reason_and_skips_recaps_and_superseded_text asserts the prompt no longer mentions images or captions, and that it allows a reason-less ban as a constraint resting on its own sentence. Every other existing test passes unchanged.
  • tests/unit/test_decision_statement.py: a reasoning equal to the outcome, case, whitespace and closing punctuation aside (other case, line breaks, a closing !), reads Decided X.; a reason-less ban reads unchanged on a re-run and neither reconcile nor retire touches it (test_decision_extract.py); tests/unit/test_context_pack_decisions.py: such a decision's line has no "because".
  • End to end against a private ClickHouse (migrated, fake LLM and embedder, auth off): a three-section document recorded its reasoned section, dropped its Recap section with the recap line, then read unchanged on a re-run; a one-sentence document was read again after the fake model's empty reply; decision.record over HTTP with reasoning equal to outcome stored the value ... Decided Client-side retries only; no server retry setting.. tests/integration/test_decision_record_source.py and test_memory_for_file_decisions.py pass against that server.
  • make format lint typecheck, the function-length gate, docs_reference.py (docs/reference/cli.md and the hand-refreshed help in tests/unit/snapshots/cli_tree.json), the CLI help snapshot, test_doc_links, test_public_copy, test_package_contracts, test_llm_stage_registry, and the unit files of the context-pack and decision modules 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 rule with unit tests on the fake model and an end-to-end run on a private 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 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 and the decision integration files; the full suites run 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 and others added 16 commits November 2, 2026 13:05
…ly again, and drops recaps and inverted alternatives

- The prompt no longer tells the model to skip a heading, an image or a
  captioned image; the image-only filter alone decides that.
- A window whose reply holds no decision, though its text is more than a
  caption, is read once more and the second reply is used. A window whose
  candidate has its quote in the text but a reasoning or rejected reason
  that is not is read once more with those spans named. A window gets at
  most one extra call; each is reported as "read again".
- A restating candidate the model marks as a constraint, whose quote holds
  a ban word, is kept with its reasoning as its outcome. decision.record's
  statement and context.pack read a reasoning equal to the outcome as no
  stated reason: "Decided X." with no "because".
- A candidate whose quote sits under a recap, recall, summary or
  background heading is dropped; the section stays in the window.
- A rejected option whose words all sit in one sentence with no negation
  or contrast word, other than the sentence giving its rejection reason,
  is left out of the record and reported.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
The prompt said a decision whose text gives no reason is not emitted,
which kept the model from offering the reason-less bans the restatement
check now keeps. A ban or an invariant stated without a reason may now
be emitted with is_constraint true and its own sentence as the reasoning;
every other decision still needs a stated reason.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…lost, and reads wrapped sentences whole

- A lost second read for a joined reason is a "read again" line, not a
  refused drop: the window was answered, its first reply's decisions are
  recorded and the exit code is unchanged.
- Sentences for the inverted-option check end at . ! ? before
  whitespace, a blank line or a list item; a single line break joins, so
  a hard-wrapped negation stays with its sentence.
- The joined-reason read fires only for a span not in the text, never
  when a span is under the 12-character floor.
- A statement with no stated reason gives the outcome the reasoning's
  room too, so a long ban keeps its end.
- Retries are their own Retried rows; the key check returns the key.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…no longer treats recall as a recap heading

- states_a_ban tests the reasoning, the span that is stored, not the
  quote: a reasoning fragment without a ban word stays dropped.
- recap, summary and background mark a recap section; recall is a
  normal heading word in a search system.
- The CLI help names the image-only skip next to the window count and
  all three recap words; cli.md and the snapshots are regenerated.
- A recap candidate with a missing reasoning is not read again (test).

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]>
…s a ban whose outcome is shorter than its sentence

- A rejected option is left out only when the candidate's own quote
  states it as part of the choice; a document that names an option in
  one sentence and rejects it in the next keeps its alternative.
- A ban whose reasoning is its whole quote is kept with no reason even
  when the model's outcome is shorter than the sentence.
- The report test covers the "read again" lines; comments, the window
  loop's docstring and the CLI help string are tidied.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…es a repeated decision once

- The inverted-option check treats over, against, versus, vs, unlike,
  replace*, favor/favour and dropped as contrast words, so "We chose X
  over Y" keeps Y as rejected.
- Of a second read for a joined reason, only candidates that repair a
  failed decision are checked: a kept decision given again under a
  reworded scenario is dropped and reported.
- A no-reason ban whose reasoning is over decision.record's outcome limit
  is judged as any other candidate.
- _read_window takes answered_already explicitly; the docs say a window
  read again costs a second call.

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

- The "no window was read" error also names a window that answered
  nothing and failed when read again.
- The docs limit "loses its window only" to a window's first call or its
  second after an empty reply; a failed second read for a joined reason
  loses nothing.
- Test: a stitched second read answered by the fallback fake model is a
  "read again" line, not a refused drop.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
- A second read's repeat of a kept decision is reported under the
  section its quote is in, not the window's first.
- The statement docs and states_reason say a reasoning equal to the
  outcome is read case, whitespace and closing punctuation aside.
- Tests: a repeat in the window's second section is named there; a
  repair with a reworded outcome and a new reasoning is recorded.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
- states_a_ban's docstring stops at the marker words; the keep rule is
  reasonless_ban's.
- The restated-reasoning exception says a ban's reasoning must fit an
  outcome (1000 characters) to be kept with no reason.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
- A second read's candidate is a repair when its outcome matches a
  failed one with whitespace runs collapsed.
- The window's first section is computed once and passed to each read.
- Tests: a repair whose failed outcome had a line break is recorded; an
  empty window whose second read is unreadable or answered by the
  fallback fake is a refused drop, exit 2.

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

- states_reason drops a closing ., !, ? or ellipsis on both sides, so
  "Never retry!" over "Never retry" reads "Decided Never retry."
- The docs name the recap exception of the joined-reason second read and
  say a second reply's candidate is checked, not read.
- Test: a reason-less ban reads unchanged on a re-run, emitted or not.

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

- The inverted-option check also treats favor*/favour*, prefer*,
  outperform*, beat(s) and compared as contrast words, so "We prefer X
  to Y" keeps Y as rejected; the docs state why the list leans wide.
- A reason-less ban whose reasoning is a fragment of its outcome is
  stored as its quote when the quote holds a ban word too.
- The second-read note says "An earlier reply gave these decisions...".
- Test: a joined rejected-option reason is asked for again, named in the
  note, and recorded repaired.

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

The read-again line for a joined reason, and its lost-read line, name the
section of the first failed decision rather than the window's first
section; the empty-reply line keeps the window's first section.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
Retried's docstring and _read_window's `section` parameter (was `first`)
say what they hold: the section a read, or its loss, is reported under.

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

- A sentence of the inverted-option check does not end after "vs.",
  "e.g." or "i.e.".
- fail, reject, avoid, compare and drop count in any form ("rejects",
  "avoids", "comparison", "drops").

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 merged commit a0661ce into main Nov 2, 2026
20 of 22 checks passed
@zlareb1
zlareb1 deleted the feat/decisions-extract-rules branch November 2, 2026 14:39
@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