Skip to content

Fixes #37961: Wait for the metrics worker before resetting for a new run - #37963

Merged
Khairajani merged 2 commits into
mainfrom
fix/operation-metrics-run-context-leak
Nov 18, 2026
Merged

Khairajani merged 2 commits into
mainfrom
fix/operation-metrics-run-context-leak

Conversation

@Khairajani

@Khairajani Khairajani commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #37961

  • When the run id changed, set_run_context dropped queued items and reset the metrics, but the item the worker had already taken was recorded after the reset, into the new run.
  • Queued items now carry a run generation. A reset bumps it under _lock, and _record_sync drops a stale item under the same lock. A new run doesn't wait for the worker.
  • Added test_new_run_drops_the_item_the_worker_is_recording: it releases the worker only after the new run has started. Fails on main every time, passes here.
  • Amended ADR:2026-11-16-operation-metrics-record-and-merge-under-one-lock (v2) with the generation rule.

🤖 Generated with Claude Code

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; the previous stale-item issue is fixed, and no new actionable issues were found.

Summary

The PR prevents queued metrics from an earlier run from entering a new run.

  • A new run keeps worker-held timings out of its metrics.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Queue metric with current generation] --> B[Worker or summary drain takes item]
  C[Reset metrics under lock] --> D[Advance generation]
  B --> E{Item generation still current?}
  D --> E
  E -->|Yes| F[Record metric under lock]
  E -->|No| G[Drop stale metric]
Loading

Reviews (2) · Last reviewed commit: "fix(ingestion): drop a stale metrics ite..." · Reviewed by Greptile

…w run

An item the worker held when a new run started was recorded after the reset,
into the new run. set_run_context now waits for it, under the same 1s bound
as summary reads, before resetting.
@Khairajani
Khairajani requested a review from a team as a code owner November 17, 2026 09:06
@github-actions

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically.

Maintainers can bypass this check by adding the skip-pr-checks label.

…f waiting

The bounded wait still leaked an item the worker recorded after it expired.
Queued items now carry the run generation; a reset bumps it under the lock and
_record_sync drops a stale item. A new run no longer waits.
@gitar-bot

gitar-bot Bot commented Nov 17, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 🟡 Medium risk

Generation-tagged metrics items are dropped after a reset, changing run-summary behavior; stale operations could otherwise be attributed to the wrong run.

Fixes a race where an item the metrics worker had already taken was recorded into the new run after a reset. Queued items now carry a run generation, and stale items are dropped under the same lock, so a new run no longer waits for the worker. No issues found.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@Khairajani
Khairajani merged commit 96ebbcd into main Nov 18, 2026
55 of 58 checks passed
@Khairajani
Khairajani deleted the fix/operation-metrics-run-context-leak branch November 18, 2026 14:07
Khairajani added a commit that referenced this pull request Nov 18, 2026
…run (#37963) (#38130)

* fix(ingestion): wait for the metrics worker before resetting for a new run

An item the worker held when a new run started was recorded after the reset,
into the new run. set_run_context now waits for it, under the same 1s bound
as summary reads, before resetting.

* fix(ingestion): drop a stale metrics item by run generation instead of waiting

The bounded wait still leaked an item the worker recorded after it expired.
Queued items now carry the run generation; a reset bumps it under the lock and
_record_sync drops a stale item. A new run no longer waits.

(cherry picked from commit 96ebbcd)
Khairajani added a commit that referenced this pull request Nov 18, 2026
…run (#37963) (#38129)

* fix(ingestion): wait for the metrics worker before resetting for a new run

An item the worker held when a new run started was recorded after the reset,
into the new run. set_run_context now waits for it, under the same 1s bound
as summary reads, before resetting.

* fix(ingestion): drop a stale metrics item by run generation instead of waiting

The bounded wait still leaked an item the worker recorded after it expired.
Queued items now carry the run generation; a reset bumps it under the lock and
_record_sync drops a stale item. A new run no longer waits.

(cherry picked from commit 96ebbcd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Operation metrics: an item the worker holds at a new run's start is counted in the new run

2 participants