Files
Jeremy 69e6f58c84 fix: stop the extraction budget handing out time it does not have
remainingSecondsForTimeout() rounded up to one second whenever less than one
remained. Since isExhausted() only covers <= 0, a fetch with 0.4s left was both
allowed and given a full second, overspending the deadline on every call - up to
25 times through the agent's tool loop.

It now returns null below one second: an explicit "cannot start", never confused
with Guzzle's "0 means no timeout". HealingContext::fetch() rejects that state -
the null check subsumes its old isExhausted() guard - and caps any explicit
timeout at the remaining budget, so the parameter cannot become a way past the
deadline.

Two other call sites needed the same distinction:

- AiConfigHealer passes this value straight to runAgent(timeout:), where null
  means "use the provider's timeout". Passing the nullable value through would
  have silently restored the unbounded 120s call this whole mechanism exists to
  prevent, so it now separates "no budget" (unbudgeted callers keep the provider
  timeout) from "budget with nothing left" (stop).
- MetaExtractionService::scrapeTimeout() does min($this->timeout, ...), and
  min(10, null) is null in PHP, which would have hit setConnectTimeout(int). The
  one-second floor now lives there, where it belongs: the scrape runs first, so
  the budget is always full, and the floor only bites on a near-zero budget.

The new test pins the actual bug: with 2 seconds of budget and 1.2 elapsed the
budget is not exhausted and has real time left, but has no whole second to hand
out. The old code returned 1 there.

Live re-check against the wedged provider is unchanged: HTTP 200 in 24.16s with
reason "timeout".
2026-08-08 19:49:38 +10:00
..
2026-06-09 15:09:50 +10:00
2026-06-09 15:09:50 +10:00