Skip to content

Fix: Pagination bug, atomic JSONL export, resilient JSON parsing - #4

Merged
Christbowel merged 1 commit into
Christbowel:mainfrom
Chocapikk:fix-robustness
Apr 19, 2026
Merged

Fix: Pagination bug, atomic JSONL export, resilient JSON parsing#4
Christbowel merged 1 commit into
Christbowel:mainfrom
Chocapikk:fix-robustness

Conversation

@Chocapikk

Copy link
Copy Markdown
Contributor

Summary

Three real bugs that can cause data loss or unnecessary API usage.

1. Pagination params dropped after page 1 (deep_scan.py)

fetch_all_commits() passes params (including per_page=100) only on the first request. Subsequent pages use params=None, so GitHub defaults to per_page=30. This means 3x more API calls than necessary on every deep scan, burning through rate limits faster.

2. JSONL export not atomic (db.py)

export_to_jsonl() opens the file in "w" mode (truncates immediately) then writes patterns and advisories. If the process crashes mid-write (SIGTERM from GitHub Actions timeout, OOM, etc.), the JSONL file is truncated and unrecoverable. Fixed by writing to a .tmp file first then using os.replace() for an atomic swap.

3. Missing JSON error handling in JSONL readers

Every JSONL reader (db.py, deep_scan.py, silent_scan.py, render.py) calls json.loads() without try/except. A single malformed line crashes the entire pipeline. Now skips bad lines with a warning instead of crashing.

Also includes the suspects_count crash fix and ruff cleanup (same as PR #1, included for branch independence).

Test plan

  • Run python -m src.deep_scan owner/repo --since 2025-01-01 --max 10 - verify pagination uses 100 per page
  • Manually corrupt a line in data/silent_results.jsonl - verify render doesn't crash
  • ruff check src/ passes with 0 errors

- Fix pagination in fetch_all_commits: params were dropped after page 1,
  causing per_page to fall back to 30 instead of 100 (3x more API calls)
- Atomic JSONL export: write to .tmp then os.replace() to prevent data
  loss if process crashes mid-export
- Add try/except on all json.loads() in JSONL readers (db.py, deep_scan.py,
  silent_scan.py, render.py) so one malformed line doesn't crash the pipeline
- Fix undefined suspects_count and unused raw_combined in deep_scan.py
- Ruff cleanup across 11 files
@Christbowel
Christbowel merged commit 838abbf into Christbowel:main Apr 19, 2026
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.

2 participants