{"record":{"id":"1424c13f8b14b06f","repo":"HKUDS/DeepTutor","slug":"cannot-rebuild-book-missing-book-spine-book-id","errorCode":null,"errorMessage":"Cannot rebuild book – missing book/spine ({book_id})","messagePattern":"Cannot rebuild book – missing book/spine \\((.+?)\\)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"deeptutor/book/engine.py","lineNumber":975,"sourceCode":"        except ValueError:\n            return False\n        except Exception:  # noqa: BLE001\n            logger.warning(f\"auto-resume failed for {book_id}\", exc_info=True)\n            return False\n        return True\n\n    async def rebuild_book(\n        self,\n        *,\n        book_id: str,\n        stream: StreamBus | None = None,\n        auto_compile: bool = True,\n    ) -> list[Page]:\n        \"\"\"Regenerate all pages while preserving the confirmed proposal/spine.\"\"\"\n        book = self.storage.load_book(book_id)\n        spine = self.storage.load_spine(book_id)\n        if book is None or spine is None:\n            raise ValueError(f\"Cannot rebuild book – missing book/spine ({book_id})\")\n\n        await self._halt_compilation(book_id)\n\n        for page in self.storage.list_pages(book_id):\n            self.storage.delete_page(book_id, page.id)\n        for chapter in spine.chapters:\n            chapter.page_ids = []\n        self.storage.save_spine(spine)\n        self.storage.save_progress(Progress(book_id=book_id))\n\n        book.status = BookStatus.SPINE_READY\n        book.page_count = 0\n        book.updated_at = time.time()\n        self.storage.save_book(book)\n        self.storage.append_log(\n            book_id,\n            f\"rebuild requested (preserve_spine=true, auto_compile={auto_compile})\",\n            op=\"rebuild\",","sourceCodeStart":957,"sourceCodeEnd":993,"githubUrl":"https://github.com/HKUDS/DeepTutor/blob/3e82f130422a813cdd73c10b21a44e9325f5821a/deeptutor/book/engine.py#L957-L993","documentation":"Rebuild precondition guard: rebuild_book requires both a stored book and a stored spine (to preserve the confirmed structure while regenerating pages); one or both are missing, so there is nothing to rebuild from.","triggerScenarios":"Thrown at deeptutor/book/engine.py:975 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Confirm the proposal (and spine) before requesting a rebuild","Recreate the book from scratch if the spine was never confirmed","Guard the rebuild UI action behind spine-completion state"],"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"}