Repository navigation
Python: fix Purview cache accounting when replacing entries - #9052
Closed
Suhas Aggarwal (suhasagg) wants to merge 1 commit into
Closed
Suhas Aggarwal (suhasagg) wants to merge 1 commit into
Suhas Aggarwal (suhasagg) wants to merge 1 commit into
Conversation
Suhas Aggarwal (suhasagg)
requested review from
SergeyMenshykh,
Tao Chen (TaoChenOSU),
Eduard van Valkenburg (eavanvalkenburg),
Giles Odigwe (giles17),
Jose Alvarez (jpalvarezl),
Evan Mattson (moonbox3),
Roger Barreto (rogerbarreto),
sophia-ramsey and
westey (westey-m)
as code owners
October 5, 2026 11:34
Suhas Aggarwal (suhasagg)
temporarily deployed
to
github-app-auth
October 5, 2026 11:34 — with
GitHub Actions
Inactive
Suhas Aggarwal (suhasagg)
temporarily deployed
to
github-app-auth
October 5, 2026 11:34 — with
GitHub Actions
Inactive
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The focused fix resolves the double-subtraction bug and includes effective regression coverage.
Review effort: Balanced
Findings: None
What changed in this PR
Fixes Purview cache byte accounting when replacing entries during eviction.
Changes:
- Removes replaced entries before eviction.
- Adds regression coverage validating tracked size against live entries.
| File | Description |
|---|---|
python/packages/purview/agent_framework_purview/_cache.py |
Corrects replacement accounting and eviction behavior. |
python/packages/purview/tests/purview/test_cache.py |
Tests larger replacements at cache capacity. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Member
|
Suhas Aggarwal (@suhasagg) Thanks for the contribution. This implements the same change as #8990, so we'll continue the work there and close this duplicate. |
This branch was previously deployed
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
Fix Purview in-memory cache byte accounting when replacing an existing
entry, particularly when the replacement requires eviction.
Problem
When an existing cache entry is replaced, its size is subtracted from
_current_size_bytes, but the old entry remains in_cachewhileeviction runs.
If eviction encounters that entry, its size can be subtracted again,
causing
_current_size_bytesto diverge from the actual size of thelive cache entries.
A regression test reproduced this on the existing implementation:
Changes
_cachebefore adjusting its size.is at capacity.
Testing
154 != 206)git diff --check: passedFixes #8988