bug_filer: Add max age argument

Bug: b/377570481
Change-Id: Iac29c0f23b7f0dd92af8f1ee6640ff6f97e65ae8
Reviewed-on: https://pigweed-review.googlesource.com/c/infra/recipes/+/247852
Pigweed-Auto-Submit: Rob Mohr <mohrr@google.com>
Presubmit-Verified: CQ Bot Account <pigweed-scoped@luci-project-accounts.iam.gserviceaccount.com>
Commit-Queue: Auto-Submit <auto-submit@pigweed-service-accounts.iam.gserviceaccount.com>
Lint: Lint 🤖 <android-build-ayeaye@system.gserviceaccount.com>
Reviewed-by: Danielle Kay <danikay@google.com>
diff --git a/recipes/bug_filer.proto b/recipes/bug_filer.proto
index 1c45514..eb20a36 100644
--- a/recipes/bug_filer.proto
+++ b/recipes/bug_filer.proto
@@ -44,4 +44,7 @@
   // Bugs are not modified at this time, they're simply forgotten by this
   // builder.
   int32 purge_timeout_days = 8;
+
+  // Max age of builds to consider.
+  int32 max_age_days = 9;
 }
diff --git a/recipes/bug_filer.py b/recipes/bug_filer.py
index 5fc16d2..73ed1c4 100644
--- a/recipes/bug_filer.py
+++ b/recipes/bug_filer.py
@@ -37,6 +37,7 @@
 from __future__ import annotations
 
 import collections
+import datetime
 import fnmatch
 import itertools
 import json
@@ -100,6 +101,7 @@
     props.is_currently_passing_builds = props.is_currently_passing_builds or 5
     props.is_currently_failing_builds = props.is_currently_failing_builds or 3
     props.purge_timeout_days = props.purge_timeout_days or 30
+    props.max_age_days = props.max_age_days or 10
 
     # Some of the logic doesn't make sense unless these conditions hold.
     assert props.was_recently_passing_builds > props.is_currently_passing_builds
@@ -135,12 +137,13 @@
 
                     key = f'{bucket.name}/{builder.name}'
 
-                    status: BuilderStatus = api.builder_status.retrieve(
+                    status = api.builder_status.retrieve(
                         bucket=bucket.name,
                         builder=builder.name,
                         n=props.was_recently_passing_builds,
                         include_incomplete=False,
                         assume_existence=True,
+                        max_age=datetime.timedelta(days=props.max_age_days),
                     )
 
                     if key in builder_state: