Repository navigation
Description
Problem or Motivation
- After feat(roadmap): run intake and scoped intake in their own pods #4567, each intake pod has an
emptyDirhome. About 240 scoped rounds a day x 47 pages give about 11,000 counted GitHub requests a day with no shared tier (estimated). - PyPI facts have no cache:
_read_pypiopens a new client for each read (src/devops_cli/roadmap/alternatives.py:251). The same tools come back on many items (pydantic-ai on 10, gidgethub on 6). - The listing snapshot of devops-cli is 23.31 MB raw and 9.21 MB with zlib (4,615 records, p99 28,340 B, max 65,177 B; measured).
Proposed Solution & Architectural Design
- One generic
TieredMapping(src/devops_cli/valkey/tiered.py, about 200 lines): aMutableMappingover an in-process LRU andValkeyCacheTier, with a key prefix, json or json+zlib values, a TTL, a 1 MiB bound, and the read and error counters. ValkeyCacheTiergetshget,hset,hscan,expire,unlinkand a WATCH helper behind its circuit breaker.ValkeySnapshotStoreandTieredSnapshotStorebehind theSnapshotStoreseam of perf(roadmap): intake reads only the issues that changed #4552:- key
valkey:roadmap:v1:snapshot:<owner>/<name>: a hash with the fieldmeta(schema,full_at,watermark) and one zlib JSONIssueRecordfor each issue; TTL 7 days; read withHSCAN COUNT 500; - the newest watermark wins: a writer WATCHes the key and writes in MULTI/EXEC only when its watermark is not older; a full read writes a temporary key and RENAMEs it;
- a load budget of 20 s; past it, the local tier or GitHub answers.
- key
- Fact, search, page, inventory and ADR caches on the same mapping (
valkey:brain:v1:<kind>:...), each key with a TTL. - Public repositories only, until
valkey-devopshas role ACL users. valkey-devops:maxmemoryfrom 96 MB to 256 MB and the limit from 128Mi to 320Mi (k8s/llm/valkey-devops.yaml:74,98). Today it holds 36.16 MiB in 2,525 keys, with 0 evictions.- Slow or down: a connect waits at most 0.25 s and a command 2 s; one failure opens the breaker for 60 s (
src/devops_cli/config/defaults.py:669-682). In that time each read is a miss and each write is skipped and counted. The reader gets the local snapshot or a GitHub read. - Instruments:
devops_cli_brain_reads_total{store,result},devops_cli_valkey_cache_errors_total{instance,op,error}anddevops_cli_brain_github_requests_saved_total{store}, with bounded labels only. - Tests on the fakeredis fixture
valkey_server(tests/support/fakes/valkey.py):- T1: the read path fills the upper tiers.
- T2: with
connected = False, reads return the local or source value, writes stay local, no second command goes out in the cooldown, and the counters showfallback. - T3: a silent loopback listener: the client has connect timeout 0.25 s and command timeout 2 s, and one timeout opens the breaker (no wall-clock bound).
- T4: after the cooldown the trial closes the breaker, the newer local snapshot replaces the older shared copy, and an older writer loses its WATCH transaction.
- T5: a value over 1 MiB is not sent, and each key has a TTL.
- T6: an old kind is not read.
Target Subsystem
Workstation Caching & Valkey (src/devops_cli/valkey/, src/devops_cli/roadmap/stores/listing_snapshot.py, k8s/llm/valkey-devops.yaml).
Existing Tool Considered
valkey-py, pybreaker and cachetools (in uv.lock), and the SnapshotStore seam of #4552. hishel is rejected: it is a shared cache by default, and GitHub answers are private with Vary: Authorization. Page ETags are rejected for listings (#4552: each new issue changes the ETag of every page). Cost: about 220,000 tokens and 6 hours to build.
Acceptance Criteria
- A test: a cold process with a warm shared snapshot reads at most 2 listing pages.
- A test: with
connected = False, a round reads the local tier or GitHub, countsfallback, and sends no second command in the 60 s cooldown. - A test: a value over 1 MiB is not sent.
- A test: no key of a private repository is written.
- The shared load time of the devops-cli snapshot is measured and stays under 20 s.
- Live drill:
valkey-devopsat 0 replicas for 10 minutes; no job fails, and the fallback share shows in Prometheus.
Dependencies
- fix(roadmap): scoped intake reads a bounded page count #3670 (the Service intake reads through the snapshot).
- test(valkey): add a contract suite for the Valkey fake #4557 (the contract suite for the Valkey fake).
Part of the project brain plan #4624.
Source: #4624
Alternatives check of 2026-11-13: not-applicable.
Class: perf, no search.
Tool: none found.
Proposed design
Problem statement
After #4567 each intake pod has its own home, so each pod keeps its own listing snapshot and each round reads the listing again. About 240 scoped rounds a day times 47 pages give about 11,000 counted GitHub requests a day. PyPI facts have no cache: _read_pypi opens a new client for each read, and the same tools come back on many items. The listing snapshot of devops-cli is 23.31 MB raw and 9.21 MB with zlib. This change shares the listing snapshot and the tool facts in Valkey.
Acceptance criteria
Requirement: Cold process reads the shared snapshot
A cold process with a warm shared snapshot MUST read at most two listing pages from GitHub.
Scenario: Warm shared snapshot
- WHEN a new process starts with a warm shared snapshot and no local file snapshot
- THEN GitHub answers at most two listing pages, and the shared load fills the local tier
Requirement: Read path fills the in-process tier
A read of the shared tier MUST fill the in-process tier.
Scenario: T1 read fills the in-process tier
- WHEN a reader reads a value that only the shared tier holds
- THEN the value lands in the in-process tier, and the next read of the key sends no command to the shared tier
Requirement: Fallback while the tier is down
With the client disconnected, a read MUST return the local or source value, a write MUST stay local, and the counters MUST count the fallback.
Scenario: T2 disconnected tier
- WHEN the client is disconnected and a round reads and writes
- THEN each read returns the local or source value, each write stays local, no second command goes out in the 60 s cooldown, and
devops_cli_brain_reads_total{result="fallback"}rises
Requirement: Timeouts open the breaker
A connect MUST wait at most 0.25 s and a command at most 2 s, and one timeout MUST open the breaker for 60 s.
Scenario: T3 silent listener
- WHEN a silent loopback listener accepts the connection and answers no command
- THEN the client's connect timeout is 0.25 s and its command timeout is 2 s, the command ends with a timeout error, the breaker opens, and the next command makes no network call
Requirement: Cooldown trial and the newest watermark
After the cooldown the trial MUST close the breaker, and a writer MUST write only when its watermark is not older than the stored one.
Scenario: T4 trial and lost WATCH
- WHEN the cooldown ends while an older writer races a newer snapshot
- THEN the trial closes the breaker, the newer snapshot replaces the older shared copy, and the older writer's WATCH transaction writes nothing
Requirement: Value bound and TTL
The mapping MUST refuse to send a value over 1 MiB and MUST set a TTL on each key it writes.
Scenario: T5 oversize value
- WHEN a caller stores a value over 1 MiB
- THEN no command carries the value, the call counts a skipped write, and each written key has a TTL
Requirement: An old key kind is not read
A reader MUST treat a value of another kind or schema as a miss.
Scenario: T6 old kind
- WHEN the shared tier holds a value under an older key kind
- THEN the reader reads the source value and writes the value under the current key kind
Requirement: No key of a private repository
The store MUST NOT write a key for a private repository while the shared Valkey has no role ACL users.
Scenario: Private repository
- WHEN a round runs for a private repository
- THEN no shared key names that repository, and the round reads the local tier or GitHub
Requirement: Shared load budget
The store MUST bound a shared load at 20 s and MUST fall back past that budget.
Scenario: Slow shared tier
- WHEN the shared tier does not answer the load within the budget
- THEN the reader returns the local snapshot or reads GitHub, and the miss is counted
Requirement: Measured shared load
A cold load of the devops-cli snapshot from the shared tier MUST end within 20 s.
Scenario: Warm devops-cli snapshot
- WHEN a cold reader loads the 9.21 MB devops-cli snapshot from the
valkey_serverfake - THEN the load ends within 20 s
Requirement: Cache Valkey memory bound
The cache Valkey MUST keep maxmemory at 240mb inside a 320Mi container limit.
Scenario: Live memory bound
- WHEN
kubectl get deployment valkey-devops -n llm -o yamlruns - THEN the output holds
--maxmemory 240mbandmemory: 320Mi
Requirement: Tool facts come from the shared cache
A second read of the same PyPI project MUST come from the shared cache and MUST send no PyPI request.
Scenario: PyPI fact reuse
- WHEN two processes read the fact of the same PyPI project
- THEN the second read sends no request to PyPI, and it returns the cached fact
Existing Tool Considered
The alternatives check of 2026-11-13 in the issue body gives not-applicable and names no tool; the block holds the class and the reason. The repository already holds valkey (valkey-py), cachetools and pybreaker in uv.lock. They give the client, the in-process LRU and the circuit breaker. None of them gives a tiered mapping over an LRU and a Valkey hash, a watermark-guarded snapshot store, a 1 MiB value bound or a zlib value codec. The change therefore builds about 200 lines of glue in src/devops_cli/valkey/tiered.py, at the cost the issue records: about 220,000 tokens and 6 hours.
Key questions
- What does the shared cache tier already give the change?:
valkey-devopsruns one replica in namespacellm. It requires a password, keeps caches only, and drops the least recently used key atmaxmemory96mb inside a 128Mi limit. Its NetworkPolicy admits only namespacedevopsand the metrics scrapers. The client isValkeyClientinsrc/devops_cli/valkey/client.py.tests/support/fakes/valkey.pygives an in-memory fake and a loopback recorder for tests. [sources: k8s/llm/valkey-devops.yaml, src/devops_cli/valkey/client.py, tests/support/fakes/valkey.py] - Which client and value codec does the shared tier use?: Use the existing
valkey(valkey-py) client through theValkeyClientseam. Store each value as JSON, and compress it with zlib above a size threshold. (best practice) [sources: uv.lock, src/devops_cli/valkey/client.py, src/devops_cli/roadmap/stores/listing_snapshot.py]- Chosen: valkey-py through
ValkeyClient. It is already a runtime dependency, and the client, its error mapping and its test fake exist. - Rejected: hishel. It is a shared cache by default, and GitHub answers are private with
Vary: Authorization. - Rejected: page ETags. Each new issue changes the ETag of every page of the listing (perf(roadmap): intake reads only the issues that changed #4552).
- Chosen: valkey-py through
- Which seam does the shared snapshot store take?: Implement
ValkeySnapshotStoreandTieredSnapshotStorebehind the existingSnapshotStoreprotocol. The callers ofintake_listingandlane_listingthen change nothing. (best practice) [sources: src/devops_cli/roadmap/stores/listing_snapshot.py]- Chosen: Implement the
SnapshotStoreprotocol. The protocol holdsloadandsave, andIncrementalListingholds one store. - Rejected: Change the callers to a new shared-cache API. It touches intake and each lane for no gain.
- Rejected: Replace
FileSnapshotStore. The local tier stays as the fallback when the shared tier is down.
- Chosen: Implement the
- How does a writer keep the newest shared snapshot?: A writer WATCHes the snapshot key, reads the stored watermark, and writes in MULTI/EXEC only when its watermark is not older. A full read writes a temporary key and RENAMEs it. The newest watermark wins. (best practice) [sources: src/devops_cli/roadmap/stores/listing_snapshot.py]
- Chosen: WATCH/MULTI/EXEC on the watermark. The snapshot already carries
full_atandwatermark, and a stale writer must not replace a newer copy. - Rejected: A
SET NXlock key. A killed pod leaves the lock behind, and the TTL of the key expires it while the lock is held. - Rejected: Last writer wins. A pod that started earlier can write over a newer snapshot and lose issues.
- Chosen: WATCH/MULTI/EXEC on the watermark. The snapshot already carries
- What bound and TTL does each shared value have?: The mapping refuses a value over 1 MiB and sets a TTL on each key. The snapshot key gets 7 days. Each other key kind gets its own TTL. (best practice) [sources: src/devops_cli/roadmap/stores/listing_snapshot.py, src/devops_cli/config/defaults.py]
- Chosen: 1 MiB value bound and a per-kind TTL. The snapshot hash holds one record per field, and the bound keeps one oversize value out.
- Rejected: No bound. One oversize value can fill the cache and drop the keys the rounds need.
- Rejected: One global TTL. Facts and snapshots age at different rates.
- What does the tier do when the shared Valkey is slow or down?: A connect waits at most 0.25 s and a command at most 2 s. One failure opens the breaker for 60 s. In that time each read is a miss and each write is skipped and counted. The reader then uses the local tier or GitHub. (best practice) [sources: src/devops_cli/config/defaults.py, uv.lock, tests/support/fakes/valkey.py]
- Chosen:
pybreakerwith 0.25 s and 2 s timeouts.pybreakeris already a dependency, and a short bound keeps a round inside its budget. - Rejected: No breaker and long timeouts. A hung command holds a round for the socket default, and each key repeats the wait.
- Rejected: Retry each failed command. It multiplies the load on a tier that is already down.
- Chosen:
- Which repositories may write to the shared tier?: Public repositories only, until
valkey-devopshas role ACL users. The store refuses a key for a private repository and counts the refusal. (best practice) [sources: k8s/llm/valkey-devops.yaml, src/devops_cli/roadmap/stores/listing_snapshot.py]- Chosen: Public repositories only. The cache Valkey has one password for all clients and no role ACL user, so a private key is readable by each client.
- Rejected: Every repository with the shared password. A private issue body would leave the boundary of its repository.
- What memory bound does the cache Valkey get?: Set
maxmemoryto 240mb and the container limit to 320Mi. The bound stays at three quarters of the limit, as the other Valkeys ofllmdo. (best practice) [sources: k8s/llm/valkey-devops.yaml]- Chosen: 240mb inside a 320Mi limit. The manifest records the three-quarters rule for the llm Valkeys (feat(ai): pinned image tags and bounded shared valkey in the llm stack #711), and 240mb keeps it.
- Rejected: 256mb inside a 320Mi limit. It puts the bound at 80% of the limit and breaks the three-quarters rule that the manifest states.
- Rejected: 96mb inside a 128Mi limit. The shared snapshot and the facts do not fit, and the evictions would grow.
- How does the store keep one snapshot in the shared tier?: Use one hash for each repository under
valkey:roadmap:v1:snapshot:<owner>/<name>. Themetafield holdsschema,full_atandwatermark. One zlib JSONIssueRecordfills each issue field. A read usesHSCAN COUNT 500. (best practice) [sources: src/devops_cli/roadmap/stores/listing_snapshot.py]- Chosen: One hash with one field for each issue. The 9.21 MB snapshot is over the 1 MiB value bound, and a hash holds each record under the bound.
- Rejected: One JSON value for the snapshot. The value is 9.21 MB, over the 1 MiB bound.
- Rejected: One key for each issue. A load of 4,615 keys costs 4,615 commands, and a hash reads 500 fields for each
HSCAN.
- How does the change cache the PyPI facts?: Put the fact cache on the same
TieredMapping, undervalkey:brain:v1:fact:pypi:<project>, with a TTL._read_pypireads through the mapping and opens a client only on a miss. (best practice) [sources: src/devops_cli/roadmap/alternatives.py, src/devops_cli/config/defaults.py]- Chosen: Shared mapping for the PyPI facts. Each round is a new process, so an in-process cache is cold at each start.
- Rejected: A per-process LRU only. Each pod starts with an empty LRU, and the same tools come back on many items.
Fit
Fits in one pull request.
Suspected block
None.
Activity
dan-petty commentedon Nov 11, 2026
Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.
perfprefix of the title gives the type.(roadmap)scope of the title gives the scope.It cuts roughly 11,000 GitHub requests per day but does not fix a broken feature or security gap.It removes most repeated listing and fact reads across intake pods, saving quota and wall-clock time.The body estimates about 220,000 tokens and 6 hours, covering a new TieredMapping, ValkeySnapshotStore, circuit-breaker logic, six tests, and config changes.Both share roadmap data in Valkey, but #4582 builds a per-item read model for the Service API while the candidate builds a shared listing snapshot and fact cache for CLI intake.devops-cli-service commentedon Nov 14, 2026
Alternatives check: not-applicable
Class: perf. The check makes no search and no model call for an item of this class.
Tool: none found
Checked on 2026-11-13. A person decides what this means for the item. The check changes no label and closes no issue.
devops-cli-service commentedon Nov 14, 2026
Refine cannot set this item to Ready at 0410772 while the items below stay open. The next refine round looks at the item again when they close, or when a person replies in a comment or edits the body.
The next refine round also looks at the item again when a commit on the default branch changes one of these files:
tests/support/fakes/valkey.py.devops-cli-service commentedon Nov 19, 2026
Next step: the stage job writes the plan of the item. See the section Proposed design of the body.
dan-petty commentedon Nov 19, 2026
This comment reports the live memory numbers of
valkey-devopsand four different memory targets for this item, and one scenario that asserts a manifest value.Live numbers (Prometheus, 2026-11-19 at about 14:50Z).
--maxmemory 96mband--maxmemory-policy allkeys-lru(k8s/llm/valkey-devops.yaml:81-82) and a 128Mi limit (:105).redis_config_maxmemory{job="valkey-devops"}is 100,663,296 (96 MiB).valkey-devops-87476c999-q5f8j(replaced on 2026-11-19T00:28Z by the image update of chore(deps): update valkey/valkey Docker tag to v9.1.4 #6344):max_over_time(redis_memory_used_bytes{job="valkey-devops"}[7d]): 100,636,856 bytes (95.97 MiB), at the bound.increase(redis_evicted_keys_total{job="valkey-devops"}[7d]): 3,600. Per 24 h window that ends at 14:54Z: 0 in each window to 2026-11-15, then 1,566 (to 11-16), 298 (to 11-17), 1,688 (to 11-18) and 50 (to 11-19).redis_keyspace_hits_total,redis_keyspace_misses_total): a hit ratio of 98.9 %.valkey-devops-5fb6cb5956-p5bgh(started 2026-11-19T00:28Z): 40.9 MiB in 2,871 keys, 0 evictions, a hit ratio of 95.0 % (54,525 hits, 2,879 misses) after a cold start.Assessment. The cache uses
allkeys-lru, so evictions at the bound are the design (manifest lines 6 and 66-70). An evicted key costs one more embedding request. 3,600 evictions a week against 909,932 hits is not a defect of the current cache. The bound matters for the shared snapshot and the tool facts that this item adds. Body line 17 is out of date: it says 36.16 MiB in 2,525 keys with 0 evictions, and it cites:74,98, which are now:81and:105.The targets do not agree.
openspec/specs/llm-valkey/spec.md:20requires--maxmemoryat most three quarters of the container limit forvalkey-devops.The owner decision of 2026-11-11 (#4624, decision 6) sets 256 MB. Only 256mb under 384Mi keeps that decision and the three-quarters rule. Before this item goes to Ready, use one target in this body, in #4624 (item 6 and the refined design) and in ADR 0023 line 134.
A scenario asserts a manifest value. Scenario "Manifest bound" (lines 143-145) reads
k8s/llm/valkey-devops.yamland assertsmaxmemory240mb and the 320Mi limit.docs/TESTING.md:61-62forbid a test that asserts a value of a manifest, and thetest-treerow refuses one (tests/gate/tree_checks/config_values.py). This body was refined on 2026-11-14, before #6080 changed the plan rules on 2026-11-17. Give the requirement a validator command or a live check as its proof, in the form of #6080 and #6083. An example of a live check isredis_config_maxmemory{job="valkey-devops"}after the rollout.dan-petty commentedon Nov 21, 2026
Decided memory target of this item, in pull request #6583:
valkey-devopsstarts valkey-server with--maxmemory 256mbunder a container memory limit of384Mi.openspec/specs/llm-valkey/spec.mdthat--maxmemoryis at most three quarters of the limit.This target replaces the numbers in the bodies: 240mb/320Mi (the refined design of this item) and 256MB/320Mi (#4624 item 6). The bodies stay as they are.
Live check after the Argo CD sync: the Deployment runs
--maxmemory 256mbwith the limit384Mi, andredis_config_maxmemory{job="valkey-devops"}is 268435456.dan-petty commentedon Nov 21, 2026
Live check of the memory bound after the merge of PR #6583 (b2a277b). Argo CD synced Application
llmat 2026-11-21T04:43:29Z. Read only, on 2026-11-21 at about 06:00Z.valkey-devops--maxmemory 256mb --maxmemory-policy allkeys-lru384Miredis_config_maxmemory{job="valkey-devops"}redis_memory_used_bytes{job="valkey-devops"}increase(redis_evicted_keys_total{job="valkey-devops"}[1h])The pod moved to another node at 05:44Z (the old pod exited with code 0), so the cache started empty then.
Still open, for a person: the drill of the acceptance criteria (
valkey-devopsat 0 replicas for 10 minutes, no job fails, anddevops_cli_brain_reads_total{result="fallback"}rises). A manual scale-down needs the self-heal of Argo CD for that Application paused first.A second review after the merge found 9 defects of the shared snapshot on main; a follow-up item will hold them.
devops-cli-service commentedon Nov 21, 2026
Released in v0.187.0: https://github.com/dan-petty/devops-cli/releases/tag/v0.187.0
devops-cli-service commentedon Nov 21, 2026
Live since 2026-11-21 06:24 UTC
fix(roadmap): Correct visibility, keys and bounds of Valkey caches (#…