Skip to content

fix(knowledge): honor cancellation during PDF extraction - #532

Open
sylvesterkaczmarek wants to merge 2 commits into
openai:mainfrom
sylvesterkaczmarek:fix/pdf-knowledge-cancellation
Open

fix(knowledge): honor cancellation during PDF extraction#532
sylvesterkaczmarek wants to merge 2 commits into
openai:mainfrom
sylvesterkaczmarek:fix/pdf-knowledge-cancellation

Conversation

@sylvesterkaczmarek

@sylvesterkaczmarek sylvesterkaczmarek commented Aug 18, 2026

Copy link
Copy Markdown

Summary

Honor the existing knowledge-base cancellation signal during PDF text extraction.

Fixes #531.

Reproduction / evidence

prepareKnowledgeBase() already accepts an AbortSignal and checks it during discovery and before staging each document. On current main, PDF handling calls extractPdf(document, bytes) without passing that signal.

Inside extractPdf(), pdf.js loads the document and then iterates through every page. There is no cancellation check in that loop. A cancellation that arrives after PDF loading begins can therefore leave the caller waiting while remaining pages are processed.

Reproduction:

  1. Use a multi-page PDF as a knowledge-base document.
  2. Start prepareKnowledgeBase with an abort signal.
  3. Trigger cancellation after PDF extraction has started.
  4. Current main has no extraction-level signal check, so page processing continues.

Expected: stop before processing further pages and propagate the caller's cancellation reason.

The regression added in this PR triggers cancellation only when the first extraction-specific signal check is reached, so it exercises the missing boundary rather than the existing discovery/staging checks.

Root cause

The signal was not propagated from prepareKnowledgeBase() into extractPdf().

Fix

  • pass the existing signal into PDF extraction;
  • check it after the PDF document loads and between page operations;
  • preserve the original cancellation reason;
  • retain pdf.js cleanup through the existing loadingTask.destroy() finally path.

Tests / validation

Added focused regression coverage for cancellation after PDF extraction begins.

The branch was created from upstream main at 99c85613b0c4b8202b33dfbd80f41884fb9eac11. Production changes are 13 additions and 3 deletions plus the regression file.

Full repository tests cannot be run in this execution environment because the repository cannot be cloned here. Pushed-head CI remains the authoritative full-suite validation.

Risk

Low. Normal successful PDF extraction is unchanged except for signal checks. Existing non-cancellation PDF failures keep their current diagnostic behavior.

@github-actions github-actions Bot added the bug Something isn't working label Aug 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Knowledge-base cancellation is ignored once PDF extraction starts

1 participant