Repository navigation
fix(utils): retain spans only for active usage scopes - #158
Draft
pengpengyi92 wants to merge 1 commit into
Draft
pengpengyi92 wants to merge 1 commit into
pengpengyi92 wants to merge 1 commit into
Conversation
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.
Summary
After the first
usage_scoperegisters the process-global collector, unrelated SDK traces are retained indefinitely. A span that finishes after its scope exits can also recreate an already-evicted bucket.Collect spans only for explicitly active scope buckets. Opening, appending, and removing a bucket use the same lock; unrelated and late callbacks cannot recreate it. Preserve token/time aggregation and additive SDK processor registration. Add seven offline regression cases using an isolated real SDK provider, covering unrelated/late spans, nested and concurrent scopes, child tasks, exceptions, and cancellation.
Related Issue
Follow-up to #130. No existing issue was found for this collector-retention defect. This does not implement the batch accounting or budget work in #127 / #132.
Verification
bash scripts/verify.shon Linux, Python 3.12.14, frozen-lock dependencies including Agents SDK 0.18.3: unchanged baseline 485 passed, 86.45% coverage; candidate 492 passed, 86.50% coverage. All five harness steps pass. The pre-push hook also verified the exact committed tree in a fresh directory with networking disconnected.python -B -m pytest tests/utils/test_usage.py --no-cov -p no:cacheprovider -qon Windows, Python 3.12.13 / SDK 0.18.3: 20 passed. The two retention regressions fail against the original implementation before the fix.pre-commit run --files quantmind/utils/usage.py tests/utils/test_usage.py, commit hooks, andgit diff --check: pass.An active scope still retains its completed spans until exit. This fixes unowned/closed-scope retention, not a fixed memory limit or an RSS/throughput guarantee.
Suggested labels:
type: bug,area: utils.Checklist
type(scope): summary.bash scripts/verify.shpasses.