{"record":{"id":"5bf9ea1e82796a7e","repo":"HKUDS/DeepTutor","slug":"cannot-mark-kb-drift-as-seen-before-all-stale-page","errorCode":null,"errorMessage":"Cannot mark KB drift as seen before all stale pages have been recompiled.","messagePattern":"Cannot mark KB drift as seen before all stale pages have been recompiled\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"deeptutor/book/kb_health.py","lineNumber":340,"sourceCode":"    *,\n    force: bool = False,\n) -> Book | None:\n    \"\"\"Re-compute and persist KB fingerprints on the book manifest.\n\n    Refuses by default while pages the last drift marked stale have not been\n    recompiled, so \"mark as seen\" cannot quietly hide work still owed.\n    ``force`` overrides that: stale detection deliberately over-marks when it\n    cannot resolve an anchor to a source document, and a user who judges a\n    flagged page fine must be able to dismiss it rather than face a banner\n    nothing will clear.\n    \"\"\"\n    store = storage or get_book_storage()\n    book = store.load_book(book_id)\n    if book is None:\n        return None\n    if book.stale_page_ids and not force:\n        if not book.stale_detected_at:\n            raise ValueError(\n                \"Cannot mark KB drift as seen before all stale pages have been recompiled.\"\n            )\n        not_recompiled = [\n            page_id\n            for page_id in book.stale_page_ids\n            if (page := store.load_page(book_id, page_id)) is None\n            or page.status.value != \"ready\"\n            or page.updated_at < book.stale_detected_at\n        ]\n        if not_recompiled:\n            raise ValueError(\n                \"Cannot mark KB drift as seen before these pages are recompiled: \"\n                + \", \".join(not_recompiled)\n            )\n    documents = fingerprint_kb_documents_batch(book.knowledge_bases, manager=manager)\n    book.kb_document_fingerprints = documents\n    book.kb_fingerprints = {name: digest_documents(docs) for name, docs in documents.items()}\n    book.stale_page_ids = []","sourceCodeStart":322,"sourceCodeEnd":358,"githubUrl":"https://github.com/HKUDS/DeepTutor/blob/3e82f130422a813cdd73c10b21a44e9325f5821a/deeptutor/book/kb_health.py#L322-L358","documentation":"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.","triggerScenarios":"Thrown at deeptutor/book/kb_health.py:340 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Recompile all stale pages first, then refresh fingerprints","Pass force=true when you have judged the flagged pages fine and want to dismiss them","Repair the missing stale_detected_at timestamp if the state is genuinely inconsistent"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"3e82f130422a813cdd73c10b21a44e9325f5821a","analyzedAt":"2026-08-27T06:57:25.364Z","contentChangedAt":"2026-08-27T06:57:25.364Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}