Skip to content
Merged
54 changes: 54 additions & 0 deletions hack/external-substrate-e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,60 @@ and `external-substrate-core-session` (the Session), started in that order
against the same Core, both with telemetry. The second starts only after the
first passed; traces are verified after both.

### Session latency and the warm-detach window

After a passed proof, and before its cleanup, the same Core, provider and
proof identity can measure session-reused, `DataOnly`, Suspend-on-detach
latency and Orka ADR 0055's warm-detach window:

```sh
LATENCY_REPEATS=3 LATENCY_WINDOW=2m LATENCY_SCENARIOS=detach,warm \
bash scripts/external-substrate-core-e2e.sh latency
```

The Job (`native-core-latency-<UTC timestamp>`, label
`orka.workspace.e2e/latency=native-core`) creates two profile/class pairs in
the run namespace through the public APIs: `lat-detach` without a window and
`lat-warm` with `retention.suspendAfterDetach` set to `LATENCY_WINDOW`. Both
allow only Session reuse and Suspend, with a 30m idle timeout and a 1h
lifetime. For each repetition it runs, one at a time:

- `detach`: a cold turn 1, the suspension on detach, and turn 2 resumed from
the Tag; then that turn's suspension.
- `warm`: a cold turn 1 and, once it settled warm, turn 2 inside the window,
which must reuse the same workload sequence and revision, provider instance,
Actor UID, worker Pod, runtime instance, supervisor boot and pool credential
Secret versions, with a new RuntimeSession and attachment epoch and no new
Tag. The RuntimePool must keep its replicas and the Actor its worker while
turn 2's own window runs; retention must then suspend with a new Tag, and
turn 3 resumes from it. The last window also expires before the next
repetition.

Every Task is timed by the client from just before Create (first observation
of each execution state and phase, prompt acceptance, `Succeeded`, and the
workspace settlement receipt). Results go to
`bin/external-substrate-core-latency-<UTC timestamp>/`: `latency.log`, the
timing lines only of Core (`ACP turn timings`, `ACP workspace runtime
started/stopped`), the provider (`Substrate runtime ready/stopped`) and the
live-followed worker Pods (`ACP runtime session created`), and the joined
`report.json` and `summary.md` (median, range and count per phase), including
each worker Pod's creation, container start and boot milestones relative to
Task creation. Secret
data, attachment token hashes and bootstrap nonces are never read into them.
The deterministic agent sleeps 2s per prompt, which `promptStream` includes.
The measurement client is built from the checkout, so a harness change needs
no new proof run. A failed measurement keeps its objects for inspection;
cleanup below retires them with the run and refuses while a measurement Job
still runs.

Session member Tasks keep their frozen authority until Session cleanup records
their runtime cleanup receipts, so cleanup first deletes every referenced
Session through Core's public API (`DELETE /api/v1/sessions/<name>`) from a Job
whose dedicated ServiceAccount in the run namespace may only read Tasks and
delete Sessions. Core authenticates it by TokenReview, which the released chart
grants and the proof's Core role omits; the proof renders, and cleanup ensures
and removes, a `tokenreviews` `create` grant for Core's ServiceAccount.

The run namespace is fixed, so a finished run (passed or failed) must be
retired before the next one:

Expand Down
73 changes: 66 additions & 7 deletions hack/external-substrate-e2e/core/cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ require_finished() {
teardown() {
kubectl delete validatingwebhookconfiguration external-substrate-core --ignore-not-found
kubectl delete namespace "${provider_namespace}" --ignore-not-found --wait=true --timeout=5m
for name in external-substrate-core external-substrate-core-fixture external-substrate-core-proof orka-workspace-substrate; do
for name in external-substrate-core external-substrate-core-fixture external-substrate-core-proof external-substrate-core-tokenreview orka-workspace-substrate; do
kubectl delete clusterrolebinding "${name}" --ignore-not-found
kubectl delete clusterrole "${name}" --ignore-not-found
done
Expand All @@ -118,12 +118,19 @@ teardown() {
kubectl -n "${client_namespace}" delete job "${session_job_name}" --ignore-not-found
kubectl -n "${client_namespace}" delete job "${namespace}" --ignore-not-found
kubectl -n "${client_namespace}" delete job -l orka.workspace.e2e/cleanup=native-core --ignore-not-found
kubectl -n "${client_namespace}" delete job -l orka.workspace.e2e/latency=native-core --ignore-not-found
}

job="$(proof_job_json)"
# A Session Job that is still running holds Tasks this cleanup would delete.
session_job="$(proof_job_json "${session_job_name}")"
[[ -z "${session_job}" ]] || require_finished "${session_job}"
# A latency measurement (core/latency.sh) still creating Tasks must finish first.
latency_jobs="$(kubectl -n "${client_namespace}" get jobs -l orka.workspace.e2e/latency=native-core -o json)"
if jq -e 'any(.items[]; all(.status.conditions[]?; .status != "True" or (.type != "Complete" and .type != "Failed")))' <<<"${latency_jobs}" >/dev/null; then
printf 'A Core latency Job has not finished; refusing to retire a running measurement.\n' >&2
exit 1
fi
# Only a confirmed absence counts; any other API error stops here (set -e).
if [[ -z "$(kubectl get namespace "${namespace}" -o name --ignore-not-found)" ]]; then
# Resume only after a cleanup that released and retired this exact run: it
Expand Down Expand Up @@ -169,6 +176,64 @@ mkdir -p "${run_dir}/image"
chmod 700 "${run_dir}"
printf 'Native Core proof cleanup artifacts: %s\n' "${run_dir}"

arch="$(kubectl get nodes -o jsonpath='{.items[0].status.nodeInfo.architecture}')"
case "${arch}" in amd64|arm64) ;; *) printf 'Unsupported node architecture: %s\n' "${arch}" >&2; exit 1 ;; esac
CGO_ENABLED=0 GOOS=linux GOARCH="${arch}" go -C hack/external-substrate-e2e build -p 4 -trimpath -o "${run_dir}/image/native-data-proof" ./core
docker build -f hack/external-substrate-e2e/core/proof.Dockerfile -t "localhost:5002/orka/native-core-proof:cleanup-${run_id}" "${run_dir}/image"
docker push "localhost:5002/orka/native-core-proof:cleanup-${run_id}"
cleanup_image="$(docker inspect -f '{{index .RepoDigests 0}}' "localhost:5002/orka/native-core-proof:cleanup-${run_id}")"

# Session member Tasks (core/latency.sh) keep their frozen authority until
# Session cleanup records their runtime cleanup receipts, so their Sessions
# are deleted first through Core's public API. Core only lets an identity of
# the run namespace act there, so a dedicated ServiceAccount in it holds
# exactly Task read and Session delete; the run namespace removes it.
if kubectl -n "${namespace}" get tasks.core.orka.ai -o json | jq -e 'any(.items[]; .spec.sessionRef.name // "" | length > 0)' >/dev/null; then
Comment thread
sozercan marked this conversation as resolved.
Resolved
# Core authenticates API callers by TokenReview, which the released chart
# grants (config/rbac/metrics_auth_role.yaml) but the proof's Core role
# omits. Runs installed before install.py rendered it get it here.
jq -n --arg ns "${namespace}" '{apiVersion:"v1",kind:"List",items:[
{apiVersion:"rbac.authorization.k8s.io/v1",kind:"ClusterRole",metadata:{name:"external-substrate-core-tokenreview"},
rules:[{apiGroups:["authentication.k8s.io"],resources:["tokenreviews"],verbs:["create"]}]},
{apiVersion:"rbac.authorization.k8s.io/v1",kind:"ClusterRoleBinding",metadata:{name:"external-substrate-core-tokenreview"},
roleRef:{apiGroup:"rbac.authorization.k8s.io",kind:"ClusterRole",name:"external-substrate-core-tokenreview"},
subjects:[{kind:"ServiceAccount",name:"orka-controller-manager",namespace:$ns}]}]}' | kubectl apply -f -
session_job="native-core-sessions-${run_id}"
jq -n --arg ns "${namespace}" --arg name "${session_job}" --arg image "${cleanup_image}" '
{apiVersion:"v1",kind:"List",items:[
{apiVersion:"v1",kind:"ServiceAccount",metadata:{name:"native-core-session-cleanup",namespace:$ns}},
{apiVersion:"rbac.authorization.k8s.io/v1",kind:"Role",metadata:{name:"native-core-session-cleanup",namespace:$ns},rules:[
{apiGroups:["core.orka.ai"],resources:["tasks"],verbs:["get","list"]},
{apiGroups:["core.orka.ai"],resources:["sessions"],verbs:["get","delete"]}]},
{apiVersion:"rbac.authorization.k8s.io/v1",kind:"RoleBinding",metadata:{name:"native-core-session-cleanup",namespace:$ns},
roleRef:{apiGroup:"rbac.authorization.k8s.io",kind:"Role",name:"native-core-session-cleanup"},
subjects:[{kind:"ServiceAccount",name:"native-core-session-cleanup",namespace:$ns}]},
{apiVersion:"batch/v1",kind:"Job",metadata:{name:$name,namespace:$ns,labels:{"orka.workspace.e2e/cleanup":"native-core-sessions"}},spec:{
backoffLimit:0,activeDeadlineSeconds:900,template:{metadata:{labels:{"orka.workspace.e2e/cleanup":"native-core-sessions"}},spec:{
serviceAccountName:"native-core-session-cleanup",restartPolicy:"Never",
securityContext:{runAsNonRoot:true,runAsUser:65532,runAsGroup:65532,seccompProfile:{type:"RuntimeDefault"}},
containers:[{name:"sessions",image:$image,imagePullPolicy:"IfNotPresent",
securityContext:{allowPrivilegeEscalation:false,readOnlyRootFilesystem:true,capabilities:{drop:["ALL"]}},
env:[{name:"SESSION_CLEANUP",value:"1"},{name:"POD_NAMESPACE",value:$ns},
{name:"CORE_API_URL",value:("http://external-substrate-core." + $ns + ".svc.cluster.local:8080")}]}]}}}}]}' |
kubectl apply -f -
start="$(date +%s)"
while true; do
session_state="$(kubectl -n "${namespace}" --request-timeout=15s get job "${session_job}" -o json)"
if jq -e 'any(.status.conditions[]?; (.type == "Failed" or .type == "FailureTarget") and .status == "True")' <<<"${session_state}" >/dev/null; then
kubectl -n "${namespace}" logs "job/${session_job}" | tee "${run_dir}/sessions.log"
printf 'Session cleanup failed; everything is retained for inspection.\n' >&2
exit 1
fi
if jq -e 'any(.status.conditions[]?; .type == "Complete" and .status == "True")' <<<"${session_state}" >/dev/null; then
kubectl -n "${namespace}" logs "job/${session_job}" | tee "${run_dir}/sessions.log"
break
fi
(( $(date +%s) - start <= 900 )) || exit 1
sleep 2
done
fi

# Tasks first, so Core settles and retires their RuntimePools and workspaces,
# then whatever a failed run left behind, through the same controllers. Session
# turns finish deleting only once their Session is archived (archive_sessions).
Expand Down Expand Up @@ -199,12 +264,6 @@ printf 'The provider released every journal and catalog in %s.\n' "${namespace}"
# The proof's own native objects: the infrastructure template and Atespace.
# The Job runs as the proof's bootstrap-owner identity and refuses to delete
# any provider-owned Actor, Data Tag or derived template that remains.
arch="$(kubectl get nodes -o jsonpath='{.items[0].status.nodeInfo.architecture}')"
case "${arch}" in amd64|arm64) ;; *) printf 'Unsupported node architecture: %s\n' "${arch}" >&2; exit 1 ;; esac
CGO_ENABLED=0 GOOS=linux GOARCH="${arch}" go -C hack/external-substrate-e2e build -p 4 -trimpath -o "${run_dir}/image/native-data-proof" ./core
docker build -f hack/external-substrate-e2e/core/proof.Dockerfile -t "localhost:5002/orka/native-core-proof:cleanup-${run_id}" "${run_dir}/image"
docker push "localhost:5002/orka/native-core-proof:cleanup-${run_id}"
cleanup_image="$(docker inspect -f '{{index .RepoDigests 0}}' "localhost:5002/orka/native-core-proof:cleanup-${run_id}")"
job_name="native-core-cleanup-${run_id}"
test "$(kubectl get namespace "${namespace}" -o jsonpath='{.metadata.uid}')" = "${namespace_uid}"
jq --arg name "${job_name}" --arg image "${cleanup_image}" --arg atespace "${owned_atespace}" --arg template "${owned_template}" '
Expand Down
11 changes: 11 additions & 0 deletions hack/external-substrate-e2e/core/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,17 @@ def rewrite(value):
objects.append({"apiVersion": "v1", "kind": "Service", "metadata": {"name": collector_service, "namespace": namespace},
"spec": {"selector": {"app": collector_service}, "ports": [{"name": "otlp-grpc", "port": 4317, "targetPort": 4317}]}})

# Core's API authenticates ServiceAccount callers (such as core/cleanup.sh's
# Session cleanup) by TokenReview, as the released chart grants through
# config/rbac/metrics_auth_role.yaml.
add_tokenreview = [
{"apiVersion": "rbac.authorization.k8s.io/v1", "kind": "ClusterRole", "metadata": {"name": "external-substrate-core-tokenreview"},
"rules": [{"apiGroups": ["authentication.k8s.io"], "resources": ["tokenreviews"], "verbs": ["create"]}]},
{"apiVersion": "rbac.authorization.k8s.io/v1", "kind": "ClusterRoleBinding", "metadata": {"name": "external-substrate-core-tokenreview"},
"roleRef": {"apiGroup": "rbac.authorization.k8s.io", "kind": "ClusterRole", "name": "external-substrate-core-tokenreview"},
"subjects": [{"kind": "ServiceAccount", "name": "orka-controller-manager", "namespace": namespace}]}]
objects.extend(add_tokenreview)

role = json.loads(pathlib.Path(core_role).read_text())
role["metadata"] = {"name": "external-substrate-core"}
# Core's API authenticates callers by TokenReview, which Orka's Helm and
Expand Down
Loading
Loading