@@ -307,13 +307,27 @@ def main() -> None:
307307 "--json" , "number,title,author,createdAt,state,headRefOid" ,
308308 ]
309309
310+ search_parts = []
310311 if args .since :
311- gh_args += ["--search" , f"created:>={ args .since .isoformat ()} " ]
312+ search_parts .append (f"created:>={ args .since .isoformat ()} " )
313+ if args .until :
314+ # Include in the search query so the API scopes results to the window,
315+ # preventing newer PRs from consuming the result budget before we reach
316+ # the target window (the search API sorts by recency of update by default).
317+ search_parts .append (f"created:<{ args .until .isoformat ()} " )
318+ if search_parts :
319+ gh_args += ["--search" , " " .join (search_parts )]
312320
313321 raw = run_gh (* gh_args )
314322 prs_raw : list [dict ] = json .loads (raw )
315323
316- # Client-side --until filter
324+ # limit_hit must be checked on the raw pre-filter list; filtering below reduces
325+ # the count so checking after would produce a false negative.
326+ limit_hit = len (prs_raw ) > effective_limit
327+ prs_raw = prs_raw [:effective_limit ]
328+
329+ # Client-side --until filter as a safety net (search query already scopes this,
330+ # but keep the guard in case gh CLI doesn't forward the query correctly).
317331 if args .until :
318332 until_iso = args .until .isoformat ()
319333 prs_raw = [p for p in prs_raw if p ["createdAt" ][:10 ] < until_iso ]
@@ -329,10 +343,6 @@ def main() -> None:
329343 filtered .append (pr )
330344 prs_raw = filtered
331345
332- # If we got more than the limit, there are additional PRs beyond this window
333- limit_hit = len (prs_raw ) > effective_limit
334- prs_raw = prs_raw [:effective_limit ]
335-
336346 pr_results : list [dict ] = []
337347 all_passing_count = 0
338348 # check_name -> PR numbers where it was the latest failing conclusion
0 commit comments