Skip to content

perf(roadmap): share the listing snapshot and tool facts in Valkey #4668

Closed

Description

@dan-petty

Problem or Motivation

  • After feat(roadmap): run intake and scoped intake in their own pods #4567, each intake pod has an emptyDir home. 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_pypi opens 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): a MutableMapping over an in-process LRU and ValkeyCacheTier, with a key prefix, json or json+zlib values, a TTL, a 1 MiB bound, and the read and error counters.
  • ValkeyCacheTier gets hget, hset, hscan, expire, unlink and a WATCH helper behind its circuit breaker.
  • ValkeySnapshotStore and TieredSnapshotStore behind the SnapshotStore seam of perf(roadmap): intake reads only the issues that changed #4552:
    • key valkey:roadmap:v1:snapshot:<owner>/<name>: a hash with the field meta (schema, full_at, watermark) and one zlib JSON IssueRecord for each issue; TTL 7 days; read with HSCAN 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.
  • 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-devops has role ACL users.
  • valkey-devops: maxmemory from 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} and devops_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 show fallback.
    • 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, counts fallback, 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-devops at 0 replicas for 10 minutes; no job fails, and the fallback share shows in Prometheus.

Dependencies

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_server fake
  • 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 yaml runs
  • THEN the output holds --maxmemory 240mb and memory: 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-devops runs one replica in namespace llm. It requires a password, keeps caches only, and drops the least recently used key at maxmemory 96mb inside a 128Mi limit. Its NetworkPolicy admits only namespace devops and the metrics scrapers. The client is ValkeyClient in src/devops_cli/valkey/client.py. tests/support/fakes/valkey.py gives 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 the ValkeyClient seam. 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).
  • Which seam does the shared snapshot store take?: Implement ValkeySnapshotStore and TieredSnapshotStore behind the existing SnapshotStore protocol. The callers of intake_listing and lane_listing then change nothing. (best practice) [sources: src/devops_cli/roadmap/stores/listing_snapshot.py]
    • Chosen: Implement the SnapshotStore protocol. The protocol holds load and save, and IncrementalListing holds 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.
  • 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_at and watermark, and a stale writer must not replace a newer copy.
    • Rejected: A SET NX lock 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.
  • 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: pybreaker with 0.25 s and 2 s timeouts. pybreaker is 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.
  • Which repositories may write to the shared tier?: Public repositories only, until valkey-devops has 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 maxmemory to 240mb and the container limit to 320Mi. The bound stays at three quarters of the limit, as the other Valkeys of llm do. (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>. The meta field holds schema, full_at and watermark. One zlib JSON IssueRecord fills each issue field. A read uses HSCAN 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, under valkey:brain:v1:fact:pypi:<project>, with a TTL. _read_pypi reads 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.

Dependencies

#4557

Activity

  1. added
    source/agent
    on Nov 11, 2026
  2. added
    type/infra
    scope/roadmap
    status/new
    value/high
    effort/high
    on Nov 11, 2026
  3. dan-petty commented on Nov 11, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/infra. The perf prefix of the title gives the type.
    • Scope: scope/roadmap. The (roadmap) scope of the title gives the scope.
    • Priority: P2-Medium. It cuts roughly 11,000 GitHub requests per day but does not fix a broken feature or security gap.
    • Value: High. It removes most repeated listing and fact reads across intake pods, saving quota and wall-clock time.
    • Effort: High. The body estimates about 220,000 tokens and 6 hours, covering a new TieredMapping, ValkeySnapshotStore, circuit-breaker logic, six tests, and config changes.
    • Related: feat(service): keep a Valkey read model of each item #4582, which asks for a different change. 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.
  4. added
    priority/p2-medium
    on Nov 11, 2026
  5. devops-cli-service commented on Nov 14, 2026

    @devops-cli-service
    Contributor

    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.

  6. devops-cli-service commented on Nov 14, 2026

    @devops-cli-service
    Contributor

    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.

  7. added
    status/ready
    and removed
    status/new
    on Nov 19, 2026
  8. devops-cli-service commented on Nov 19, 2026

    @devops-cli-service
    Contributor

    Next step: the stage job writes the plan of the item. See the section Proposed design of the body.

  9. dan-petty commented on Nov 19, 2026

    @dan-petty
    OwnerAuthor

    This comment reports the live memory numbers of valkey-devops and 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).

    • The manifest sets --maxmemory 96mb and --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).
    • Old pod 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):
      • Peak 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).
      • Keyspace hits 909,932 and misses 10,464 in 7 d (redis_keyspace_hits_total, redis_keyspace_misses_total): a hit ratio of 98.9 %.
    • New pod 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 :81 and :105.

    The targets do not agree. openspec/specs/llm-valkey/spec.md:20 requires --maxmemory at most three quarters of the container limit for valkey-devops.

    Source maxmemory Limit Bound / limit
    ADR 0023 line 134 256 MB not given not known
    #4624 body item 6 (line 37), and this body line 17 256 MB 320Mi 80 %, breaks the rule
    #4624 refined design: requirement "The shared cache tier keeps its data bound below its limit" and key question "What are the limits of valkey-devops?" 256mb 384Mi 67 %
    This body: requirement "Cache Valkey memory bound" and its key question (lines 140-145, 175-178) 240mb 320Mi 75 %

    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.yaml and asserts maxmemory 240mb and the 320Mi limit. docs/TESTING.md:61-62 forbid a test that asserts a value of a manifest, and the test-tree row 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 is redis_config_maxmemory{job="valkey-devops"} after the rollout.

  10. added
    owner/agent
    status/in-progress
    and removed
    status/ready
    on Nov 21, 2026
  11. dan-petty commented on Nov 21, 2026

    @dan-petty
    OwnerAuthor

    Decided memory target of this item, in pull request #6583: valkey-devops starts valkey-server with --maxmemory 256mb under a container memory limit of 384Mi.

    • 256 MiB keeps decision 6 of feat(roadmap): track the project brain #4624 (256 MB).
    • 256 MiB is two thirds of 384Mi, so it keeps the rule of openspec/specs/llm-valkey/spec.md that --maxmemory is 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 256mb with the limit 384Mi, and redis_config_maxmemory{job="valkey-devops"} is 268435456.

  12. removed
    status/in-progress
    owner/agent
    on Nov 21, 2026
  13. dan-petty commented on Nov 21, 2026

    @dan-petty
    OwnerAuthor

    Live check of the memory bound after the merge of PR #6583 (b2a277b). Argo CD synced Application llm at 2026-11-21T04:43:29Z. Read only, on 2026-11-21 at about 06:00Z.

    Check Value Expected Result
    Container command of valkey-devops --maxmemory 256mb --maxmemory-policy allkeys-lru 256mb pass
    Memory limit of the container 384Mi 384Mi pass
    redis_config_maxmemory{job="valkey-devops"} 268,435,456 268,435,456 (256 MiB) pass
    redis_memory_used_bytes{job="valkey-devops"} 1,238,888 below the bound pass
    increase(redis_evicted_keys_total{job="valkey-devops"}[1h]) 0 - -

    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-devops at 0 replicas for 10 minutes, no job fails, and devops_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.

  14. devops-cli-service commented on Nov 21, 2026

    @devops-cli-service
    Contributor
  15. devops-cli-service commented on Nov 21, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-21 06:24 UTC

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/highpriority/p2-mediumscope/roadmapsource/agenttype/infravalue/high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions