knowledge: table fragments + exact prompt log (run G fixes) #4

Merged
onibot merged 1 commits from feature/prompt-log into main 2026-10-20 20:23:21 +02:00
Owner

Run G fixes — the 8/80 hang had TWO root causes, both fixed and live-verified against real Wikipedia.

1. The 22k table chunk was a parser bug. The world-rivers table marks each data row's leading cell with !scope="row"| (a row-label th); parse_tables flagged any row touching a ! as header, so 227 data rows collapsed into ONE header of 1,825 cells and zero rows — flattened by the prose enrichment into the single 22,021-char chunk that hung the call. Fix: header row = ALL cells are ! cells; mixed rows are data. The world table now parses as 8 cols × 227 rows.

2. Exact prompt log (your ask): every LM call's full rendered prompt now lands in runs/<ts>/prompts/NN-stage.txt — NN mirrors the budget counter, so 08-EXTRACT.txt IS call 8/80 — plus size/duration lines in run.log (prompt #8 stage=EXTRACT chars=... tokens~...). Implemented as a dspy global callback; stage labels come from a module stack because dspy fires the module and LM callbacks with different call_ids (verified with DummyLM probes before writing it).

Plus your steer — tables reach the extractor as fragments, never dumps:

  • tables_as_chunks: ≤40 rows per fragment, every fragment repeats header + caption, part i/N markers ("troç 2/10" is visible to the LLM).
  • STOP_TABLE: after one fragment the extractor can declare the table's subject wrong for the question; fixed code skips the remaining parts of that table. LIST answer's table never re-enters extract.
  • The == Tables == prose enrichment is gone from fetch_rich (the giant chunk's birthplace; it also let verify_count cite the table as "prose" — now impossible).
  • Fragment candidates pass the same containment check (prose + full table text as target).

Verified: live smoke — world article: 10 chunks, none >5k; world table = 6 fragments (max 5,787 chars); Italy discharge fragment intact (Po/1540). Prompt-log E2E: real FloopRun with a stage-aware fake LM writes 01-INIT.txt + 02-ANSWER.txt with exact prompts. Suite 47/47 (4 new tests in knowledge/tests/tablefrags.py).

**Run G fixes** — the 8/80 hang had TWO root causes, both fixed and live-verified against real Wikipedia. **1. The 22k table chunk was a parser bug.** The world-rivers table marks each data row's leading cell with `!scope="row"|` (a row-label th); `parse_tables` flagged any row touching a `!` as header, so 227 data rows collapsed into ONE header of 1,825 cells and zero rows — flattened by the prose enrichment into the single 22,021-char chunk that hung the call. Fix: header row = ALL cells are `!` cells; mixed rows are data. The world table now parses as **8 cols × 227 rows**. **2. Exact prompt log** (your ask): every LM call's full rendered prompt now lands in `runs/<ts>/prompts/NN-stage.txt` — `NN` mirrors the budget counter, so `08-EXTRACT.txt` IS call 8/80 — plus size/duration lines in run.log (`prompt #8 stage=EXTRACT chars=... tokens~...`). Implemented as a dspy global callback; stage labels come from a module stack because dspy fires the module and LM callbacks with **different** call_ids (verified with DummyLM probes before writing it). **Plus your steer — tables reach the extractor as fragments, never dumps:** - `tables_as_chunks`: ≤40 rows per fragment, **every** fragment repeats header + caption, part i/N markers ("troç 2/10" is visible to the LLM). - `STOP_TABLE`: after one fragment the extractor can declare the table's subject wrong for the question; fixed code skips the remaining parts of that table. LIST answer's table never re-enters extract. - The `== Tables ==` prose enrichment is gone from `fetch_rich` (the giant chunk's birthplace; it also let `verify_count` cite the table as "prose" — now impossible). - Fragment candidates pass the same containment check (prose + full table text as target). **Verified:** live smoke — world article: 10 chunks, none >5k; world table = 6 fragments (max 5,787 chars); Italy discharge fragment intact (Po/1540). Prompt-log E2E: real FloopRun with a stage-aware fake LM writes `01-INIT.txt` + `02-ANSWER.txt` with exact prompts. Suite 47/47 (4 new tests in `knowledge/tests/tablefrags.py`).
onibot added 1 commit 2026-10-20 20:23:18 +02:00
Run G hung at call 8/80 for minutes with no way to see what was sent.
Reproducing it found TWO root causes, both fixed here:

1. THE 22K TABLE CHUNK WAS A PARSER BUG, not just a size problem. The
   world-rivers table marks each data row's leading cell with
   '!scope="row"|' (a row-label th); parse_tables flagged any row that
   touched a '!' as a header row, so all 227 data rows collapsed into ONE
   header of 1,825 cells and zero rows. tables_as_text then flattened
   that monster into a single 22,021-char prose chunk. Fix: a row is a
   header row only if ALL its cells are '!' cells; mixed rows are data
   rows. Live: the world table now parses as 8 cols x 227 rows.

2. NO PROMPT OBSERVABILITY. The log's CALL/OUTPUT lines never carried
   what the LM actually received. floop/llm.py now installs a dspy global
   callback (PromptLogCallback): every LM call's exact rendered prompt
   lands in runs/<ts>/prompts/NN-stage.txt (NN mirrors the budget counter
   -- 08-EXTRACT.txt IS call 8/80), plus size/duration lines in run.log.
   Stage comes from a module stack (dspy fires on_module_start with a
   DIFFERENT call_id than the inner LM call -- verified with DummyLM
   probes), not a call_id map.

Plus the design Emili steered (tables reach the extractor as typed
fragments, never prose dumps):
- tables_as_chunks: per-table fragments of <=40 rows, EVERY fragment
  repeats header + caption, part i/N markers; the extractor always knows
  which table ('troç 2/10') it is reading.
- STOP_TABLE: the extractor may early-skip a table whose subject is
  wrong for the question after one fragment; fixed code skips the rest
  of THAT table. ExtractSignature teaches the protocol.
- fetch_rich no longer appends the '== Tables ==' enrichment to prose
  (the giant chunk's birthplace; also let verify_count cite the table as
  'prose'). Tables reach the extract path only as fragments; LIST and
  harvest keep reading page.tables directly.
- fragment candidates pass the same containment check against prose +
  full table text; LIST answer's table never re-enters extract.

Tests: knowledge/tests/tablefrags.py (fragment generation/render,
STOP_TABLE skipping, fragment extraction with containment, prompt log
files + log lines). Live smoke: world article 10 chunks none >5k; world
table = 6 fragments (max 5,787c); Italy discharge fragment intact
(Po/1540). Full suite 47/47.
onibot merged commit 770ec616a9 into main 2026-10-20 20:23:21 +02:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: onibot/floop#4