Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 46 additions & 5 deletions braintrust/examples/gke-loop-runtime/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ uses the same URL. To override it for Loop only, set `BRAINTRUST_APP_URL` in

```sh
helm --kube-context <worker> 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
```

Expand All @@ -52,9 +52,48 @@ uses the same URL. To override it for Loop only, set `BRAINTRUST_APP_URL` in
--values <your GKE 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 <worker> 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`
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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: "<gke_isolated_workers.checkpoint_store>"
4 changes: 2 additions & 2 deletions braintrust/examples/gke-loop-runtime/sandbox-service.yaml
Original file line number Diff line number Diff line change
@@ -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: "<discovery.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:
Expand Down
2 changes: 2 additions & 0 deletions braintrust/templates/loop-runtime-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 }}
Expand Down
67 changes: 66 additions & 1 deletion braintrust/tests/loop-runtime-autoscaling_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -239,10 +272,42 @@ tests:
loopRuntime.replicas: 3
loopRuntime.autoscaling: null
asserts:
- equal: *capacityTarget
template: loop-runtime-configmap.yaml
- equal:
path: spec.replicas
value: 3
template: loop-runtime-deployment.yaml
- 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
3 changes: 3 additions & 0 deletions braintrust/tests/loop-runtime-configmap_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions braintrust/tests/migrations_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions braintrust/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading