Skip to content

fix: extract pptx text in presentation order - #9235

Closed
leonlaiyc wants to merge 1 commit into
kirodotdev:mainfrom
leonlaiyc:fix/codex-astra-20260907
Closed

leonlaiyc wants to merge 1 commit into
kirodotdev:mainfrom
leonlaiyc:fix/codex-astra-20260907

Conversation

@leonlaiyc

Copy link
Copy Markdown
Contributor

Problem / Motivation

Reordering a PowerPoint deck does not rename its slide parts. doc_parser sorts
ppt/slides/slideN.xml and uses N as the displayed slide number, so the Office
text preview silently restores filename order instead of showing the presentation.

Reproduced on main at 91513fa01 with a valid three-slide deck, saved and
independently reopened using python-pptx:

Presentation order: Executive summary, Recommendation, Detailed appendix
Kiro Crew order:    Detailed appendix, Executive summary, Recommendation

With max_chars=1, extraction keeps only Detailed appendix. The fixed code
returns Executive summary as Slide 1 in both full and capped extraction.

Why it matters

The dashboard's /api/file-office-preview uses this parser through an already-open
archive and a text budget. A reordered deck therefore has incorrect slide labels,
and a long preview can omit its actual opening slides. The shared attachment
extractor also uses this parser when supplying document text to the agent.

What changed (motivation → approach → change)

Read p:sldIdLst from ppt/presentation.xml, resolve its internal slide
relationships, and number results by presentation position. This follows the
PresentationML structure.
The new metadata reads use the existing bounded ZIP reader and defusedxml parser.

Blank or unresolved entries keep their positions; unreferenced parts are omitted.
Each resolved ZIP part is extracted only once, so repeated references in malformed
metadata cannot multiply decompression or retained text beyond the vetted inventory.
The extraction budget still prevents later slides from being read. Incomplete
containers without a presentation manifest retain the existing best-effort
filename scan, while present-but-unreadable metadata does not fall back to an
invented order. No new dependency or endpoint change.

Tests

  • Before the production change: 12 new cases failed and the unchanged-order
    control passed against main.
  • Parser and Office-preview endpoint suites: 70 passed, covering reordered decks through path and open-handle
    callers, capped reads, blank and unreferenced slides, internal relationship
    targets, unreadable relationships, bounded metadata, and malformed/DTD XML.
  • Repeated-reference regression failed before its repair; the final tests also
    cover distinct relationship IDs targeting the same slide part.
  • Relevant isort, flake8, mypy, and repository Black gate pass.

The focused command was:

python -m pytest test/test_doc_parser.py test/test_doc_parser_pptx_order.py test/test_file_office_preview.py -q --override-ini="addopts=-n auto --dist loadgroup --max-worker-restart=2"

A broader local run was not clean: the full backend suite hit timeouts and was
stopped, and whole-tree lint/type runs reported findings in unchanged files with
newer local tool versions. This PR does not claim whole-repository validation.

Manual verification

Generated a valid deck with python-pptx, moved its first slide to the end, saved
and reopened it with that independent reader, then ran the public extract_text
API against the same file before and after the fix. Both full and capped output
now agree with the reopened presentation. python-pptx was used only for this probe;
the committed regression fixtures use the standard library.

Related Issues

Found by inspection. Checked all 371 open PRs at admission, refreshed the full
inventory after rebasing, and checked targeted issue/PR searches and local claims.
No open PR touches doc_parser.py or covers
presentation-order extraction. #4650 concerns a separate File Explorer viewer.

Pattern harvest

Rule candidate: review-prompt
Pattern: an archive member's filename or identifier is not its display order;
follow the container's ordering metadata and test a reordered valid document.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@leonlaiyc
leonlaiyc requested review from a team and iamwhatever September 7, 2026 12:37
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 7, 2026
@github-actions

github-actions Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5, fork) — ✅ PASS

Premise-level review of 552be51fa47edd8cbc88462273ea96d7f5502a35 via the fork AI-review pipeline — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

First-Principles-Verdict: PASS

A reproduced ordering defect fixed at its cause — the container's ordering metadata replaces filename sorting — with every behavior delta declared.

What this change ships

Intent: make PPTX text extraction show slides in the order the presentation actually plays, with correct labels — a FIX.

  1. PPTX previews and attachment text follow presentation order, not ZIP filename numbers — justified
  2. Slide N labels are presentation positions, surviving reorders — justified
  3. Capped extraction keeps the real opening slide instead of the lowest-numbered file — justified
  4. Decks missing ppt/presentation.xml keep the old filename best-effort — justified
  5. Present-but-unreadable ordering metadata yields empty text, never filename order — declared
  6. Unreferenced slide parts disappear from output — declared
  7. Repeated references extract a part once, bounding decompression — justified
  8. Blank/unresolved slides keep their numbers (label gaps) — declared
  9. Dashboard spec section updated in the same commit — mandated by AGENTS.md

The fix sits at cause level: filename N was never display order per the PresentationML spec, and the change reads sldIdLst instead of patching symptoms per caller. Consumers counted: 2 real callers of extract_text reach this path (dashboard/handlers/files.py:2694, messaging/attachments.py:454). Duplicate check: the only other PPTX reader is knowledge/readers.py:_read_pptx (python-pptx, already presentation-ordered, dependency-gated out of SUPPORTED) — not a mechanism this could reuse without adding a dependency doc_parser deliberately avoids. Sibling count for the root cause (filename-as-order): grepped _SLIDE_RE/filename sorting — 1 site, fixed here; DOCX/PDF have no per-part ordering. New helper _pptx_slide_order is private with 1 caller — not public surface.

Watch

Item 5 is the one regression a human should weigh: a deck whose presentation.xml or rels is corrupt or over-cap previously extracted text in filename order, now returns "". Declared ("does not fall back to an invented order") and consistent with the defect being fixed, but it trades wrong-order text for no text.

[FIRST-PRINCIPLES-REVIEWED] 552be51

@github-actions

github-actions Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5, fork) — ✅ PASS

Design-level review of 552be51fa47edd8cbc88462273ea96d7f5502a35 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Reviewing PR #9235: a fix so PPTX text extraction follows p:sldIdLst presentation order instead of ZIP filename order. I read the authoritative patch and the base doc_parser.py.

The problem is real (filename order silently diverges from presentation order after a reorder, mislabeling slides and letting a capped preview drop the actual opening slides), and the fix targets the root cause by reading the container's own ordering manifest rather than patching the sort. Failure behavior is deliberate and tested: missing manifest keeps the old best-effort scan, present-but-broken manifest fails closed rather than inventing an order, repeated references are deduped, and the metadata reads reuse the existing bounded ZIP reader and defusedxml. The spec doc is updated in the same commit. No scope creep; description matches the diff in both directions.

Design-Verdict: PASS

Root-cause fix using the format's own ordering manifest, with deliberate, tested failure modes and unchanged parser contract.

[DESIGN-REVIEWED] 552be51

@github-actions

github-actions Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review (fork) — ✅ no blocking findings

Reviewed 552be51fa47edd8cbc88462273ea96d7f5502a35 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 552be51

@github-actions

github-actions Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Opus 4.8 Review (fork) — ✅ no blocking findings

Reviewed 552be51fa47edd8cbc88462273ea96d7f5502a35 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 552be51

@leonlaiyc
leonlaiyc force-pushed the fix/codex-astra-20260907 branch from d3d3e82 to 552be51 Compare September 8, 2026 01:57
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 8, 2026
@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Sep 12, 2026
@dwu96 dwu96 added the needs-pr-triage PR scanner: awaiting automated triage label Sep 15, 2026
@chenmingwei23 chenmingwei23 added drive-to-green PR claimed by drive-to-green pipeline and removed needs-pr-triage PR scanner: awaiting automated triage labels Sep 15, 2026
@chenmingwei23

Copy link
Copy Markdown
Contributor

Kiro Crew [operator: chenmingwei23#de330d0c]

Triaged as solvable and claimed for the drive-to-green pipeline.

The red backend lanes are not caused by this branch. The failing run is from
2026-09-08 and the Windows shard-4 failure is test/test_work_ledger.py:1392
("expected 3 threads to report already_bound, got 2") plus Windows sharing and
event-loop noise. A 3-file pptx text-extraction diff cannot reach the work-ledger
concurrency test.

Remaining real blocker is the merge conflict. Plan: rebase onto current main so CI
cuts a fresh merge ref, then let the lanes re-run. test_work_ledger.py will not be
touched from this PR; if that red survives a fresh base it is main-owned and will
be reported separately.

Content security scan passed with no findings.

@iamwhatever

Copy link
Copy Markdown
Contributor

Thank you @leonlaiyc for this fix — correctly previewing reordered .pptx decks in true presentation order (OOXML sldIdLst, not ZIP part names).

To carry it cleanly through the in-repo CI + review lanes, I opened an in-repo replacement PR that supersedes this one, preserving your authorship (your commit is cherry-picked with a Co-authored-by trailer):

Every review lane is green there (GPT 5.6, Opus 5, Design, First Principles, UX, Security Scope) and all backend/build/integration checks pass. Closing this fork PR in favor of #14876; full credit for the fix is yours. 🙏

@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Sep 29, 2026
@mbriones98 mbriones98 removed the drive-to-green PR claimed by drive-to-green pipeline label Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor) merge conflict Branch has merge conflicts with its base — author must resolve before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants