@@ -817,19 +817,75 @@ async def _fetch_and_extract(self, url: str, question: str,
817817 logger .info (f"Skipping low-quality extraction from { url } " )
818818 return None
819819 return parsed
820- # If JSON parsing fails, treat entire response as evidence
821- return {
822- "url" : url ,
823- "title" : title or page .get ("title" , "" ),
824- "og_image" : page .get ("og_image" , "" ),
825- "rational" : "LLM extraction (raw)" ,
826- "evidence" : response [:3000 ],
827- "summary" : response [:500 ],
828- }
820+ # Preserve a substantive non-JSON reply as raw evidence. An empty
821+ # final answer is different: reasoning models can spend their whole
822+ # generation inside a stripped thinking block, which previously
823+ # created a fake finding whose summary/evidence were both empty.
824+ raw_response = str (response or "" ).strip ()
825+ if raw_response :
826+ if is_low_quality (raw_response ):
827+ logger .info (f"Skipping low-quality extraction from { url } " )
828+ return None
829+ return {
830+ "url" : url ,
831+ "title" : title or page .get ("title" , "" ),
832+ "og_image" : page .get ("og_image" , "" ),
833+ "rational" : "LLM extraction (raw)" ,
834+ "evidence" : raw_response [:3000 ],
835+ "summary" : raw_response [:500 ],
836+ }
837+
838+ logger .warning (
839+ "Structured extraction returned an empty final answer for %s; "
840+ "preserving bounded rendered-page evidence" ,
841+ url ,
842+ )
843+ return self ._rendered_page_finding (url , title , page , content )
829844 except Exception as e :
830845 logger .warning (f"LLM extraction failed for { url } : { e } " )
846+ # Retrieval already succeeded. Retain a bounded excerpt so a
847+ # transient or model-specific extractor failure does not erase the
848+ # page, its attribution, and all useful input to synthesis.
849+ return self ._rendered_page_finding (url , title , page , content )
850+
851+ @staticmethod
852+ def _rendered_page_finding (
853+ url : str ,
854+ title : str ,
855+ page : Dict ,
856+ content : str ,
857+ ) -> Optional [Dict ]:
858+ """Build a source-grounded fallback from successfully rendered text."""
859+ rendered = str (content or "" ).strip ()
860+ if not rendered :
831861 return None
832862
863+ evidence = rendered [:6000 ]
864+ if len (rendered ) > 6000 :
865+ last_para = evidence .rfind ("\n \n " )
866+ if last_para > 4800 :
867+ evidence = evidence [:last_para ]
868+
869+ summary = evidence [:1200 ]
870+ if len (evidence ) > 1200 :
871+ last_para = summary .rfind ("\n \n " )
872+ if last_para > 800 :
873+ summary = summary [:last_para ]
874+
875+ return {
876+ "url" : url ,
877+ "title" : title or page .get ("title" , "" ),
878+ "og_image" : page .get ("og_image" , "" ),
879+ "rational" : (
880+ "The page rendered successfully, but the research model did "
881+ "not return a usable structured extraction. Bounded original "
882+ "page evidence was retained instead."
883+ ),
884+ "evidence" : evidence ,
885+ "summary" : summary ,
886+ "extraction_mode" : "rendered_page_fallback" ,
887+ }
888+
833889 # ------------------------------------------------------------------
834890 # SYNTHESIZE
835891 # ------------------------------------------------------------------
@@ -916,6 +972,12 @@ async def _final_report(self, question: str, report: str) -> str:
916972 max_tokens = self .max_report_tokens ,
917973 timeout = 180 ,
918974 )
975+ if not str (result or "" ).strip ():
976+ logger .warning (
977+ "Final report model returned an empty final answer; "
978+ "keeping the source-grounded evolving report"
979+ )
980+ return report
919981
920982 # If report is too short, ask the LLM to expand it
921983 if len (result .split ()) < 400 :
@@ -1057,8 +1119,17 @@ def _format_findings(self, findings: List[Dict]) -> str:
10571119 title = f .get ("title" , "" )
10581120 summary = f .get ("summary" , "" )
10591121 evidence = f .get ("evidence" , "" )
1060- # Use summary if available, fall back to truncated evidence
1061- content = summary if summary else (evidence [:1000 ] if evidence else "(no content)" )
1122+ # Give synthesis both the extractor's conclusion and its actual
1123+ # evidence. Previously a non-empty summary silently displaced the
1124+ # evidence field, weakening source grounding even on good runs.
1125+ if evidence :
1126+ bounded_evidence = evidence [:4000 ]
1127+ if summary and not bounded_evidence .startswith (summary ):
1128+ content = f"Summary: { summary } \n \n Evidence:\n { bounded_evidence } "
1129+ else :
1130+ content = bounded_evidence
1131+ else :
1132+ content = summary or "(no content)"
10621133 parts .append (f"**Finding { i } ** — [{ title } ]({ url } )\n { content } " )
10631134 return "\n \n " .join (parts )
10641135
@@ -1085,6 +1156,7 @@ def get_stats(self) -> Dict:
10851156 "Rounds" : self .round_count ,
10861157 "Queries" : len (self .queries_used ),
10871158 "URLs" : len (self .urls_fetched ),
1159+ "Findings" : len (self .findings ),
10881160 "Model" : self .llm_model ,
10891161 }
10901162 if self .providers_used :
0 commit comments