openai / openai/codex-security
Knowledge-base cancellation is ignored once PDF extraction starts
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 10.8k
- Forks
- 801
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 257
Description
Summary
prepareKnowledgeBase() checks its AbortSignal during path discovery and before staging each document, but the signal is not passed into extractPdf().
Once a PDF has been read and pdf.js parsing begins, the extraction loop processes every page without another cancellation check:
const document = await loadingTask.promise;
const pages: string[] = [];
for (let number = 1; number <= document.numPages; number++) {
const content = await (await document.getPage(number)).getTextContent();
pages.push(...);
}
Impact
Canceling a scan while a large or expensive PDF knowledge-base document is being parsed does not stop that work promptly. The caller remains blocked in knowledge-base preparation until extraction finishes or fails, even though cancellation is already part of this API and is honored elsewhere in the same function.
The staging directory is eventually cleaned up by the existing outer error path, but CPU/time can continue being spent after cancellation.
Expected behavior
Propagate the signal into PDF extraction and check it after loading the document and between page operations, so cancellation stops before processing further pages and still destroys the pdf.js loading task in finally.
Suggested fix
Pass signal to extractPdf(), call signal?.throwIfAborted() before each page (and after page text extraction), and add a regression that aborts on the first PDF-extraction-specific signal check. That regression should fail on current main, where only the outer preparation checks occur.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing prepareKnowledgeBase() into extractPdf(), focusing on the existing AbortSignal checks and the pdf.js loading-task cleanup path. Add the regression described in the issue, then verify that aborting at the first PDF-extraction-specific check stops further page processing while the loading task is still destroyed in finally.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 72/100