Skip to content

fix(telemetry): Keep the age metrics' reads across pods - #6326

Merged
dan-petty merged 8 commits into
mainfrom
fix/3634-the-age-metrics-keep-their-reads
Nov 19, 2026
Merged

dan-petty merged 8 commits into
mainfrom
fix/3634-the-age-metrics-keep-their-reads

Conversation

@devops-cli-service

@devops-cli-service devops-cli-service Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Issue #3634 reports a metrics row that spent 627 to 1000 GitHub requests an hour after #3601, against 222 to 305 before it, because each new pod read the label events of every open Item again. This change keeps those label times in item-label-times.json of each repository, keyed by the updated_at of each Item, so a new pod reads no events of an Item that the file holds. A round reads the events of at most 20 Items, oldest entry first, so Items that move in each round do not keep another Item out.

Measured cost of one new pod: 24 GitHub requests in its first round over 30 open Items, the 4 fixed reads of the row and 20 label-event reads. The count is the sum of devops_cli_github_requests_total for row metrics in one offline round against the GitHub fake. The plan said 25, because the fixed reads were 5 then; #6095 set METRICS_ROW_GITHUB_REQUEST_BUDGET to 4.

Closes #3634

Change: openspec/changes/archive/2026-11-18-3634-the-age-metrics-keep-their-reads/

@devops-cli-service devops-cli-service Bot added type/bug Type bug: the code does not do what it must scope/telemetry OpenTelemetry tracing spans, Prometheus metrics, and Jaeger labels Nov 18, 2026
@devops-cli-service
devops-cli-service Bot force-pushed the fix/3634-the-age-metrics-keep-their-reads branch 4 times, most recently from a7e6db9 to ed33f94 Compare November 18, 2026 22:01
@devops-cli-service

Copy link
Copy Markdown
Contributor Author

The steps of the job:

Step Status Attempts Tokens in/out Last failing command
group 1 done 2 3471350/21416 pytest on base: tests/github/test_item_label_times.py
group 2 done 2 12322029/40609 pytest on base: tests/github/test_github_metrics.py, tests/github/test_github_metrics_request_budget.py
group 3 done 1 4853665/35773 -
group 4 done 1 10514752/25884 pytest on base: tests/roadmap/test_roadmap_run_metrics.py
group 5 done 1 844574/5522 -
group 6 done 1 1203719/5128 -
  • scoped check pre-push: passed, 10 s
  • scoped check static: passed, 31 s
  • scoped check tests: passed, 35 s
  • scoped check strength: passed, 0 s
  • scoped check tests: the changed files select more than 30 test modules, so only the changed test modules ran. The required checks of CI run the others
  • group 3: skipped, group 3: kind other
  • group 5: skipped, group 5: kind other
  • group 6: skipped, group 6: kind other
  • fail-to-pass of group 1: fails on the base commit. Tests that fail on the base commit: tests.github.test_item_label_times::test_a_record_that_cannot_be_written_logs_one_error, tests.github.test_item_label_times::test_the_record_round_trips_through_its_file, tests.github.test_item_label_times::test_a_missing_record_reads_as_an_empty_record.
  • fail-to-pass of group 2: fails on the base commit. Tests that fail on the base commit: tests.github.test_github_metrics_request_budget::test_one_round_of_one_page_stays_within_the_request_budget, tests.github.test_github_metrics_request_budget::test_one_more_page_of_open_items_fails_the_budget, tests.github.test_github_metrics::test_a_round_reads_the_label_events_of_at_most_20_items, tests.github.test_github_metrics::test_an_age_is_the_clock_minus_the_labeled_event_of_the_status, tests.github.test_github_metrics::test_a_closed_item_leaves_the_record, tests.github.test_github_metrics::test_a_round_reads_an_items_label_events_only_when_its_status_or_owner_changes, tests.github.test_github_metrics::test_a_round_keeps_the_entry_of_an_item_it_deferred, tests.github.test_github_metrics::test_a_failed_label_read_keeps_the_item_counts_and_sends_no_age, tests.github.test_github_metrics::test_a_new_process_reads_no_label_events_of_an_item_the_record_holds, tests.github.test_github_metrics::test_a_round_of_one_repository_keeps_the_label_times_of_another, tests.github.test_github_metrics::test_a_deferred_item_is_read_before_a_new_one.
  • verify of group 3: uv run devops ci test tests/github/test_github_metrics_request_budget.py exits 0.
================================================================================================================== test session starts ===================================================================================================================
platform linux -- Python 3.14.10, pytest-9.2.0, pluggy-1.7.0
rootdir: /home/devops/.data/agent/worktrees/w-3634
configfile: pyproject.toml
plugins: xdist-3.8.0, cov-7.1.0, asyncio-1.4.1.post1, hypothesis-6.170.15, platformdirs-4.14.7, time-machine-3.6.0, mock-3.17.0, anyio-4.16.0, syrupy-7.0.2, timeout-2.4.0
asyncio: mode=Mode.AUTO, debug=False, asyncio_default_fixture_loop_scope=None, asyncio_default_test_loop_scope=function
timeout: 600.0s
timeout method: signal
timeout func_only: False
collected 3 items

tests/github/test_github_metrics_request_budget.py ...                                                                                                                                                                                             [100%]

=================================================================================================================== 3 passed in 0.97s ====================================================================================================================
Bytecode compiled 23342 files in 552ms
Bytecode compiled 23342 files in 581ms
/home/devops/.data/agent/worktrees/w-3634/.venv/lib/python3.14/site-packages/pytest_asyncio/plugin.py:300: PytestDeprecationWarning: The configuration option "asyncio_default_fixture_loop_scope" is unset.
The event loop scope for asynchronous fixtures will default to the "fixture" caching scope. Future versions of pytest-asyncio will default the loop scope for asynchronous fixtures to "function" scope. Set the default fixture loop scope explicitly in order to avoid unexpected behavior in the future. Valid fixture loop scopes are: "function", "class", "module", "package", "session"

  warnings.warn(PytestDeprecationWarning(_DEFAULT_FIXTURE_LOOP_SCOPE_UNSET))
  • fail-to-pass of group 4: fails on the base commit. Tests that fail on the base commit: tests.roadmap.test_roadmap_run_metrics::test_the_metrics_row_keeps_the_label_times_in_the_state_directory_of_its_repository.
  • verify of group 5: uv run devops ci docs exits 0.
\u2139 Quality gate root: /home/devops/.data/agent/worktrees/w-3634
\u2713 All documentation files are up to date.
Bytecode compiled 23342 files in 573ms
Bytecode compiled 23342 files in 567ms
  • verify of group 6: uv run devops ci docs exits 0.
\u2139 Quality gate root: /home/devops/.data/agent/worktrees/w-3634
\u2713 All documentation files are up to date.
Bytecode compiled 23342 files in 599ms
Bytecode compiled 23342 files in 588ms

@dan-petty

Copy link
Copy Markdown
Owner

Advisory pre-merge review (automated; a person decides).

Recommendation: hold. The code is correct and well tested, but the pull request body closes #3634 with two acceptance criteria that it does not deliver. Fix the body (findings 1 and 2) and the minor findings, then merge.

Reviewed head: ed33f94d5.

Findings

# Severity Where Problem Evidence Fix
1 major PR body Criterion 1 of #3634 says: "state the number in the pull request". The body states no request count. Task 3.1 is ticked and says that the body states the number. The body has three parts: the problem paragraph, Closes #3634 and the change path. tests/github/test_github_metrics_request_budget.py:187 test_a_new_pod_sends_24_requests_in_its_first_round asserts 24. Add one line: one new pod sends 24 GitHub requests in its first round over 30 open Items (4 fixed reads and 20 label-event reads). Say that the plan's 25 became 24 because #6095 set METRICS_ROW_GITHUB_REQUEST_BUDGET to 4 (metrics.py:97).
2 major PR body (Closes #3634); archived tasks.md task 6.1 Criterion "Run live: the metrics row stays near its level before #3601 over a period with two rollouts" is not done. Task 6.1 is ticked, but nobody posted the two readings on #3634. The closing keyword closes the issue at merge, so nothing tracks the live check. The last comment on #3634 is the bot notice of 2026-11-18T22:08:31Z "Pull request #6326 is ready for review". No comment gives a reading. The PR only adds the check steps to docs/CLUSTER.md item 12. Replace Closes #3634 with a plain reference, and keep #3634 open until a person posts the two readings after deployment. Alternative: move the live criterion to a new linked issue, then keep Closes.
3 minor docs/CLUSTER.md:45 (item 12) The live check does not compare like with like. The doc query adds status!="304", but the issue measured the 222 to 305 band with no status filter. The doc says "for a repository", but the issue query sums every repository. The plan review on #3634 flagged this as a major false_premise, and no change fixed it. Issue body: sum by (row)(increase(devops_cli_github_requests_total[1h])), about 222 to 305 an hour. Doc: ...{job="roadmap-service", row="metrics", status!="304"}[1h] ... "it holds about 222 to 305 requests an hour for a repository". Remove "for a repository". Compare with the issue's unfiltered query, or say that the band has no status filter and give the filtered query only as the cost against the rate limit.
4 minor src/devops_cli/github/metrics.py:551-562 (_items_to_read) The cap can starve Items. Moved Items always come first, in store order. If 20 or more earlier Items move between rounds, a later Item never gets a read, and its claim age is never sent. Line 562: return (moved + new)[:_MAX_ITEM_AGE_READS_PER_ROUND]. A scratch script ran _label_times for 10 rounds with Items 1 to 21 moved in each round. Output on each round: [21, 22] 22 in times: False; last line: never read after 10 rounds: [22]. Read the moved Items oldest kept updated_at first, or rotate the start of the list each round. Add a test with more than 20 Items that move in each round.
5 minor src/devops_cli/github/item_label_times.py:67-68 The warning for an unreadable record is false. It says "this round reads the label events of every Item". An unreadable file gives an empty record, which is not None, so the cap of 20 applies. Both runners pass a record path (run.py:1330, run.py:1990), so the live row always has the cap. read_item_label_times returns ItemLabelTimesRecord(); _items_to_read cuts to _MAX_ITEM_AGE_READS_PER_ROUND (20). Say that the round reads the label events of at most 20 Items and writes the file again.
6 minor src/devops_cli/github/item_label_times.py (except branch of read_item_label_times); tests/github/test_item_label_times.py No test covers the read-failure path. If that branch breaks, a corrupt record file raises out of get_item_age_metrics. Mutation: except (OSError, ValueError) changed to except ZeroDivisionError gave 78 passed on the four changed test files. Write invalid JSON to the record path. Assert an empty ItemLabelTimesRecord() and one warning that names the file.
7 minor tests/github/test_github_metrics.py:1506 Task 2.1 is ticked, but the rename was not done. The name says only_when_its_status_or_owner_changes. The test and the new requirement use updated_at. Line 1506: def test_a_round_reads_an_items_label_events_only_when_its_status_or_owner_changes(. Its docstring says "because the write moved its updated_at". Rename to test_a_round_reads_an_items_label_events_only_when_its_updated_at_moves.
8 nit src/devops_cli/github/metrics.py:693-697 with _labeled_at at 604-613 A new owned Item that the cap defers has no times. The warning then says "No labeled event of ... on #N", but the round did not read the history. Line 695 passes times.get(item.number, {}); line 612 logs the warning. Skip the claim lookup, or log a different line, when item.number not in times.
9 nit archived tasks.md:25, tasks.md:41-51, proposal.md:15 The archived plan says 25 requests and names ..._25_requests_.... Tasks 5.1/5.2 and 6.1/6.2 repeat the same edit. Task 6.1 has no Verification line. tasks.md:25: "Add test_a_new_pod_sends_25_requests_in_its_first_round"; the code has the 24-request test. No archive edit is necessary if the PR body gives the 24-vs-25 reason (finding 1).

Lens results that this report does not keep

  • Test shard 1 took 5:00. Nothing proves that this PR made it slower, so it is not a finding.
  • The branch is 4 commits behind origin/main. This is a note only. The required checks make the branch current before merge.

Checks that ran

  • PR body and draft state read with devops gh api: draft=false, body as quoted in findings 1 and 2.
  • Issue fix(telemetry): the age metrics keep their reads across pods #3634: the acceptance criteria and the last comments read with devops gh api. No live reading is on the issue.
  • ruff check and ruff format --check on the 8 changed Python files: pass.
  • mypy --strict on the 3 changed source files: no issues.
  • devops ci test on the 4 changed test files: 78 passed.
  • devops docs generate --check: all documentation files are up to date.
  • Base run: the head test files fail on origin/main (6ff83d43f) at import, because base has no item_label_times module.
  • Nine mutations of the head code. Seven were caught (no record passed, cap removed, order swapped, updated_at ignored, deferred entries dropped, closed Items kept, record always empty). The non-atomic write and the disabled read-error handler were not caught; the second is finding 6.
  • Starvation script for finding 4: run two times, by a lens and by this report, with the same result.
  • git grep finds no reference to reset_item_age_cache or _item_label_times in src, tests, docs or openspec/specs.
  • The title is a Conventional Commit with the scope telemetry; the "Semantic PR title" check passed. All check runs on ed33f94d5 ended with success or skipped.
  • A scan of the added lines found no private address, internal host name, email address or device path.

@dan-petty
dan-petty marked this pull request as draft November 19, 2026 01:29
@dan-petty
dan-petty force-pushed the fix/3634-the-age-metrics-keep-their-reads branch from ed33f94 to c4115e6 Compare November 19, 2026 02:22
@dan-petty

Copy link
Copy Markdown
Owner

Fixes for the advisory review (#6326 (comment)). New head: c4115e6e2. The fix commit 4a294edc1 comes before the archive commit, and the archive commit stays last.

Findings

# Result How
1 fixed The body now gives the measured count: 24 GitHub requests in the first round of one new pod over 30 open Items (4 fixed reads, 20 label-event reads). It says how the count was measured (the sum of devops_cli_github_requests_total for row metrics in one offline round against the GitHub fake) and why it is not 25 (#6095 set METRICS_ROW_GITHUB_REQUEST_BUDGET to 4).
2 fixed in a different way Closes #3634 stays. The project records the live proof as a comment on the issue after the merge (docs/ROADMAP_WORKFLOW.md, the live proof of #2968). The archived task 6.1 now covers only the edit of docs/CLUSTER.md item 12 and has a Verification line. The "Workflow follow-up" of the archived tasks.md names the live check after the merge.
3 fixed docs/CLUSTER.md item 12 now gives the query of the issue for row metrics, with no status filter: sum by (row) (increase(devops_cli_github_requests_total{row="metrics"}[1h])). It says that the band of 222 to 305 is for all repositories together, with no status filter. The status!="304" query is named only as the cost against the rate limit, and not for the band.
4 fixed _items_to_read now reads the Items oldest entry first: an Item that the record does not hold first, then the moved Items by the updated_at that their entry holds. A deferred Item keeps its older entry, so it comes first in the next round. The order that the review proposed (moved Items, oldest first, then new Items) does not fix the repro of the review: 21 moved Items fill the cap in each round, so Item 22 with no entry still gets no read. The spec requirement "The row reads the label events of at most 20 Items in one round" now gives this order. The scenario "A deferred Item comes first" is replaced by "The oldest entry comes first" and "Items that move in each round do not keep an Item out". The main spec, the archived delta, design.md, proposal.md and tasks.md agree with the code. New tests: test_items_that_move_in_each_round_do_not_starve_another_item (21 Items move before each round, one Item has no entry: two rounds read all 22) and test_a_round_reads_the_item_with_the_oldest_entry_first.
5 fixed The warning for an unreadable record now says "this round reads the label events of at most 20 Items and writes the file again".
6 fixed New test test_a_record_that_cannot_be_read_logs_one_warning_and_reads_as_empty: it writes invalid JSON to the record path and asserts an empty ItemLabelTimesRecord(), one warning that names the file, and the text "at most 20 Items".
7 fixed Renamed to test_a_round_reads_an_items_label_events_only_when_its_updated_at_moves.
8 fixed The round looks up the claim of an owned Item only when it has the label times of that Item. An Item with no entry that the cap defers gets no false "No labeled event" warning in this round. New test test_an_owned_item_that_the_cap_defers_logs_no_missing_label_event.
9 fixed The archived proposal.md, design.md and task 3.1 now say 24 requests and test_a_new_pod_sends_24_requests_in_its_first_round, with the #6095 reason. The repeated tasks 5.2 and 6.2 are removed.

Test record

  • uv run devops ci --check --only lint,format,docs,constructs,openspec,test-settings,test-tree,startup-imports,swallowed-failures: all pass.
  • uv run devops ci test tests/github/test_github_metrics.py tests/github/test_github_metrics_request_budget.py tests/github/test_item_label_times.py tests/roadmap/test_roadmap_run_metrics.py tests/github/test_gh_api_status_branch_protection_secrets_dry_run.py tests/roadmap/stores/test_roadmap_store_tool_issues.py: 111 passed. After the rebase onto origin/main, the first four files: 81 passed.
  • uv run mypy src/devops_cli/github/metrics.py src/devops_cli/github/item_label_times.py: no issues.

Fail-to-pass

uv run devops ci fail-to-pass --base ed33f94d5 (the head before this fix):

failed on base: tests.github.test_github_metrics::test_items_that_move_in_each_round_do_not_starve_another_item (assert (40, [1, 2, 3, 4, 5, 6, ...]) == (40, [1, 2, 3, 4, 5, 6, ...]))
failed on base: tests.github.test_github_metrics::test_a_round_reads_the_item_with_the_oldest_entry_first (assert [1, 2, 3] == [3, 2, 1])
failed on base: tests.github.test_github_metrics::test_an_owned_item_that_the_cap_defers_logs_no_missing_label_event (AssertionError: assert (['No labeled...round.'], 0.0) == ([], 0.0))
failed on base: tests.github.test_item_label_times::test_a_record_that_cannot_be_read_logs_one_warning_and_reads_as_empty (assert (ItemLabelTim..., True, False) == (ItemLabelTim...1, True, True))
4 failed on base (4 failed and 66 passed in tests/github/test_github_metrics.py, tests/github/test_item_label_times.py; 0 errored).

All four pass on the new head.

Live check after the merge

After the merge and the deployment of the new image, run the check of docs/CLUSTER.md item 12: roll roadmap-service two times with an hour between the rollouts, read sum by (row) (increase(devops_cli_github_requests_total{row="metrics"}[1h])) after each hour, compare each value with the band of 222 to 305 requests an hour, and post the two readings with their times as a comment on #3634.

devops-cli-service Bot and others added 8 commits November 19, 2026 05:05
The metrics row read every moved Item before every Item with no entry,
in the order of the open list. When 20 or more held Items moved before
each round, an Item with no entry and an Item in the 21st place never
got a read. The round now reads the Items oldest entry first: an Item
that the record does not hold, then a moved Item by the updated_at of
its entry. A deferred Item keeps its older entry, so it comes first in
the next round.

An owned Item with no entry that the cap defers has no label times in
the round, so the round skips its claim and logs no false "No labeled
event" warning. The warning for an unreadable record now says that the
round reads at most 20 Items. docs/CLUSTER.md compares the band of the
issue with the same query, with no status filter, for all repositories.
The plan states 24 requests for one new pod (#6095 set the fixed reads
to 4), drops the repeated tasks and names the live check that follows
the merge.
@dan-petty
dan-petty force-pushed the fix/3634-the-age-metrics-keep-their-reads branch from c4115e6 to da41c1e Compare November 19, 2026 05:06
@dan-petty
dan-petty marked this pull request as ready for review November 19, 2026 05:14
@dan-petty
dan-petty merged commit ad0ee60 into main Nov 19, 2026
25 checks passed
@dan-petty
dan-petty deleted the fix/3634-the-age-metrics-keep-their-reads branch November 19, 2026 11:11
dan-petty-release Bot added a commit that referenced this pull request Nov 19, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.179.5](v0.179.4...v0.179.5)
(2026-11-19)


### Bug Fixes

* **ai:** bound the number of prewarm model label values
([#6391](#6391))
([e3fa4f1](e3fa4f1))
* **ci:** count a changed test that errors on base as proof
([#6379](#6379))
([6881b4c](6881b4c))
* **deps:** update Helm release argo-cd to v10.18.2
([#6398](#6398))
([2604ace](2604ace))
* **infra:** Fix the offline separator of a comma limit
([#6387](#6387))
([98493e4](98493e4))
* **roadmap:** Name the cause of a stopped verification run
([#6333](#6333))
([bbf308d](bbf308d))
* **roadmap:** Stage a long plan body and a null optional text
([#6351](#6351))
([053aabc](053aabc))
* **telemetry:** Keep the age metrics' reads across pods
([#6326](#6326))
([ad0ee60](ad0ee60))


### Code Refactoring

* **ai:** rank the benchmark with numpy and pytrec-eval
([#6388](#6388))
([051217e](051217e))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: dan-petty-release[bot] <346998822+dan-petty-release[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope/telemetry OpenTelemetry tracing spans, Prometheus metrics, and Jaeger type/bug Type bug: the code does not do what it must

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(telemetry): the age metrics keep their reads across pods

1 participant