Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Ordinary PDF and AI problems are all reported as "The AI provider failed"

Chiusa
#194 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@Anshuu2004 ci sta già lavorando.

Dal 24/10/2026.

  • #197 di @Anshuu2004 — integrata

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
api, backend, testing

Direzione di ricerca

Start with apps/genAI/app/rag/rag_system.py and apps/genAI/app/main.py, then read errors.py and tests/test_generate_quiz.py alongside the existing PDF and unusable-response handling. Check how conftest.py builds PDFs before adding cases for encrypted and corrupt files, wrong-shaped JSON, and non-PDF bytes. Done means each case returns the specified client-facing error and has a test.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Backend first issue bug help wanted

Several ordinary, user-caused problems in the AI service surface as a 502 blaming the provider, which sends the host to debug the wrong system.

1. A password-protected or corrupt PDF

apps/genAI/app/rag/rag_system.py:68 calls PdfReader(pdf_path).pages with no exception handling:

  • Password-protected PDF → 502 "The AI provider failed: FileNotDecryptedError"
  • Non-PDF bytes sent with a PDF content type → 502 "The AI provider failed: PdfStreamError"

Both are everyday mistakes — a DRM-protected textbook chapter, a truncated upload. The provider was never contacted.

The service already models this correctly elsewhere: PdfHasNoText maps to a 422 in main.py:46. These just need the same treatment.

2. Model output that parses but has the wrong shape

rag_system.py:236 assumes the parsed JSON is a dict containing a list:

payload = _extract_json(str(response.content))
for item in payload.get("questions", []):

_extract_json only guarantees valid JSON, not that shape. Each of these returns 502 "The AI provider failed: AttributeError":

Model returns
[{"text": "q"}] top-level array has no .get
{"questions": "oops"} not iterable as expected
{"questions": {"a": 1}} same

There is already a ValueError → 502 "unusable response" path for output that cannot be parsed at all. These shapes slip past it into the generic handler.

3. The content-type check gives no real guarantee

main.py:77 trusts the client-supplied header:

if file.content_type != "application/pdf":
    raise HTTPException(status_code=400, detail="Only PDF files are allowed.")

Anything labelled application/pdf passes and then fails deep inside pypdf as case 1. A %PDF- magic-byte check on the first bytes written is cheap and definitive.

What a fix looks like
  • Wrap PdfReader and map FileNotDecryptedError to a 422 saying the PDF is password-protected, and a parse failure to a 400 saying the file is not a readable PDF.
  • Validate the parsed payload — isinstance(payload, dict) and questions being a list — and raise ValueError so the existing "unusable response" path handles it.
  • Check the magic bytes rather than only the header.
Tests to add

tests/test_generate_quiz.py is already good on the happy path and on validation. These failure modes are the gap:

  • JSON that parses but has the wrong shape — the existing test_unusable_model_output_is_502 only uses prose, so it exercises a different branch
  • An encrypted PDF and a corrupt one — make_pdf() in conftest.py can only build valid PDFs
  • A provider timeout — errors.py has a 504 branch for APITimeoutError that nothing currently reaches
Definition of done
  • A password-protected PDF returns a 4xx telling the user what is wrong
  • Malformed model output returns the existing "unusable response" message, not an AttributeError
  • A file that is not a PDF is rejected before pypdf sees it
  • Each case has a test
Lingua principale
TypeScript
Stelle
21
Fork
7
Merge medio
5h 6m
PR unite (30g)
29

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di TheCodeHeist-Coder/Rexial

Tutte le issue di TheCodeHeist-Coder/Rexial

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.