Skip to content

WS-ART-001-03B3B2: add bounded PDF guide extraction - #231

Merged
abiorh-claw merged 2 commits into
mainfrom
codex/ws-art-001-03b3b2-pdf-extractor
Jul 31, 2026
Merged

WS-ART-001-03B3B2: add bounded PDF guide extraction#231
abiorh-claw merged 2 commits into
mainfrom
codex/ws-art-001-03b3b2-pdf-extractor

Conversation

@Abiorh001

@Abiorh001 Abiorh001 commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

WS-ART-001-03B3B2 PR Trust Bundle

Chunk

WS-ART-001-03B3B2 — PDF Extractor (L1).

Goal and human-approved intent

Install only the dependency approved in merged 03B3B1 and add bounded PDF text
extraction inside the existing hidden, isolated guide-extraction framework.
Guide uploads remain independent from contributor ZIP submissions. This chunk
does not activate AUTH, invoke sufficiency, or begin OOXML/image work.

What changed and why

  • Added the exact hash-bound pypdf==6.14.2 wheel to runtime dependencies and
    the lockfile.
  • Added a PDF-only adapter that rejects encrypted, malformed, interactive,
    attached, embedded, external, and active PDFs; enforces 500 pages; and emits
    deterministic compact JSON with explicit page boundaries.
  • Loads the trusted adapter only for PDF after process resource limits, then
    installs seccomp before reading or parsing untrusted bytes.
  • Added PDF policy v2 so pre-support v1 unsupported attempts cannot replay.
    Exact-lineage retry custody resets once to the new policy and preserves the
    old immutable evidence.
  • Assigned the new focused test to the existing shared_foundations lane and
    updated the artifact specification and initiative status.

Design chosen

The existing GuideExtractionRunner and child protocol remain authoritative.
The parent sees only the server-derived pdf classification and bounded result.
There is no second parser runtime, direct provider access, raw agent input, or
new authorization path. Canonical output is {"pages":[...]}.

Rejected alternatives were parsing during upload, loading pypdf for every
format, retaining PDF as policy-v1 unsupported, accepting partial extraction,
or allowing arbitrary PDF actions.

Scope control and product behavior

All changed files are in the corrected chunk contract. The only contract
additions are the existing persistence service, its policy replay test, and the
canonical lane inventory required to make the original acceptance criteria
executable. No provider, AUTH, Celery, submission, review, compensation,
reputation, OCR, OOXML, image, route, or agent-assembly behavior changes.

PDF failures remain internal bounded extraction outcomes and never become guide
insufficiency decisions. Only successful current-policy canonical content can
later enter sufficiency.

Acceptance criteria proof

  • Exact 500/501 page boundary is tested.
  • Malformed and encrypted documents are rejected.
  • Forms, XFA, attachments, embedded/file-spec objects, open/additional actions,
    JavaScript, named/launch/submit/import/external actions, URI links, widgets,
    and rich media are rejected with bounded codes.
  • Import graph and execution-order tests confine the parser to the PDF child:
    limits, trusted import, seccomp, then untrusted parsing.
  • Workspace cleanup, child failure, timeout, cancellation, input/output limits,
    and protocol validation reuse and exercise the existing framework proofs.
  • The isolated PostgreSQL regression proves v1 unsupported evidence is not
    replayed after PDF policy v2 and that v2 success becomes the replay target.

Tests and checks

  • uv run python scripts/check_guide_extractor_dependencies.py — pass.
  • uv lock --check — pass; wheel URL/hash matches the approved manifest.
  • uv run ruff check app tests scripts — pass.
  • Focused PDF/extraction/architecture suite — 77 passed before the final added
    order/action cases; targeted final repair suite — 31 passed.
  • New PDF module coverage — 94.81 percent (above 90 percent).
  • Isolated PostgreSQL policy replay test — 1 passed.
  • CI lane inventory tests — pass; test_guide_pdf.py is in
    shared_foundations.
  • Stale-contract scan, Markdown links, and git diff --check — pass.
  • Repository-wide 78 percent coverage and hosted semantic lanes remain for the
    GitHub Backend gate; no local full-suite run was used.

Test delta and CI integrity

No test or assertion was removed, skipped, or weakened. New adversarial cases
cover actual action annotations rather than only synthetic root keys. No
workflow, lane count, coverage threshold, or failure behavior changed. Hosted
installation remains protected by the exact direct wheel URL/hash and the
dependency checker; the lockfile records the same bytes.

Reviewer results

  • Architecture: initial High findings repaired; re-review pass with one Low
    import-style proof hardening item, also repaired.
  • Security/auth: pass.
  • QA: initial action-dictionary High repaired; re-review pass.
  • Product/ops: pass.
  • Senior engineering: initial verification/DB seed/scope findings repaired;
    final re-review pass.
  • CI integrity: pass with informational hosted-install notes.
  • Docs: pass.
  • Reuse/dedup: pass with Low future shared-normalizer advice.
  • Test delta: initial missing-case and branch-proof findings repaired; final
    re-review pass.

External review

CodeRabbit and hosted GitHub gates have not run yet. Their findings remain
external merge evidence and must be checked after the draft PR opens.

Remaining risks and follow-up

pypdf is an untrusted-format parser, so OS termination remains an essential
control. The trusted dependency import intentionally precedes descriptor-only
seccomp because Python import needs filesystem reads; resource limits are
already installed and no untrusted bytes are read until after seccomp.

03B3B3A (OOXML security) and 03B3B4 (image metadata) remain separate chunks.
03B4 sufficiency continuation cannot start until all required format chunks
merge.

Human review focus and merge ownership

Review the exact wheel/hash, active-content deny semantics, 500-page boundary,
trusted-import/seccomp ordering, PDF policy-v2 replay reset, and deterministic
page JSON. A human owns merge approval; the agent will not merge this PR.

Summary by CodeRabbit

  • New Features

    • Added bounded PDF guide extraction with page-preserving, deterministic JSON output.
    • Supports PDFs up to 500 pages while rejecting encrypted, malformed, active, embedded, or external-content files.
    • Applies isolated processing with resource limits and security protections before parsing.
  • Bug Fixes

    • Updated extraction policy handling so changed PDF policies receive fresh retry budgets and do not replay obsolete attempts.
  • Documentation

    • Documented PDF processing rules, rejection behavior, security controls, and verification coverage.

@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@Abiorh001, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 46 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: ed9ed66f-1f5e-45db-a9a4-32e2563426ba

📥 Commits

Reviewing files that changed from the base of the PR and between 4352acf and decd36f.

📒 Files selected for processing (6)
  • .agent-loop/initiatives/WS-ART-001-immutable-artifact-storage/REVIEW_LOG.md
  • .agent-loop/initiatives/WS-ART-001-immutable-artifact-storage/reviews/WS-ART-001-03B3B2-external-review-response.md
  • .agent-loop/initiatives/WS-ART-001-immutable-artifact-storage/reviews/WS-ART-001-03B3B2-pr-trust-bundle.md
  • backend/app/modules/artifacts/guide_pdf.py
  • backend/tests/test_guide_pdf.py
  • docs/spec_artifact_storage_service.md
📝 Walkthrough

Walkthrough

The change adds bounded PDF extraction with pinned pypdf, active-content rejection, deterministic JSON output, isolated worker sequencing, format-specific policy versions, and retry-budget reset handling.

Changes

PDF extraction

Layer / File(s) Summary
Format-specific policy and retry handling
backend/app/modules/artifacts/guide_extraction.py, backend/app/modules/artifacts/guide_extraction_service.py, backend/tests/test_guide_bindings.py
PDF extraction uses a distinct policy version. Retry budgets reset when the policy changes and preserve exact lineage rules.
Bounded PDF adapter
backend/app/modules/artifacts/guide_pdf.py, backend/pyproject.toml, backend/tests/test_guide_pdf.py, backend/tests/test_artifact_architecture.py
The pinned adapter enforces page and object limits, rejects unsafe PDF content, and returns deterministic page-delimited JSON.
Isolated worker integration
backend/app/modules/artifacts/guide_extraction_worker.py, backend/tests/test_guide_extraction.py, docs/spec_artifact_storage_service.md
The worker loads the adapter after resource limits and before seccomp, then converts adapter failures into bounded extraction results.
Verification and review records
.agent-loop/initiatives/WS-ART-001-immutable-artifact-storage/..., backend/scripts/run_test_lanes.py
Planning records, review evidence, test-lane assignment, and focused verification commands cover the PDF extraction scope.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

Suggested reviewers: abiorh-claw

Sequence Diagram(s)

sequenceDiagram
  participant ExtractionService
  participant IsolatedWorker
  participant PDFAdapter
  ExtractionService->>IsolatedWorker: start PDF extraction
  IsolatedWorker->>IsolatedWorker: apply resource limits
  IsolatedWorker->>PDFAdapter: lazy-load adapter
  IsolatedWorker->>IsolatedWorker: install seccomp
  IsolatedWorker->>PDFAdapter: parse PDF payload
  PDFAdapter-->>IsolatedWorker: canonical JSON or bounded failure
  IsolatedWorker-->>ExtractionService: persist extraction result
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 19.35% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely identifies the main change: bounded PDF guide extraction.
Description check ✅ Passed The description covers the change, design, scope, tests, reviewer results, risks, follow-up work, and merge ownership requirements.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/ws-art-001-03b3b2-pdf-extractor

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Abiorh001
Abiorh001 marked this pull request as ready for review July 31, 2026 09:15

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
docs/spec_artifact_storage_service.md (1)

1292-1305: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider documenting the internal object-inspection bound.

This section enumerates concrete numeric bounds for the PDF adapter (500 pages, etc.), but omits the _MAXIMUM_INSPECTED_OBJECTS (100,000) bound and its pdf_object_limit failure code implemented in guide_pdf.py. Add it here for consistency with the rest of this exhaustively bounded specification.

As per coding guidelines, docs/**/*.md should "Prefer evidence-backed documentation over vague product claims"; documenting this concrete, already-enforced bound keeps the spec fully evidence-backed.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/spec_artifact_storage_service.md` around lines 1292 - 1305, Update the
PDF extraction specification near the existing page and failure-bound
descriptions to document the enforced _MAXIMUM_INSPECTED_OBJECTS limit of
100,000 objects and identify pdf_object_limit as the corresponding bounded
internal failure outcome, preserving the existing claims about other limits and
sanitized agent-visible results.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@backend/app/modules/artifacts/guide_pdf.py`:
- Around line 112-127: Update the exception handling in extract_pdf to include
the concrete pypdf parsing failures KeyError and IndexError in the existing
malformed-PDF except clause, so bounded_extract receives
PdfExtractionFailure("malformed", "invalid_pdf") rather than classifying these
cases as parser failures.

---

Nitpick comments:
In `@docs/spec_artifact_storage_service.md`:
- Around line 1292-1305: Update the PDF extraction specification near the
existing page and failure-bound descriptions to document the enforced
_MAXIMUM_INSPECTED_OBJECTS limit of 100,000 objects and identify
pdf_object_limit as the corresponding bounded internal failure outcome,
preserving the existing claims about other limits and sanitized agent-visible
results.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e73e743e-ef15-43d4-8e26-3731cf104b6a

📥 Commits

Reviewing files that changed from the base of the PR and between 54bcee0 and 4352acf.

⛔ Files ignored due to path filters (1)
  • backend/uv.lock is excluded by !**/*.lock
📒 Files selected for processing (15)
  • .agent-loop/initiatives/WS-ART-001-immutable-artifact-storage/REVIEW_LOG.md
  • .agent-loop/initiatives/WS-ART-001-immutable-artifact-storage/STATUS.md
  • .agent-loop/initiatives/WS-ART-001-immutable-artifact-storage/chunks/WS-ART-001-03B3B2-pdf-extractor.md
  • .agent-loop/initiatives/WS-ART-001-immutable-artifact-storage/reviews/WS-ART-001-03B3B2-pr-trust-bundle.md
  • backend/app/modules/artifacts/guide_extraction.py
  • backend/app/modules/artifacts/guide_extraction_service.py
  • backend/app/modules/artifacts/guide_extraction_worker.py
  • backend/app/modules/artifacts/guide_pdf.py
  • backend/pyproject.toml
  • backend/scripts/run_test_lanes.py
  • backend/tests/test_artifact_architecture.py
  • backend/tests/test_guide_bindings.py
  • backend/tests/test_guide_extraction.py
  • backend/tests/test_guide_pdf.py
  • docs/spec_artifact_storage_service.md

Comment thread backend/app/modules/artifacts/guide_pdf.py
@abiorh-claw
abiorh-claw self-requested a review July 31, 2026 10:23
@abiorh-claw
abiorh-claw merged commit 081dfe7 into main Jul 31, 2026
4 checks passed
@abiorh-claw
abiorh-claw deleted the codex/ws-art-001-03b3b2-pdf-extractor branch July 31, 2026 11:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants