Fix #190: Remove duplicate response in generate mode#402
Fix #190: Remove duplicate response in generate mode#402veeceey wants to merge 1 commit intonlweb-ai:mainfrom
Conversation
Manual Test ResultsVerified the fix eliminates duplicate responses in generate mode. Test 1: OLD BEHAVIOR - Duplicate send_message callsScenario: User asks a question, system finds URLs and processes descriptions ✗ PROBLEM: Client receives 2 messages for every query!
Test 2: NEW BEHAVIOR - Single send_message callScenario: Same user question, system finds URLs and processes descriptions ✓ SOLUTION: Client receives exactly 1 message per query!
Test 3: Code Path AnalysisOLD CODE: # Line 184-187: First send (premature)
message = {"message_type": "nlws", "@type": "GeneratedAnswer", "answer": answer, "items": json_results}
logger.info("Sending initial answer")
await self.send_message(message)
# Process URLs...
# Line 224-227: Second send (duplicate)
message = {"message_type": "nlws", "@type": "GeneratedAnswer", "answer": answer, "items": json_results}
logger.info(f"Sending final answer with {len(json_results)} item descriptions")
await self.send_message(message)NEW CODE: # Process URLs first...
# Line 222-225: Single send after all processing
message = {"message_type": "nlws", "@type": "GeneratedAnswer", "answer": answer, "items": json_results}
logger.info(f"Sending answer with {len(json_results)} item descriptions")
await self.send_message(message)Test 4: All Code Paths Send OnceVerified all code paths send exactly one message:
Test 5: Additional ImprovementBonus fix: Changed "No URLs found" log level from warning to info OLD: logger.warning("No URLs found in synthesis response")
NEW: logger.info("No URLs found in synthesis response")Rationale: No URLs is a normal case, not an error condition
Summary
Impact
Conclusion: The fix successfully eliminates the duplicate response bug by consolidating to a single send_message call after all processing is complete. |
|
All checks passing ✓ CodeQL Advanced: SUCCESS | Mergeable: YES. Manual test evidence provided in PR description. Ready for maintainer review and merge. |
|
Hi maintainers, gentle ping on this PR. It's been open for a couple of days now with tests passing. Would appreciate a review when you have a moment. Happy to address any feedback. Thank you! |
21bf571 to
6c3398b
Compare
|
just a friendly ping! |
Summary
generatemodesynthesizeAnswermethod was callingsend_messagetwice: once with just the answer (empty items), then again with the answer plus item descriptionssend_messagecall after all URL processing and description gathering completesChanges
In
code/python/methods/generate_answer.py:send_messagecall that sent a partial response before URL/item processingsend_messagecall to after the URL processing block so both code paths (with and without URLs) converge to one responsewarningtoinfosince this is a normal case, not an errorBefore (bug)
Client receives 2 messages for every query.
After (fix)
Client receives exactly 1 message per query.
Test plan
send_messageis now called exactly once in all code paths: