diff --git a/braintrust/examples/gke-loop-runtime/README.md b/braintrust/examples/gke-loop-runtime/README.md index b41364f..5a509c2 100644 --- a/braintrust/examples/gke-loop-runtime/README.md +++ b/braintrust/examples/gke-loop-runtime/README.md @@ -39,7 +39,7 @@ uses the same URL. To override it for Loop only, set `BRAINTRUST_APP_URL` in ```sh helm --kube-context upgrade --install sandbox-service \ - https://braintrust-cf-us-east-1.s3.amazonaws.com/sandbox-service/1f4b6826c61064575b3db956b67625133257bd8a6e49e4ea86cdb55012dd53a7/sandbox-service-0.1.0.tgz \ + https://braintrust-cf-us-east-1.s3.amazonaws.com/sandbox-service/062fbf5e1090e1f624eda6d6f9dfe7af05921e3d90a6405d330feb7866775ad2/sandbox-service-0.1.0.tgz \ --namespace braintrust-sandbox --values braintrust/examples/gke-loop-runtime/sandbox-service.yaml --wait ``` @@ -52,9 +52,48 @@ uses the same URL. To override it for Loop only, set `BRAINTRUST_APP_URL` in --values --values braintrust/examples/gke-loop-runtime/values.yaml --wait ``` -Workers run at a fixed count. One `c4-standard-8-lssd` worker holds about seven -1 vCPU / 2 GiB sandboxes; beyond that, new sandboxes fail with -`CapacityExhausted`. Raise `replicas` in `sandbox-service.yaml` to add workers. +Worker `replicas` is a floor; the controller scales from demand and usable capacity +within `controller.maxReplicas` and the Terraform node-pool maximum. Reserve an +extra worker for upgrades; requests can return `CapacityExhausted` while scaling +or at those limits. + +## Filesystem retention + +Retention is off unless the overlay is applied. Keep the worker chart, worker image +and Loop Runtime image compatible. Terraform selects the worker package from +`loopRuntime.sandboxServiceChart` in the chosen Braintrust Helm release. + +Apply the GCP checkpoint-storage update first, then copy +`gke_isolated_workers.checkpoint_store` into `sandbox-service-retention.yaml`. +Only worker nodes receive checkpoint-bucket access through their node identity. + +Apply the overlay using the same published worker chart and image as above: + +```sh +helm --kube-context upgrade --install sandbox-service \ + https://braintrust-cf-us-east-1.s3.amazonaws.com/sandbox-service/062fbf5e1090e1f624eda6d6f9dfe7af05921e3d90a6405d330feb7866775ad2/sandbox-service-0.1.0.tgz \ + --namespace braintrust-sandbox \ + --values braintrust/examples/gke-loop-runtime/sandbox-service.yaml \ + --values braintrust/examples/gke-loop-runtime/sandbox-service-retention.yaml --wait +``` + +With `--reuse-values`, explicitly set both retention values and a compatible image. +The controller owns scaling and draining; retain its eviction protections. + +Upgrade replacements default to a 15-minute drain deadline; expiry can lose active +edits or local-only checkpoints. Change `SANDBOX_SERVICE_WORKER_DRAIN_TIMEOUT_SECONDS` +in `controller.env`, or use `0` to wait indefinitely. Ordinary scale-down has no +such deadline. + +Workers still use local SSD/XFS. Checkpoints preserve files at completed idle sleep +or preserving drain, excluding running processes and later edits. Allow local disk +headroom for checkpoints and active sandboxes, and verify file recovery across +sleep, wake, and worker replacement before relying on it. + +Keep the bucket, URI and encryption key stable while retained sandboxes exist. +Coordinate rollback before disabling retention. Infrastructure removal retains +the bucket; import the original storage before re-enabling workers. See the +[storage lifecycle](https://github.com/braintrustdata/terraform-google-braintrust-data-plane/blob/main/ISOLATED_WORKERS.md#storage-and-lifecycle). Loop Runtime defaults to one pod. Rolling updates use `maxSurge: 1` and `maxUnavailable: 0`, giving a 1 → 2 → 1 rollout. Increase `loopRuntime.replicas` @@ -72,7 +111,9 @@ The application must expose the gauge `loop_runtime_claimed_conversation_utiliza An image without that endpoint or gauge cannot drive metric-based scaling; there is no image-version gate. The HPA owns replicas while enabled; disabling it restores `loopRuntime.replicas`. Enabling it on an existing Deployment can initially reset the count to one. -This scales runtime pods only; provision worker replicas separately for the expected sandbox capacity. +The HPA target also sets sandbox capacity headroom, with a 1% sandbox minimum. +HPA targets below 1% stay unchanged; disabled autoscaling keeps the sandbox target +at 50%. Worker and node-pool maximums still bound sandbox capacity. Sandbox administration is disabled by default. Set `loopRuntime.enableSandboxAdmin: true` to allow authorized sysadmins to inspect and terminate sandboxes. diff --git a/braintrust/examples/gke-loop-runtime/sandbox-service-retention.yaml b/braintrust/examples/gke-loop-runtime/sandbox-service-retention.yaml new file mode 100644 index 0000000..c743367 --- /dev/null +++ b/braintrust/examples/gke-loop-runtime/sandbox-service-retention.yaml @@ -0,0 +1,4 @@ +# Overlay for a Sandbox Service release that supports filesystem retention. +# Apply the GCP infrastructure update first, then use its checkpoint_store output. +filesystemRetention: true +checkpointStore: "" diff --git a/braintrust/examples/gke-loop-runtime/sandbox-service.yaml b/braintrust/examples/gke-loop-runtime/sandbox-service.yaml index 3688e5a..e0c5e21 100644 --- a/braintrust/examples/gke-loop-runtime/sandbox-service.yaml +++ b/braintrust/examples/gke-loop-runtime/sandbox-service.yaml @@ -1,8 +1,8 @@ # Values for the Sandbox Service worker chart, installed in the isolated worker cluster. # Every <...> value comes from the GCP Terraform output gke_isolated_workers. hostname: "" -image: public.ecr.aws/braintrust/sandbox-service:v2.21.0 -# Fixed worker capacity. The worker node pool autoscales, so raising this is a values change. +image: public.ecr.aws/braintrust/sandbox-service:v2.24.0 +# Worker floor. The controller scales from sandbox demand within the node-pool limits. replicas: 1 gitResources: true nodePrep: diff --git a/braintrust/templates/loop-runtime-configmap.yaml b/braintrust/templates/loop-runtime-configmap.yaml index 4ad7787..1d1cab7 100644 --- a/braintrust/templates/loop-runtime-configmap.yaml +++ b/braintrust/templates/loop-runtime-configmap.yaml @@ -2,6 +2,7 @@ {{- if include "braintrust.loopRuntime.enabled" . -}} {{- $bucket := printf "gs://%s" .Values.objectStorage.google.brainstoreBucket -}} {{- $sandbox := .Values.loopRuntime.sandbox -}} +{{- $autoscaling := include "braintrust.loopRuntime.autoscaling" . | fromYaml -}} apiVersion: v1 kind: ConfigMap metadata: @@ -39,6 +40,7 @@ data: BRAINSTORE_OBJECT_STORE_CACHE_FILE_SIZE: 5Gi BRAINSTORE_OBJECT_STORE_CACHE_MEMORY_LIMIT: 256Mi LOOP_RUNTIME_MAX_CLAIMED_CONVERSATIONS: "2" + LOOP_RUNTIME_SANDBOX_CAPACITY_TARGET_UTILIZATION_PERCENT: {{ maxf 1 (float64 ($autoscaling.targetConversationUtilization | default "50")) | quote }} BRAINSTORE_CONTROL_PLANE_TELEMETRY: {{ list .Values.global.controlPlaneTelemetry "metrics" "traces" | compact | join "," | quote }} NO_COLOR: "1" EXO_SANDBOX_SERVICE_DNS_URL: {{ $sandbox.dnsUrl | quote }} diff --git a/braintrust/tests/loop-runtime-autoscaling_test.yaml b/braintrust/tests/loop-runtime-autoscaling_test.yaml index 41ee6c3..0cc9b50 100644 --- a/braintrust/tests/loop-runtime-autoscaling_test.yaml +++ b/braintrust/tests/loop-runtime-autoscaling_test.yaml @@ -13,6 +13,8 @@ tests: values: &values - __fixtures__/base-values.yaml - __fixtures__/loop-runtime-values.yaml + set: + loopRuntime.autoscaling.targetConversationUtilization: 0 asserts: - hasDocuments: count: 0 @@ -24,6 +26,10 @@ tests: path: spec.replicas value: 1 template: loop-runtime-deployment.yaml + - equal: &capacityTarget + path: data.LOOP_RUNTIME_SANDBOX_CAPACITY_TARGET_UTILIZATION_PERCENT + value: "50" + template: loop-runtime-configmap.yaml - it: should reject a zero autoscaling minimum template: loop-runtime-hpa.yaml @@ -70,9 +76,27 @@ tests: loopRuntime.autoscaling.enabled: true loopRuntime.autoscaling.targetConversationUtilization: "101" asserts: - - failedTemplate: + - failedTemplate: &invalidTarget errorMessage: loopRuntime.autoscaling.targetConversationUtilization must be greater than 0 and at most 100 + - it: should reject a zero conversation utilization target + template: loop-runtime-hpa.yaml + values: *values + set: + loopRuntime.autoscaling.enabled: true + loopRuntime.autoscaling.targetConversationUtilization: 0 + asserts: + - failedTemplate: *invalidTarget + + - it: should reject an empty conversation utilization target + template: loop-runtime-hpa.yaml + values: *values + set: + loopRuntime.autoscaling.enabled: true + loopRuntime.autoscaling.targetConversationUtilization: "" + asserts: + - failedTemplate: *invalidTarget + - it: should reject a relative metrics endpoint template: loop-runtime-hpa.yaml values: *values @@ -155,6 +179,8 @@ tests: set: loopRuntime.autoscaling.enabled: true asserts: &autoscalingDefaults + - equal: *capacityTarget + template: loop-runtime-configmap.yaml - equal: path: spec.minReplicas value: 1 @@ -198,6 +224,10 @@ tests: metricsPath: /capacity targetConversationUtilization: "75" asserts: + - equal: + <<: *capacityTarget + value: "75" + template: loop-runtime-configmap.yaml - equal: path: spec.minReplicas value: 2 @@ -226,6 +256,9 @@ tests: loopRuntime.enabled: false loopRuntime.autoscaling.enabled: true asserts: + - hasDocuments: + count: 0 + template: loop-runtime-configmap.yaml - hasDocuments: count: 0 template: loop-runtime-hpa.yaml @@ -239,6 +272,8 @@ tests: loopRuntime.replicas: 3 loopRuntime.autoscaling: null asserts: + - equal: *capacityTarget + template: loop-runtime-configmap.yaml - equal: path: spec.replicas value: 3 @@ -246,3 +281,33 @@ tests: - hasDocuments: count: 0 template: loop-runtime-hpa.yaml + + - it: should share a fractional HPA target with sandbox capacity + values: *values + set: + loopRuntime.autoscaling.enabled: true + loopRuntime.autoscaling.targetConversationUtilization: 35.5 + asserts: + - equal: + <<: *capacityTarget + value: "35.5" + template: loop-runtime-configmap.yaml + - equal: + path: spec.metrics[0].pods.target.averageValue + value: "35.5" + template: loop-runtime-hpa.yaml + + - it: should preserve sub-percent HPA targets while respecting the sandbox minimum + values: *values + set: + loopRuntime.autoscaling.enabled: true + loopRuntime.autoscaling.targetConversationUtilization: "0.5" + asserts: + - equal: + <<: *capacityTarget + value: "1" + template: loop-runtime-configmap.yaml + - equal: + path: spec.metrics[0].pods.target.averageValue + value: "0.5" + template: loop-runtime-hpa.yaml diff --git a/braintrust/tests/loop-runtime-configmap_test.yaml b/braintrust/tests/loop-runtime-configmap_test.yaml index 019b250..3b0154c 100644 --- a/braintrust/tests/loop-runtime-configmap_test.yaml +++ b/braintrust/tests/loop-runtime-configmap_test.yaml @@ -75,6 +75,9 @@ tests: - equal: path: data.LOOP_RUNTIME_MAX_CLAIMED_CONVERSATIONS value: "2" + - equal: + path: data.LOOP_RUNTIME_SANDBOX_CAPACITY_TARGET_UTILIZATION_PERCENT + value: "50" - isNull: path: data.BRAINSTORE_LOCKS_URI diff --git a/braintrust/tests/migrations_test.yaml b/braintrust/tests/migrations_test.yaml index 13e4dbe..68c1a35 100644 --- a/braintrust/tests/migrations_test.yaml +++ b/braintrust/tests/migrations_test.yaml @@ -28,6 +28,7 @@ tests: set: api.image.repository: registry.example/custom-api api.image.tag: v2.15.0 + brainstore.image.tag: v2.23.0 asserts: - isKind: of: Job @@ -631,6 +632,7 @@ tests: - __fixtures__/loop-runtime-values.yaml set: api.image.tag: deadbeef + brainstore.image.tag: v2.23.0 deploymentOrdering.minimumVersion: v2.15.0 deploymentOrdering.migrationImageTag: v2.23.0 asserts: diff --git a/braintrust/values.yaml b/braintrust/values.yaml index fb51071..9d55d3d 100644 --- a/braintrust/values.yaml +++ b/braintrust/values.yaml @@ -309,6 +309,8 @@ loopRuntime: repository: public.ecr.aws/braintrust/loop-runtime tag: v2.24.0 pullPolicy: IfNotPresent + # Separate worker chart, pinned with this release for the Terraform installer. + sandboxServiceChart: "https://braintrust-cf-us-east-1.s3.amazonaws.com/sandbox-service/062fbf5e1090e1f624eda6d6f9dfe7af05921e3d90a6405d330feb7866775ad2/sandbox-service-0.1.0.tgz" # Requires the same GKE custom-metrics prerequisites as api.autoscaling. # Without the application metric, the HPA cannot perform metric-driven scaling. autoscaling: