Skip to content

fix: prevent capturing stale NotebookLM responses#28

Open
bluzername wants to merge 1 commit intoPleasePrompto:masterfrom
bluzername:fix/stale-response-polling
Open

fix: prevent capturing stale NotebookLM responses#28
bluzername wants to merge 1 commit intoPleasePrompto:masterfrom
bluzername:fix/stale-response-polling

Conversation

@bluzername
Copy link
Copy Markdown

Problem

When using ask_question.py on a notebook that already has chat history, the script can return a stale/older response instead of the newly generated answer.

I was hitting this myself - the script kept returning the generic notebook intro text instead of the actual answer that was visible in the browser UI. Very confusing.

Root Cause

The polling logic at line 141 does elements[-1] to get the "newest" response, but this is wrong because:

  1. NotebookLM chat history hydrates asynchronously - the last element after submit is not always the new answer
  2. Previously existing responses are not distinguished from new ones
  3. Transient placeholders like "Reading through pages..." or "Finding key words..." can be treated as final text
  4. The 120s timeout is too tight for notebooks with many sources

What I changed

Rewrote the response polling section in scripts/ask_question.py:

Before submit:

  • Snapshot all existing response texts into a set

During polling:

  • Scan responses from newest to oldest (reversed order)
  • Skip responses that were already present before submission (the key fix)
  • Skip the user's own question echoed back
  • Skip known transient placeholders ("reading through pages", "finding key words", etc.)
  • Apply stability check (3 consecutive same text) only on the new candidate

Timeout:

  • Increased from 120s to 300s for large notebooks with many sources

How it works now

1. Record existing responses -> {"old answer 1", "old answer 2", ...}
2. Submit question
3. Poll: find newest response NOT in the snapshot
4. Wait for it to stabilize (3 consecutive polls with same text)
5. Return the stable new answer

The old approach was just taking elements[-1] which could be any previously existing response.

Closes #25

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ask_question.py can capture stale NotebookLM responses instead of the newly generated answer

1 participant