fix(batch): harden gateway status/results parsing against null counts and malformed lines - #17
Conversation
… and malformed lines
`get_batch_status` read `result.get("request_counts", {})`, which returns None
(not `{}`) when the OpenAI-compatible gateway sends `"request_counts": null` —
a legitimate response while a batch is still validating/queued. The following
`counts.get("total", ...)` then raised `AttributeError`, crashing every poll of
such a batch. Use `or {}` so null is treated like absent (0% progress).
`download_results` parsed the output file with a bare list comprehension over
`json.loads(line)`; a truncated or corrupt line (untrusted gateway content)
raised an uncaught `json.JSONDecodeError`, leaking an internal parse error past
the gateway boundary. Wrap the parse and raise the module's typed `GatewayError`
with the offending line number instead.
Adds two regression tests (null request_counts poll; malformed result line ->
GatewayError). Full tests/test_batch_api_client.py: 12 passed; ruff clean.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HdCssGnNMhKHNu3TXFstWH
|
Warning Review limit reached
Next review available in: 21 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
Comment |
|
The failing Those base findings are the exact set being annotated as reviewed false-positives in #16; this PR goes green on Semgrep once that base fix (or an equivalent Generated by Claude Code |
There was a problem hiding this comment.
Pull request overview
OpenCode cannot approve yet because required coverage evidence did not pass.
Review outcome
1. HIGH .github/workflows/opencode-review.yml:1 - Coverage evidence did not prove required test/docstring evidence
-
Problem: The required coverage-evidence job result was
failure, so OpenCode cannot establish approval sufficiency for this head. -
Root cause: Automated approval is only valid when the same-head coverage-evidence job proves supported repository test suites passed and configured docstring gates passed or were advisory, or reports not applicable because no supported source files or package manifests exist. Missing, failed, skipped, unavailable, or unsupported-tooling test evidence is a blocker.
-
Fix: Install or configure the repository test/docstring evidence tooling when source files or package manifests exist, rerun the current-head coverage-evidence job, and approve only after it reports
successwith required evidence or explicit no-source not-applicable evidence. -
Regression test: Keep the approval branch checking
needs.coverage-evidence.result == successbefore posting APPROVE, and publish REQUEST_CHANGES when coverage-evidence blocker states such as cancelled, skipped, failed, unsupported-tooling, or below-100 evidence are present. -
Result: REQUEST_CHANGES
-
Reason: coverage-evidence result was
failure, so required test/docstring evidence was not proven for current head4614901061fd1158009902984a1d96dc2004c70b. -
Head SHA:
4614901061fd1158009902984a1d96dc2004c70b -
Workflow run: 30514784578
-
Workflow attempt: 1
Coverage evidence
Coverage Decision
- Result: FAIL
- Test evidence: not proven passing
- Docstring evidence: not proven passing when configured
- Failure count: 1
Changed-File Evidence Map
flowchart LR
PR["PR changed files"] --> Evidence["OpenCode bounded evidence"]
Evidence --> S1["Changed file: batch_api_client.py"]
S1 --> I1["repository behavior"]
I1 --> R1["Review risk: Changed file: batch_api_client.py"]
R1 --> V1["required checks"]
Evidence --> S2["Test: test_batch_api_client.py"]
S2 --> I2["regression suite"]
I2 --> R2["Review risk: Test: test_batch_api_client.py"]
R2 --> V2["targeted test run"]
OpenCode Review Overview
Pull request overviewOpenCode cannot approve yet because required coverage evidence did not pass. Review outcome1. HIGH .github/workflows/opencode-review.yml:1 - Coverage evidence did not prove required test/docstring evidence
Coverage evidenceCoverage Decision
Changed-File Evidence Mapflowchart LR
PR["PR changed files"] --> Evidence["OpenCode bounded evidence"]
Evidence --> S1["Changed file: batch_api_client.py"]
S1 --> I1["repository behavior"]
I1 --> R1["Review risk: Changed file: batch_api_client.py"]
R1 --> V1["required checks"]
Evidence --> S2["Test: test_batch_api_client.py"]
S2 --> I2["regression suite"]
I2 --> R2["Review risk: Test: test_batch_api_client.py"]
R2 --> V2["targeted test run"]
|
Annotate 15 reviewed Semgrep false positives without weakening the SAST gate. Current head is tree-identical to the exact code snapshot whose Semgrep and Security Scan runs passed; the stale old-head OpenCode review was dismissed after the central coverage workflow was repaired.
Superseded by current head f8b694b. The old REQUEST_CHANGES was solely a central coverage-evidence infrastructure failure on head 4614901; the central workflow has since been repaired. The branch was refreshed onto main after #16, and compare d8d1889...f8b694b confirms the effective PR diff remains exactly the two reviewed source/test files. Fresh current-head checks have been triggered.
The defects
Two unhandled external-input crash paths in
pg_llm_batch/batch_api_client.py, both parsing an OpenAI-compatible gateway response:get_batch_status—AttributeErroronrequest_counts: null. The code readcounts = result.get("request_counts", {}). When the gateway returns{"request_counts": null, ...}— a legitimate response while a batch is stillvalidating/queued — the key is present, so.get(..., {})returnsNone, not{}. The next line,counts.get("total", 0), then raisesAttributeError: 'NoneType' object has no attribute 'get', crashing every poll of such a batch (anddownload_results, which polls first).download_results— uncaughtjson.JSONDecodeErroron a malformed output line. Results were parsed with[json.loads(line) for line in content.strip().split("\n") if line]. A truncated or corrupt output file (untrusted gateway content) raises a rawjson.JSONDecodeErrorthat leaks past the gateway boundary instead of the module's typedGatewayError.The fix
counts = result.get("request_counts") or {}— treatsnulllike absent, so the progress math never dereferencesNone(0% progress for a not-yet-counted batch).GatewayError(the module's existing error type, already raised elsewhere in these functions) with the offending line number, so malformed downloads surface as a typed, boundary-appropriate error.Two regression tests added: a poll with
request_counts: null(crashed before, now 0%) and a malformed result line (leakedJSONDecodeErrorbefore, nowGatewayError).Verification
uv run pytest tests/test_batch_api_client.py→ 12 passed (10 existing + 2 new).ruff check pg_llm_batch/batch_api_client.py tests/test_batch_api_client.py→ clean.batch_api_client.py.🤖 Generated with Claude Code
https://claude.ai/code/session_01HdCssGnNMhKHNu3TXFstWH
Generated by Claude Code