PageIndex icon indicating copy to clipboard operation
PageIndex copied to clipboard

Recoverable TOC repair failures disappear from unresolved results and bypass retries

Open llz1515 opened this issue 4 weeks ago • 0 comments

Problem

When a TOC repair task raises a recoverable exception, its original entry is removed from the gathered results and never returned as unresolved. The outer retry loop therefore treats the failed repair as finished. This is a failure-item lifecycle problem, independent of whether the proposed page number was right.

Baseline and environment

Reproduced on current main at 646deeb650005885f44001471d15ab9eab1bbc13 (rechecked 2026-11-04), Python 3.11.15, macOS 26.6 arm64. Minimal reproduction dependencies: requests 2.34.2, urllib3 2.8.0, PyPDF2 3.0.1, PyYAML 6.0.3 and python-dotenv 1.2.4. Run from the repository root with PYTHON_DOTENV_DISABLED=1 PYTHONPATH=. python repro.py.

No model API or live PageIndex service was called. These are deterministic function/transport reproductions, not real-model end-to-end tests. No issue template or contribution guide was present in the repository at this baseline.

Minimal reproduction

import asyncio
import json
import logging
from unittest.mock import patch
from pageindex import page_index_classic as classic


async def main():
    toc = [{"title": "A", "physical_index": 1}, {"title": "B", "physical_index": 2}]
    bad = [{"list_index": 1, "title": "B", "physical_index": 2}]
    calls = 0

    async def temporary_failure(*args, **kwargs):
        nonlocal calls
        calls += 1
        raise TimeoutError("synthetic transient failure")

    with patch.object(classic, "single_toc_item_index_fixer", temporary_failure):
        result, unresolved = await classic.fix_incorrect_toc_with_retries(
            toc, [("A", 1), ("B", 1)], bad, max_attempts=3,
            logger=logging.getLogger("repro"),
        )
    print(json.dumps({"max_attempts": 3, "calls": calls, "toc": result,
                      "unresolved": unresolved}, indent=2))


asyncio.run(main())

Actual result

max_attempts: 3
calls: 1
toc: [{"title": "A", "physical_index": 1}, {"title": "B", "physical_index": 2}]
unresolved: []

Expected behavior and scope

With the injected timeout on every attempt, B should remain unresolved, with its list index, title, original page and diagnostic reason, after three bounded attempts (or an explicit failure should propagate). A temporary first failure followed by success should get a second attempt. Mixed batches should retry only remaining failures; unrecoverable exceptions and cancellation must still propagate. This issue does not propose another model retry framework. The injected error is synthetic, not an observed provider outage.

Cause and related work

asyncio.gather(..., return_exceptions=True) preserves the input/result correspondence, but fix_incorrect_toc filters exceptions out before constructing invalid_results. fix_incorrect_toc_with_retries stops when that list is empty. Rechecked issue and PR searches for fix_incorrect_toc: #66/#67/#167 concern index shadowing, while #622 changes retry/error handling but the reproduction still fails on main containing it. Related to #55: retaining unsuccessful items is a prerequisite for reliable targeted page-index repair. I intend to include only this prerequisite in the #55 contribution, rather than open an unrelated extra fix PR.

Source: repair aggregation and retry loop

AI-assisted investigation; reproduction results above were executed locally.

llz1515 avatar Nov 04 '26 04:11 llz1515