Skip to content

fix: correct inverted condition in DefaultDictWithTimeout TTL refresh#2274

Open
wishhyt wants to merge 1 commit intoqodo-ai:mainfrom
wishhyt:fix/ttl-dict-refresh-condition
Open

fix: correct inverted condition in DefaultDictWithTimeout TTL refresh#2274
wishhyt wants to merge 1 commit intoqodo-ai:mainfrom
wishhyt:fix/ttl-dict-refresh-condition

Conversation

@wishhyt
Copy link
Copy Markdown

@wishhyt wishhyt commented Mar 18, 2026

Summary

  • DefaultDictWithTimeout.__refresh() uses > where it should use < in the refresh throttle condition
  • This means: when time since last refresh exceeds the interval, cleanup is skipped; when it's less than the interval, cleanup runs on every access
  • The result is that expired entries are never evicted during low-frequency access (memory leak), while cleanup runs unnecessarily often during high-frequency access (performance waste)
  • This class is used for push trigger deduplication in github_app.py

Changes

pr_agent/servers/utils.py: Changed > to < in the refresh interval comparison

Test plan

  • Verify that entries are properly evicted after their TTL expires
  • Verify that cleanup does not run on every access when access frequency is higher than the refresh interval

The refresh throttle condition used `>` (skip when elapsed time exceeds
interval) instead of `<` (skip when elapsed time is less than interval).
This caused cleanup to run on every access during high-frequency usage
while never running during low-frequency access, effectively preventing
expired entries from being evicted.

Made-with: Cursor
@qodo-free-for-open-source-projects
Copy link
Copy Markdown
Contributor

Review Summary by Qodo

Fix inverted TTL refresh condition in DefaultDictWithTimeout

🐞 Bug fix

Grey Divider

Walkthroughs

Description
• Corrects inverted TTL refresh condition in DefaultDictWithTimeout
• Changes comparison from > to < for proper cleanup throttling
• Fixes memory leak from expired entries never being evicted
• Prevents unnecessary cleanup runs during high-frequency access
Diagram
flowchart LR
  A["Inverted Condition<br/>time > interval"] -->|Bug| B["Skip cleanup<br/>when should run"]
  A -->|Bug| C["Run cleanup<br/>when should skip"]
  D["Corrected Condition<br/>time < interval"] -->|Fix| E["Skip cleanup<br/>when elapsed < interval"]
  D -->|Fix| F["Run cleanup<br/>when elapsed >= interval"]
  E --> G["Proper TTL eviction"]
  F --> G
Loading

Grey Divider

File Changes

1. pr_agent/servers/utils.py 🐞 Bug fix +1/-1

Correct TTL refresh throttle condition operator

• Fixed inverted comparison operator in __refresh() method from > to <
• Corrects throttle logic to skip cleanup when elapsed time is less than refresh interval
• Ensures expired entries are properly evicted during low-frequency access
• Prevents unnecessary cleanup execution during high-frequency access

pr_agent/servers/utils.py


Grey Divider

Qodo Logo

@qodo-free-for-open-source-projects
Copy link
Copy Markdown
Contributor

qodo-free-for-open-source-projects bot commented Mar 18, 2026

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant