fix(insight): fail open on NaN sampling_rate + on-change note - #699
Conversation
5f0f49a to
9993f32
Compare
Pull Request is not mergeable
This comment has been minimized.
This comment has been minimized.
Pull Request is not mergeable
This comment has been minimized.
This comment has been minimized.
Pull Request is not mergeable
NaN compares False to everything, so a NaN sampling_rate flowed through _should_sample and sampled OUT every execution, silently disabling all instrumentation. _resolve_sampling_rate now fails open to 1.0 (full sampling), matching the JS plugin. Adds focused tests and a README note that on-change exporter calls run synchronously on the checkpoint path (async work tracked in #687).
9993f32 to
2d540e2
Compare
Claude AI reviewReviewed the full diff ( Correctness of the fix: Tests: Both new unit tests exercise the fix meaningfully — one directly asserts Docs: The README addition is a plain informational note about synchronous exporter calls in Determinism/replay: No functional, typing, or test-coverage issues found. One very minor stylistic nit (the Reviewed commit |
Codex AI reviewNo actionable findings. Residual risk is low: NaN sampling is covered by unit-level hook simulation, but not through the local runner end to end. Reviewed commit |
What
Stacked follow-up on #632 (base branch
feat/workflow-insight-plugin).Fixes a correctness bug and adds a documentation note:
sampling_rate=NaNfails open to1.0. NaN comparesFalseto everyoperand, so a NaN rate flowed straight through
_should_sample(
rate >= 1→ False,rate <= 0→ False,x < NaN→ False) and silentlysampled out every execution, disabling all instrumentation.
_resolve_sampling_ratenow detects NaN and coerces it to1.0(fullsampling), matching the JS plugin's treatment of non-finite/invalid rates.
All other sampling behavior (clamping of out-of-range values,
Nonehandling) isunchanged.
README note that in
on-changemode exporter calls currently runsynchronously on the SDK checkpoint path, so slow exporters can delay
workflow progress. Asynchronous scheduling/coalescing is deferred and
tracked in [Feature]: Add workflow insight plugin #687.
Tests
test_resolve_sampling_rate_nan_fails_open_to_one—_resolve_sampling_rate(float("nan")) == 1.0.test_nan_sampling_rate_emits_instead_of_silently_disabling— a pluginconfigured with
sampling_rate=NaNstill emits a record and surfaces thewarning.
Validation
hatch run types:check: Success, no issues.hatch fmt --check(ruff check + format): all checks passed, 17 files formatted.hatch build: sdist + wheel built.lintcommit.py): PASS.Notes
feat/workflow-insight-plugin(do not merge until feat: add Workflow Insight instrumentation plugin #632 lands).