Skip to content

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

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-039 (code, Low) — --strip-urls mask/strip swallows trailing sentence punctuation and closing brackets/quotes
    severity Low · reachability documented-opt-in · intent intended-but-harmful · confidence confirmed · single reviewer · reproduced end to end
    Failure scenario. Chunks contain unbalanced parentheses and run-on sentences wherever a URL ended a clause. Downstream SFT data learns broken punctuation.
    Where. forgelm/ingestion.py:192, forgelm/ingestion.py:574-578
    Recommended fix. Trim trailing [.,;:!?'")]] from each match (balanced-paren aware, as linkifiers do) before replacing, for example with a replacement callback.

  • CR-A12-040 (code, Low) — PDF dedup removes intra-page blank lines and indentation for PDFs with 3 or more pages, even when nothing is stripped
    severity Low · reachability default · intent intended-but-harmful · confidence confirmed · single reviewer · reproduced end to end
    Failure scenario. The same document split into a 2-page excerpt and a 30-page full version is chunked differently. Code listings in multi-page technical PDFs lose their indentation.
    Where. forgelm/ingestion.py:418-421, forgelm/ingestion.py:446, forgelm/ingestion.py:1491
    Recommended fix. Rewrite a page only when lines were actually removed, and remove matched lines in place (keeping blank lines and original indentation) instead of rebuilding from stripped lines.

  • CR-A12-041 (code, Low) — PDF edge dedup strips repeated body lines beyond the documented 3-row window
    severity Low · reachability default · intent contract-violation · confidence confirmed · single reviewer · reproduced end to end
    Failure scenario. Slide-deck or form PDFs with short pages lose legitimately repeated body lines (labels, recurring instructions), and the result contradicts the stated contract.
    Where. forgelm/ingestion.py:271-275, forgelm/ingestion.py:302-303, forgelm/ingestion.py:434-444
    Recommended fix. Either correct the docstring to describe the iterative peel, or limit the total peel depth per page to the window and require repeating lines to be contiguous with the page edge.

  • CR-A12-042 (code, Low) — Front-matter page-number signal undercounts consecutive standalone page numbers (non-overlapping \n\d{1,3}\n)
    severity Low · reachability default · intent intended-but-harmful · confidence likely · single reviewer · reproduced end to end
    Failure scenario. The documented heuristic ('>= 5 inline page-number matches') fires or not depending on pypdf's reading order, not on the page content.
    Where. forgelm/ingestion.py:732, forgelm/ingestion.py:771-775
    Recommended fix. Use a lookahead/multiline form such as re.compile(r'^\d{1,3}$', re.M) to count standalone number lines.

  • CR-A12-043 (code, Low) — EPUB extraction breaks sentences at every inline tag and relies on source whitespace for paragraph boundaries
    severity Low · reachability default · intent intended-but-harmful · confidence confirmed · single reviewer · reproduced end to end
    Failure scenario. SFT rows from EPUBs contain mid-sentence line breaks around every emphasised word. A minified EPUB chapter becomes a single chunk far above --chunk-size.
    Where. forgelm/ingestion.py:1344-1347, forgelm/ingestion.py:1491-1507
    Recommended fix. Walk block-level elements (p, h1-h6, li, blockquote, pre) and join their get_text(' ', strip=True) with '\n\n'.

  • CR-A12-044 (code, Low) — Script-sanity cause classifier labels any Latin-1 offenders as 'pypdf font fallback', including on TXT files and UTF-8 mojibake
    severity Low · reachability default · intent contract-violation · confidence likely · single reviewer · reproduced end to end
    Failure scenario. The operator is told to run forgelm doctor for the pypdf normaliser when the real fix is --input-encoding. The structured cause_hint in notes_structured misleads automation.
    Where. forgelm/_script_sanity.py:322-326, forgelm/_script_sanity.py:351-353
    Recommended fix. Check offenders against _pypdf_normalise's source glyph tables for the font-fallback label, and add a Latin-1 double-encoding (Ã/Â/Ä/Å lead bytes) mojibake pattern.

  • CR-A12-045 (code, Low) — Paragraph and markdown packers charge a separator to the first item, so the first chunk of each run is held 2 characters below the cap
    severity Low · reachability default · intent intended-but-harmful · confidence confirmed · independently confirmed · reproduced end to end
    Failure scenario. Two paragraphs whose joined length equals --chunk-size exactly are split when they start a document and packed together anywhere else.
    Where. forgelm/ingestion.py:1499-1505, forgelm/ingestion.py:1501, forgelm/ingestion.py:1505, forgelm/ingestion.py:1762-1768
    Recommended fix. Use cost = para_len + (2 if current else 0), as the token variant does.

  • CR-A12-046 (code, Low) — An explicit --overlap with --strategy paragraph is silently ignored, although help says it must be 0/unset and markdown rejects it
    severity Low · reachability default · intent intended-but-harmful · confidence likely · single reviewer · reproduced end to end
    Failure scenario. An operator who forgets --strategy sliding expects overlapping context windows and gets non-overlapping paragraphs, with no signal.
    Where. forgelm/ingestion.py:1858, forgelm/ingestion.py:2409, forgelm/cli/_parser.py:230
    Recommended fix. Reject non-zero overlap for paragraph (as markdown does), or at least log a WARNING.

  • CR-A12-047 (code, Low) — Side effects and late validation: output parents are created before parameter checks, and chunk/page-range parameters are validated only when a qualifying file is reached
    severity Low · reachability default · intent intended-but-harmful · confidence confirmed · independently confirmed · reproduced end to end
    Failure scenario. 'forgelm ingest docs/ --chunk-size 0' on a directory whose files are all empty or unreadable exits 0 with the 'Ingest produced 0 chunks' warning instead of a config error. A typo in --output creates stray directories on every failed attempt.
    Where. forgelm/ingestion.py:2334-2347, forgelm/ingestion.py:2397, forgelm/ingestion.py:1453, forgelm/ingestion.py:980
    Recommended fix. Move all parameter validation (chunk_size>0, overlap bounds per strategy, chunk_tokens>0, page_range start>=1 and start<=end) to the top of ingest_path and mkdir only afterwards. Fix the comment at 640-642.

  • CR-A12-048 (code, Low) — Strip-pattern SIGALRM handler raises a generic OSError that can escape _apply_one outside its try, leaving the handler installed and exiting 2
    severity Low · reachability default · intent intended-but-harmful · confidence likely · single reviewer · not reproduced (code trace)
    Failure scenario. A pattern that finishes almost exactly at the 5 s mark aborts the ingest with exit 2 instead of being applied or skipped. A threaded library caller gets no ReDoS bound and no warning.
    Where. forgelm/_strip_pattern.py:432, forgelm/_strip_pattern.py:441, forgelm/_strip_pattern.py:381, forgelm/_strip_pattern.py:415
    Recommended fix. Disarm the alarm inside the try right after subn returns, or set a flag in the handler instead of raising late. Log once at WARNING when timeout_s is set but the guard cannot be installed.

  • CR-A12-050 (code, Low) — Quality pre-signal samples only the first 5000 chunks but reports as if it covered the corpus
    severity Low · reachability default · intent intended-but-harmful · confidence likely · independently confirmed · reproduced end to end
    Where. forgelm/ingestion.py:2453-2461, forgelm/ingestion.py:2556-2575, forgelm/ingestion.py:2682-2733, forgelm/ingestion.py:2752-2780
    Recommended fix. Use reservoir sampling or a stride so the 5000 samples span all files, and state in the note that the figure is a sample.

  • CR-A12-051 (code, Low) — CLI-to-library wiring of ingest is largely unverified: dispatcher tests mock ingest_path, the JSON envelopes and the missing-extra exit code never execute, and 11 flags can be dropped without a faili…
    severity Low · reachability default · intent contract-violation · confidence confirmed · independently confirmed · reproduced end to end
    Failure scenario. A refactor of the kwargs block in _run_ingest_cmd silently turns --recursive into a shallow walk, or drops --strip-pattern / --keep-frontmatter / --language-hint; or changes the JSON envelope's success / key names that CI consumers parse; or maps a missing extra to exit 1. All 340+ ingest tests stay green.
    Where. forgelm/cli/subcommands/_ingest.py:123-125, forgelm/cli/subcommands/_ingest.py:154-178 (ingest_path kwargs), 228-236 (OptionalDependencyError route), 238-264 (JSON envelope), forgelm/cli/subcommands/_ingest.py:185, forgelm/cli/subcommands/_ingest.py:228-264
    Recommended fix. Add real main() tests (argv through the parser) that assert, via the written JSONL / JSON envelope, each flag's effect (recursive, strip-pattern, strip-urls, keep-frontmatter, epub flag, md-frontmatter, no-quality-presignal, language-hint, tokenizer/chunk-tokens), the JSON success and error envelopes, exit 2 for OptionalDependencyError (simulate with monkeypatch.delitem on sys.modules), and exi…

  • CR-A12-052 (code, Low) — F-034 PDF pipeline: the default-on front-matter drop, multi-column probe, second-pass dedup and encrypted-PDF rejection have no behavioural test; the one test touching the drop monkeypatches the func…
    severity Low · reachability default · intent intended-and-acceptable · confidence confirmed · independently confirmed · reproduced end to end
    Failure scenario. A change that makes _drop_frontmatter_pages never drop, or drop real body pages, or an index shift in --page-range that loses the first requested page, passes the whole suite.
    Where. forgelm/ingestion.py:779-811, forgelm/ingestion.py:644, forgelm/ingestion.py:993-1008, forgelm/ingestion.py:1017-1023
    Recommended fix. Add a synthetic-PDF test (the _synth_multipage_pdf helper already exists) with ToC head and tail pages asserting exact dropped indices, the default-vs-keep_frontmatter contrast and body preservation; change the page-range assertion to 'and' plus negative checks; assert the multi-column warning through ingest_path with a patched visitor; assert the encrypted-PDF warning text.

  • CR-A12-053 (code, Low) — Quality pre-signal and script-sanity have no positive or wiring tests at ingest level; the pre-signal 'flags' test asserts only that a block exists
    severity Low · reachability default · intent intended-but-harmful · confidence likely · single reviewer · reproduced end to end
    Failure scenario. The advertised end-of-run corruption pre-signal silently stops flagging corrupt PDFs (the 74/82-chunk case it was built for) and no test notices; or --script-sanity-threshold is ignored.
    Where. forgelm/ingestion.py:2682-2780, forgelm/ingestion.py:554-562, tests/test_ingestion_reliability.py:366-377, tests/test_script_sanity.py:1-217
    Recommended fix. Add one corrupt-text fixture per check asserting by_check counts and samples_flagged; assert script_sanity_summary and the triggered counter through ingest_path with a Turkish-corrupted TXT, including the threshold override and the normalised-glyph no-false-positive case.

  • CR-A12-054 (code, Low) — Token-aware chunking (--chunk-tokens/--overlap-tokens/--tokenizer) is almost untested: both token chunkers, the real batch-tokenizer path and the ingest_path token setup have zero coverage
    severity Low · reachability documented-opt-in · intent intended-and-acceptable · confidence confirmed · independently confirmed · reproduced end to end
    Failure scenario. The overlap argument is dropped from token-sliding or the separator budget is removed, so chunks overshoot the model max_length the operator sized them for, with all tests green.
    Where. forgelm/ingestion.py:1876-1904, forgelm/ingestion.py:1907-1954, forgelm/ingestion.py:1786-1820, forgelm/ingestion.py:2395-2416
    Recommended fix. Add tests using the local tiny tokenizer fixture (no network) or a stub exposing a real batched __call__, asserting token length <= cap for sliding, overlap content, paragraph soft-cap semantics and the ingest_path wiring.

  • CR-A12-055 (code, Low) — Weak or behaviour-pinning tests: they pin silent no-ops, accept invalid inputs, or assert docstring text instead of behaviour
    severity Low · reachability default · intent intended-and-acceptable · confidence confirmed · single reviewer · reproduced end to end
    Failure scenario. A library caller's typo in normalise_profile silently skips glyph repair; docstring-pinning tests pass while the behaviour regresses.
    Where. tests/test_ingestion_reliability.py:335, tests/test_ingestion_reliability.py:625, tests/test_ingestion_reliability.py:1444, tests/test_pypdf_normalise.py:47
    Recommended fix. Validate normalise_profile against PROFILES in ingest_path (ValueError, exit 1) and replace the pinning tests with behavioural ones; keep apply_profile permissive if forward-compat is intended.

  • CR-A12-056 (code, Low) — Unused module constants whose docstrings claim consumers
    severity Low · reachability unreachable · intent intended-and-acceptable · confidence likely · single reviewer · not reproduced (code trace)
    Failure scenario. Misleading documentation: _quality.py's docstring says tests pin the check names, but tests had 0 references to _QUALITY_CHECKS.
    Where. forgelm/_pypdf_normalise.py:33, forgelm/_pypdf_normalise.py:82, forgelm/model.py:52, forgelm/wizard/_state.py:282
    Recommended fix. Delete the constants or add the consumer or test the docstrings claim.

  • CR-A12-057 (code, Low) — Forgelm ingest --pii-mask / --secrets-mask / --all-mask pays a 2.3 s start-up cost and loads torch, transformers and spaCy to run two stdlib regex maskers
    severity Low · reachability default · intent intended-but-harmful · confidence likely · single reviewer · reproduced end to end
    Where. forgelm/ingestion.py:2376-2392, forgelm/ingestion.py:2389, forgelm/data_audit/_optional.py:74
    Recommended fix. Fixed by the lazy handles in finding 1, or by moving mask_pii/mask_secrets behind a package-free module so from .data_audit import ... does not execute the whole facade.

  • CR-A12-058 (code, Low) — ReDoS time budget is a silent no-op on Windows and in worker threads for --strip-pattern and reverse-pii --type custom
    severity Low · reachability documented-opt-in · intent intended-but-harmful · confidence likely · independently confirmed · not reproduced (code trace)
    Failure scenario. A Windows CI job passes a catastrophic-backtracking pattern and the process hangs with no indication that the advertised budget was never armed.
    Where. forgelm/_strip_pattern.py:381-386, forgelm/cli/subcommands/_reverse_pii.py:412-423, forgelm/cli/_parser.py:412, forgelm/_strip_pattern.py:410-412
    Recommended fix. Emit one WARNING when a custom regex is used and the guard cannot be armed.

  • CR-A12-059 (code, Low) — library_api_reference lists OptionalDependencyError for audit_dataset, which never raises it
    severity Low · reachability default · intent contract-violation · confidence likely · single reviewer · reproduced end to end
    Failure scenario. except OptionalDependencyError (import from forgelm.ingestion) does not catch the audit error.
    Where. docs/reference/library_api_reference.md:246, docs/reference/library_api_reference.md:260, docs/reference/library_api_reference.md:264, docs/reference/library_api_reference.md:265
    Recommended fix. Change the table to name ImportError (with install hint) for audit_dataset and train(), state the 0-6 exit-code set, fix the test citation (EN/TR, performance guide) and the guide's 'pairs' key.

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
    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: ingestionbugsecurityseverity: lowsource: review-2026-10wave: 4

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions