Uh oh!
There was an error while loading. Please reload this page.
docs(flashcards): correct error-contract comment (#300 review follow-up) - #336
Conversation
…ment The docstring claimed the contract "mirrors the legacy call_gemini flashcard path," but that only held for the 4 import seams (which already returned [] on bad JSON). For /generate the legacy path *raised* on malformed output — surfacing a 502 — whereas the unified agent path degrades it to []. Reword so the comment states this is a deliberate contract change for /generate, not a faithful mirror. Comment-only. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Deploying with |
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs | frontend-staging | 3634817 | Commit Preview URL Branch Preview URL | Jul 15 2026, 04:49 AM |
Warning Review limit reached
Next review available in:30 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: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
AndresL230
left a comment
There was a problem hiding this comment.
Approving. Both headline claims verified against the pre-#300 code at 756d276, and the new wording is strictly more accurate than what it replaces.
The old comment said the /generate path "mirrors the legacy call_gemini flashcard path" — that was flatly wrong. Legacy /generate (gemini_service.generate_flashcards) parsed with an unguarded json.loads(cleaned) and raised ValueError, which routes/flashcards.py:203-204 caught as bare Exception → 502. So it raised; it did not degrade to []. The legacy import seams' _parse_card_json genuinely did return [] on JSONDecodeError. The correction is real.
I verified the comment empirically rather than by inspection — patched flashcard_agent.run and observed actual behavior:
| Injected failure | Actual result | Matches comment? |
|---|---|---|
Schema retry exhaustion (UnexpectedModelBehavior) | [] → HTTP 200 | ✅ bullet 1 |
ModelHTTPError(503) | retried once, then raised → 502 | ✅ bullet 2 |
ModelHTTPError(401) | raised → 502 | ✅ bullet 3 |
RuntimeError | raised → 502 | ✅ bullet 3 |
ContentFilterError | [] → HTTP 200 | ❌ not described |
| Token-limit overrun | [] → HTTP 200 | ❌ not described |
Also confirmed ModelHTTPError is not a subclass of UnexpectedModelBehavior (siblings under AgentRunError), so the except ordering at :251/:254 is safe and result can't be None at :263. 35/35 tests pass.
Merging as-is, but bullet 1 is under-inclusive — and the real bug is the code, not the comment.ContentFilterErroris a subclass of UnexpectedModelBehavior (MRO: ContentFilterError → UnexpectedModelBehavior → AgentRunError → RuntimeError), so the except at :251 swallows content-filter blocks too. That is not theoretical here: pydantic_ai/models/google.py:152-158 maps RECITATION → content_filter, and Gemini returns RECITATION precisely when output closely reproduces source material — while agents/flashcard.py's system prompt instructs the model to "Base card content on the material provided; do not invent facts it does not support."
Concrete: student generates flashcards from a textbook chapter → Gemini finishes with RECITATION → POST /api/flashcards/generate returns 200 {"cards": []}. Zero cards, nothing to retry, indistinguishable from "no cards found." That is verbatim the P1 #300's review raised. Same for a token-limit overrun against the pinned max_tokens=8192, realistic on large OCR markdown.
The fix is to narrow the catch so ContentFilterError propagates → 502, not to broaden the sentence. Filed separately — no reason to hold a docs correction on it.
Two smaller nits, non-blocking: "a deliberate contract change for /generate" is incomplete (legacy call_gemini raised on empty/filtered responses before_parse_card_json ran, so the import seams changed too — they only returned [] on genuinely bad JSON); and bullet 3's "propagates → 502" holds for four of five seams — /import/parse catches ValueError → 422 first (routes/flashcards.py:391-392), currently harmless since everything re-raised derives from RuntimeError.
Follow-up to the code review of #300.
_run_flashcard_agent's docstring claimed the error contract "mirrors the legacycall_geminiflashcard path." That's only true for the 4 import seams (which already returned[]on bad JSON). For/generate, the legacy path raised on malformed output (surfacing a 502); the unified agent path degrades it to[]. Reworded to state this is a deliberate contract change for/generate, not a faithful mirror.Comment-only; no behavior change.
test_flashcard_import_service.py35/35 pass.🤖 Generated with Claude Code