From ecaf3fff0448c9258e8d9bdf414f791d9c3011ed Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 10 Oct 2026 09:45:36 +0000 Subject: [PATCH 1/3] perf(canary): date-bound the per-role run list to one 15-day tier (#1259 option B) promote-all spent ~750 s of 925 s on 'run list -L 1000' calls (11 workflows x 4 repos, ~20 s each), although every window the gate samples starts at most ~2 weeks back. _agent_run_json now reads the per-role list with --created >= (CANARY_RUNS_HORIZON_TIERS, days, default '15'; EMPTY disables), sharing the tier logic with _ingress_horizon via _horizon_from. One fixed tier so every window shares ONE fetch per (repo, workflow). No refetch when the bounded list hits the 1000 cap: GitHub lists newest-first, so a capped bounded list is exactly the newest-1000 the unbounded call returns (existing truncation behavior, unchanged). Windows older than the tier, and an empty window, keep the unbounded read. Refs #1259 Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MjXPsBTaL6WV9AhCH2ajuv --- scripts/canary-rollout.sh | 22 +++++++-- tests/canary_rollout.bats | 97 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 113 insertions(+), 6 deletions(-) diff --git a/scripts/canary-rollout.sh b/scripts/canary-rollout.sh index d641d4d15..6d2052afa 100755 --- a/scripts/canary-rollout.sh +++ b/scripts/canary-rollout.sh @@ -983,8 +983,15 @@ _run_jobs_json() { # cuts the list at its own `since`, and the "list reached CANARY_INGRESS_RUN_LIMIT" fail-closed guard # is unchanged (a bounded list that hits the cap is judged exactly like an unbounded one). _ingress_horizon() { - local since="$1" tiers="${CANARY_INGRESS_HORIZON_TIERS-8 15}" s now days t - _INGRESS_FROM="" + _horizon_from "$1" "${CANARY_INGRESS_HORIZON_TIERS-8 15}" + _INGRESS_FROM="$_HORIZON_FROM" +} + +# _horizon_from — the tier logic behind _ingress_horizon, sets _HORIZON_FROM (also used for the +# per-role run lists, _agent_run_json, #1259 option B). +_horizon_from() { + local since="$1" tiers="$2" s now days t + _HORIZON_FROM="" [ -n "$since" ] || return 0 s="$(_epoch "$since")" case "$s" in ''|*[!0-9]*|0) return 0 ;; esac @@ -996,7 +1003,7 @@ _ingress_horizon() { for t in $tiers; do case "$t" in ''|*[!0-9]*) continue ;; esac if [ "$days" -le "$t" ]; then - _INGRESS_FROM="$(date -u -d "-${t} days" +%Y-%m-%d 2>/dev/null || date -u -v"-${t}d" +%Y-%m-%d 2>/dev/null || true)" + _HORIZON_FROM="$(date -u -d "-${t} days" +%Y-%m-%d 2>/dev/null || date -u -v"-${t}d" +%Y-%m-%d 2>/dev/null || true)" return 0 fi done @@ -1195,7 +1202,14 @@ _agent_run_json() { [ -n "${_TIMING_CALLS:-}" ] && { printf . >> "$_TIMING_CALLS" 2>/dev/null || true; } # call counter (CANARY_TIMING) if [ -z "$repo" ] || [ "$repo" = '*' ]; then echo '[]'; return 0; fi _reg_run_workflow "$agent"; wf="$_REG_VAL" - raw="$(_repo_wf_runs_cached "$repo" "$wf" 1)" || rc=$? + # Date-bound the per-role list (#1259, option B): every window the gate samples starts at most ~2 weeks back, so the + # newest 1000 runs of a busy workflow are mostly older than anything read. One fixed tier (CANARY_RUNS_HORIZON_TIERS, + # days, default "15"; EMPTY disables the bound) so every window shares ONE fetch per (repo, workflow). No fallback + # read is needed when the bounded list hits the 1000 cap: GitHub returns newest-first, so it is then exactly the + # newest-1000 the unbounded call returns (the existing truncation behavior, unchanged). A window older than the tier + # (a long soak) gets the unbounded list as before. + _horizon_from "$since" "${CANARY_RUNS_HORIZON_TIERS-15}" + raw="$(_repo_wf_runs_cached "$repo" "$wf" 1 1000 "$_HORIZON_FROM")" || rc=$? if [ "$rc" -eq 3 ]; then rc=0; _reg_ingress_wf; iwf="$_REG_VAL" iraw="$(_ingress_runs_fetch "$repo" "$iwf" "$since")" || rc=$? diff --git a/tests/canary_rollout.bats b/tests/canary_rollout.bats index 76c2a09b8..accd79161 100644 --- a/tests/canary_rollout.bats +++ b/tests/canary_rollout.bats @@ -6523,10 +6523,11 @@ GHEOF [ "$status" -eq 0 ] local from; from="$(date -u -d '-8 days' +%Y-%m-%d)" grep -q -- "run list --repo org/busy --workflow Agent Ingress -L 5000 --created >=$from " "$GH_LOG" - # the per-role workflow lookup is NOT date-bounded + # the per-role workflow lookup is date-bounded too, to its own single 15-day tier (#1259 option B; it was unbounded + # before — this assertion is flipped deliberately) run grep -- "--workflow Dev-Lead Agent" "$GH_LOG" [ "$status" -eq 0 ] - [[ "$output" != *"--created"* ]] + [[ "$output" == *"--created >=$(date -u -d '-15 days' +%Y-%m-%d)"* ]] : > "$GH_LOG" run env CANARY_RINGS="$INGRESS_RINGS" CANARY_GH_RETRY_SLEEP=0 CANARY_GH_RETRIES=1 bash -c " source '$ORCH'; set +e @@ -6969,3 +6970,95 @@ YML [ "$status" -eq 0 ] [ -z "$output" ] } + +# ── #1259 option B: the per-role (legacy) run list is date-bounded to one 15-day tier ───────────────────── +# The gate only samples windows that start at most ~2 weeks back, so the newest 1000 runs of a busy workflow were +# mostly dead weight (promote-all spent ~750 s of 925 s on `run list -L 1000`). The stub honors `--created` the +# way GitHub does (newest-first, createdAt date >= bound), so bounded and unbounded reads can be compared. +_legacy_runs_stub() { + export TMPDIR="$BATS_TEST_TMPDIR" + STUB_BIN="$(mktemp -d "$BATS_TEST_TMPDIR/stub.XXXXXX")"; export PATH="$STUB_BIN:$PATH" + export GH_LOG="$BATS_TEST_TMPDIR/gh-legacy.log"; : > "$GH_LOG" + export FIXTURE="$BATS_TEST_TMPDIR/legacy-runs.json" + local d2 d9 d14 d20 + d2="$(date -u -d '-2 days' +%Y-%m-%dT10:00:00Z)"; d9="$(date -u -d '-9 days' +%Y-%m-%dT10:00:00Z)" + d14="$(date -u -d '-14 days' +%Y-%m-%dT10:00:00Z)"; d20="$(date -u -d '-20 days' +%Y-%m-%dT10:00:00Z)" + jq -n --arg a "$d2" --arg b "$d9" --arg c "$d14" --arg d "$d20" '[ + {conclusion:"success",createdAt:$a,databaseId:1,workflowName:"Dev-Lead Agent"}, + {conclusion:"failure",createdAt:$b,databaseId:2,workflowName:"Dev-Lead Agent"}, + {conclusion:"success",createdAt:$c,databaseId:3,workflowName:"Dev-Lead Agent"}, + {conclusion:"failure",createdAt:$d,databaseId:4,workflowName:"Dev-Lead Agent"}]' > "$FIXTURE" + cat > "$STUB_BIN/gh" <<'GHEOF' +#!/usr/bin/env bash +echo "$*" >> "$GH_LOG" +created=""; prev="" +for a in "$@"; do [ "$prev" = "--created" ] && created="${a#>=}"; prev="$a"; done +case "$1 $2" in + "run list") jq -c --arg c "$created" '[.[] | select($c == "" or (.createdAt[0:10] >= $c))]' "$FIXTURE" ;; + *) echo '{}' ;; +esac +GHEOF + chmod +x "$STUB_BIN/gh" +} +_ago() { date -u -d "-$1 days" +%Y-%m-%dT%H:%M:%SZ; } + +@test "_agent_run_json: the per-role run list is fetched date-bounded to the 15-day tier for a recent window (#1259 option B)" { + _legacy_runs_stub + run env CANARY_RINGS="$RINGS" CANARY_GH_RETRY_SLEEP=0 CANARY_GH_RETRIES=1 bash -c " + source '$ORCH'; set +e; _agent_run_json dev-lead org/legacy '$(_ago 5)' | jq -r '[.[].databaseId] | join(\",\")'" + [ "$status" -eq 0 ] + [ "$output" = "1" ] + grep -q -- "--created >=$(date -u -d '-15 days' +%Y-%m-%d)" "$GH_LOG" + grep -q -- "-L 1000" "$GH_LOG" +} + +@test "_agent_run_json: a window older than the tier, or an empty window, reads the unbounded list as before (#1259 option B)" { + _legacy_runs_stub + run env CANARY_RINGS="$RINGS" CANARY_GH_RETRY_SLEEP=0 CANARY_GH_RETRIES=1 bash -c " + source '$ORCH'; set +e; _agent_run_json dev-lead org/legacy '$(_ago 21)' | jq -r '[.[].databaseId] | join(\",\")'" + [ "$status" -eq 0 ] + [ "$output" = "1,2,3,4" ] + ! grep -q -- "--created" "$GH_LOG" + : > "$GH_LOG" + run env CANARY_RINGS="$RINGS" CANARY_GH_RETRY_SLEEP=0 CANARY_GH_RETRIES=1 bash -c " + source '$ORCH'; set +e; _agent_run_json dev-lead org/legacy '' | jq -r '[.[].databaseId] | join(\",\")'" + [ "$output" = "1,2,3,4" ] + ! grep -q -- "--created" "$GH_LOG" +} + +@test "_agent_run_json: CANARY_RUNS_HORIZON_TIERS='' disables the per-role bound (#1259 option B)" { + _legacy_runs_stub + run env CANARY_RUNS_HORIZON_TIERS='' CANARY_RINGS="$RINGS" CANARY_GH_RETRY_SLEEP=0 CANARY_GH_RETRIES=1 bash -c " + source '$ORCH'; set +e; _agent_run_json dev-lead org/legacy '$(_ago 5)' | jq -r '[.[].databaseId] | join(\",\")'" + [ "$status" -eq 0 ] + [ "$output" = "1" ] + ! grep -q -- "--created" "$GH_LOG" +} + +@test "_agent_run_json: bounded and unbounded reads give the same runs for every window within the tier (#1259 option B)" { + _legacy_runs_stub + local days out_b out_u + for days in 1 3 5 10 13 14; do + out_b="$(env CANARY_RINGS="$RINGS" CANARY_GH_RETRY_SLEEP=0 CANARY_GH_RETRIES=1 bash -c "source '$ORCH'; set +e; _agent_run_json dev-lead org/legacy '$(_ago $days)'")" + out_u="$(env CANARY_RUNS_HORIZON_TIERS='' CANARY_RINGS="$RINGS" CANARY_GH_RETRY_SLEEP=0 CANARY_GH_RETRIES=1 bash -c "source '$ORCH'; set +e; _agent_run_json dev-lead org/legacy '$(_ago $days)'")" + [ -n "$out_b" ] + [ "$out_b" = "$out_u" ] || { echo "window=$days bounded=$out_b unbounded=$out_u"; return 1; } + done +} + +@test "_agent_run_json: windows of different ages share ONE per-role fetch, and a capped bounded list triggers no refetch (#1259 option B)" { + _legacy_runs_stub + local cache="$BATS_TEST_TMPDIR/rc-legacy"; mkdir -p "$cache" + run env _RUNS_CACHE_DIR="$cache" CANARY_RINGS="$RINGS" CANARY_GH_RETRY_SLEEP=0 CANARY_GH_RETRIES=1 bash -c " + source '$ORCH'; set +e + for d in 2 7 11 14; do _agent_run_json dev-lead org/legacy \"\$(date -u -d \"-\$d days\" +%Y-%m-%dT%H:%M:%SZ)\" >/dev/null; done" + [ "$status" -eq 0 ] + [ "$(grep -c '^run list ' "$GH_LOG")" -eq 1 ] + # A bounded list that fills the 1000 cap IS the newest-1000 (newest-first), so it is used as is: no second read. + : > "$GH_LOG"; cache="$BATS_TEST_TMPDIR/rc-legacy-cap"; mkdir -p "$cache" + jq -c '[range(1000) as $i | {conclusion:"success",createdAt:"2026-10-09T10:00:00Z",databaseId:$i,workflowName:"Dev-Lead Agent"}]' <<< 'null' > "$FIXTURE" + run env _RUNS_CACHE_DIR="$cache" CANARY_RINGS="$RINGS" CANARY_GH_RETRY_SLEEP=0 CANARY_GH_RETRIES=1 bash -c " + source '$ORCH'; set +e; _agent_run_json dev-lead org/legacy '$(_ago 5)' | jq 'length'" + [ "$output" = "1000" ] + [ "$(grep -c '^run list ' "$GH_LOG")" -eq 1 ] +} From 390e637f7df513e4f616572994343fc4b59325f6 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 10 Oct 2026 17:52:18 +0000 Subject: [PATCH 2/3] test(canary): assert run status and grep exit 1 in the option B tests (#1259) Address Gemini review on #1282: assert [ "$status" -eq 0 ] right after each run before checking output, and replace '! grep -q' absence checks with 'run grep -q' + [ "$status" -eq 1 ] so a missing file or error cannot pass as 'pattern absent'. Test-only; no behavior change. Refs #1259 Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MjXPsBTaL6WV9AhCH2ajuv --- tests/canary_rollout.bats | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/canary_rollout.bats b/tests/canary_rollout.bats index accd79161..39860d186 100644 --- a/tests/canary_rollout.bats +++ b/tests/canary_rollout.bats @@ -7018,12 +7018,15 @@ _ago() { date -u -d "-$1 days" +%Y-%m-%dT%H:%M:%SZ; } source '$ORCH'; set +e; _agent_run_json dev-lead org/legacy '$(_ago 21)' | jq -r '[.[].databaseId] | join(\",\")'" [ "$status" -eq 0 ] [ "$output" = "1,2,3,4" ] - ! grep -q -- "--created" "$GH_LOG" + run grep -q -- "--created" "$GH_LOG" + [ "$status" -eq 1 ] : > "$GH_LOG" run env CANARY_RINGS="$RINGS" CANARY_GH_RETRY_SLEEP=0 CANARY_GH_RETRIES=1 bash -c " source '$ORCH'; set +e; _agent_run_json dev-lead org/legacy '' | jq -r '[.[].databaseId] | join(\",\")'" + [ "$status" -eq 0 ] [ "$output" = "1,2,3,4" ] - ! grep -q -- "--created" "$GH_LOG" + run grep -q -- "--created" "$GH_LOG" + [ "$status" -eq 1 ] } @test "_agent_run_json: CANARY_RUNS_HORIZON_TIERS='' disables the per-role bound (#1259 option B)" { @@ -7032,7 +7035,8 @@ _ago() { date -u -d "-$1 days" +%Y-%m-%dT%H:%M:%SZ; } source '$ORCH'; set +e; _agent_run_json dev-lead org/legacy '$(_ago 5)' | jq -r '[.[].databaseId] | join(\",\")'" [ "$status" -eq 0 ] [ "$output" = "1" ] - ! grep -q -- "--created" "$GH_LOG" + run grep -q -- "--created" "$GH_LOG" + [ "$status" -eq 1 ] } @test "_agent_run_json: bounded and unbounded reads give the same runs for every window within the tier (#1259 option B)" { @@ -7059,6 +7063,7 @@ _ago() { date -u -d "-$1 days" +%Y-%m-%dT%H:%M:%SZ; } jq -c '[range(1000) as $i | {conclusion:"success",createdAt:"2026-10-09T10:00:00Z",databaseId:$i,workflowName:"Dev-Lead Agent"}]' <<< 'null' > "$FIXTURE" run env _RUNS_CACHE_DIR="$cache" CANARY_RINGS="$RINGS" CANARY_GH_RETRY_SLEEP=0 CANARY_GH_RETRIES=1 bash -c " source '$ORCH'; set +e; _agent_run_json dev-lead org/legacy '$(_ago 5)' | jq 'length'" + [ "$status" -eq 0 ] [ "$output" = "1000" ] [ "$(grep -c '^run list ' "$GH_LOG")" -eq 1 ] } From bcac9b6cdf5507e8aa435a97340178703300dcdc Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 10 Oct 2026 18:43:30 +0000 Subject: [PATCH 3/3] test(canary): date the capped-list fixture relative to now (#1259) The option B capped-list test hardcoded createdAt 2026-10-09, but the stub filters on createdAt >= today-15d, so after ~2026-10-24 every fixture row is filtered out and the test fails on the date alone. Generate the date relative to now (Graphite review on #1282). Verified red with a stale fixed date, green with the relative date. Test-only. Refs #1259 Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MjXPsBTaL6WV9AhCH2ajuv --- tests/canary_rollout.bats | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/canary_rollout.bats b/tests/canary_rollout.bats index 39860d186..6a66fce30 100644 --- a/tests/canary_rollout.bats +++ b/tests/canary_rollout.bats @@ -7052,7 +7052,7 @@ _ago() { date -u -d "-$1 days" +%Y-%m-%dT%H:%M:%SZ; } @test "_agent_run_json: windows of different ages share ONE per-role fetch, and a capped bounded list triggers no refetch (#1259 option B)" { _legacy_runs_stub - local cache="$BATS_TEST_TMPDIR/rc-legacy"; mkdir -p "$cache" + local cache="$BATS_TEST_TMPDIR/rc-legacy" recent; mkdir -p "$cache" run env _RUNS_CACHE_DIR="$cache" CANARY_RINGS="$RINGS" CANARY_GH_RETRY_SLEEP=0 CANARY_GH_RETRIES=1 bash -c " source '$ORCH'; set +e for d in 2 7 11 14; do _agent_run_json dev-lead org/legacy \"\$(date -u -d \"-\$d days\" +%Y-%m-%dT%H:%M:%SZ)\" >/dev/null; done" @@ -7060,7 +7060,9 @@ _ago() { date -u -d "-$1 days" +%Y-%m-%dT%H:%M:%SZ; } [ "$(grep -c '^run list ' "$GH_LOG")" -eq 1 ] # A bounded list that fills the 1000 cap IS the newest-1000 (newest-first), so it is used as is: no second read. : > "$GH_LOG"; cache="$BATS_TEST_TMPDIR/rc-legacy-cap"; mkdir -p "$cache" - jq -c '[range(1000) as $i | {conclusion:"success",createdAt:"2026-10-09T10:00:00Z",databaseId:$i,workflowName:"Dev-Lead Agent"}]' <<< 'null' > "$FIXTURE" + # Dated relative to now: a fixed date would fall behind the stub's 15-day bound and filter every row out. + recent="$(date -u -d '-1 days' +%Y-%m-%dT10:00:00Z)" + jq -n -c --arg c "$recent" '[range(1000) as $i | {conclusion:"success",createdAt:$c,databaseId:$i,workflowName:"Dev-Lead Agent"}]' > "$FIXTURE" run env _RUNS_CACHE_DIR="$cache" CANARY_RINGS="$RINGS" CANARY_GH_RETRY_SLEEP=0 CANARY_GH_RETRIES=1 bash -c " source '$ORCH'; set +e; _agent_run_json dev-lead org/legacy '$(_ago 5)' | jq 'length'" [ "$status" -eq 0 ]