Repository navigation
Labels
effort/mediumEffort Mediumpriority/p2-mediumPriority P2: standard worksource/agentFiled by an agenttype/refactorType refactor: a new structure, same behaviorvalue/mediumValue Medium
Description
Friction
- Two bounded in-process caches are hand-written on
OrderedDict, each with its own lock and its own eviction: the embedding LRU cache and the webhook replay guard. - The in-memory cache of the Cloudflare Radar client is a plain
dictwith no bound and no expiry. - cachetools is already a dependency, and the GitHub session transport uses its
LRUCache.
Evidence
Checked at main a752a14.
_EmbeddingLRUCachekeeps anOrderedDict(src/devops_cli/ai/rag/embeddings.py:109).- The webhook replay guard keeps an
OrderedDict(src/devops_cli/server/routes/webhooks.py:164). CloudflareRadarClientkeepsself._cache: dict[str, NetworkReputationRecord] = {}(src/devops_cli/security/vulnerability_lookup.py:443).pyproject.toml:71pinscachetools==7.1.8.src/devops_cli/github/session_transport.pyuses it.- The owner comment of 2026-10-08 on fix(valkey): one validated URL names every Valkey endpoint, valkey-py dials an address that one check vetted, and the unused cache layer goes #1113 folded this refactor into fix(valkey): one validated URL names every Valkey endpoint, valkey-py dials an address that one check vetted, and the unused cache layer goes #1113 because the agent filing quota was spent. The quota no longer exists. v0.2.39 already deleted the other two parts of that comment:
ai/rag/cache.pyandai/harness/compaction.py. - The
OrderedDictcache of the OSV client (vulnerability_lookup.py:209) goes with feat(review): dependency advisories and the package inventory come from osv-scanner over the lockfiles, offline, with each advisory's own severity #1146, not here. - After the split, fix(valkey): one validated URL names every Valkey endpoint, valkey-py dials an address that one check vetted, and the unused cache layer goes #1113 only tracks its child issues, and no pull request closes fix(valkey): one validated URL names every Valkey endpoint, valkey-py dials an address that one check vetted, and the unused cache layer goes #1113 itself. So this candidate asks for a change that no other issue holds.
Existing tool considered
- cachetools (
LRUCache,TTLCache) gives a bounded cache with eviction and expiry. It is already a pinned dependency.
Proposed remedy
- Replace
_EmbeddingLRUCacheand the webhook replay guard withcachetools.LRUCache, kept under the locks that exist. Keep the hit and miss counters. - Bound the Radar memory cache with
cachetools.TTLCache(maxsize=..., ttl=<the threat-intel TTL>).
Acceptance criteria
-
rg -n 'OrderedDict' src/devops_cli/ai/rag/embeddings.py src/devops_cli/server/routes/webhooks.pyprints nothing. - Eviction at capacity, the hit and miss counts and the embedding-cache metrics behave as today. The tests that exist pass, moved where necessary.
- A webhook delivery id seen within the capacity of the cache is still refused as a replay.
- The Radar memory cache holds at most its bound and drops entries after the TTL. The test uses the timer of cachetools or a fake clock, never wall time.
- Tests run offline, with fakes only at the HTTP edge or the process edge. No test patches a
devops_cliname. -
uv run devops cipasses.
Source: #1113
Proposed design
Problem statement
Three in-process caches are hand-written or unbounded. Two use OrderedDict with manual eviction. One is a plain dict with no bound and no expiry. cachetools is already a pinned dependency. This change replaces all three with cachetools.LRUCache or TTLCache. It keeps the existing locks, hit and miss counters, and replay refusal behavior.
Acceptance criteria
- Criterion 1: No OrderedDict import or usage remains in the embedding cache or webhook replay guard files.
Verification: Runrg -n 'OrderedDict' src/devops_cli/ai/rag/embeddings.py src/devops_cli/server/routes/webhooks.py. The command prints nothing. - Criterion 2: Eviction at capacity, hit and miss counts, and embedding-cache metrics behave as before the change.
Verification: Run the existing tests for the embedding cache. All tests pass. - Criterion 3: A webhook delivery id seen within the cache capacity is still refused as a replay.
Verification: Run the webhook replay test. The delivery is refused. - Criterion 4: The Radar memory cache holds at most its bound and drops entries after the TTL.
Verification: Run the Radar cache test. It uses the timer of cachetools or a fake clock, never wall time. - Criterion 5: Tests run offline with fakes only at the HTTP edge or the process edge.
Verification: Inspect the test code. No test patches a devops_cli name. - Criterion 6: The full CI pipeline passes.
Verification: Runuv run devops ci. The command exits with code 0.
Key questions
- What maxsize and TTL does the Radar memory cache use?: The body leaves both as placeholders. A person sets the maxsize and the TTL value before implementation. (proposed)
- What maxsize does the webhook replay guard currently use?: The code defines a bound on the OrderedDict. The exact value is read from the existing code at that location. [sources: src/devops_cli/server/routes/webhooks.py:164]
- Do the existing locks stay around the new cachetools objects?: Yes. The body states the caches are kept under the locks that exist. (proposed)
- Does the embedding cache keep its hit and miss counters after the refactor?: Yes. The body states to keep the hit and miss counters. (proposed)
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Metadata
Metadata
Assignees
Labels
effort/mediumEffort Mediumpriority/p2-mediumPriority P2: standard worksource/agentFiled by an agenttype/refactorType refactor: a new structure, same behaviorvalue/mediumValue Medium
Type
Projects
- StatusShow more project fieldsReady
- StatusShow more project fieldsNew
Activity
dan-petty commentedon Oct 23, 2026
Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones on the board.
The candidate changes cache implementations to use cachetools.The change improves code quality and maintainability.The change helps with caching behavior in several parts of the system.The change requires replacing hand-written caches with cachetools.dan-petty commentedon Oct 28, 2026
Status set to Ready at bb46660 (see proposed design in issue body).
chore(main): release 0.14.0 (#2609)