Skip to content

fix(metrics): replace insert with replace in on_enter to avoid panic on async span re-entry#2891

Merged
bug-ops merged 2 commits intomainfrom
fix/metrics-bridge-span-reentry
Apr 11, 2026
Merged

fix(metrics): replace insert with replace in on_enter to avoid panic on async span re-entry#2891
bug-ops merged 2 commits intomainfrom
fix/metrics-bridge-span-reentry

Conversation

@bug-ops
Copy link
Copy Markdown
Owner

@bug-ops bug-ops commented Apr 11, 2026

Summary

  • ExtensionsMut::insert in tracing-subscriber panics if the extension slot is already occupied (assertion self.replace(val).is_none())
  • For async spans, on_enter fires on every poll cycle — a SpanEntry from a prior enter is still present when the span re-enters during its destructor (observed with Instrumented<OpenAiProvider::chat::closure> in the memory tier promotion loop)
  • Fix: switch insertreplace in metrics_bridge.rs:on_enter; replace overwrites without panicking, which is the correct semantic for tracking the most recent enter timestamp

Test plan

  • cargo +nightly fmt --check — passed
  • cargo clippy --workspace -- -D warnings — passed
  • cargo nextest run --config-file .github/nextest.toml --workspace --lib --bins — 7842 tests passed
  • Manual: cargo run --features full -- --tui --config .local/config/testing.toml no longer aborts with panic in a destructor during cleanup

…on async span re-entry

ExtensionsMut::insert panics when the extension slot is already occupied.
For async spans, on_enter fires on every poll cycle, so a SpanEntry from
a prior enter is still present when the span re-enters during its destructor
(e.g. drop of Instrumented<OpenAiProvider::chat::closure> in the memory
tier promotion loop). Switching to replace silently overwrites the existing
value, which is the correct semantic for tracking the most recent enter time.
@github-actions github-actions Bot added rust Rust code changes core zeph-core crate bug Something isn't working size/XS Extra small PR (1-10 lines) labels Apr 11, 2026
@bug-ops bug-ops enabled auto-merge (squash) April 11, 2026 13:44
@github-actions github-actions Bot added the ci CI/CD configuration label Apr 11, 2026
@bug-ops bug-ops merged commit 134333f into main Apr 11, 2026
76 of 80 checks passed
@bug-ops bug-ops deleted the fix/metrics-bridge-span-reentry branch April 11, 2026 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ci CI/CD configuration core zeph-core crate rust Rust code changes size/XS Extra small PR (1-10 lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant