Fix lost expiration index updates in the filesystem lease storage #22971
All Vouch review confidence checks passed
Residual risk 0.15 = Change Risk (0.37) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.37 · 235 lines diff across 2 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.327
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #22971"
general
weight: 0.35
afonsojanu
Closes #22935
Two lease renewals can land close enough together that they both read the same snapshot of the shared
expirations.jsonindex before either one writes back. Whichever one saves last wins, and the other's update just disappears. Since the reaper only ever looks at that index to decide what's expired, losing a single update is enough to have it revoke a lease that's still perfectly alive. The reporter hit this in production on a long-running flow that got killed with a bare 410 about half an hour in, with every renewal up to that point having succeeded.I added an
asyncio.Lockaround the read, modify, and write of the index in_update_expiration_indexand_remove_from_expiration_index, so two updates can't interleave anymore.I also changed
read_expired_lease_idsto check the actual lease file before reporting something as expired. The lease file is whatrenew_leasestamps directly, so it's the source of truth, and the index is only supposed to be a shortcut to it. This means that if the index ever ends up stale for some other reason down the road, a stale entry becomes harmless instead of fatal. If the lease file is missing entirely, that entry really is orphaned, so it still gets reported as expired and cleaned up.For tests, I added one that forces the interleaving deterministically (delaying the first index read just long enough for a second concurrent update to finish first, instead of hoping the event loop schedules it unluckily), and one that backdates an index entry while leaving the lease file untouched, to confirm the reaper no longer trusts a stale index on its own. Both fail against the code on main and pass with the fix.
Ran the full
tests/server/concurrency/andtests/server/services/test_repossessor.pysuites locally (61 tests, all passing), plus ruff and mypy on the changed files with nothing new flagged.