Skip to content

fix(corpus): enforce max_documents cumulatively across .jsonl files in directory walks#230

Merged
himanshu231204 merged 2 commits into
OpenAgentHQ:mainfrom
Nitjsefnie-OSC:fix/corpus-maxdocs-cross-jsonl
Jul 23, 2026
Merged

fix(corpus): enforce max_documents cumulatively across .jsonl files in directory walks#230
himanshu231204 merged 2 commits into
OpenAgentHQ:mainfrom
Nitjsefnie-OSC:fix/corpus-maxdocs-cross-jsonl

Conversation

@Nitjsefnie

Copy link
Copy Markdown
Contributor

Fixes #224

The cumulative max_documents check in _load_documents' directory branch sat inside the non-jsonl else, so it never ran after a .jsonl file was processed — the cap was enforced per-file, never cumulatively (grows unbounded with more jsonl files). The check now runs after both branches, trimming documents to the cap before breaking. Single-file loads and non-jsonl directories are behaviorally unchanged (the per-file append never overshoots there, so the trim is a no-op) — all of #222's merged regression tests stay green.

New tests: 2 jsonl files × 3 lines with max_documents=2 → exactly 2 (fails on main with assert 4 == 2, matching the issue repro), and a mixed jsonl+txt directory capping correctly (fails on main with assert 3 == 2). Full suite: 961 passed, 4 skipped. The two ruff findings in auditor.py are pre-existing on main (verified) — new code adds none.

Generated by Claude Fable 5 (brief, review), Claude Opus 4.8 (implementation)

…es (OpenAgentHQ#224)

In `_load_documents`' directory branch the cumulative cap check
(`len(documents) >= self.max_documents`) sat only inside the non-jsonl
`else` branch, so it never ran after a `.jsonl` file. `_load_jsonl_documents`
caps within a single file only (its local list resets per call), so a
directory of `.jsonl` files silently blew past `max_documents` — a memory /
safety bound — while a directory of `.txt` files capped correctly.

Move the cap check out of the `else` so it runs after both branches, and
trim the extended list to `max_documents` before breaking. Behavior for
single-file loads and `.txt`-only directories is unchanged (a per-file
`.txt` append never overshoots, so the trim is a no-op there).

Regression: a directory of 2 jsonl files x 3 lines with max_documents=2 now
loads exactly 2 (was 4), and a mixed jsonl+txt directory caps at 2 (was 3).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@himanshu231204

Copy link
Copy Markdown
Member

/oc review pr

@opencode-agent

Copy link
Copy Markdown
Contributor

Review: fix/corpus-maxdocs-cross-jsonl

The bug is correctly diagnosed. In the original _load_documents directory branch, the max_documents cap check lived inside the non-jsonl else at line 205 (old), so after processing a .jsonl file, the cap was never enforced cumulatively — it only capped within a single _load_jsonl_documents call.

The fix (one line dedented, one line relocated) moves the cap check to run after both the jsonl and non-jsonl branches. Correct and minimal.

Tests directly exercise _load_documents and reproduce the exact scenario from #224: two jsonl files × 3 lines with max_documents=2 → 2, and a mixed jsonl+txt directory → 2. These would fail on main.

Nit: none. The change is surgical, the tests are clear, and the PR description accurately describes the problem and fix.

Verdict: Ready to merge.

New%20session%20-%202026-07-23T20%3A51%3A49.787Z
opencode session  |  github run

@himanshu231204
himanshu231204 merged commit f9a72a3 into OpenAgentHQ:main Jul 23, 2026
8 checks passed
@github-actions

Copy link
Copy Markdown

🎉 Congratulations @Nitjsefnie!

Your pull request has been successfully merged into main. 🚀

Thank you for contributing to OpenAgentHQ and helping improve the project.

We truly appreciate your contribution and hope to see you back with more amazing PRs!

Happy Open Sourcing! ❤️

opencode-agent Bot added a commit that referenced this pull request Jul 23, 2026
Use slicing (documents[:self.max_documents]) instead of in-place
delete (del documents[self.max_documents:]) to match the fix
already merged in PR #230.
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.

corpus(auditor): max_documents not enforced across .jsonl files in a directory walk

2 participants