fix: close build and fetch spans on their error paths - #101
Merged
Merged
Conversation
ApprovabilityVerdict: Would Approve Macroscope's review found this PR approvable — This is a focused observability bug fix that closes existing build and fetch spans on errors without changing successful processing behavior. The implementation is localized and includes tests for failure reporting and duplicate termination prevention. Not approved because:
No code changes detected at Review your spending limits in Billing settings. You can add or adjust custom eligibility rules. Learn more. |
jaronoff97
added this pull request to stack #102
September 15, 2026 02:46
smithclay
previously approved these changes
Sep 15, 2026
Base automatically changed from
fix/matcher-index-allocation-failures
to
master
September 15, 2026 16:12
jaronoff97
dismissed
smithclay’s stale review
September 15, 2026 16:12
The merge-base changed after approval.
Closes #100. `buildIndex` started a span and only terminated it on success, so `TooManyPolicies`, a failed `processPolicy`, and a failed `finish` all left the span open in the telemetry. `HttpProvider.fetchAndNotify` always terminated its span, but reported a failed fetch as an ordinary completion. `SpanGuard` had no failure terminator, only `completed` and `done`, so neither site could record what actually happened. - Add `SpanGuard.failed(err)`, which records the error name and emits at `.err` so a failure stays visible even on a debug span. - Track termination in the guard. The first terminator wins and later ones no-op, so a `defer completed` paired with an `errdefer failed` reports the failure instead of contradicting it. - Use `errdefer |err| span.failed(err)` at both span sites. A sweep of `started(` found only these two call sites, so no other span has this gap. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Satisfies ziglint Z010. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
jaronoff97
force-pushed
the
fix/span-failure-terminator
branch
from
September 15, 2026 16:12
aee8c13 to
502efcc
Compare
smithclay
approved these changes
Sep 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #100. Stacked on #99, so it targets that branch. Retarget to
masteronce #99 merges.The problem
buildIndexstarts a span and only terminates it on success:Three ways out leave the span dangling. This is pre-existing and was identical in all three of the old per-signal
buildfunctions. #99 factored those into one function, which is why this is now a single-site fix.HttpProvider.fetchAndNotifyhas the other half of the problem. It usesdefer span.completed(...), so the span always closes, but a failed fetch is reported as an ordinary completion.Neither site could do better, because
SpanGuardhad onlycompletedanddone. There was no way to say the span ended badly.The fix
SpanGuard.failed(err)records the error name and emits at.err, so a failure stays visible even when the span itself is a debug span.The first terminator wins. The guard now tracks whether it has been terminated, and later terminators no-op. That makes the natural pairing safe:
On the error path the failure is recorded and the completion that follows is a no-op. On the success path only the completion runs. Without the flag this pairing would emit two contradictory terminations.
Both span sites now use
errdefer |err| span.failed(err).Scope
A sweep of
started(acrosssrc/found exactly two call sites, both fixed here. No other span has this gap.Tests
failed, a followingcompletedanddoneemit nothing.Verification
zig build test -Doptimize=ReleaseSafepasses.🤖 Generated with Claude Code