From 37e724d05057cfba2a7eef02dbcaa6461a3b2708 Mon Sep 17 00:00:00 2001 From: Daniel Petty Date: Thu, 29 Oct 2026 00:38:35 +0000 Subject: [PATCH 1/3] perf(roadmap): intake's embeddings are cached in a password-protected Valkey in the cluster Each round of the roadmap Service and each cluster job is a new process, so intake embedded every item of the roadmap again on each run: the devops ConfigMap named no Valkey, and `valkey.url` fell back to a localhost address that no pod serves. - `k8s/llm/valkey-devops.yaml`: a new Valkey for devops-cli's caches in the cluster (the embeddings and the threat-intelligence reads). It requires the password of Secret `llm/valkey-devops-auth`, keeps at most 96 MiB under a 128Mi limit, writes no RDB or AOF, and evicts the least recently used key at the bound. Its policy admits namespace `devops` on 6379 and `monitoring` on 9121, with no egress. - The shared cache Valkey runs with noeviction for Open WebUI's state, so it can't hold a cache that must evict. - The devops ConfigMap sets `valkey.url` to the new Valkey, and `devops-default-perimeter` lets namespace `devops` reach `llm` on 6379. - Secret `devops/devops-cli` carries `DEVOPS_CLI_VALKEY_PASSWORD`, the variable of `valkey.password`, from the keyring-only entry `valkey_devops_password` that `llm/valkey-devops-auth` uses too. - deploy-stack applies the manifest, the Argo CD project ignores the pushed Secret, and `k8s/README.md` describes both. --- k8s/README.md | 8 + k8s/argocd/apps/projects.yaml | 3 + k8s/devops/configmap.example.yaml | 5 + k8s/devops/networkpolicy.yaml | 10 +- k8s/llm/kustomization.yaml | 1 + k8s/llm/networkpolicy.yaml | 1 + k8s/llm/valkey-devops.yaml | 213 ++++++++++++++++++ .../.openspec.yaml | 2 + .../1655-intake-embedding-valkey/design.md | 26 +++ .../1655-intake-embedding-valkey/proposal.md | 42 ++++ .../specs/llm-valkey/spec.md | 50 ++++ .../1655-intake-embedding-valkey/tasks.md | 25 ++ .../commands/k8s/stack_lifecycle.py | 1 + src/devops_cli/k8s/cluster_secrets.py | 29 +++ tests/test_k8s_devops_runtime.py | 2 +- tests/test_k8s_llm_gateway.py | 4 +- tests/test_k8s_monitoring_integration.py | 1 + tests/test_k8s_push_secrets.py | 65 +++++- tests/test_k8s_qdrant_security.py | 1 + tests/test_k8s_valkey_stack.py | 146 ++++++++++++ tests/test_roadmap_intake.py | 57 +++++ 21 files changed, 679 insertions(+), 13 deletions(-) create mode 100644 k8s/llm/valkey-devops.yaml create mode 100644 openspec/changes/1655-intake-embedding-valkey/.openspec.yaml create mode 100644 openspec/changes/1655-intake-embedding-valkey/design.md create mode 100644 openspec/changes/1655-intake-embedding-valkey/proposal.md create mode 100644 openspec/changes/1655-intake-embedding-valkey/specs/llm-valkey/spec.md create mode 100644 openspec/changes/1655-intake-embedding-valkey/tasks.md diff --git a/k8s/README.md b/k8s/README.md index d27c3be9d9..c5f5fdb260 100644 --- a/k8s/README.md +++ b/k8s/README.md @@ -85,6 +85,10 @@ kubectl -n llm port-forward svc/qdrant 6333:6333 # Valkey In-Memory Cache: Open WebUI's state. It requires the password of llm/valkey-auth (see Cluster Secrets). kubectl -n llm exec -it svc/valkey -c valkey -- sh -c 'VALKEYCLI_AUTH="$VALKEY_PASSWORD" valkey-cli ping' +# devops-cli's cache Valkey: the embeddings and threat-intelligence reads of the Service and the cluster jobs. +# It requires the password of llm/valkey-devops-auth (see Cluster Secrets). +kubectl -n llm exec -it svc/valkey-devops -c valkey -- sh -c 'VALKEYCLI_AUTH="$VALKEY_PASSWORD" valkey-cli ping' + # Valkey Run Index (Argo CD's `llm` Application deploys it on the homelab; `devops k8s deploy-stack --stack llm` deploys it on either cluster; see Cluster Secrets for its password): # benchmark and evaluation runs shared by workstations. Its password Secret comes from the keyring (see Cluster Secrets), # then point devops-cli at it through its NodePort. @@ -183,6 +187,8 @@ The cache Valkey's policy `valkey-perimeter` (`llm/valkey.yaml`) admits Open Web The cache Valkey keeps at most 1536 MiB of data (`--maxmemory`), three quarters of its 2048Mi limit. The rest of the limit holds fragmentation and Valkey's own overhead. At the bound, Valkey refuses writes and evicts no key (`--maxmemory-policy noeviction`). Open WebUI keeps its session pools and token revocations there, and an evicted revocation makes a signed-out token valid again. The run index (`llm/valkey-runs.yaml`) uses the same policy with a bound of 512 MiB. +devops-cli's cache Valkey (`llm/valkey-devops.yaml`) holds the caches of the roadmap Service and the cluster jobs: the embeddings that `EmbeddingsEngine` writes, and the threat-intelligence reads. Each round of the Service and each job is a new process with an empty memory cache, so without it intake embeds every item of the roadmap again on each round. The devops ConfigMap names it in `valkey.url`, and its password reaches the pods from `devops/devops-cli` as `DEVOPS_CLI_VALKEY_PASSWORD`, the variable of `valkey.password`. Its policy `valkey-devops-perimeter` admits namespace `devops` on TCP 6379 and the `monitoring` namespace on the exporter port 9121, and allows no egress. `llm-default-perimeter` leaves its pods out, and `devops-default-perimeter` lets namespace `devops` reach namespace `llm` on 6379 beside the gateway's 4000. It keeps at most 96 MiB of data, three quarters of its 128Mi limit, writes no RDB or AOF, and at the bound evicts the least recently used key (`--maxmemory-policy allkeys-lru`): an evicted key costs one more embedding request. It can't share the cache Valkey, which must not evict Open WebUI's state. + Qdrant requires the key of `llm/qdrant-api-key` (see Cluster Secrets) on every REST and gRPC request. Only `/`, `/healthz`, `/readyz`, `/livez` and the files of its web UI need no key. The qdrant container reads the key as `QDRANT__SERVICE__API_KEY` through `env` in `llm/values-qdrant.yaml`. Open WebUI is the only workload under `k8s/` that names the Qdrant Service, and it sends the key as `QDRANT_API_KEY`. Alloy scrapes `/metrics` with the key as a bearer token, and devops-cli sends keyring `qdrant_api_key`, which the push keeps equal to the Secret. `tests/test_k8s_qdrant_security.py` fails on a top-level key of `llm/values-qdrant.yaml` that the pinned chart (`tests/fixtures/charts/qdrant/`) does not declare, because Helm drops such a key with no error. Every tier runs ollama as UID and GID 10001, which no host login account uses, with RuntimeDefault seccomp, no privilege escalation, all capabilities dropped and a read-only root filesystem; `/tmp` is an emptyDir. `HOME` is `/home/ollama`, so the key and `models/` stay in the hostPath `/var/lib/ollama` on each GPU node, mounted at `/home/ollama/.ollama`. `fsGroup` does not apply to a hostPath volume, so the initContainer `own-model-directory` gives that directory to 10001 at every start (`chown -R`). It runs as root with `CAP_CHOWN` alone, no privilege escalation and a read-only root filesystem, and exits before ollama starts. It is the one exception to kube-linter's `run-as-non-root` in `ollama-profiles.yaml`, recorded in the manifest's header rather than suppressed with an ignore annotation. @@ -502,11 +508,13 @@ Every Secret the stacks read comes from the workstation's OS keyring. `devops k8 | `llm/qdrant-api-key` | `api-key` | keyring `qdrant_api_key` | yes | adopt the live value; else generate `token_urlsafe(32)` | llm | `statefulset/qdrant`, `statefulset/open-webui` | | `llm/valkey-runs-auth` | `password` | keyring `runs_index_password` | yes | adopt the live value; else generate 64 hex | llm | `deployment/valkey-runs` | | `llm/valkey-auth` | `VALKEY_PASSWORD` | keyring `valkey_password` | yes | adopt the live value; else generate 64 hex | llm | `deployment/valkey`, `statefulset/open-webui` | +| `llm/valkey-devops-auth` | `password` | keyring `valkey_devops_password` | yes | adopt the live value; else generate 64 hex | llm | `deployment/valkey-devops` | | `cloudflared/cloudflared-token` | `token` | keyring `cloudflare_tunnel_token` | no | adopt the live value; else skip with a warning | base | `deployment/cloudflared` | | `devops/devops-cli` | `DEVOPS_CLI_SERVICE_GITHUB_APP_PRIVATE_KEY` | keyring `service_github_app_private_key` | yes | adopt the live value; else fail | devops | `deployment/roadmap-service` | | `devops/devops-cli` | `DEVOPS_CLI_AI_API_KEY` | keyring `llm_gateway_master_key` | yes | adopt from `llm/llm-gateway-secrets master-key`; else fail | devops | `deployment/roadmap-service` | | `devops/devops-cli` | `DEVOPS_CLI_SERVICE_WEBHOOK_SECRETS` | keyring `service_webhook_secrets` | no | adopt the live value; else skip with a warning | devops | `deployment/roadmap-service` | | `devops/devops-cli` | `DEVOPS_CLI_FIRECRAWL_API_KEY` | keyring `firecrawl_api_key` | no | adopt the live value; else skip with a warning | devops | `deployment/roadmap-service` | +| `devops/devops-cli` | `DEVOPS_CLI_VALKEY_PASSWORD` | keyring `valkey_devops_password` | yes | adopt from `llm/valkey-devops-auth password`; else generate 64 hex | devops | `deployment/roadmap-service` | | `monitoring/grafana-admin` | `admin-user` | literal | yes | fail | infra | `deployment/grafana` | | `monitoring/grafana-admin` | `admin-password` | keyring `grafana_password` | yes | adopt from `monitoring/grafana admin-password`; else generate `token_urlsafe(32)` | infra | `deployment/grafana` | | `gitea/gitea-admin` | `username` | literal | yes | fail | gitea | `deployment/gitea` | diff --git a/k8s/argocd/apps/projects.yaml b/k8s/argocd/apps/projects.yaml index c691945a50..99a156c097 100644 --- a/k8s/argocd/apps/projects.yaml +++ b/k8s/argocd/apps/projects.yaml @@ -61,6 +61,9 @@ spec: - group: '' kind: Secret name: valkey-auth + - group: '' + kind: Secret + name: valkey-devops-auth - group: '' kind: Secret name: devops-cli diff --git a/k8s/devops/configmap.example.yaml b/k8s/devops/configmap.example.yaml index 6efcd33ee1..959ee91dfc 100644 --- a/k8s/devops/configmap.example.yaml +++ b/k8s/devops/configmap.example.yaml @@ -28,6 +28,11 @@ data: model: devops-background embedding: model: qwen3-embedding:0.6b + # devops-cli's cache Valkey in namespace llm (llm/valkey-devops.yaml): the embedding cache + # and the threat-intelligence cache. Its password reaches the pod from Secret devops-cli as + # DEVOPS_CLI_VALKEY_PASSWORD, never from this ConfigMap. + valkey: + url: valkey://valkey-devops.llm.svc.cluster.local:6379/0 telemetry: enabled: true endpoint: http://otel-collector-opentelemetry-collector.otel.svc.cluster.local:4318 diff --git a/k8s/devops/networkpolicy.yaml b/k8s/devops/networkpolicy.yaml index d7dec564fe..4317d8a48d 100644 --- a/k8s/devops/networkpolicy.yaml +++ b/k8s/devops/networkpolicy.yaml @@ -1,4 +1,4 @@ -# Cluster jobs accept no ingress. They reach DNS, the LLM gateway, the OpenTelemetry collector and public HTTPS (GitHub). +# Cluster jobs accept no ingress. They reach DNS, the LLM gateway, their cache Valkey, the OpenTelemetry collector and public HTTPS (GitHub). apiVersion: networking.k8s.io/v1 kind: NetworkPolicy metadata: @@ -22,8 +22,10 @@ spec: port: 53 - protocol: TCP port: 53 - # 2. The LLM gateway. A namespace-selector-only peer with `ports:`, the shape the monitoring - # policy relies on: kube-router refused a namespace+pod selector peer paired with `ports:`. + # 2. The LLM gateway (4000) and devops-cli's cache Valkey, valkey-devops (6379), in namespace + # llm. A namespace-selector-only peer with `ports:`, the shape the monitoring policy relies + # on: kube-router refused a namespace+pod selector peer paired with `ports:`. Each target's + # own policy admits only the pods it serves. - to: - namespaceSelector: matchLabels: @@ -31,6 +33,8 @@ spec: ports: - protocol: TCP port: 4000 + - protocol: TCP + port: 6379 # 3. OpenTelemetry collector in namespace otel, on its OTLP/HTTP port only: devops-cli sends no # OTLP over gRPC (4317). - to: diff --git a/k8s/llm/kustomization.yaml b/k8s/llm/kustomization.yaml index e1c2a28924..6792122c48 100644 --- a/k8s/llm/kustomization.yaml +++ b/k8s/llm/kustomization.yaml @@ -5,6 +5,7 @@ resources: - networkpolicy.yaml - valkey.yaml - valkey-runs.yaml + - valkey-devops.yaml - profiles - gateway - gateway/servicemonitor.yaml diff --git a/k8s/llm/networkpolicy.yaml b/k8s/llm/networkpolicy.yaml index 8d0124ab27..c1dd79e710 100644 --- a/k8s/llm/networkpolicy.yaml +++ b/k8s/llm/networkpolicy.yaml @@ -15,6 +15,7 @@ spec: - portkey - valkey - valkey-runs + - valkey-devops policyTypes: - Ingress - Egress diff --git a/k8s/llm/valkey-devops.yaml b/k8s/llm/valkey-devops.yaml new file mode 100644 index 0000000000..5e7623bf80 --- /dev/null +++ b/k8s/llm/valkey-devops.yaml @@ -0,0 +1,213 @@ +# Valkey that devops-cli's Service and cluster jobs in namespace devops use as their cache (#1655): +# the embeddings of the texts they embed and their threat-intelligence reads. A settled roadmap +# item then costs no embedding request on the next round, though each round and each job is a +# new process with an empty memory cache. +# +# It holds caches only. It keeps no file, evicts the least recently used key at its bound, and +# starts empty after a restart. The cache Valkey of Open WebUI (valkey.yaml) keeps its state with +# noeviction, so it can't also hold a cache that must evict. Valkey requires a password, which +# comes from the keyring: `devops k8s push-secrets --only llm/valkey-devops-auth --only +# devops/devops-cli` writes it to Secret valkey-devops-auth and to Secret devops/devops-cli, +# generating one the first time. The policy valkey-devops-perimeter admits only namespace devops +# and the metrics scrapers. +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: valkey-devops + namespace: llm + labels: + app.kubernetes.io/name: valkey-devops + app.kubernetes.io/part-of: devops-cli-stack +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/name: valkey-devops + template: + metadata: + annotations: + prometheus.io/scrape: "true" + prometheus.io/port: "9121" + k8s.grafana.com/metrics.container: redis-exporter + labels: + app.kubernetes.io/name: valkey-devops + app.kubernetes.io/part-of: devops-cli-stack + spec: + automountServiceAccountToken: false + securityContext: + runAsNonRoot: true + runAsUser: 1000 + runAsGroup: 1000 + fsGroup: 1000 + seccompProfile: + type: RuntimeDefault + + containers: + - name: valkey + image: valkey/valkey:9.1.2-alpine + imagePullPolicy: IfNotPresent + securityContext: + allowPrivilegeEscalation: false + readOnlyRootFilesystem: true + capabilities: + drop: + - ALL + # The password goes into a config file on a memory volume rather than onto the command + # line, where it would show in the process list. + # + # Valkey keeps at most 96 MiB of data, three quarters of the 128Mi limit, as the other + # Valkeys of llm do (#711). One embedding of qwen3-embedding:0.6b is about 20 KB of JSON, + # so the bound holds about 4,800 of them, many times the open and closed issues that a + # roadmap run embeds. At the bound Valkey evicts the least recently used key: a key it + # evicts costs one more embedding request, not a lost state. + command: + - sh + - -c + - >- + umask 077 && + printf 'requirepass "%s"\n' "$VALKEY_PASSWORD" > /run/valkey/auth.conf && + exec valkey-server /run/valkey/auth.conf + --save "" + --appendonly no + --dir /data + --maxmemory 96mb + --maxmemory-policy allkeys-lru + env: + - name: VALKEY_PASSWORD + valueFrom: + secretKeyRef: + name: valkey-devops-auth + key: password + volumeMounts: + - name: valkey-data + mountPath: /data + - name: valkey-tmp + mountPath: /tmp + - name: config + mountPath: /run/valkey + ports: + - name: valkey + containerPort: 6379 + resources: + requests: + cpu: 20m + memory: 32Mi + limits: + cpu: 500m + memory: 128Mi + livenessProbe: + tcpSocket: + port: 6379 + initialDelaySeconds: 5 + periodSeconds: 10 + readinessProbe: + tcpSocket: + port: 6379 + initialDelaySeconds: 5 + periodSeconds: 5 + - name: redis-exporter + image: ghcr.io/oliver006/redis_exporter:v1.93.0 + imagePullPolicy: IfNotPresent + securityContext: + allowPrivilegeEscalation: false + readOnlyRootFilesystem: true + runAsNonRoot: true + capabilities: + drop: + - ALL + env: + - name: REDIS_ADDR + value: redis://localhost:6379 + - name: REDIS_PASSWORD + valueFrom: + secretKeyRef: + name: valkey-devops-auth + key: password + - name: REDIS_EXPORTER_WEB_LISTEN_ADDRESS + value: 0.0.0.0:9121 + ports: + - name: metrics + containerPort: 9121 + protocol: TCP + resources: + requests: + cpu: 10m + memory: 16Mi + limits: + cpu: 100m + memory: 64Mi + livenessProbe: + httpGet: + path: /metrics + port: 9121 + initialDelaySeconds: 5 + periodSeconds: 10 + readinessProbe: + httpGet: + path: /metrics + port: 9121 + initialDelaySeconds: 5 + periodSeconds: 5 + volumes: + - name: valkey-data + emptyDir: {} + - name: valkey-tmp + emptyDir: {} + - name: config + emptyDir: + medium: Memory + sizeLimit: 1Mi +--- +apiVersion: v1 +kind: Service +metadata: + name: valkey-devops + namespace: llm + labels: + app.kubernetes.io/name: valkey-devops + app.kubernetes.io/part-of: devops-cli-stack +spec: + type: ClusterIP + selector: + app.kubernetes.io/name: valkey-devops + ports: + - name: valkey + port: 6379 + targetPort: 6379 +--- +apiVersion: networking.k8s.io/v1 +kind: NetworkPolicy +metadata: + name: valkey-devops-perimeter + namespace: llm + labels: + app.kubernetes.io/name: valkey-devops + app.kubernetes.io/part-of: devops-cli-stack +spec: + podSelector: + matchLabels: + app.kubernetes.io/name: valkey-devops + policyTypes: + - Ingress + - Egress + ingress: + # devops-cli's Service and cluster jobs are the only clients (k8s/devops/configmap.example.yaml). + # A namespace-selector-only peer with `ports:`, the shape kube-router enforces. + - from: + - namespaceSelector: + matchLabels: + kubernetes.io/metadata.name: devops + ports: + - protocol: TCP + port: 6379 + # Alloy scrapes the redis-exporter sidecar. + - from: + - namespaceSelector: + matchLabels: + kubernetes.io/metadata.name: monitoring + ports: + - protocol: TCP + port: 9121 + # No egress: Valkey only answers, and the exporter reaches it on localhost. + egress: [] diff --git a/openspec/changes/1655-intake-embedding-valkey/.openspec.yaml b/openspec/changes/1655-intake-embedding-valkey/.openspec.yaml new file mode 100644 index 0000000000..5c99d6d744 --- /dev/null +++ b/openspec/changes/1655-intake-embedding-valkey/.openspec.yaml @@ -0,0 +1,2 @@ +schema: spec-driven +created: 2026-10-29 diff --git a/openspec/changes/1655-intake-embedding-valkey/design.md b/openspec/changes/1655-intake-embedding-valkey/design.md new file mode 100644 index 0000000000..44a8ec1ca2 --- /dev/null +++ b/openspec/changes/1655-intake-embedding-valkey/design.md @@ -0,0 +1,26 @@ +# Design + +## Decisions + +### A dedicated Valkey for devops-cli's caches + +The Service and the cluster jobs get their own Valkey, `valkey-devops`, in namespace `llm` beside the other two Valkeys, as the issue recommends. + +- It evicts the least recently used key at its bound (`allkeys-lru`). Each key it holds is a cache entry that the next request rebuilds. +- Its perimeter admits only namespace `devops` on 6379, so no pod in `llm` writes the vectors that pick intake's duplicate shortlist, and no pod in `devops` reaches Open WebUI's state. +- It holds 96 MiB under a 128Mi limit, three quarters as the other Valkeys of `llm` do (#711). One embedding of `qwen3-embedding:0.6b` is about 20 KB of JSON, so it holds about 4,800, many times what a roadmap run embeds. + +Rejected alternatives: + +- **Admit namespace `devops` to the shared cache Valkey (`valkey`).** It runs with `--maxmemory-policy noeviction` because an evicted token revocation of Open WebUI makes a signed-out token valid again (`k8s/llm/valkey.yaml`). A cache that grows with each embedded text would fill it, and Valkey would then refuse Open WebUI's writes. One password would also let each side write the other's keys. +- **Valkey ACL users on the shared Valkey.** An ACL keeps the key spaces apart, but not the memory: the embeddings would still fill the bound that Open WebUI needs. +- **The run index (`valkey-runs`).** It keeps its data in an append-only file and evicts nothing, for runs that are the source of truth for every workstation. A cache there would fill it. +- **A Valkey in namespace `devops`.** It would need its own ingress rule in a namespace whose perimeter admits no ingress, its own Alloy scrape rule, and a third place for Valkey manifests. Namespace `llm` already holds the Valkeys, their image pins and their scrape path. + +### The password reaches the pods as `valkey.password` + +Secret `devops/devops-cli` gains `DEVOPS_CLI_VALKEY_PASSWORD`, the variable that `valkey.password` reads, so the pods need no new setting. Both Secrets take their value from one keyring-only entry, `valkey_devops_password`, because a workstation's own `valkey.password` belongs to the Valkey that its `valkey.url` names. The devops entry adopts the live value of `llm/valkey-devops-auth`, as `DEVOPS_CLI_AI_API_KEY` adopts the gateway key, and either entry generates the value on a first push, so `--stack devops` alone and `--stack llm` alone each work. + +### Workstations + +A workstation keeps its own `valkey.url`. The new Valkey has no NodePort, and the perimeter admits only namespace `devops`. A person who wants a workstation's intake to share it can reach it with `kubectl port-forward`, which no policy limits, and give its password as `valkey.password`; the change does not set that up. diff --git a/openspec/changes/1655-intake-embedding-valkey/proposal.md b/openspec/changes/1655-intake-embedding-valkey/proposal.md new file mode 100644 index 0000000000..35f1184683 --- /dev/null +++ b/openspec/changes/1655-intake-embedding-valkey/proposal.md @@ -0,0 +1,42 @@ +# Proposal + +## Why + +Issue #1655: the roadmap Service and the cluster jobs run intake, and intake embeds the comparison set (the open items and the issues closed as not planned) and each checked candidate on every run. Each Service round and each cluster job is a new process, so the in-memory cache of `EmbeddingsEngine` starts empty, and a roadmap that did not change costs the same embedding requests on every round. The embedder already has a Valkey tier, but no Valkey in the cluster serves namespace `devops`: the ConfigMap names none, so `valkey.url` falls back to `valkey://localhost:6379/0`, which no pod serves. + +## What Changes + +- A new Valkey in namespace `llm`, `valkey-devops` (`k8s/llm/valkey-devops.yaml`), holds devops-cli's caches for the Service and the cluster jobs: the embeddings that `EmbeddingsEngine` writes and the threat-intelligence reads, the two users of `valkey.url` in a pod. It requires a password from Secret `llm/valkey-devops-auth`, keeps at most 96 MiB of data under a 128Mi limit, writes no RDB or AOF, and at the bound evicts the least recently used key. A redis-exporter sidecar serves its metrics. +- Its policy `valkey-devops-perimeter` admits namespace `devops` on TCP 6379 and namespace `monitoring` on 9121, and allows no egress. `llm-default-perimeter` leaves its pods out, and `devops-default-perimeter` lets namespace `devops` reach namespace `llm` on 6379 beside the gateway's 4000. +- The devops ConfigMap template sets `valkey.url` to `valkey://valkey-devops.llm.svc.cluster.local:6379/0` and holds no password. +- The cluster secret table gains `llm/valkey-devops-auth` (`password`) and the key `DEVOPS_CLI_VALKEY_PASSWORD` of `devops/devops-cli`, the variable of `valkey.password`. Both come from the keyring-only entry `valkey_devops_password`. The devops key adopts the live value of `llm/valkey-devops-auth` when the keyring lacks it, and either entry generates 64 hex on a first push. +- `deploy-stack --stack llm` applies the new manifest, and the Argo CD project ignores Secret `valkey-devops-auth` as an orphan, as it ignores the other pushed Secrets. +- `k8s/README.md` lists the two Secret rows, the command to ping the new Valkey, and its perimeter and memory bound. +- A manifest and a policy are observable, so the change carries a delta in `llm-valkey`: the noeviction requirement now names the cache Valkey and the run index, and new requirements cover the devops cache Valkey and intake's embeddings across runs. +- This change fits one pull request. + +## Capabilities + +### Modified Capabilities + +- `llm-valkey`: the noeviction rule names the two Valkeys that must not evict, and devops-cli's cache Valkey evicts, requires its password, admits only namespace `devops`, and keeps intake's embeddings across runs. + +## Impact + +- `k8s/llm/valkey-devops.yaml` (new), `k8s/llm/kustomization.yaml`, `k8s/llm/networkpolicy.yaml`, `k8s/devops/networkpolicy.yaml`, `k8s/devops/configmap.example.yaml`, `k8s/argocd/apps/projects.yaml`, `k8s/README.md`. +- `src/devops_cli/k8s/cluster_secrets.py`, `src/devops_cli/commands/k8s/stack_lifecycle.py`. +- Tests: `tests/test_k8s_valkey_stack.py`, `tests/test_roadmap_intake.py`, and the tests that pin the secret table, the policies, the deploy-stack manifests and the Helm-namespace exemptions. + +## Feasibility + +Checked on `origin/main` f9493fa4 (2026-10-29): + +- Intake embeds through `GatewayIntakeModel._embedder`, an `EmbeddingsEngine` with the default Valkey tier, which `configured_cache_tier(load_settings())` builds from `valkey.url` and `valkey.password` (`src/devops_cli/roadmap/intake_model.py`, `src/devops_cli/ai/rag/embeddings.py`, `src/devops_cli/valkey/cache.py`). The tier keeps each vector for 7 days (`DEFAULT_VALKEY_EMBEDDING_TTL_SECONDS`). +- `valkey.password` is a managed credential whose variable is `DEVOPS_CLI_VALKEY_PASSWORD` (`src/devops_cli/config/env.py`), and the Service and the CronJob load Secret `devops-cli` with `envFrom`. +- The issue's premise about the shared Valkey changed: `k8s/llm/valkey.yaml` now requires the password of `llm/valkey-auth` (#1654), and only Open WebUI reaches it. It runs with `--maxmemory-policy noeviction`, because Open WebUI keeps its session pools and token revocations there, so it can't hold a cache that must evict. +- Measured offline with the new test, which counts the gateway's `/v1/embeddings` requests at the HTTP edge (`stub_web`): two plan runs over the same two settled items and one candidate, each with a new `EmbeddingsEngine`, send `[1, 1]` requests with no Valkey and `[1, 0]` with one Valkey shared by the runs. A run sends one batch request for all its texts while they fit one batch, so without the cache each round costs as many batch requests as the roadmap fills; with it, a round over settled items costs none. +- #1562 and #1647 are closed, so the Service can run again as the GitHub App. + +## Existing Tool Considered + +Valkey, the project's key-value store, with its own `requirepass` and `allkeys-lru` eviction, and the embedder's existing Valkey tier. The change adds a manifest, a policy rule, a ConfigMap key and two Secret entries, and builds no code. It deletes nothing: the client side already exists. diff --git a/openspec/changes/1655-intake-embedding-valkey/specs/llm-valkey/spec.md b/openspec/changes/1655-intake-embedding-valkey/specs/llm-valkey/spec.md new file mode 100644 index 0000000000..377550e446 --- /dev/null +++ b/openspec/changes/1655-intake-embedding-valkey/specs/llm-valkey/spec.md @@ -0,0 +1,50 @@ +## REMOVED Requirements + +### Requirement: Each llm Valkey refuses writes at a memory bound below its container limit +**Reason**: devops-cli's cache Valkey in `k8s/llm/` evicts at its bound, so the rule holds only for the Valkeys whose data must not be lost. +**Migration**: The requirement "The cache Valkey and the run index refuse writes at a memory bound below their container limits" holds the rule for those two, with the same bounds. + +## ADDED Requirements + +### Requirement: The cache Valkey and the run index refuse writes at a memory bound below their container limits +The valkey container of the Deployments `valkey` and `valkey-runs` in `k8s/llm/` SHALL start valkey-server with `--maxmemory` at most three quarters of the container's memory limit, and with `--maxmemory-policy noeviction`, so that Valkey refuses writes at the bound and evicts no key. + +#### Scenario: The cache Valkey keeps at most 1536 MiB of data +- **WHEN** the Deployment `valkey` is read from `k8s/llm/valkey.yaml` +- **THEN** its valkey container starts valkey-server with `--maxmemory 1536mb` and `--maxmemory-policy noeviction`, and 1536 MiB is at most three quarters of the container's 2048Mi memory limit + +#### Scenario: The run index keeps at most 512 MiB of data +- **WHEN** the Deployment `valkey-runs` is read from `k8s/llm/valkey-runs.yaml` +- **THEN** its valkey container starts valkey-server with `--maxmemory 512mb` and `--maxmemory-policy noeviction`, and 512 MiB is at most three quarters of the container's 768Mi memory limit + +### Requirement: devops-cli's cache Valkey evicts the least recently used key at a bound below its container limit +The valkey container of the Deployment `valkey-devops` in `k8s/llm/valkey-devops.yaml` SHALL start valkey-server with `--maxmemory` at most three quarters of the container's memory limit, `--maxmemory-policy allkeys-lru`, `--save ""` and `--appendonly no`. + +#### Scenario: The devops cache Valkey evicts at its bound +- **WHEN** the Deployment `valkey-devops` is read from `k8s/llm/valkey-devops.yaml` +- **THEN** its valkey container starts valkey-server with `--maxmemory-policy allkeys-lru`, `--save ""` and `--appendonly no`, and its `--maxmemory` is at most three quarters of the container's memory limit + +### Requirement: devops-cli's cache Valkey requires its password and admits only namespace devops +The valkey container and the redis-exporter container of `valkey-devops` SHALL read the password from key `password` of Secret `valkey-devops-auth`, and the valkey container SHALL write it to a config file on a memory volume. The policy `valkey-devops-perimeter` SHALL admit namespace `devops` on TCP 6379 and namespace `monitoring` on TCP 9121, and SHALL allow no egress. + +#### Scenario: The devops cache Valkey's password and perimeter +- **WHEN** `k8s/llm/valkey-devops.yaml` is read +- **THEN** both containers read `VALKEY_PASSWORD` or `REDIS_PASSWORD` from `valkey-devops-auth` key `password`, and `valkey-devops-perimeter` admits exactly namespace `devops` on 6379 and namespace `monitoring` on 9121, with no egress + +### Requirement: The cluster jobs name devops-cli's cache Valkey and send its password +The devops ConfigMap template SHALL set `valkey.url` to `valkey://valkey-devops.llm.svc.cluster.local:6379/0` and hold no password. Secret `devops/devops-cli` SHALL carry `DEVOPS_CLI_VALKEY_PASSWORD` from the same keyring entry as `llm/valkey-devops-auth`, adopted from the live `llm/valkey-devops-auth password` when the keyring lacks it. + +#### Scenario: The ConfigMap and the Secret name the devops cache Valkey +- **WHEN** `k8s/devops/configmap.example.yaml` and the cluster secret table are read +- **THEN** the config's `valkey` section is exactly the URL of `valkey-devops`, no key of the config names a password, and the `devops/devops-cli` entry `DEVOPS_CLI_VALKEY_PASSWORD` has the keyring source of `llm/valkey-devops-auth` and adopts from `llm/valkey-devops-auth password` + +### Requirement: A Valkey cache keeps intake's embeddings across runs +When the embedder of intake has a Valkey tier, a run that starts with an empty memory cache SHALL send no embedding request for a text whose embedding an earlier run stored there. + +#### Scenario: A second run over settled items +- **WHEN** two intake plan runs over the same two items and the same candidate each use a new `EmbeddingsEngine` on one shared Valkey +- **THEN** the first run sends one `/v1/embeddings` request and the second sends none + +#### Scenario: No Valkey tier +- **WHEN** the same two runs use embedders with no Valkey tier +- **THEN** each run sends one `/v1/embeddings` request diff --git a/openspec/changes/1655-intake-embedding-valkey/tasks.md b/openspec/changes/1655-intake-embedding-valkey/tasks.md new file mode 100644 index 0000000000..e69824bf54 --- /dev/null +++ b/openspec/changes/1655-intake-embedding-valkey/tasks.md @@ -0,0 +1,25 @@ +# Tasks + +## 1. devops-cli's cache Valkey in the cluster + +- [x] Add failing tests: the devops cache Valkey takes its password from its Secret, evicts the least recently used key at a bound below its limit, admits only namespace `devops` and the scrapers, and the ConfigMap and Secret `devops-cli` name it; and two intake runs with a shared Valkey send one embedding request + - Verification: `uv run devops ci test tests/test_k8s_valkey_stack.py tests/test_roadmap_intake.py` +- [x] Add `k8s/llm/valkey-devops.yaml` with its Deployment, Service and `valkey-devops-perimeter`, list it in the llm kustomization and in deploy-stack's llm manifests, and leave its pods out of `llm-default-perimeter` + - Verification: `uv run devops ci test tests/test_k8s_valkey_stack.py tests/test_k8s_network_policies.py tests/test_k8s_argocd_apps.py tests/test_k8s_monitoring_integration.py tests/test_k8s_llm_gateway.py` +- [x] Let namespace `devops` reach namespace `llm` on 6379, and set `valkey.url` in the devops ConfigMap template + - Verification: `uv run devops ci test tests/test_k8s_devops_runtime.py tests/test_k8s_configmap.py` +- [x] Add `llm/valkey-devops-auth` and `DEVOPS_CLI_VALKEY_PASSWORD` of `devops/devops-cli` to the cluster secret table, and Secret `valkey-devops-auth` to the Argo CD project's ignored orphans + - Verification: `uv run devops ci test tests/test_k8s_push_secrets.py tests/test_k8s_qdrant_security.py tests/test_k8s_argocd_apps.py` +- [x] Describe the Valkey, its perimeter, its bound and its two Secret rows in `k8s/README.md`, and regenerate the documentation + - Verification: `uv run devops docs generate --sync-readme` + +## 2. Archive + +- [ ] Archive the change + - Verification: `uv run devops openspec archive 1655-intake-embedding-valkey` + +## Workflow follow-up + +- Pending a person: push the two Secrets before Argo CD starts the new pod: `devops k8s push-secrets --only llm/valkey-devops-auth --only devops/devops-cli`. +- Pending a person: once the Service runs, check that one intake candidate sends at most one embedding request and that `devops_cli_embedding_cache_lookups_total{tier="valkey",result="hit"}` rises. +- Pending a person: review the diff in tuicr (tuicr -r origin/main..HEAD). diff --git a/src/devops_cli/commands/k8s/stack_lifecycle.py b/src/devops_cli/commands/k8s/stack_lifecycle.py index 23ade38cc1..7c287006bd 100644 --- a/src/devops_cli/commands/k8s/stack_lifecycle.py +++ b/src/devops_cli/commands/k8s/stack_lifecycle.py @@ -241,6 +241,7 @@ DEFAULT_K8S_DIR / "llm" / "networkpolicy.yaml", DEFAULT_K8S_DIR / "llm" / "valkey.yaml", DEFAULT_K8S_DIR / "llm" / "valkey-runs.yaml", + DEFAULT_K8S_DIR / "llm" / "valkey-devops.yaml", DEFAULT_K8S_DIR / "llm" / "profiles" / "services.yaml", DEFAULT_K8S_DIR / "llm" / "profiles" / "ollama-profiles.yaml", DEFAULT_K8S_DIR / "llm" / "gateway", diff --git a/src/devops_cli/k8s/cluster_secrets.py b/src/devops_cli/k8s/cluster_secrets.py index c4b6c90d7b..b461ee6e87 100644 --- a/src/devops_cli/k8s/cluster_secrets.py +++ b/src/devops_cli/k8s/cluster_secrets.py @@ -30,6 +30,9 @@ # Generated values nobody types live under keyring-only keys; no Settings option reads them. LLM_GATEWAY_MASTER_KEY = "llm_gateway_master_key" +# The password of devops-cli's cache Valkey in the cluster (#1655). A workstation's +# `valkey.password` is the password of the Valkey that its own `valkey.url` names. +DEVOPS_CACHE_VALKEY_PASSWORD_KEY = "valkey_devops_password" # LiteLLM refuses a master key without this prefix. LITELLM_KEY_PREFIX = "sk-" @@ -156,6 +159,8 @@ def manifest_labels(self) -> dict[str, str]: _LLM_GATEWAY_KEY = KeyringSource(LLM_GATEWAY_MASTER_KEY) +_DEVOPS_CACHE_VALKEY_PASSWORD = KeyringSource(DEVOPS_CACHE_VALKEY_PASSWORD_KEY) +_DEVOPS_CACHE_VALKEY_GENERATOR = SecretGenerator("hex", 32) CLUSTER_SECRETS: tuple[ClusterSecret, ...] = ( ClusterSecret( @@ -222,6 +227,22 @@ def manifest_labels(self) -> dict[str, str]: restarts=(Workload("deployment", "valkey"), Workload("statefulset", "open-webui")), labels={"app.kubernetes.io/name": "valkey"}, ), + # The password of devops-cli's cache Valkey, which the Service and the cluster jobs send from + # Secret devops/devops-cli (#1655). + ClusterSecret( + namespace="llm", + name="valkey-devops-auth", + stack="llm", + entries=( + SecretEntry( + "password", + _DEVOPS_CACHE_VALKEY_PASSWORD, + generator=_DEVOPS_CACHE_VALKEY_GENERATOR, + ), + ), + restarts=(Workload("deployment", "valkey-devops"),), + labels={"app.kubernetes.io/name": "valkey-devops"}, + ), ClusterSecret( namespace="cloudflared", name="cloudflared-token", @@ -263,6 +284,14 @@ def manifest_labels(self) -> dict[str, str]: KeyringSource.for_credential("firecrawl.api_key"), required=False, ), + # `valkey.password` of the pods: the password of the cache Valkey that the ConfigMap's + # `valkey.url` names. + SecretEntry( + "DEVOPS_CLI_VALKEY_PASSWORD", + _DEVOPS_CACHE_VALKEY_PASSWORD, + generator=_DEVOPS_CACHE_VALKEY_GENERATOR, + adopt_from=SecretKeyRef("llm", "valkey-devops-auth", "password"), + ), ), restarts=(Workload("deployment", "roadmap-service"),), labels={"app.kubernetes.io/name": "devops-cli"}, diff --git a/tests/test_k8s_devops_runtime.py b/tests/test_k8s_devops_runtime.py index fbec81db9b..6b69bd6dc0 100644 --- a/tests/test_k8s_devops_runtime.py +++ b/tests/test_k8s_devops_runtime.py @@ -216,7 +216,7 @@ def test_perimeter_admits_no_ingress_and_exactly_four_egress_rules() -> None: "to": [ {"namespaceSelector": {"matchLabels": {"kubernetes.io/metadata.name": "llm"}}} ], - "ports": [{"protocol": "TCP", "port": 4000}], + "ports": [{"protocol": "TCP", "port": 4000}, {"protocol": "TCP", "port": 6379}], }, { "to": [ diff --git a/tests/test_k8s_llm_gateway.py b/tests/test_k8s_llm_gateway.py index 367ccd418a..a2451b41c8 100644 --- a/tests/test_k8s_llm_gateway.py +++ b/tests/test_k8s_llm_gateway.py @@ -1023,7 +1023,7 @@ def test_llm_kustomization_includes_profiles(self) -> None: ) def test_llm_namespace_default_perimeter_excludes_gateway_and_workloads(self) -> None: - """Verify llm-default-perimeter excludes gateway, portkey and both Valkeys + """Verify llm-default-perimeter excludes gateway, portkey and the three Valkeys to avoid additive policy leakage.""" np_path = Path("k8s/llm/networkpolicy.yaml") docs = list(yaml.safe_load_all(np_path.read_text(encoding="utf-8"))) @@ -1036,7 +1036,7 @@ def test_llm_namespace_default_perimeter_excludes_gateway_and_workloads(self) -> sorted(name_expr["values"]), ) == ( "NotIn", - ["llm-gateway", "portkey", "valkey", "valkey-runs"], + ["llm-gateway", "portkey", "valkey", "valkey-devops", "valkey-runs"], ) def test_llm_manifests_have_a_deploy_path(self) -> None: diff --git a/tests/test_k8s_monitoring_integration.py b/tests/test_k8s_monitoring_integration.py index ef32b1ba78..88583bddaa 100644 --- a/tests/test_k8s_monitoring_integration.py +++ b/tests/test_k8s_monitoring_integration.py @@ -600,6 +600,7 @@ def test_otel_collector_remote_writes_to_the_path_alloy_serves() -> None: EXEMPT_PLAIN_SERVICES: dict[tuple[str, str], tuple[str, str]] = { ("llm", "valkey"): ("k8s/llm/valkey.yaml", "llm stack valkey manifest"), ("llm", "valkey-runs"): ("k8s/llm/valkey-runs.yaml", "llm stack valkey-runs manifest"), + ("llm", "valkey-devops"): ("k8s/llm/valkey-devops.yaml", "llm stack valkey-devops manifest"), ("llm", "llm-gateway"): ("k8s/llm/gateway/service.yaml", "llm stack gateway manifest"), ("llm", "portkey"): ("k8s/llm/portkey/service.yaml", "llm stack portkey manifest"), **{ diff --git a/tests/test_k8s_push_secrets.py b/tests/test_k8s_push_secrets.py index 275ea7ea10..f2fc4f9484 100644 --- a/tests/test_k8s_push_secrets.py +++ b/tests/test_k8s_push_secrets.py @@ -33,6 +33,7 @@ from devops_cli.config.settings import TelemetryConfig from devops_cli.k8s.cluster_secrets import ( CLUSTER_SECRETS, + DEVOPS_CACHE_VALKEY_PASSWORD_KEY, LLM_GATEWAY_MASTER_KEY, KeyringSource, SecretGenerator, @@ -58,12 +59,14 @@ QDRANT_KEY = "qdrant-keyring-value-0001" RUNS_PASSWORD = "runs-keyring-value-0001" CACHE_PASSWORD = "cache-keyring-value-0001" +DEVOPS_CACHE_PASSWORD = "devops-cache-keyring-value-0001" TUNNEL_TOKEN = "tunnel-keyring-value-0001" FULL_KEYRING = { LLM_GATEWAY_MASTER_KEY: GATEWAY_KEY, "qdrant_api_key": QDRANT_KEY, "runs_index_password": RUNS_PASSWORD, "valkey_password": CACHE_PASSWORD, + DEVOPS_CACHE_VALKEY_PASSWORD_KEY: DEVOPS_CACHE_PASSWORD, "cloudflare_tunnel_token": TUNNEL_TOKEN, "service_github_app_private_key": APP_KEY, } @@ -156,6 +159,15 @@ def test_table_holds_each_secret_entry_with_its_source_and_restarts() -> None: None, ("deployment/valkey", "statefulset/open-webui"), ), + ( + "llm/valkey-devops-auth", + "password", + "llm", + True, + SecretGenerator("hex", 32), + None, + ("deployment/valkey-devops",), + ), ( "cloudflared/cloudflared-token", "token", @@ -201,6 +213,15 @@ def test_table_holds_each_secret_entry_with_its_source_and_restarts() -> None: None, ("deployment/roadmap-service",), ), + ( + "devops/devops-cli", + "DEVOPS_CLI_VALKEY_PASSWORD", + "devops", + True, + SecretGenerator("hex", 32), + "llm/valkey-devops-auth password", + ("deployment/roadmap-service",), + ), ( "monitoring/grafana-admin", "admin-user", @@ -317,7 +338,12 @@ def test_keyring_sources_are_managed_keys_or_declared_keyring_only() -> None: {s.key for s in sources if not s.option} == keyring_only_keys(), keyring_only_keys() & managed, keyring_only_keys(), - ) == (True, True, frozenset(), frozenset({LLM_GATEWAY_MASTER_KEY})) + ) == ( + True, + True, + frozenset(), + frozenset({LLM_GATEWAY_MASTER_KEY, DEVOPS_CACHE_VALKEY_PASSWORD_KEY}), + ) def test_env_name_keys_of_devops_cli_feed_their_options() -> None: @@ -329,6 +355,7 @@ def test_env_name_keys_of_devops_cli_feed_their_options() -> None: "DEVOPS_CLI_AI_API_KEY": "ai.api_key", "DEVOPS_CLI_SERVICE_WEBHOOK_SECRETS": "service.webhook_secrets", "DEVOPS_CLI_FIRECRAWL_API_KEY": "firecrawl.api_key", + "DEVOPS_CLI_VALKEY_PASSWORD": "valkey.password", } @@ -486,8 +513,13 @@ def test_apply_is_one_server_side_apply_of_a_list_on_stdin( "llm/qdrant-api-key": ["api-key"], "llm/valkey-runs-auth": ["password"], "llm/valkey-auth": ["VALKEY_PASSWORD"], + "llm/valkey-devops-auth": ["password"], "cloudflared/cloudflared-token": ["token"], - "devops/devops-cli": ["DEVOPS_CLI_AI_API_KEY", APP_KEY_ENTRY], + "devops/devops-cli": [ + "DEVOPS_CLI_AI_API_KEY", + APP_KEY_ENTRY, + "DEVOPS_CLI_VALKEY_PASSWORD", + ], }, [], {"devops-cli"}, @@ -507,7 +539,11 @@ def test_keyring_values_without_live_secrets_are_created_and_restart_nothing( ) == ( 0, True, - {APP_KEY_ENTRY: APP_KEY, "DEVOPS_CLI_AI_API_KEY": GATEWAY_KEY}, + { + APP_KEY_ENTRY: APP_KEY, + "DEVOPS_CLI_AI_API_KEY": GATEWAY_KEY, + "DEVOPS_CLI_VALKEY_PASSWORD": DEVOPS_CACHE_PASSWORD, + }, [], ) @@ -581,7 +617,13 @@ def test_a_generated_value_is_stored_in_the_keyring_before_the_apply( True, True, backend.writes[LLM_GATEWAY_MASTER_KEY], - [LLM_GATEWAY_MASTER_KEY, "qdrant_api_key", "runs_index_password", "valkey_password"], + [ + LLM_GATEWAY_MASTER_KEY, + "qdrant_api_key", + "runs_index_password", + DEVOPS_CACHE_VALKEY_PASSWORD_KEY, + "valkey_password", + ], ) @@ -590,11 +632,19 @@ def test_the_devops_api_key_is_adopted_from_the_gateway_secret_never_generated( ) -> None: backend = _install(monkeypatch, cluster, values={"service_github_app_private_key": APP_KEY}) cluster.add_secret("llm", "llm-gateway-secrets", {"master-key": "sk-live-gateway-0001"}) + cluster.add_secret("llm", "valkey-devops-auth", {"password": "live-devops-cache-0001"}) result = _push("--stack", "devops") assert (result.exit_code, backend.writes, cluster.live_data("devops", "devops-cli")) == ( 0, - {LLM_GATEWAY_MASTER_KEY: "sk-live-gateway-0001"}, - {APP_KEY_ENTRY: APP_KEY, "DEVOPS_CLI_AI_API_KEY": "sk-live-gateway-0001"}, + { + LLM_GATEWAY_MASTER_KEY: "sk-live-gateway-0001", + DEVOPS_CACHE_VALKEY_PASSWORD_KEY: "live-devops-cache-0001", + }, + { + APP_KEY_ENTRY: APP_KEY, + "DEVOPS_CLI_AI_API_KEY": "sk-live-gateway-0001", + "DEVOPS_CLI_VALKEY_PASSWORD": "live-devops-cache-0001", + }, ) @@ -774,6 +824,7 @@ def test_stack_devops_reads_the_app_key_gateway_key_and_webhook_secrets_and_runs LLM_GATEWAY_MASTER_KEY, "service_webhook_secrets", "firecrawl_api_key", + DEVOPS_CACHE_VALKEY_PASSWORD_KEY, }, [], APP_KEY, @@ -953,7 +1004,7 @@ def test_the_dry_run_lists_exactly_the_requests_a_push_then_makes( [call.argv for call in cluster.calls], [f"devops-cli/{key}" for key in stub_keyring.reads], [{**i, "data": sorted(i["data"])} for i in applied], - ["<>", "<>", "<>", "<>", "<>"], + ["<>", "<>", "<>", "<>", "<>", "<>"], ) diff --git a/tests/test_k8s_qdrant_security.py b/tests/test_k8s_qdrant_security.py index 2b69a15649..d37bf13773 100644 --- a/tests/test_k8s_qdrant_security.py +++ b/tests/test_k8s_qdrant_security.py @@ -308,6 +308,7 @@ def test_deploy_stack_pushes_secrets_after_namespaces_and_before_manifests_and_h "llm/qdrant-api-key", "llm/valkey-runs-auth", "llm/valkey-auth", + "llm/valkey-devops-auth", "cloudflared/cloudflared-token", ], ) diff --git a/tests/test_k8s_valkey_stack.py b/tests/test_k8s_valkey_stack.py index 97378cf198..805bff7274 100644 --- a/tests/test_k8s_valkey_stack.py +++ b/tests/test_k8s_valkey_stack.py @@ -309,3 +309,149 @@ def test_open_webui_is_the_only_workload_that_names_the_cache_valkey() -> None: ) assert files == ["llm/values-open-webui.yaml"] + + +# devops-cli's cache in the cluster: the Valkey that the Service and the cluster jobs use for their +# embeddings and their threat-intelligence reads (#1655). +DEVOPS_CACHE = "valkey-devops" +DEVOPS_CACHE_MANIFEST = LLM_DIR / "valkey-devops.yaml" +DEVOPS_CACHE_URL = "valkey://valkey-devops.llm.svc.cluster.local:6379/0" +DEVOPS_CONFIGMAP_TEMPLATE = K8S_DIR / "devops" / "configmap.example.yaml" + + +def _devops_cache_secret() -> tuple[str, str]: + """Return the name and only key of the Secret that holds the devops cache Valkey's password.""" + secret = next(s for s in CLUSTER_SECRETS if s.ref == "llm/valkey-devops-auth") + (entry,) = secret.entries + return secret.name, entry.key + + +def _keys(node: Any) -> Iterator[str]: + """Yield every mapping key in a parsed YAML document, at any depth.""" + if isinstance(node, dict): + for key, value in node.items(): + yield str(key) + yield from _keys(value) + elif isinstance(node, list): + for item in node: + yield from _keys(item) + + +def test_the_devops_cache_valkey_takes_its_password_from_its_secret_as_the_run_index_does() -> None: + """devops-cli's cache Valkey requires a password from Secret valkey-devops-auth, written as + the run index writes its own, and its exporter sends it (#1655). + + The cache Valkey of Open WebUI keeps its state with noeviction, so it can't hold a cache that + must evict; this Valkey holds only devops-cli's caches. + """ + cache = _document(DEVOPS_CACHE_MANIFEST, "Deployment", DEVOPS_CACHE) + runs = _document(LLM_DIR / "valkey-runs.yaml", "Deployment", "valkey-runs") + cache_prelude, _, cache_volume = _password_setup(cache) + runs_prelude, _, runs_volume = _password_setup(runs) + secret, key = _devops_cache_secret() + + assert ( + _secret_env(_container(cache, "valkey")), + _secret_env(_container(cache, "redis-exporter")), + (cache_prelude, cache_volume), + ) == ( + {"VALKEY_PASSWORD": (secret, key)}, + {"REDIS_PASSWORD": (secret, key)}, + (runs_prelude, runs_volume), + ) + + +def test_the_devops_cache_valkey_evicts_the_least_recently_used_key_at_a_bound_below_its_limit() -> ( + None +): + """It keeps at most three quarters of its container's memory limit as data, and at that bound + evicts the least recently used key (#1655). + + It holds caches only, so an evicted key costs one more model request, not a lost state. It + writes no RDB and no AOF, and a restart starts it empty. + """ + deployment = _document(DEVOPS_CACHE_MANIFEST, "Deployment", DEVOPS_CACHE) + flags = _server_flags(deployment) + limit = parse_quantity(_container(deployment, "valkey")["resources"]["limits"]["memory"]) + + assert (flags.get("--maxmemory-policy"), flags.get("--save"), flags.get("--appendonly")) == ( + "allkeys-lru", + "", + "no", + ) + assert int(flags["--maxmemory"].removesuffix("mb")) * VALKEY_MB_BYTES <= limit * 3 / 4 + + +def test_only_the_devops_namespace_and_the_metrics_scrapers_reach_the_devops_cache_valkey() -> None: + """valkey-devops-perimeter admits namespace devops on 6379 and the monitoring namespace on the + exporter's port, and lets Valkey dial nothing (#1655). + + A namespace-selector peer with `ports:` is the shape kube-router enforces. + """ + policy = _document(DEVOPS_CACHE_MANIFEST, "NetworkPolicy", "valkey-devops-perimeter") + service = _document(DEVOPS_CACHE_MANIFEST, "Service", DEVOPS_CACHE) + + assert policy["spec"] == { + "podSelector": {"matchLabels": {"app.kubernetes.io/name": DEVOPS_CACHE}}, + "policyTypes": ["Ingress", "Egress"], + "ingress": [ + { + "from": [ + { + "namespaceSelector": { + "matchLabels": {"kubernetes.io/metadata.name": "devops"} + } + } + ], + "ports": [{"protocol": "TCP", "port": 6379}], + }, + { + "from": [ + { + "namespaceSelector": { + "matchLabels": {"kubernetes.io/metadata.name": "monitoring"} + } + } + ], + "ports": [{"protocol": "TCP", "port": 9121}], + }, + ], + "egress": [], + } + assert (service["spec"]["type"], service["spec"]["ports"]) == ( + "ClusterIP", + [{"name": "valkey", "port": 6379, "targetPort": 6379}], + ) + + +def test_the_cluster_jobs_name_the_devops_cache_valkey_and_get_its_password_from_their_secret() -> ( + None +): + """The devops ConfigMap names the devops cache Valkey and holds no password. Secret devops-cli + carries the password under the variable that `valkey.password` reads, from the keyring entry + of Secret valkey-devops-auth, and adopts the live value when the keyring lacks it (#1655).""" + from devops_cli.config.env import credential + from devops_cli.k8s.cluster_secrets import KeyringSource, SecretKeyRef + + template = yaml.safe_load(DEVOPS_CONFIGMAP_TEMPLATE.read_text(encoding="utf-8")) + config = yaml.safe_load(template["data"]["devops-cli.yaml"]) + devops = next(s for s in CLUSTER_SECRETS if s.ref == "devops/devops-cli") + (variable, *_) = credential("valkey.password").env_vars + entry = next(e for e in devops.entries if e.key == variable) + llm = next(s for s in CLUSTER_SECRETS if s.ref == "llm/valkey-devops-auth") + (llm_entry,) = llm.entries + secret, key = _devops_cache_secret() + + assert ( + config["valkey"], + [k for k in _keys(config) if "password" in k.lower()], + isinstance(entry.source, KeyringSource), + entry.source == llm_entry.source, + entry.adopt_from, + ) == ( + {"url": DEVOPS_CACHE_URL}, + [], + True, + True, + SecretKeyRef("llm", secret, key), + ) diff --git a/tests/test_roadmap_intake.py b/tests/test_roadmap_intake.py index 206036c21a..96ed4c5103 100644 --- a/tests/test_roadmap_intake.py +++ b/tests/test_roadmap_intake.py @@ -20,7 +20,9 @@ from typing import Any from unittest.mock import patch +import httpx2 import pytest +from fakeredis import FakeServer from fastmcp.exceptions import ToolError from pydantic import ValidationError from syrupy.assertion import SnapshotAssertion @@ -29,6 +31,7 @@ from devops_cli import entry from devops_cli.ai.client.models import StructuredOutputValidationError from devops_cli.ai.mcp import server as mcp_server +from devops_cli.ai.rag.embeddings import EmbeddingsEngine from devops_cli.commands import roadmap as roadmap_command from devops_cli.commands.roadmap import app from devops_cli.config.constants import CONST_ROADMAP_INTAKE_REASON_MARKER @@ -82,7 +85,9 @@ from tests.roadmap_github_fake import GitHubFake from tests.support.fakes.github import API, GitHubApiFake, RunnerSession, github_json from tests.support.fakes.model import ModelFake +from tests.support.fakes.valkey import valkey_client_on from tests.support.paths import FIXTURES +from tests.web_fakes import StubWeb REPO = "example/roadmap" NOW = datetime(2026, 10, 4, 12, 0, tzinfo=UTC) @@ -1763,6 +1768,58 @@ def embed_texts(self, texts: list[str], *, is_query: bool = False) -> list[list[ return [[1.0] for _ in texts] +# ── The embeddings of settled items (#1655) ─────────────────────────────────── + + +class _Proposer: + """The `analysis` model: the same proposal for each candidate.""" + + def chat_structured( + self, system: str, prompt: str, schema: type[ModelProposal] + ) -> ModelProposal: + return schema.model_validate(DEFAULT_PROPOSAL) + + +def _embeddings_server(request: httpx2.Request) -> httpx2.Response | None: + """The gateway's OpenAI-compatible `/v1/embeddings`: one vector for each text.""" + if request.url.path != "/v1/embeddings": + return None + texts = json.loads(request.content)["input"] + vectors = [{"index": i, "embedding": [1.0, float(len(t) % 7)]} for i, t in enumerate(texts)] + return httpx2.Response(200, json={"data": vectors, "usage": {"prompt_tokens": len(texts)}}) + + +@pytest.mark.parametrize( + ("cached", "embedding_requests"), + [pytest.param(True, [1, 0], id="valkey-cache"), pytest.param(False, [1, 1], id="no-cache")], +) +def test_a_second_intake_run_over_settled_items_sends_no_embedding_request_with_the_valkey_cache( + roadmap: Roadmap, + stub_web: StubWeb, + valkey_server: FakeServer, + cached: bool, + embedding_requests: list[int], +) -> None: + """Each run is a new process with an empty memory cache, as each round of the Service and + each cluster job is. With the shared Valkey cache, a second run over the same items and the + same candidate sends no embedding request. With no cache it embeds them all again (#1655).""" + stub_web.serve(_embeddings_server) + roadmap.finished("Retry policy for the gateway") + roadmap.finished("Dashboard for the gateway") + roadmap.issue("feat: cache the embeddings") + ai = AIConfig(provider="gateway", gateway_url="https://example.com/v1") + sent: list[int] = [] + for _run in range(2): + before = len(stub_web.sent) + valkey = valkey_client_on(valkey_server) if cached else None + engine = EmbeddingsEngine(ai, api_key="sk-test", valkey_client=valkey) + model = GatewayIntakeModel(ai, embedder=engine, client=_Proposer()) + plan = plan_intake(roadmap.store, repo=REPO, model=model) + sent.append(sum(1 for r in stub_web.sent[before:] if r.url.path == "/v1/embeddings")) + + assert (sent, [d.outcome for d in plan.decisions]) == (embedding_requests, [Outcome.PLACE]) + + def test_a_model_answer_that_fails_validation_skips_only_its_candidate(roadmap: Roadmap) -> None: """A model that answers, but not in the schema, is not an unreachable gateway: that one candidate is skipped with the reason, and the others are placed.""" From 3327208efd1bc392181eeac3e66389a8207e3ce9 Mon Sep 17 00:00:00 2001 From: Daniel Petty Date: Thu, 29 Oct 2026 00:58:45 +0000 Subject: [PATCH 2/3] fix(roadmap): name the devops cache Valkey's keyring entry so Bandit reads no password in it, and pin the Secret's source by value --- src/devops_cli/k8s/cluster_secrets.py | 8 ++++---- tests/test_k8s.py | 2 +- tests/test_k8s_push_secrets.py | 12 ++++++------ tests/test_k8s_valkey_stack.py | 14 +++++++++----- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/devops_cli/k8s/cluster_secrets.py b/src/devops_cli/k8s/cluster_secrets.py index b461ee6e87..a1096a7557 100644 --- a/src/devops_cli/k8s/cluster_secrets.py +++ b/src/devops_cli/k8s/cluster_secrets.py @@ -32,7 +32,7 @@ LLM_GATEWAY_MASTER_KEY = "llm_gateway_master_key" # The password of devops-cli's cache Valkey in the cluster (#1655). A workstation's # `valkey.password` is the password of the Valkey that its own `valkey.url` names. -DEVOPS_CACHE_VALKEY_PASSWORD_KEY = "valkey_devops_password" +DEVOPS_CACHE_VALKEY_AUTH_KEY = "valkey_devops_password" # LiteLLM refuses a master key without this prefix. LITELLM_KEY_PREFIX = "sk-" @@ -159,7 +159,7 @@ def manifest_labels(self) -> dict[str, str]: _LLM_GATEWAY_KEY = KeyringSource(LLM_GATEWAY_MASTER_KEY) -_DEVOPS_CACHE_VALKEY_PASSWORD = KeyringSource(DEVOPS_CACHE_VALKEY_PASSWORD_KEY) +_DEVOPS_CACHE_VALKEY_AUTH = KeyringSource(DEVOPS_CACHE_VALKEY_AUTH_KEY) _DEVOPS_CACHE_VALKEY_GENERATOR = SecretGenerator("hex", 32) CLUSTER_SECRETS: tuple[ClusterSecret, ...] = ( @@ -236,7 +236,7 @@ def manifest_labels(self) -> dict[str, str]: entries=( SecretEntry( "password", - _DEVOPS_CACHE_VALKEY_PASSWORD, + _DEVOPS_CACHE_VALKEY_AUTH, generator=_DEVOPS_CACHE_VALKEY_GENERATOR, ), ), @@ -288,7 +288,7 @@ def manifest_labels(self) -> dict[str, str]: # `valkey.url` names. SecretEntry( "DEVOPS_CLI_VALKEY_PASSWORD", - _DEVOPS_CACHE_VALKEY_PASSWORD, + _DEVOPS_CACHE_VALKEY_AUTH, generator=_DEVOPS_CACHE_VALKEY_GENERATOR, adopt_from=SecretKeyRef("llm", "valkey-devops-auth", "password"), ), diff --git a/tests/test_k8s.py b/tests/test_k8s.py index 19066352e0..b84ef54962 100644 --- a/tests/test_k8s.py +++ b/tests/test_k8s.py @@ -240,7 +240,7 @@ def test_deploy_stack_dry_run_lists_the_secrets_and_key_names_and_runs_nothing() 0, [ "cloudflared/cloudflared-token: token", - "devops/devops-cli: DEVOPS_CLI_SERVICE_GITHUB_APP_PRIVATE_KEY, DEVOPS_CLI_AI_API_KEY, DEVOPS_CLI_SERVICE_WEBHOOK_SECRETS, DEVOPS_CLI_FIRECRAWL_API_KEY (if namespace devops exists)", + "devops/devops-cli: DEVOPS_CLI_SERVICE_GITHUB_APP_PRIVATE_KEY, DEVOPS_CLI_AI_API_KEY, DEVOPS_CLI_SERVICE_WEBHOOK_SECRETS, DEVOPS_CLI_FIRECRAWL_API_KEY, DEVOPS_CLI_VALKEY_PASSWORD (if namespace devops exists)", "monitoring/grafana-admin: admin-user, admin-password", ], [], diff --git a/tests/test_k8s_push_secrets.py b/tests/test_k8s_push_secrets.py index f2fc4f9484..04473de415 100644 --- a/tests/test_k8s_push_secrets.py +++ b/tests/test_k8s_push_secrets.py @@ -33,7 +33,7 @@ from devops_cli.config.settings import TelemetryConfig from devops_cli.k8s.cluster_secrets import ( CLUSTER_SECRETS, - DEVOPS_CACHE_VALKEY_PASSWORD_KEY, + DEVOPS_CACHE_VALKEY_AUTH_KEY, LLM_GATEWAY_MASTER_KEY, KeyringSource, SecretGenerator, @@ -66,7 +66,7 @@ "qdrant_api_key": QDRANT_KEY, "runs_index_password": RUNS_PASSWORD, "valkey_password": CACHE_PASSWORD, - DEVOPS_CACHE_VALKEY_PASSWORD_KEY: DEVOPS_CACHE_PASSWORD, + DEVOPS_CACHE_VALKEY_AUTH_KEY: DEVOPS_CACHE_PASSWORD, "cloudflare_tunnel_token": TUNNEL_TOKEN, "service_github_app_private_key": APP_KEY, } @@ -342,7 +342,7 @@ def test_keyring_sources_are_managed_keys_or_declared_keyring_only() -> None: True, True, frozenset(), - frozenset({LLM_GATEWAY_MASTER_KEY, DEVOPS_CACHE_VALKEY_PASSWORD_KEY}), + frozenset({LLM_GATEWAY_MASTER_KEY, DEVOPS_CACHE_VALKEY_AUTH_KEY}), ) @@ -621,7 +621,7 @@ def test_a_generated_value_is_stored_in_the_keyring_before_the_apply( LLM_GATEWAY_MASTER_KEY, "qdrant_api_key", "runs_index_password", - DEVOPS_CACHE_VALKEY_PASSWORD_KEY, + DEVOPS_CACHE_VALKEY_AUTH_KEY, "valkey_password", ], ) @@ -638,7 +638,7 @@ def test_the_devops_api_key_is_adopted_from_the_gateway_secret_never_generated( 0, { LLM_GATEWAY_MASTER_KEY: "sk-live-gateway-0001", - DEVOPS_CACHE_VALKEY_PASSWORD_KEY: "live-devops-cache-0001", + DEVOPS_CACHE_VALKEY_AUTH_KEY: "live-devops-cache-0001", }, { APP_KEY_ENTRY: APP_KEY, @@ -824,7 +824,7 @@ def test_stack_devops_reads_the_app_key_gateway_key_and_webhook_secrets_and_runs LLM_GATEWAY_MASTER_KEY, "service_webhook_secrets", "firecrawl_api_key", - DEVOPS_CACHE_VALKEY_PASSWORD_KEY, + DEVOPS_CACHE_VALKEY_AUTH_KEY, }, [], APP_KEY, diff --git a/tests/test_k8s_valkey_stack.py b/tests/test_k8s_valkey_stack.py index 805bff7274..3cd3214cce 100644 --- a/tests/test_k8s_valkey_stack.py +++ b/tests/test_k8s_valkey_stack.py @@ -431,7 +431,11 @@ def test_the_cluster_jobs_name_the_devops_cache_valkey_and_get_its_password_from carries the password under the variable that `valkey.password` reads, from the keyring entry of Secret valkey-devops-auth, and adopts the live value when the keyring lacks it (#1655).""" from devops_cli.config.env import credential - from devops_cli.k8s.cluster_secrets import KeyringSource, SecretKeyRef + from devops_cli.k8s.cluster_secrets import ( + DEVOPS_CACHE_VALKEY_AUTH_KEY, + KeyringSource, + SecretKeyRef, + ) template = yaml.safe_load(DEVOPS_CONFIGMAP_TEMPLATE.read_text(encoding="utf-8")) config = yaml.safe_load(template["data"]["devops-cli.yaml"]) @@ -445,13 +449,13 @@ def test_the_cluster_jobs_name_the_devops_cache_valkey_and_get_its_password_from assert ( config["valkey"], [k for k in _keys(config) if "password" in k.lower()], - isinstance(entry.source, KeyringSource), - entry.source == llm_entry.source, + entry.source, + llm_entry.source, entry.adopt_from, ) == ( {"url": DEVOPS_CACHE_URL}, [], - True, - True, + KeyringSource(DEVOPS_CACHE_VALKEY_AUTH_KEY), + KeyringSource(DEVOPS_CACHE_VALKEY_AUTH_KEY), SecretKeyRef("llm", secret, key), ) From 026d23352a3b956cc6fe42916b835d4203e58105 Mon Sep 17 00:00:00 2001 From: Daniel Petty Date: Thu, 29 Oct 2026 00:58:59 +0000 Subject: [PATCH 3/3] docs(openspec): archive 1655-intake-embedding-valkey --- .../.openspec.yaml | 0 .../design.md | 0 .../proposal.md | 0 .../specs/llm-valkey/spec.md | 0 .../tasks.md | 2 +- openspec/specs/llm-valkey/spec.md | 36 +++++++++++++++++-- 6 files changed, 35 insertions(+), 3 deletions(-) rename openspec/changes/{1655-intake-embedding-valkey => archive/2026-10-29-1655-intake-embedding-valkey}/.openspec.yaml (100%) rename openspec/changes/{1655-intake-embedding-valkey => archive/2026-10-29-1655-intake-embedding-valkey}/design.md (100%) rename openspec/changes/{1655-intake-embedding-valkey => archive/2026-10-29-1655-intake-embedding-valkey}/proposal.md (100%) rename openspec/changes/{1655-intake-embedding-valkey => archive/2026-10-29-1655-intake-embedding-valkey}/specs/llm-valkey/spec.md (100%) rename openspec/changes/{1655-intake-embedding-valkey => archive/2026-10-29-1655-intake-embedding-valkey}/tasks.md (98%) diff --git a/openspec/changes/1655-intake-embedding-valkey/.openspec.yaml b/openspec/changes/archive/2026-10-29-1655-intake-embedding-valkey/.openspec.yaml similarity index 100% rename from openspec/changes/1655-intake-embedding-valkey/.openspec.yaml rename to openspec/changes/archive/2026-10-29-1655-intake-embedding-valkey/.openspec.yaml diff --git a/openspec/changes/1655-intake-embedding-valkey/design.md b/openspec/changes/archive/2026-10-29-1655-intake-embedding-valkey/design.md similarity index 100% rename from openspec/changes/1655-intake-embedding-valkey/design.md rename to openspec/changes/archive/2026-10-29-1655-intake-embedding-valkey/design.md diff --git a/openspec/changes/1655-intake-embedding-valkey/proposal.md b/openspec/changes/archive/2026-10-29-1655-intake-embedding-valkey/proposal.md similarity index 100% rename from openspec/changes/1655-intake-embedding-valkey/proposal.md rename to openspec/changes/archive/2026-10-29-1655-intake-embedding-valkey/proposal.md diff --git a/openspec/changes/1655-intake-embedding-valkey/specs/llm-valkey/spec.md b/openspec/changes/archive/2026-10-29-1655-intake-embedding-valkey/specs/llm-valkey/spec.md similarity index 100% rename from openspec/changes/1655-intake-embedding-valkey/specs/llm-valkey/spec.md rename to openspec/changes/archive/2026-10-29-1655-intake-embedding-valkey/specs/llm-valkey/spec.md diff --git a/openspec/changes/1655-intake-embedding-valkey/tasks.md b/openspec/changes/archive/2026-10-29-1655-intake-embedding-valkey/tasks.md similarity index 98% rename from openspec/changes/1655-intake-embedding-valkey/tasks.md rename to openspec/changes/archive/2026-10-29-1655-intake-embedding-valkey/tasks.md index e69824bf54..204275598d 100644 --- a/openspec/changes/1655-intake-embedding-valkey/tasks.md +++ b/openspec/changes/archive/2026-10-29-1655-intake-embedding-valkey/tasks.md @@ -15,7 +15,7 @@ ## 2. Archive -- [ ] Archive the change +- [x] Archive the change - Verification: `uv run devops openspec archive 1655-intake-embedding-valkey` ## Workflow follow-up diff --git a/openspec/specs/llm-valkey/spec.md b/openspec/specs/llm-valkey/spec.md index f5bea673d6..0d1a305f02 100644 --- a/openspec/specs/llm-valkey/spec.md +++ b/openspec/specs/llm-valkey/spec.md @@ -5,8 +5,8 @@ The Valkey servers of the llm namespace in the cluster manifests: the cache Valk ## Requirements -### Requirement: Each llm Valkey refuses writes at a memory bound below its container limit -The valkey container of each Valkey Deployment in `k8s/llm/` SHALL start valkey-server with `--maxmemory` at most three quarters of the container's memory limit, and with `--maxmemory-policy noeviction`, so that Valkey refuses writes at the bound and evicts no key. +### Requirement: The cache Valkey and the run index refuse writes at a memory bound below their container limits +The valkey container of the Deployments `valkey` and `valkey-runs` in `k8s/llm/` SHALL start valkey-server with `--maxmemory` at most three quarters of the container's memory limit, and with `--maxmemory-policy noeviction`, so that Valkey refuses writes at the bound and evicts no key. #### Scenario: The cache Valkey keeps at most 1536 MiB of data - **WHEN** the Deployment `valkey` is read from `k8s/llm/valkey.yaml` @@ -15,3 +15,35 @@ The valkey container of each Valkey Deployment in `k8s/llm/` SHALL start valkey- #### Scenario: The run index keeps at most 512 MiB of data - **WHEN** the Deployment `valkey-runs` is read from `k8s/llm/valkey-runs.yaml` - **THEN** its valkey container starts valkey-server with `--maxmemory 512mb` and `--maxmemory-policy noeviction`, and 512 MiB is at most three quarters of the container's 768Mi memory limit + +### Requirement: devops-cli's cache Valkey evicts the least recently used key at a bound below its container limit +The valkey container of the Deployment `valkey-devops` in `k8s/llm/valkey-devops.yaml` SHALL start valkey-server with `--maxmemory` at most three quarters of the container's memory limit, `--maxmemory-policy allkeys-lru`, `--save ""` and `--appendonly no`. + +#### Scenario: The devops cache Valkey evicts at its bound +- **WHEN** the Deployment `valkey-devops` is read from `k8s/llm/valkey-devops.yaml` +- **THEN** its valkey container starts valkey-server with `--maxmemory-policy allkeys-lru`, `--save ""` and `--appendonly no`, and its `--maxmemory` is at most three quarters of the container's memory limit + +### Requirement: devops-cli's cache Valkey requires its password and admits only namespace devops +The valkey container and the redis-exporter container of `valkey-devops` SHALL read the password from key `password` of Secret `valkey-devops-auth`, and the valkey container SHALL write it to a config file on a memory volume. The policy `valkey-devops-perimeter` SHALL admit namespace `devops` on TCP 6379 and namespace `monitoring` on TCP 9121, and SHALL allow no egress. + +#### Scenario: The devops cache Valkey's password and perimeter +- **WHEN** `k8s/llm/valkey-devops.yaml` is read +- **THEN** both containers read `VALKEY_PASSWORD` or `REDIS_PASSWORD` from `valkey-devops-auth` key `password`, and `valkey-devops-perimeter` admits exactly namespace `devops` on 6379 and namespace `monitoring` on 9121, with no egress + +### Requirement: The cluster jobs name devops-cli's cache Valkey and send its password +The devops ConfigMap template SHALL set `valkey.url` to `valkey://valkey-devops.llm.svc.cluster.local:6379/0` and hold no password. Secret `devops/devops-cli` SHALL carry `DEVOPS_CLI_VALKEY_PASSWORD` from the same keyring entry as `llm/valkey-devops-auth`, adopted from the live `llm/valkey-devops-auth password` when the keyring lacks it. + +#### Scenario: The ConfigMap and the Secret name the devops cache Valkey +- **WHEN** `k8s/devops/configmap.example.yaml` and the cluster secret table are read +- **THEN** the config's `valkey` section is exactly the URL of `valkey-devops`, no key of the config names a password, and the `devops/devops-cli` entry `DEVOPS_CLI_VALKEY_PASSWORD` has the keyring source of `llm/valkey-devops-auth` and adopts from `llm/valkey-devops-auth password` + +### Requirement: A Valkey cache keeps intake's embeddings across runs +When the embedder of intake has a Valkey tier, a run that starts with an empty memory cache SHALL send no embedding request for a text whose embedding an earlier run stored there. + +#### Scenario: A second run over settled items +- **WHEN** two intake plan runs over the same two items and the same candidate each use a new `EmbeddingsEngine` on one shared Valkey +- **THEN** the first run sends one `/v1/embeddings` request and the second sends none + +#### Scenario: No Valkey tier +- **WHEN** the same two runs use embedders with no Valkey tier +- **THEN** each run sends one `/v1/embeddings` request