[Python] Reuse per-thread metrics containers in BundleBasedDirectRunner #41358
All Vouch review confidence checks passed
Residual risk 0.18 = Change Risk (0.33) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.33 · 150 lines diff across 1 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Shallow Review Depth
shallow_review_depth
0.344
Diff Size
diff_size
0.300
Real PR Conversation Timeline
1 comments
"Review active on #41358"
general
weight: 0.35
Mola-maker
Summary
BundleBasedDirectRunnerallocated a freshMetricsContainerfor every bundle, butStateSamplercaches oneScopedStateper step per worker thread and keeps using it. The cached state kept the first bundle's container, so counter increments made in later bundles were never recorded inPipelineResult.metrics(), and metrics first used in a later bundle were missing entirely.TransformExecutornow keeps one container per step per worker thread, matching the lifetime of the cachedScopedState, and resets it at the start of each bundle socommit_physicalstill receives only that bundle's updates. The state sampler is unchanged andScopedStatestays immutable.Fixes #41352
Testing
BundleBasedRunnerTest.test_metrics_across_multiple_bundles: aTestStreamsends elements in separate bundles and asserts both counters, which fails before the change ({'seen': 1}) and passes after ({'seen': 2, 'second_bundle': 1}).pytest apache_beam/runners/direct/ apache_beam/runners/worker/statesampler_test.py(31 passed) with the compiledstatesampler_fastextension, and again with the pure-Python sampler forced.yapf --diffclean on both changed files.