@@ -32,13 +32,17 @@ class RunRequest(BaseModel):
3232class RunResponse (BaseModel ):
3333 a : AgentRunResult
3434 b : AgentRunResult
35+ note : str | None = (
36+ None # set when the page body couldn't be fetched (SERP-only run)
37+ )
3538
3639
3740@router .post ("" , response_model = RunResponse )
3841async def run (req : RunRequest ) -> RunResponse :
3942 try :
40- # Fail fast if the page can't be fetched — don't burn LLM tokens first.
41- await FetchPageTool (replay = False ).run (FetchPageInput (url = req .url ))
43+ # Probe the page once. A bot-block no longer fails the run — fetch_page degrades
44+ # to a SERP-only audit and tells the user via `note`.
45+ probe = await FetchPageTool (replay = False ).run (FetchPageInput (url = req .url ))
4246 a = await run_agent_a (
4347 req .url ,
4448 req .keyword ,
@@ -57,24 +61,17 @@ async def run(req: RunRequest) -> RunResponse:
5761 )
5862 # …then consolidate the diary into the playbook so the NEXT run sees it.
5963 await run_janitor ()
60- except httpx .HTTPStatusError as exc :
61- code = exc .response .status_code
62- raise HTTPException (
63- status_code = 502 ,
64- detail = (
65- f"Couldn't fetch { req .url } (HTTP { code } ). The site likely blocks "
66- "automated requests (bot protection). Try a different page."
67- ),
68- ) from exc
6964 except httpx .HTTPError as exc :
65+ # A page bot-block degrades gracefully (see fetch_page); this only fires for
66+ # other live HTTP failures, e.g. the SERP call.
7067 raise HTTPException (
7168 status_code = 502 ,
72- detail = f"Couldn't reach { req . url } : { exc .__class__ .__name__ } . Try a different page." ,
69+ detail = f"Live request failed : { exc .__class__ .__name__ } . Try again or a different page." ,
7370 ) from exc
7471 except ReplayMissError as exc :
7572 raise HTTPException (status_code = 409 , detail = str (exc )) from exc
7673 except RuntimeError as exc :
7774 # e.g. live SERP needs SERP_API_KEY
7875 raise HTTPException (status_code = 502 , detail = str (exc )) from exc
7976
80- return RunResponse (a = a , b = b )
77+ return RunResponse (a = a , b = b , note = None if probe . fetch_ok else probe . fetch_note )
0 commit comments