HKUDS/DeepTutor · error · ValueError

Cannot mark KB drift as seen before all stale pages have…

Error message

Cannot mark KB drift as seen before all stale pages have been recompiled.

What it means

Invariant guard in refresh_book_fingerprints: the book still has stale_page_ids from the last drift detection, and stale_detected_at is missing, so 'mark as seen' is refused — clearing drift would hide pages that still owe a recompile.

Solutions

  1. Recompile all stale pages first, then refresh fingerprints
  2. Pass force=true when you have judged the flagged pages fine and want to dismiss them
  3. Repair the missing stale_detected_at timestamp if the state is genuinely inconsistent
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at deeptutor/book/kb_health.py:340 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of HKUDS/DeepTutor@3e82f13042 (2026-08-27). Data as JSON: /api/errors/5bf9ea1e82796a7e. Report an issue: GitHub.

Appendix: source

Thrown at deeptutor/book/kb_health.py:340

    *,
    force: bool = False,
) -> Book | None:
    """Re-compute and persist KB fingerprints on the book manifest.

    Refuses by default while pages the last drift marked stale have not been
    recompiled, so "mark as seen" cannot quietly hide work still owed.
    ``force`` overrides that: stale detection deliberately over-marks when it
    cannot resolve an anchor to a source document, and a user who judges a
    flagged page fine must be able to dismiss it rather than face a banner
    nothing will clear.
    """
    store = storage or get_book_storage()
    book = store.load_book(book_id)
    if book is None:
        return None
    if book.stale_page_ids and not force:
        if not book.stale_detected_at:
            raise ValueError(
                "Cannot mark KB drift as seen before all stale pages have been recompiled."
            )
        not_recompiled = [
            page_id
            for page_id in book.stale_page_ids
            if (page := store.load_page(book_id, page_id)) is None
            or page.status.value != "ready"
            or page.updated_at < book.stale_detected_at
        ]
        if not_recompiled:
            raise ValueError(
                "Cannot mark KB drift as seen before these pages are recompiled: "
                + ", ".join(not_recompiled)
            )
    documents = fingerprint_kb_documents_batch(book.knowledge_bases, manager=manager)
    book.kb_document_fingerprints = documents
    book.kb_fingerprints = {name: digest_documents(docs) for name, docs in documents.items()}
    book.stale_page_ids = []

View on GitHub (pinned to 3e82f13042)