Skip to content

[Wave 4] Low/info — Module sweep: Document ingestion (PDF/DOCX/EPUB/TXT/MD) (part 2/3) #674

Open

Description

@cemililik

Wave 4 · 20 finding(s) in 20 fix package(s). Fix these whenever a pull request touches this module ("clean the module you touch").

Findings

  • CR-A12-061 (code, Low) — DOCX footnotes and endnotes are silently dropped; comments are excluded (arguably correct), and neither choice is documented
    severity Low · reachability default · intent intended-but-harmful · confidence likely · single reviewer · reproduced end to end
    Failure scenario. A legal memo whose statutory citations sit in footnotes is ingested. The corpus loses every citation and the run reports success.
    Where. forgelm/ingestion.py:1093-1098, forgelm/ingestion.py:1210-1217, docs/reference/data_ingestion_architecture.md:163-170
    Recommended fix. Either extract footnotes and endnotes (appended per document or inlined as [^n]) or document the exclusion and record a per-file count in notes_structured. Document that comments are intentionally excluded.

  • CR-A12-062 (code, Low) — In-tree file symlinks (and hard links) put the same document into the training JSONL more than once, and nothing reports it
    severity Low · reachability default · intent intended-but-harmful · confidence confirmed · independently confirmed · reproduced end to end
    Failure scenario. A corpus holds docs/policy.pdf and latest.pdf -> docs/policy.pdf, a common 'current version' alias. forgelm ingest --recursive writes the policy's chunks twice. The SFT set over-weights that document, and the run reports two processed files with no warning.
    Where. forgelm/ingestion.py:2004, forgelm/ingestion.py:2005, forgelm/ingestion.py:2418, forgelm/wizard/_byod.py:112
    Recommended fix. Track (st_dev, st_ino) of each yielded file, or resolve() it, and skip repeats with a note in result.notes. Combine this with the M-A12-038 fix (refuse or opt-in for symlinks that resolve outside the input root).

  • CR-A12-063 (code, Low) — Forgelm ingest has no catch-all, so exceptions outside the named classes (for example the TypeError from _count_section_tokens) escape as a traceback with exit 1 and empty JSON stdout
    severity Low · reachability default · intent intended-but-harmful · confidence confirmed · independently confirmed · reproduced end to end · already tracked: KNOWN-OPEN C33-CLI-ERROR-ENVELOPE — docs/roadmap/phase-16-trust-surface-hardening.md:497-508 (S7 open)
    Failure scenario. A CI step runs forgelm ingest --output-format json | jq on a corpus plus a tokenizer dir copied from a third party. A malformed tokenizer makes transformers raise KeyError or TypeError. The step gets exit 1 ("config error, do not retry") and empty stdout, so jq fails with a parse error rather than reading success:false and an error string. The same crash in the chunking phase (MemoryError, RuntimeError from a tokenizer backend) is also reported as exit 1 instead of the runtime-error code 2.
    Where. forgelm/cli/subcommands/_ingest.py:153-236 (confirmed), forgelm/cli/_dispatch.py:113-121, forgelm/cli/_dispatch.py:156-169, forgelm/ingestion.py:2073-2075
    Recommended fix. Add a final narrow-commented except Exception after OptionalDependencyError in _run_ingest_cmd. It should emit the 2-key envelope via _emit_error_and_exit with exit 2 and log the traceback at ERROR (mirror _training.py:173). Then reconcile error-handling.md:93 with the three existing top-level catches. Wrap the _load_tokenizer errors so the message names the --tokenizer value.

  • CR-A12-064 (code, Low) — MemoryError and RecursionError in extraction are soft-skipped as 'corrupt file': WARNING with an empty message, exit 0, success:true
    severity Low · reachability default · intent intended-but-harmful · confidence likely · single reviewer · reproduced with stubs
    Failure scenario. A decompression-bomb DOCX exhausts memory in one worker. The MemoryError is swallowed as a skip, the corpus ships without that document, and the pipeline sees exit 0 with only an uninformative WARNING line.
    Where. forgelm/ingestion.py:2065-2076, forgelm/ingestion.py:2073
    Recommended fix. Re-raise MemoryError and RecursionError (or add them next to ImportError and IngestParameterError) so they reach the CLI handler. Include type(exc).name in the skip warning.

  • CR-A12-065 (code, Low) — Tokenizer-load failures that do reach an envelope carry no context (which tokenizer, which file)
    severity Low · reachability default · intent intended-but-harmful · confidence confirmed · single reviewer · reproduced end to end
    Failure scenario. An operator with several tokenizer directories gets only a JSON column offset and cannot tell which file or flag is at fault.
    Where. forgelm/ingestion.py:1978-1994, forgelm/ingestion.py:2407, forgelm/cli/subcommands/_ingest.py:207-212
    Recommended fix. Wrap the from_pretrained call and re-raise with Could not load tokenizer {model_name!r}: .... Choose the exit class deliberately (the same wrapper is the natural place to fix the exit-2 typo case).

  • CR-A12-066 (code, Low) — --page-range is applied to every PDF in a directory run, so one PDF shorter than START aborts the whole batch; neither the help nor the docs describe this
    severity Low · reachability default · intent intended-but-harmful · confidence likely · single reviewer · reproduced end to end
    Failure scenario. An operator ingests a directory of reports with --page-range 12-400 to skip a 12-page front matter. One appendix PDF in the folder has 8 pages. Ingest processes every file before it in sorted order, then hits the appendix, aborts with exit 1 and discards all output. A contributor who can drop a short PDF into a shared corpus directory can block every --page-range ingest of that directory. The failure is closed (no partial output), so the impact is availability and wasted compute, not integrity.
    Where. forgelm/ingestion.py:978, forgelm/ingestion.py:689, forgelm/ingestion.py:2065, forgelm/ingestion.py:691
    Recommended fix. Either document the contract in the help, the guide and the user manual (the range applies to every PDF; one PDF shorter than START aborts the batch; END is clamped), or change the per-file behaviour for directory inputs: skip a PDF whose page count is below START with a WARNING and record the skip in notes_structured, and keep the hard error for single-file inputs. Also fix the stale comment at…

  • CR-A12-067 (code, Low) — Script-sanity flags every clean NFD-encoded text in a supported language: combining diacritics are out-of-script and ingest never NFC-normalises
    severity Low · reachability documented-opt-in · intent contract-violation · confidence confirmed · independently confirmed · reproduced end to end
    Failure scenario. An operator ingests a clean Turkish TXT corpus exported from a macOS tool, which stores text in NFD, with --language-hint tr. Every file logs 'Script-sanity warning ... 10.18% of non-whitespace chars fall outside the expected blocks' with combining marks as top offenders and no cause. notes_structured.script_sanity_summary.files_triggered then equals the file count, which hides any real font-fallback corruption among them.
    Where. forgelm/_script_sanity.py:122-262, forgelm/_script_sanity.py:303-313, forgelm/_script_sanity.py:422-427, forgelm/ingestion.py:554-562
    Recommended fix. Run unicodedata.normalize('NFC', ch) before the lookup, or NFC the text once before counting. Alternatively, treat combining marks (category Mn) that follow an in-script base letter as in-script. Add a test with a clean NFD sample per supported language.

  • CR-A12-068 (code, Low) — Per-language allow-lists miss letters and common symbols: French œ/æ, es/pt ordinals º/ª, €/₺/°/§; one occurrence in a short clean file crosses 1.5 %
    severity Low · reachability default · intent intended-but-harmful · confidence confirmed · single reviewer · reproduced end to end
    Failure scenario. A French FAQ corpus of many short .md/.txt files that mention 'sœur', 'œuvre' or prices in € is ingested with --language-hint fr. Several clean files raise a script-sanity WARNING and appear in script_sanity_summary.per_file, so the signal operators use to spot real extraction corruption becomes noise.
    Where. forgelm/_script_sanity.py:86-104, forgelm/_script_sanity.py:123-153, forgelm/_script_sanity.py:154-164, forgelm/_script_sanity.py:165-171
    Recommended fix. Add œ Œ æ Æ to fr, ẞ to de, º ª to es/pt/it, ü to pt and ê plus uppercase forms to en. Add a curated universal symbol set to _UNIVERSAL_ALLOW (€, the local currency sign including ₺, °, §, ©, ®, ™, ×, ½, ·, −, soft hyphen) or the Currency Symbols block. Add one clean-prose silence test per supported language, with short-line cases.

  • CR-A12-069 (code, Low) — File-order claim 'lexicographic ordering across OS' does not hold: Path sorting ignores case on Windows
    severity Low · reachability default · intent contract-violation · confidence confirmed · independently confirmed · reproduced with stubs
    Failure scenario. The same corpus ingested on a Windows workstation and a Linux CI runner yields JSONL files with different row order and different hashes.
    Where. forgelm/ingestion.py:2004, docs/reference/data_ingestion_architecture.md:633-634
    Recommended fix. Sort with key=lambda p: p.relative_to(root).as_posix(), or scope the doc claim to a single OS.

  • CR-A12-070 (code, Low) — BOM-dependent codecs (utf-16/utf-32) on BOM-less TXT/MD raise despite errors='replace', so files are skipped and the run exits 0
    severity Low · reachability documented-opt-in · intent contract-violation · confidence confirmed · independently confirmed · reproduced end to end
    Failure scenario. An operator assumes a UTF-16 corpus and passes --input-encoding utf-16, but some files have no BOM. Those files disappear from the output with only a per-file 'Skipping' warning, and the run succeeds.
    Where. forgelm/ingestion.py:1382, forgelm/ingestion.py:2072-2074, docs/guides/ingestion.md:396-400
    Recommended fix. Catch UnicodeDecodeError on the explicit-codec path and re-decode the bytes (path.read_bytes().decode(encoding, 'replace') still raises for a missing BOM, so fall back to the -le/-be variant or report it as an operator error). Alternatively, narrow the docs to say that BOM-required codecs fail per file.

  • CR-A12-071 (code, Low) — Ingest log lines interpolate raw corpus filenames with %s, so control characters and newlines reach the terminal and log
    severity Low · reachability default · intent intended-but-harmful · confidence confirmed · single reviewer · reproduced end to end
    Failure scenario. A corpus contains a file named 'evil\x1b[31mRED\x07.pdf' (or one with an OSC/cursor-movement sequence). Each warning and summary line emits the raw escape sequence, which can recolour, rewrite or hide earlier terminal and log lines. The page-range defence covers only one message family.
    Where. forgelm/ingestion.py:987, forgelm/ingestion.py:2074, forgelm/ingestion.py:2185, forgelm/ingestion.py:2633
    Recommended fix. Use %r (or a shared safe-path formatter) for file paths in every ingest log line.

  • CR-A12-072 (code, Low) — A paragraph-strategy chunk can start mid-sentence in PDFs, because page breaks are treated as paragraph breaks
    severity Low · reachability default · intent contract-violation · confidence likely · single reviewer · reproduced end to end
    Failure scenario. An operator ingests a policy PDF with the default paragraph strategy. Any sentence that spans a page break becomes the tail of one SFT example and the head of the next, so the model trains on fragments that start mid-sentence, exactly what performance.md:135 says cannot happen.
    Where. forgelm/ingestion.py:1017, forgelm/ingestion.py:1491, forgelm/ingestion.py:1349, docs/guides/performance.md:135
    Recommended fix. Join PDF pages with a single '\n' (or merge across a page break when the page does not end in sentence-final punctuation). Otherwise, document that for PDFs a page break is a paragraph boundary and the mid-sentence guarantee holds only within a page.

  • CR-A12-073 (code, Low) — performance.md ingest example lists a 'semantic' strategy the CLI rejects, and ingest --help contradicts behaviour for --overlap with paragraph
    severity Low · reachability default · intent contract-violation · confidence likely · single reviewer · reproduced end to end
    Failure scenario. A user copies the documented strategy and gets an argparse error. The help text and the guide disagree about whether --overlap is allowed with paragraph.
    Where. docs/guides/performance.md:119, docs/guides/performance.md:121, docs/guides/performance.md:131, forgelm/ingestion.py:1856-1868
    Recommended fix. Drop 'semantic' from the CLI example (or note that the CLI does not accept it), and align the --overlap help text with the actual ignore behaviour, or reject non-zero values.

  • CR-A12-074 (code, Low) — The PII-masking manual says per-category info survives only in audit pii_summary, but ingest reports per-category redaction counts; the page also keeps a stale [EMAIL_REDACTED] tag and a locale table
    severity Low · reachability default · intent contract-violation · confidence confirmed · independently confirmed · reproduced end to end
    Where. docs/usermanuals/en/data/pii-masking.md:49, docs/usermanuals/en/data/pii-masking.md:58, docs/usermanuals/en/data/pii-masking.md:75-83, docs/usermanuals/en/data/pii-masking.md:94-98
    Recommended fix. Reword :49 to name the ingest pii_redaction_counts as a second place the per-category counts appear. Replace '[EMAIL_REDACTED]' at :58 with '[REDACTED]'. Delete the Locales table, or recast it as plain 'patterns covered'. Fix :94-98 to show forgelm audit --pii-ml --pii-ml-language or remove it. Apply all of this to EN and TR.

  • CR-A12-075 (code, Low) — Front-matter drop is invisible in the text summary, and a fully dropped PDF is reported as 'no extractable text' / 'empty/unreadable'
    severity Low · reachability default · intent intended-but-harmful · confidence likely · independently confirmed · reproduced end to end
    Failure scenario. An operator who reads only the text summary (or runs with --log-level ERROR) never learns that pages were removed. One who sees the zero-chunk warning on a table-only PDF is sent to look for an OCR or scan problem that does not exist.
    Where. forgelm/ingestion.py:1002-1008, forgelm/ingestion.py:2184-2186, forgelm/ingestion.py:2547-2553, forgelm/ingestion.py:2623-2630
    Recommended fix. Add an extra_notes line with per-file counts when pages are dropped. Record the cause in the skip path (e.g. 'all N pages dropped by front-matter heuristic; use --keep-frontmatter'). Report 1-based page numbers, or label the indices as 0-based.

  • CR-A12-076 (code, Low) — Per-page PDF extraction failures are dropped without any count: a run that loses 9 of 10 pages reports success:true, files_processed=1
    severity Low · reachability default · intent intended-but-harmful · confidence confirmed · independently confirmed · reproduced with stubs
    Failure scenario. A CI ingest step that gates on the JSON envelope (success, files_skipped == 0) accepts a corpus whose PDFs lost most of their pages to a pypdf font or xref bug. The training data is then silently truncated.
    Where. forgelm/ingestion.py:650-662 (except at :653, warning :654-659, text='' :660, drop :661-662), forgelm/ingestion.py:107-141, forgelm/cli/subcommands/_ingest.py:238-262, docs/reference/data_ingestion_architecture.md:153-156
    Recommended fix. Count failed pages per file in _ExtractContext. Expose pdf_pages_failed (total, and per-file names) in IngestionResult, notes_structured and extra_notes. Optionally add a fail threshold.

  • CR-A12-077 (code, Low) — strip_paragraph_packed_headers runs inside _extract_pdf on page blocks before chunking, not after paragraph packing as its docstring and docs state
    severity Low · reachability default · intent contract-violation · confidence likely · independently confirmed · reproduced end to end
    Failure scenario. A training deck or quiz PDF has section-divider slides that carry only the logo line and footer. The page pass empties them, the second pass's denominator shrinks, and the repeated question stems or 'Key takeaways' lines are deleted from every content slide. The note calls them header lines.
    Where. forgelm/ingestion.py:450-466, forgelm/ingestion.py:467-481, forgelm/ingestion.py:1010-1018, forgelm/ingestion.py:2553
    Recommended fix. Compute the cutoff over the original page count, or remove the pass and fold its intent into the page-level window. If it is kept, run it where the docs say it runs (on packed chunks) and correct the three doc surfaces. Do not let it apply paragraph-level stripping to 1-2-page documents.

  • CR-A12-078 (code, Low) — Sliding token chunks exceed --chunk-tokens by 1-3 tokens in 11-16% of chunks, because the emitter strips the decoded window's leading space and the first word then re-tokenizes into more pieces
    severity Low · reachability default · intent intended-but-harmful · confidence likely · single reviewer · reproduced end to end
    Failure scenario. chunk_tokens=1024 with max_length=1024: about 14% of rows come out 1025-1027 tokens long, and SFT keep_start truncation drops their last 1-3 tokens, usually the end of a sentence. Ingest reports nothing.
    Where. forgelm/ingestion.py:1876-1904, forgelm/ingestion.py:1880-1881, forgelm/ingestion.py:2199, docs/reference/data_ingestion_architecture.md:377
    Recommended fix. Strip before slicing, or trim the stripped payload back to N ids by re-encoding, or relax the docstring to 'approximately'. Count chunks that exceed N.

  • CR-A12-079 (code, Low) — Directory discovery filters only on file suffix: hidden/tooling trees, dotfiles and OS/editor by-products (AppleDouble '._*', '~$' lock files) are ingested as training rows
    severity Low · reachability default · intent intended-but-harmful · confidence confirmed · independently confirmed · reproduced end to end
    Failure scenario. I ran forgelm ingest corpus --recursive --output out/rec.jsonl on a tree that also held .git/, .venv/lib/python3.13/site-packages/..., .tox/, node_modules/, .pytest_cache/, .ipynb_checkpoints/, .obsidian/ and .hidden_notes.txt. It exited 0 with success:true and wrote 20 rows. 13 of those rows came from hidden or tooling paths: 'GITDIR hook readme', 'VENV Apache License...', '[console_scripts]\nVENV = x:y', 'requests' (top_level.txt), 'NODEMODULES left-pad readme', the pytest-cache README, the s…
    Where. forgelm/ingestion.py:1997-2006, forgelm/ingestion.py:2004, forgelm/ingestion.py:2005, forgelm/wizard/_byod.py:54-60 (confirmed)
    Recommended fix. Skip any path whose component relative to input_path starts with '.', plus well-known tooling directories, in both _iter_input_files and _directory_has_ingestible_files. Report the number of pruned files in notes_structured. Document the rule in the guide and the architecture reference (EN and TR). Add tests.

  • CR-A12-080 (code, Low) — Architecture reference says unsupported extensions in a directory increment files_skipped (and misstates the ingest exit-code table); discovery filters them out before counting
    severity Low · reachability default · intent contract-violation · confidence likely · independently confirmed · reproduced end to end
    Failure scenario. The recursive fixture tree held 7 files with unsupported suffixes (#notes.md#, notes.md~, .notes.md.swp, notes.md.bak, image.png, .git/description, .git/COMMIT_EDITMSG). The run reported files_skipped 3, which were exactly the 3 extraction failures (._report.pdf, report.pdf, ~$report.docx).
    Where. docs/reference/data_ingestion_architecture.md:498 (confirmed), docs/reference/data_ingestion_architecture.md:653 (confirmed), docs/reference/data_ingestion_architecture-tr.md:497 (confirmed), docs/reference/data_ingestion_architecture-tr.md:653 (confirmed)
    Recommended fix. Correct both tables (EN and TR) to say that unsupported files in directories are ignored and not counted, or add an explicit files_ignored count to notes_structured.

Done when

  • Every finding above is fixed or closed with a reason (tick it here).
  • Code fixes carry a test; doc fixes update the Turkish mirror in the same PR.

Found by the October 2026 ForgeLM code and documentation review against commit cab2947. Code links point at that commit; line numbers may have moved since. Finding IDs (CR-…, DOC-…, TECH-…) are stable references for this backlog.

Activity

  1. added
    bug
    area: ingestion
    backlog: known
    security
    severity: low
    source: review-2026-10
    wave: 4
    on Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: ingestionbacklog: knownbugsecurityseverity: lowsource: review-2026-10wave: 4

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions