ROUTE migrates to the typed-output law: the attendant is a closed enum
rendered into the prompt's JSON schema — an invalid pick is impossible
by contract (AdapterParseError after dspy's own re-ask).
- Attendant(str, Enum): knowledge logic analytic numeric floop user
(str mixin keeps the machine's == and `in EXPERT_ENGINES` intact)
- The per-field desc now carries the routing guidance (what each
attendant is FOR) — replacing the 'one of: ...' list in the old
string contract
- The machine's invalid-attendant branch stays as a contract guard
- New tests/typed_route.py: enum parses through the real adapter path
(RawEngine + cache=False), out-of-set attendant raises, str
compatibility holds
VERIFIED: suite 13/13 green; wire test with real glm-5.3-flash routes
all three probes correctly (knowledge / numeric / knowledge).
The typed-output migration starts with the machine's decomposition step:
the pipe contract ('text | deps | answer_type' lines) is gone — dspy
renders the Subquestion schema natively.
- Subquestion(BaseModel): text + depends_on: list[int] +
answer_type: AnswerType (enum rendered into the prompt's JSON schema)
- InitSignature/MissingSignature.subquestions: list[Subquestion]
- init_decompose keeps the (subs, raw) machine contract: a
schema-violating response raises AdapterParseError after dspy's own
JSON re-ask; its lm_response becomes the degrade signal so the
run-I law survives typing — the machine still routes the ORIGINAL
question, never garbage
- bare-number texts still dropped (now in _subs_from_typed)
- parse_subquestions kept as LEGACY for tests
Tests rewritten for the REAL adapter path (RawEngine + cache=False):
DummyLM bypasses the adapter; and dspy's disk cache (~/.dspy_cache)
cross-contaminates scripted tests sharing a fake model name — both
pitfalls found while migrating.
VERIFIED:
- suite 12/12 green (robust_init rewritten: 6/6 — E2E typed parse,
bare-number drop, garbage degrade, machine degrade, atomic case,
raw-response prompt log)
- live E2E (ollama-cloud glm-5.3-flash): INIT renders the enum schema,
glm returns depends_on ints + valid enums, machine dicts clean,
full run answers Rajoy with citations. NOTE: dspy's disk cache made
the second run's INIT a 0.2s cache hit — runs share the cache.
Two fixes from his 22/10 re-run log, both small and deterministic:
1. THE ABLATION MASK WAS QUOTE-BLINDED (run L: Q1 stayed silent over
the Pedro page that run J flags). The Pedro paragraph interleaves
all three readings in ONE quote ('...Secretary-General ... ninth
president of Socialist International...'), and _carries matched
the picked value by substring over dst OR quote — so masking SI's
support masked the PM/PSOE rows too; round 1 answered UNKNOWN and
the audit died silent. The DST-FIRST LAW: when a row has a
meaningful dst (non-empty, non-numeric) it is the VALUE BEARER and
the mask matches IT; the quote is a fallback only for
empty/numeric dsts. Same law in _carries_target for each round's
surviving value, with one addition: the judge's round value may be
an OFFICE DESCRIPTION ('prime minister of Spain') while the row's
dst is the ENTITY ('Spain') — resolve by reciprocal token
containment, or the loop dies after one alternative.
2. THE ADAPTER RE-ASK WAS INVISIBLE TO THE BUDGET (run L: prompts #9
and #10 were both ANSWER — #10 5 chars shorter, 340s, the
ChatAdapter's JSON-fallback second wire call after a parse
failure; llm_calls said 9/80 while 10 hit the wire). THE METER:
the prompt-log callback already sees every LM call — a second LM
call with NO new module forward between them is the adapter
fallback re-firing inside the same Predict. Count it, log the
line, and charge the budget through a meter hook the machine
wires at construction. A re-ask at the ceiling does not kill the
run (the call already happened). dspy's BEHAVIOUR IS UNTOUCHED —
his call: the fallback stays, it is future self-improvement
signal (which prompts the model formats badly), not a bug.
Tests: knowledge/tests/ablation.py +3 — run-L regression (interleaved
one-paragraph quote flags all three readings), office-description
resolution, numeric-dst quote fallback. tests/reask_meter.py +3 —
fallback detected and charged on the REAL adapter path (custom engine
returning raw text, marker-less first response), separate forwards NOT
flagged (the ablation-rounds shape), ceiling charge survives. Suite
12/12 files green (74 tests). Live smokes: the run-L interleaved-quote
page flags SI+PM+SG through the full pipeline; the run-J
separate-quotes smoke still passes.
Run I ('Who was the President before Pedro Sanchez?'): the INIT LM wrote
its own line numbers as an extra first pipe field ('1 | Who was... |
none | OPEN'), the naive parse took '1' as the subquestion text, ROUTE
classified Q1='1' as numeric, and the machine burned four calls on
garbage before luck produced the answer. Two of the fixes close the same
observability gap that hid the root cause for a day.
1. PARSER (parse_subquestions): shifts the numbered form (>=4 fields
with a bare number first) and drops any text that is a bare number —
a routable question is text, never '1'. Enumerator prefixes ('1.')
inside the text field are stripped. Well-formed lines parse exactly
as before (regression-tested).
2. INIT DEGRADE (machine): init_decompose now returns (subs, raw).
Non-empty raw that parses to nothing = model garbage — degrade to
the ORIGINAL question as one OPEN subquestion (routable, logged,
budget-safe). Empty raw keeps the old law: the question is atomic,
stop and synthesize — never fabricate a subquestion.
3. RAW RESPONSE LOG (the ask behind the ask): prompts/NN-stage.txt now
carries the exact LM response after the prompt. Run I's parsed
'OUTPUT INIT: 1\n2' could not show what the model actually wrote —
the raw text is in the file from now on; the log stays line-based.
Tests: tests/robust_init.py — the numbered form, bare-number drop,
enumerator strip, happy-path regression, the degrade, the atomic stop,
raw-response capture. Suite 59/59. Smoke: the exact run-I transcript
replayed through the real machine (DummyLM) parses to Q1/Q2 real
subquestions and answers Mariano Rajoy.
log-09 bug: a KG-served set answered the fan-out top-3 with adda, adige,
arno — the alphabetical list_members order masquerading as a ranking.
- edges.list_ord (auto-migrated): each member_of edge records its row
position in the source table; list_members(ordered=True) returns source
order, list_is_ordered() tells whether the set has proven order
- ingest writes ordinals; fresh-serve and _serve_set keep table order and
set coverage.ranked accordingly
- fan-out top-N: slices ONLY ranked lists; an unranked list refuses the
slice, expands all entities, and says so in notes + thinking (never
silently alphabetical)
- regression test: Po/Adige/Tiber first; unordered set -> all expanded
(a) Disjointness guard (knowledge/expert.py): a LIST ingest whose members
don't overlap the entities the parent's evidence names is refused; the
gather continues to the next article. Run-08's 'flow of Po/Adige/Tiber'
answered by the Amazon from a world-wide table can no longer happen.
(b) Fan-out planner (floop/machine.py): a 'for each' subquestion over a list
row expands deterministically into N entity questions + one join.
Top-N bound respected ('those three' over 22 rows -> top 3 by table
order, logged). The join is a deterministic sum over the entity rows
(verified=True: computation is its own proof), partial sums named.
Entity rows are tagged fan_group in provenance so the join finds them.
Also: LIST ingest keeps TABLE ORDER (ranked tables rank; alphabetical sort
destroyed the ranking) — dict.fromkeys dedup.
Budget: 40 -> 80 (a 3-entity fan-out needs ~3x a scalar question).
Verified live (cold KG, 2 runs): list ingest in table order, slice top-3,
fan-out -> 3 entity questions + join, Po answered with verbatim quote
(1,460 m3/s). 28/28 tests (fan-out expansion+join, top-N slice, guard).
- KnowledgeStore._migrate(): idempotent additive migration on open — a
pre-2026-10-19 KG no longer crashes the set gate with 'no such column'
- _lm_dead(): transport/timeout deaths abort the run with notes (no answer
beats a made-up one); code bugs still crash loudly
- tests: migration from a hand-built old-schema store; LM-death abort (24/24)
A) SET GATE: enumerations are answered only from membership sets, never from mention rows (the probe early-exit that served 'Armenia, Cyprus, Georgia, Turkey' to 'what countries are in Europe' is dead). Sets carry origin_question; the gate matches stem-Jaccard>=0.5 so a set is served to its own question only. B) SETOP ENGINE: logic's first real engine — a count over list rows is computed (difference/intersection/count over norm_name'd items, table markers 'Austria*' == 'Austria'), before ROUTE, zero LLM calls, verified=True because the computation IS the check. C) Catalog honesty: knowledge 'lists are ONE fetch', logic 'how-many over lists in evidence', floop 'NOT mere size'. Plus four substrate bugs the live runs exposed: LM-proxy prompt cache (instant answers are cache hits, never trust zero latency), _context rendering list rows as scalars ('E1: 50' routed 'those countries' to user), <br> concatenation in multi-value name cells, multi-line refs leaking into values ('franceincludes the 101 departments' -> France dropped from EU -> 24 not 23). Cold E2E: Q1 50 states ingested, Q2 27 EU members ingested, Q3 difference computed = 23, cited over E1/E2. 22/22 tests.