fix(bookstack): prevent thinking-text flicker, remove page ID citations#102
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problems
1. Thinking-text flicker — Intermediate reasoning text generated by the model before a tool call was streamed to the UI, then wiped by
text_clear, causing a jarring flash that users couldn't read before it disappeared.2. Page ID citations — Custom on-prem models cited pages as
"From 'X' (page 61):"using the internal numeric page ID, which is meaningless to users. The model was picking up"id": 61from theget_pagetool response and treating it as a page number. The model was also generating preamble text ("Now I have all the information…") before the answer despite the existing prompt instruction.Fixes
bookstack_agent/ui/app/components/chat-page.tsx— RAF-based text bufferingtext_chunkevents are now accumulated in a ref and flushed to React state once per animation frame (requestAnimationFrame). Iftext_cleararrives before the RAF fires (which happens when thinking-text and the subsequent tool-use event arrive in the same TCP packet / event-loop tick), the buffer is discarded silently — no DOM update, no flicker. Once the gate opens (first RAF fires without atext_clear), subsequent chunks stream in normally per frame.src/aieng_bot/bookstack/tools.py— strip IDs fromget_pageresponseRemoved
id,book_id,chapter_id, andupdated_atfrom theget_pagetool output. The model now only seesname,markdown, andurl— exactly what it needs to answer and cite. With no numeric ID visible, it can't accidentally use one as a "page number."src/aieng_bot/bookstack/prompts.py— stronger citation and no-preamble rules"Now I have all the information…","Let me synthesize…", etc.)## Sourcesinstruction: "NEVER include page numbers, numeric IDs, or any internal identifiers. Use only the page title and its URL." — written to be unambiguous for models that don't follow nuanced instructions as reliably as Claude.Test plan
pytest tests/bookstack/)## Sourceslists titles + URLs with no(page N)annotations