oficina / equipo Public

plans: Task 17 live-check plan for Paul's approval

One AWS CLI plan for the dev account (kass, eu-west-1), run once after
approval: network, connector, image, SNS, contract, controller sequence
and crash check, orphan reaping, R7 facts, teardown and spend.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 6908c5222e2af1575f5bd96f26c1cde3d8f87921 parent 60a0682
1 file changed, +1,369 −0
  • docs/superpowers/plans/2026-11-23-hosted-1a-task17-live-plan.md +1,369 −0
diff --git a/docs/superpowers/plans/2026-11-23-hosted-1a-task17-live-plan.md b/docs/superpowers/plans/2026-11-23-hosted-1a-task17-live-plan.md
new file mode 100644
index 00000000..88a1e7ba
--- /dev/null
+++ b/docs/superpowers/plans/2026-11-23-hosted-1a-task17-live-plan.md
@@ -0,0 +1,1369 @@
+# Hosted runners 1a, Task 17: live check plan (for Paul's approval, 2026-11-23)
+
+**Status:** draft for approval. Nothing in this file has been run. No AWS command or SDK call of any
+kind was made while writing it.
+
+**What Paul approves:** every command below, run once, in the order in "Order of execution", by one
+agent, in AWS account `640012953448` (profile `kass`), region `eu-west-1`, with every resource tagged
+`purpose=equipo-hosted-dev`. Nothing touches account `149757027610` (`equipo-hosted`). Any change to a
+command, any extra AWS call, and any result that differs from a step's "Expected" comes back to Paul
+before the next command runs.
+
+**Sources:** plan `2026-11-19-hosted-runners-slice-1a.md` (Task 17, Global constraints); spec
+`2026-11-18-hosted-runners-microvms.md` §3, §10, §15; `internal/isolatedjob/awsjob/doc.go`,
+`runner.go`, `network.go`, `live_test.go`; `cmd/equipo-hosted-controller/config.go`, `main.go`,
+`crashpoint.go`, `keygen_live_test.go`; `internal/hostedclient/live_test.go`; rulings R7, R17, R21,
+R22, R28 to R30 in the SDD progress file; the pre-flight report
+`.superpowers/sdd/2026-11-19-hosted-runners-slice-1a/task-17-preflight-report.md` (commits
+`d94d7454`, `1ebf6e61`, `60a06822`). CLI command and flag names were checked against the AWS CLI
+2.36.10 service models installed in `~/.local/aws-cli/v2/2.36.10` and against the AWS SDK for Go v2
+sources (`lambdamicrovms@v1.13.0`, `lambdacore@v1.14.0`). AWS documentation pages used:
+`microvms-images`, `microvms-getting-started`, `microvms-networking`, `microvms-launching`,
+`microvms-security` (all under `docs.aws.amazon.com/lambda/latest/dg/`), the managed policy page for
+`AWSLambdaNetworkConnectorOperatorPolicy`, and the Lambda pricing page.
+
+## What the run proves
+
+1. The adapter's contract passes against real MicroVMs (`TestLiveContract`).
+2. The controller on docs-t1, bound to `127.0.0.1`, drives one Small VM through launch, drain,
+ quiescent, suspend, resume (epoch and timings recorded) and stop with proof.
+3. A controller killed between the provider call and transaction 2 leaves exactly one VM, which
+ Replay claims after a restart.
+4. A VM planted outside the controller is stopped by the reaper after the 10-minute grace.
+5. The R7 facts AWS does not document are measured and recorded (section 9).
+6. Everything is torn down and confirmed gone by type and by tag.
+
+## Order of execution
+
+Sections are numbered as Paul asked, but they run in this order, because the client-token facts
+decide how to read the contract results, and the facts VMs must be gone before the controller's
+reaper starts listing:
+
+| Run order | Section | Roughly |
+| --- | --- | --- |
+| 1 | 0. Guard rails | 10 min |
+| 2 | 1. Network | 10 min |
+| 3 | 2. Connector | 10 to 15 min |
+| 4 | 3. Image | 30 to 40 min |
+| 5 | 4. SNS topic | 2 min |
+| 6 | 5. Controller config, keys and TLS | 10 min |
+| 7 | 9.A to 9.F (facts, by CLI, no controller running) | 35 min |
+| 8 | 6. Live contract | 30 min |
+| 9 | 7. Controller sequence and crash check | 40 min |
+| 10 | 8. Orphan | 20 min |
+| 11 | 9.G (final facts) | 5 min |
+| 12 | 10. Teardown and verification | 40 to 70 min |
+| 13 | 10.8 Spend record, at least 24 h later | 5 min |
+
+## Rules that hold for every step
+
+- **Stop and ask.** Any non-zero exit that a step does not list as expected, any output that differs
+ from "Expected", any error text not named in the step, and any prompt for credentials: stop. Run
+ only the safe stop below, then report to Paul with the exact command and output. Do not retry with
+ changed flags, do not try alternatives, do not "fix" a resource.
+- **Safe stop** (pre-approved, the only thing that runs after an abort): stop the controller if it
+ runs (section 7.7 command), terminate every live VM from this run's image (section 10.1 commands),
+ and leave every other resource in place for Paul to decide.
+- **Ledger first.** Every ID is written to the ledger by `rec` in the same command that creates it,
+ before anything else runs. The ledger is the only list teardown works from. Never delete anything
+ that is not in the ledger.
+- **Shell state does not persist** between agent tool calls. Every block below starts with
+ `. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1`, which reloads the profile, the helpers and the
+ ledger and checks the account. If `$TMPDIR` is different from the path printed in step 0.2, stop
+ and ask.
+- **Sandbox network.** AWS calls need the agent sandbox to allow `*.amazonaws.com` (STS, EC2, IAM,
+ Lambda, S3, SNS, CloudWatch Logs, Resource Groups Tagging, and in 10.8 Cost Explorer) and whatever
+ host the `kass` credential process contacts. Declare these in `allowed_domains`; nothing else.
+- **docs-t1 rules.** The controller listens on `127.0.0.1` only (API and metrics). The hook server in
+ section 3 listens on `:9000` inside the MicroVM, not on docs-t1. Scratch is under
+ `$TMPDIR/equipo-t17` and is deleted in 10.7. Go caches stay at their defaults; no `GOCACHE`,
+ `GOMODCACHE` or `GOTMPDIR`. No sudo.
+- **Polling loops** use `sleep` inside a loop. Blocks that can run longer than the tool's 10-minute
+ foreground limit (2.3, 3.8, 6.1, 7.2, 7.5, 8.2, 10.2, 10.3) run with the Bash tool's
+ `run_in_background`; wait for the exit notification, then read the output. Do the same for any
+ other block if the harness refuses a foreground command that sleeps.
+- **Records.** After each section, append its results (IDs, outputs named in "Record", timings) to
+ `docs/superpowers/plans/HOSTED-SLICE1-PROGRESS.md` under a new heading `## Task 17 live run
+ (2026-11-2x)`. Commit that file locally at the end (subject under 80 characters); do not push.
+
+---
+
+## 0. Guard rails
+
+### 0.1 Check the local tools (no AWS call)
+
+```sh
+cd /home/paulca/amadan.net/oficina/equipo-hosted-1a && git log --oneline -1 && git status --short
+aws --version
+go version
+for t in jq openssl sha256sum curl ss python3; do command -v "$t" >/dev/null || echo "MISSING $t"; done
+```
+
+- Expected: HEAD is `60a06822` or a later commit on `hosted-runners-1a` that Paul has named; `git
+ status` empty or only untracked scratch; `aws-cli/2.36.x`; `go1.26.x`; no `MISSING` line.
+- Abort if: HEAD is not the approved commit, or a tool is missing.
+
+### 0.2 Write the environment file and the ledger (no AWS call)
+
+```sh
+mkdir -p "$TMPDIR/equipo-t17"/{out,image,iam,keys,bin} && chmod 700 "$TMPDIR/equipo-t17" && echo "T17=$TMPDIR/equipo-t17"
+cat > "$TMPDIR/equipo-t17/env.sh" <<'EOF'
+unset AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN AWS_DEFAULT_PROFILE
+export AWS_PROFILE=kass AWS_REGION=eu-west-1 AWS_DEFAULT_REGION=eu-west-1 AWS_PAGER=""
+export T17="$TMPDIR/equipo-t17"
+export LEDGER="$T17/ledger.env"
+export REPO=/home/paulca/amadan.net/oficina/equipo-hosted-1a
+export ACCOUNT=640012953448
+export NAME=equipo-hosted-dev-t17
+export TAGV=equipo-hosted-dev
+export NO_INGRESS=arn:aws:lambda:eu-west-1:aws:network-connector:aws-network-connector:NO_INGRESS
+export LOG_GROUP=/aws/lambda-microvms/equipo-hosted-dev-t17
+export API=127.0.0.1:18443 METRICS=127.0.0.1:18444
+# rec NAME VALUE: append to the ledger at once; refuse anything that names the hosted account.
+rec() {
+ case "$2" in *149757027610*) echo "ABORT: $1=$2 names account 149757027610"; return 1;; esac
+ [ -n "$2" ] && [ "$2" != None ] && [ "$2" != null ] || { echo "ABORT: $1 is empty ($2)"; return 1; }
+ printf 'export %s=%q\n' "$1" "$2" >> "$LEDGER"
+ printf '%s %s=%s\n' "$(date -u +%FT%TZ)" "$1" "$2" >> "$T17/ledger.log"
+ export "$1=$2"
+}
+guard() {
+ local a; a=$(aws sts get-caller-identity --query Account --output text) || { echo "ABORT: STS failed"; return 1; }
+ [ "$a" = "$ACCOUNT" ] || { echo "ABORT: account is $a, not $ACCOUNT"; return 1; }
+}
+vm_state() { aws lambda-microvms get-microvm --microvm-identifier "$1" --query state --output text 2>&1; }
+# wait_vm ID STATE SECONDS: poll every 5 s; GONE accepts TERMINATED or not found.
+wait_vm() {
+ local end=$(( $(date +%s) + $3 )) s
+ while :; do
+ s=$(vm_state "$1"); echo "$(date -u +%T) $1 $s"
+ [ "$s" = "$2" ] && return 0
+ [ "$2" = GONE ] && { [ "$s" = TERMINATED ] || case "$s" in *ResourceNotFound*) true;; *) false;; esac; } && return 0
+ [ "$(date +%s)" -ge "$end" ] && return 1
+ sleep 5
+ done
+}
+# live_vms: every MicroVM in the account and region that is not TERMINATED, any image.
+live_vms() { aws lambda-microvms list-microvms --query "items[?state!='TERMINATED'].[microvmId,state,imageArn,startedAt]" --output text; }
+# our_live: live VMs from this run's image only.
+our_live() { aws lambda-microvms list-microvms --query "items[?state!='TERMINATED' && imageArn=='$IMAGE_ARN'].[microvmId,state,startedAt]" --output text; }
+metrics() { curl -fsS "http://$METRICS/metrics" | grep -E '^equipo_hosted_'; }
+[ -f "$LEDGER" ] && . "$LEDGER"
+true
+EOF
+touch "$TMPDIR/equipo-t17/ledger.env" "$TMPDIR/equipo-t17/ledger.log"
+```
+
+- Expected: one line `T17=<path>`. Record that path; every later block must see the same `$TMPDIR`.
+- Abort if: the directory cannot be created.
+
+### 0.3 First AWS command: who am I
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" && aws sts get-caller-identity --query '[Account,Arn]' --output text
+```
+
+- Expected: `640012953448` and an ARN in that account.
+- Abort if: the account is anything else, or the call fails. Nothing else runs.
+
+### 0.4 Nothing else is running MicroVMs here, and nothing from an earlier run is left
+
+The controller's reaper stops every live VM in the account and region that its job table does not
+know, after 10 minutes. It must never meet a VM that is not ours.
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1
+echo "live VMs:"; live_vms
+echo "images:"; aws lambda-microvms list-microvm-images --query 'items[].[name,imageArn,state]' --output text
+echo "connectors:"; aws lambda-core list-network-connectors --query 'NetworkConnectors[].[Name,Arn,State]' --output text
+echo "tagged:"; aws resourcegroupstaggingapi get-resources --tag-filters Key=purpose,Values=$TAGV --query 'ResourceTagMappingList[].ResourceARN' --output text
+```
+
+- Expected: no live VMs; no image or connector whose name starts with `equipo-hosted-dev-t17`; no
+ resource tagged `purpose=equipo-hosted-dev`.
+- Abort if: any live VM exists (whoever owns it), or any name or tag above is already taken. Paul
+ decides; the run does not touch them.
+- Note: the `list-network-connectors` output key is read from the CLI model
+ (`NetworkConnectors`); see UNCONFIRMED U3.
+
+---
+
+## 1. Network
+
+### 1.1 VPC with DNS support and DNS hostnames off
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1
+VPC=$(aws ec2 create-vpc --cidr-block 10.177.0.0/16 \
+ --tag-specifications "ResourceType=vpc,Tags=[{Key=purpose,Value=$TAGV},{Key=Name,Value=$NAME}]" \
+ --query Vpc.VpcId --output text) && rec VPC "$VPC" || exit 1
+aws ec2 wait vpc-available --vpc-ids "$VPC"
+aws ec2 modify-vpc-attribute --vpc-id "$VPC" --enable-dns-hostnames '{"Value":false}'
+aws ec2 modify-vpc-attribute --vpc-id "$VPC" --enable-dns-support '{"Value":false}'
+aws ec2 describe-vpc-attribute --vpc-id "$VPC" --attribute enableDnsSupport --query EnableDnsSupport.Value --output text
+aws ec2 describe-vpc-attribute --vpc-id "$VPC" --attribute enableDnsHostnames --query EnableDnsHostnames.Value --output text
+aws ec2 describe-vpcs --vpc-ids "$VPC" --query 'Vpcs[0].Tags' --output text
+```
+
+- Expected: a `vpc-` ID in the ledger; both attribute reads print `False`; tags show
+ `purpose equipo-hosted-dev` and `Name equipo-hosted-dev-t17`.
+- Abort if: either attribute reads `True`, or the tags are missing.
+
+### 1.2 One VM subnet
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1
+SUBNET=$(aws ec2 create-subnet --vpc-id "$VPC" --cidr-block 10.177.1.0/24 --availability-zone eu-west-1a \
+ --tag-specifications "ResourceType=subnet,Tags=[{Key=purpose,Value=$TAGV},{Key=Name,Value=$NAME-vm}]" \
+ --query Subnet.SubnetId --output text) && rec SUBNET "$SUBNET" || exit 1
+aws ec2 wait subnet-available --subnet-ids "$SUBNET"
+aws ec2 describe-subnets --subnet-ids "$SUBNET" --query 'Subnets[0].[VpcId,CidrBlock,AvailabilityZone,MapPublicIpOnLaunch]' --output text
+```
+
+- Expected: `<VPC> 10.177.1.0/24 eu-west-1a False`.
+- Abort if: any field differs.
+
+### 1.3 Its own route table, local route only
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1
+RTB=$(aws ec2 create-route-table --vpc-id "$VPC" \
+ --tag-specifications "ResourceType=route-table,Tags=[{Key=purpose,Value=$TAGV},{Key=Name,Value=$NAME-vm}]" \
+ --query RouteTable.RouteTableId --output text) && rec RTB "$RTB" || exit 1
+RTB_ASSOC=$(aws ec2 associate-route-table --route-table-id "$RTB" --subnet-id "$SUBNET" \
+ --query AssociationId --output text) && rec RTB_ASSOC "$RTB_ASSOC" || exit 1
+aws ec2 describe-route-tables --route-table-ids "$RTB" --query 'RouteTables[0].Routes[].[DestinationCidrBlock,DestinationIpv6CidrBlock,GatewayId,State]' --output text
+aws ec2 describe-route-tables --filters Name=association.subnet-id,Values="$SUBNET" --query 'RouteTables[].RouteTableId' --output text
+```
+
+- Expected: exactly one route line, `10.177.0.0/16 None local active`; the subnet's table is `$RTB`.
+- Abort if: any other route, or the subnet maps to another table.
+
+### 1.4 Security group with no rules
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1
+SG=$(aws ec2 create-security-group --group-name "$NAME-vm" --description "Task 17 VM group, no rules" --vpc-id "$VPC" \
+ --tag-specifications "ResourceType=security-group,Tags=[{Key=purpose,Value=$TAGV},{Key=Name,Value=$NAME-vm}]" \
+ --query GroupId --output text) && rec SG "$SG" || exit 1
+EGRESS_RULES=$(aws ec2 describe-security-group-rules --filters Name=group-id,Values="$SG" \
+ --query 'SecurityGroupRules[?IsEgress].SecurityGroupRuleId' --output text)
+echo "default egress rules: $EGRESS_RULES"
+aws ec2 revoke-security-group-egress --group-id "$SG" --security-group-rule-ids $EGRESS_RULES --query Return --output text
+aws ec2 describe-security-groups --group-ids "$SG" --query 'SecurityGroups[0].[length(IpPermissions),length(IpPermissionsEgress)]' --output text
+aws ec2 describe-security-group-rules --filters Name=group-id,Values="$SG" --query 'length(SecurityGroupRules)' --output text
+```
+
+- Expected: one default egress rule ID (`sgr-...`, the IPv4 all-traffic rule); revoke prints `True`;
+ then `0 0` and `0`.
+- Abort if: more than one default egress rule, revoke fails, or any rule remains.
+- Record: VPC, subnet, route table, group IDs, and the three verification outputs.
+
+---
+
+## 2. Connector
+
+### 2.1 Operator role for the connector's network interfaces
+
+The connector needs an IAM role Lambda assumes to create its network interfaces in the subnet. AWS
+publishes a managed policy for it; the SDK says the role also needs delete and describe permissions,
+which the managed policy does not hold, so a small inline policy adds them.
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1
+cat > "$T17/iam/operator-trust.json" <<'EOF'
+{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":{"Service":"lambda.amazonaws.com"},"Action":"sts:AssumeRole","Condition":{"StringEquals":{"aws:SourceAccount":"640012953448"}}}]}
+EOF
+cat > "$T17/iam/operator-extra.json" <<'EOF'
+{"Version":"2012-10-17","Statement":[
+ {"Effect":"Allow","Action":"ec2:DeleteNetworkInterface","Resource":"arn:aws:ec2:eu-west-1:640012953448:network-interface/*"},
+ {"Effect":"Allow","Action":["ec2:DescribeNetworkInterfaces","ec2:DescribeSubnets","ec2:DescribeSecurityGroups","ec2:DescribeVpcs"],"Resource":"*"}]}
+EOF
+OPERATOR_ROLE=$NAME-connector-operator
+OPERATOR_ROLE_ARN=$(aws iam create-role --role-name "$OPERATOR_ROLE" --description "Task 17 connector ENI operator" \
+ --assume-role-policy-document "file://$T17/iam/operator-trust.json" --tags Key=purpose,Value=$TAGV \
+ --query Role.Arn --output text) && rec OPERATOR_ROLE "$OPERATOR_ROLE" && rec OPERATOR_ROLE_ARN "$OPERATOR_ROLE_ARN" || exit 1
+aws iam attach-role-policy --role-name "$OPERATOR_ROLE" --policy-arn arn:aws:iam::aws:policy/AWSLambdaNetworkConnectorOperatorPolicy
+aws iam put-role-policy --role-name "$OPERATOR_ROLE" --policy-name t17-eni-extra --policy-document "file://$T17/iam/operator-extra.json"
+aws iam wait role-exists --role-name "$OPERATOR_ROLE"
+aws iam list-attached-role-policies --role-name "$OPERATOR_ROLE" --query 'AttachedPolicies[].PolicyName' --output text
+aws iam list-role-policies --role-name "$OPERATOR_ROLE" --query PolicyNames --output text
+sleep 15
+```
+
+- Expected: role ARN `arn:aws:iam::640012953448:role/equipo-hosted-dev-t17-connector-operator`;
+ attached `AWSLambdaNetworkConnectorOperatorPolicy`; inline `t17-eni-extra`. The 15 s wait lets IAM
+ propagate.
+- Abort if: any call fails.
+
+### 2.2 Create the VPC_EGRESS connector for MicroVMs
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1
+aws lambda-core create-network-connector --name "$NAME-egress" \
+ --configuration "{\"VpcEgressConfiguration\":{\"SubnetIds\":[\"$SUBNET\"],\"SecurityGroupIds\":[\"$SG\"],\"NetworkProtocol\":\"IPv4\",\"AssociatedComputeResourceTypes\":[\"MicroVm\"]}}" \
+ --operator-role "$OPERATOR_ROLE_ARN" --tags purpose=$TAGV --client-token "$NAME-egress-1" \
+ --output json > "$T17/out/2.2-connector.json" || exit 1
+rec CONN_ARN "$(jq -r .Arn "$T17/out/2.2-connector.json")" && rec CONN_ID "$(jq -r .Id "$T17/out/2.2-connector.json")" || exit 1
+jq '{Arn,Id,State}' "$T17/out/2.2-connector.json"
+```
+
+- Expected: `Arn` of the form `arn:aws:lambda:eu-west-1:640012953448:network-connector:<Id>`,
+ `State` `PENDING`. No `ElasticIpConfiguration` is set, so the connector gets no Elastic IPs.
+- Abort if: an error, or the ARN does not have that form.
+
+### 2.3 Wait for ACTIVE (spike: about 4.5 min; bound 15 min)
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1
+for i in $(seq 1 60); do
+ s=$(aws lambda-core get-network-connector --identifier "$CONN_ARN" --query State --output text)
+ echo "$(date -u +%T) $s"; [ "$s" = ACTIVE ] && break
+ [ "$s" = FAILED ] && { aws lambda-core get-network-connector --identifier "$CONN_ARN" --query '[StateReason,StateReasonCode]' --output text; exit 1; }
+ sleep 15
+done
+[ "$s" = ACTIVE ] || exit 1
+```
+
+- Expected: `ACTIVE` within 15 min. Record the time it took.
+- Abort if: `FAILED` (record `StateReason` and `StateReasonCode`), or not ACTIVE after 15 min.
+
+### 2.4 Read the version and build the version-qualified ARN
+
+There is no publish call: each update creates a new version, and `Version` on the unqualified read
+is the current one. The installed CLI's model has no `LatestVersionArn` field (the Go SDK has it), so
+the plan builds the qualified ARN as `<Arn>:<Version>`, the form the networking guide prints. The
+controller's network audit later confirms it: it reads the connector by this ARN and requires
+`VersionArn` to equal it (`network.go`, `checkConnector`).
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1
+CONN_VERSION=$(aws lambda-core get-network-connector --identifier "$CONN_ARN" --query Version --output text) && rec CONN_VERSION "$CONN_VERSION" || exit 1
+rec CONN_QARN "$CONN_ARN:$CONN_VERSION" || exit 1
+[ "$(echo "$CONN_QARN" | awk -F: '{print NF, $7}')" = "8 $CONN_ID" ] && echo "qualified ARN shape ok: $CONN_QARN"
+aws lambda-core get-network-connector --identifier "$CONN_QARN" \
+ --query '[State,Version,Configuration.VpcEgressConfiguration.SubnetIds,Configuration.VpcEgressConfiguration.SecurityGroupIds,Configuration.VpcEgressConfiguration.AssociatedComputeResourceTypes]' --output json
+aws ec2 describe-network-interfaces --filters Name=subnet-id,Values="$SUBNET" --query 'NetworkInterfaces[].[NetworkInterfaceId,Status,InterfaceType,Description]' --output text
+```
+
+- Expected: `CONN_VERSION` is a whole number (likely `1`); "qualified ARN shape ok"; the qualified
+ read shows `ACTIVE`, the version, `[SUBNET]`, `[SG]`, `["MicroVm"]`. The connector's network
+ interfaces are listed (Lambda owns them; they are not ours to delete and are not put in the ledger
+ as deletable).
+- Abort if: the version is not numeric, the qualified read fails, or the subnet or group lists hold
+ anything else.
+- Record: connector ARN, ID, version, qualified ARN, time to ACTIVE, the interface IDs.
+
+---
+
+## 3. Image
+
+The API builds an image from a zip in S3 that holds a `Dockerfile` and its files, on a
+Lambda-managed base image, using a build role that can read the zip and write build logs
+(`microvms-images`, `microvms-getting-started`). It needs no ECR repository. Memory, x86_64 and the
+`ALL` OS capability are set per image version, so the Small (2048 MiB) and Large (4096 MiB) sizes are
+two versions of one image: create, then one update.
+
+The image is the smallest thing that answers the lifecycle hooks: a static Go binary that returns 200
+to every hook path on port 9000 inside the VM. The run hook must answer, because the adapter always
+sends a run hook payload and the VM takes traffic only after `/run` returns 200.
+
+### 3.1 S3 bucket for the code artifact
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1
+BUCKET=$NAME-$ACCOUNT-$(openssl rand -hex 3)
+aws s3api create-bucket --bucket "$BUCKET" --create-bucket-configuration LocationConstraint=eu-west-1 --query Location --output text && rec BUCKET "$BUCKET" || exit 1
+aws s3api put-public-access-block --bucket "$BUCKET" --public-access-block-configuration BlockPublicAcls=true,IgnorePublicAcls=true,BlockPublicPolicy=true,RestrictPublicBuckets=true
+aws s3api put-bucket-tagging --bucket "$BUCKET" --tagging "TagSet=[{Key=purpose,Value=$TAGV}]"
+aws s3api get-bucket-tagging --bucket "$BUCKET" --query 'TagSet[].[Key,Value]' --output text
+```
+
+- Expected: the bucket's location, then `purpose equipo-hosted-dev`.
+- Abort if: any call fails.
+
+### 3.2 Build log group (created by us so it carries the tag)
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1
+aws logs create-log-group --log-group-name "$LOG_GROUP" --tags purpose=$TAGV && rec LOG_GROUP_CREATED "$LOG_GROUP" || exit 1
+aws logs put-retention-policy --log-group-name "$LOG_GROUP" --retention-in-days 1
+aws logs describe-log-groups --log-group-name-prefix "$LOG_GROUP" --query 'logGroups[].[logGroupName,retentionInDays]' --output text
+```
+
+- Expected: `/aws/lambda-microvms/equipo-hosted-dev-t17 1`.
+- Abort if: the group already exists or a call fails.
+
+### 3.3 Build role
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1
+cat > "$T17/iam/build-trust.json" <<'EOF'
+{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":{"Service":"lambda.amazonaws.com"},"Action":"sts:AssumeRole"}]}
+EOF
+cat > "$T17/iam/build-policy.json" <<EOF
+{"Version":"2012-10-17","Statement":[
+ {"Effect":"Allow","Action":["s3:GetObject"],"Resource":"arn:aws:s3:::$BUCKET/*"},
+ {"Effect":"Allow","Action":["logs:CreateLogGroup","logs:CreateLogStream","logs:PutLogEvents"],"Resource":"arn:aws:logs:eu-west-1:$ACCOUNT:*"}]}
+EOF
+BUILD_ROLE=$NAME-image-build
+BUILD_ROLE_ARN=$(aws iam create-role --role-name "$BUILD_ROLE" --description "Task 17 MicroVM image build" \
+ --assume-role-policy-document "file://$T17/iam/build-trust.json" --tags Key=purpose,Value=$TAGV \
+ --query Role.Arn --output text) && rec BUILD_ROLE "$BUILD_ROLE" && rec BUILD_ROLE_ARN "$BUILD_ROLE_ARN" || exit 1
+aws iam put-role-policy --role-name "$BUILD_ROLE" --policy-name t17-build --policy-document "file://$T17/iam/build-policy.json"
+aws iam wait role-exists --role-name "$BUILD_ROLE"
+aws iam list-role-policies --role-name "$BUILD_ROLE" --query PolicyNames --output text
+sleep 15
+```
+
+- Expected: role ARN in `640012953448`; inline policy `t17-build`. This is the trust policy and
+ permission set the getting-started guide prints, narrowed to this bucket and this account's logs.
+ It is a build role only: no VM ever gets an execution role (spec §3, §15).
+- Abort if: any call fails.
+
+### 3.4 The hook binary, the Dockerfile and the zip (local only)
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" || exit 1
+cd "$T17/image" || exit 1
+cat > hookd.go <<'EOF'
+// hookd answers every Lambda MicroVM lifecycle hook with 200. Task 17 only.
+package main
+
+import (
+ "io"
+ "log"
+ "net/http"
+)
+
+func main() {
+ http.HandleFunc("/aws/lambda-microvms/runtime/v1/", func(w http.ResponseWriter, r *http.Request) {
+ n, _ := io.Copy(io.Discard, r.Body)
+ log.Printf("hook %s %d bytes", r.URL.Path, n)
+ w.WriteHeader(http.StatusOK)
+ })
+ log.Fatal(http.ListenAndServe(":9000", nil))
+}
+EOF
+cat > Dockerfile <<'EOF'
+FROM public.ecr.aws/lambda/microvms:al2023-minimal
+COPY hookd /usr/local/bin/hookd
+CMD ["/usr/local/bin/hookd"]
+EOF
+cat > hooks.json <<'EOF'
+{"port":9000,
+ "microvmHooks":{"run":"ENABLED","runTimeoutInSeconds":10,"resume":"ENABLED","resumeTimeoutInSeconds":10,
+ "suspend":"ENABLED","suspendTimeoutInSeconds":10,"terminate":"ENABLED","terminateTimeoutInSeconds":10},
+ "microvmImageHooks":{"ready":"ENABLED","readyTimeoutInSeconds":120,"validate":"DISABLED"}}
+EOF
+CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags=-s -o hookd hookd.go || exit 1
+chmod 0755 hookd
+python3 -I -m zipfile -c app.zip Dockerfile hookd || exit 1
+python3 -I -m zipfile -l app.zip
+file hookd 2>/dev/null || head -c 4 hookd | od -c | head -1
+sha256sum app.zip
+```
+
+- Expected: the zip lists `Dockerfile` and `hookd`; `hookd` is an x86-64 ELF; one sha256 line.
+- Abort if: the build fails.
+
+### 3.5 The image digest, and the upload that proves it
+
+AWS has no content digest for a MicroVM image. The controller's allowlist key
+(`sha256:` and 64 lower-case hex digits, `config.go`) is therefore the SHA-256 of the exact code
+artifact zip the image is built from. The upload sends that checksum and S3 refuses the object if the
+bytes differ; the read-back shows S3 holds the same checksum. `get-microvm-image-version` later shows
+which S3 object each version was built from (`codeArtifact.uri`). Slice 1b replaces this with
+certificates.
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1
+cd "$T17/image" || exit 1
+rec DIGEST "sha256:$(sha256sum app.zip | cut -d' ' -f1)" || exit 1
+B64=$(openssl dgst -sha256 -binary app.zip | base64)
+aws s3api put-object --bucket "$BUCKET" --key t17/app.zip --body app.zip --checksum-algorithm SHA256 --checksum-sha256 "$B64" \
+ --query ChecksumSHA256 --output text && rec ARTIFACT "s3://$BUCKET/t17/app.zip" || exit 1
+GOT=$(aws s3api head-object --bucket "$BUCKET" --key t17/app.zip --checksum-mode ENABLED --query ChecksumSHA256 --output text)
+[ "$GOT" = "$B64" ] && echo "S3 checksum matches $DIGEST"
+```
+
+- Expected: `DIGEST` like `sha256:<64 hex>`; put-object prints `$B64`; "S3 checksum matches".
+- Abort if: the checksums differ.
+
+### 3.6 Pick the managed base image and a version that supports x86_64
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1
+aws lambda-microvms list-managed-microvm-images --query 'items[].imageArn' --output text
+BASE_ARN=$(aws lambda-microvms list-managed-microvm-images --query "items[?ends_with(imageArn, ':microvm-image:al2023-1')].imageArn | [0]" --output text) && rec BASE_ARN "$BASE_ARN" || exit 1
+aws lambda-microvms list-managed-microvm-image-versions --image-identifier "$BASE_ARN" --query 'items[].[imageVersion,createdAt]' --output text
+BASE_VER=$(aws lambda-microvms list-managed-microvm-image-versions --image-identifier "$BASE_ARN" --query 'items[].imageVersion' --output text | tr '\t' '\n' | sort -V | tail -1)
+[ "${BASE_VER%%.*}" -ge 3 ] 2>/dev/null && rec BASE_VER "$BASE_VER" || { echo "ABORT: newest base version $BASE_VER is below 3"; exit 1; }
+```
+
+- Expected: `arn:aws:lambda:eu-west-1:aws:microvm-image:al2023-1`; the newest version is 3 or later
+ (x86_64 needs version 3 or later). The installed CLI drops the `status` and
+ `supportedCpuConfigurations` fields of this list; if the version cannot build x86_64, 3.7 fails
+ with a `ValidationException`, which is a stop.
+- Abort if: no `al2023-1` image, or the newest version is below 3.
+
+### 3.7 Create the image: Small version (2048 MiB, X86_64, ALL)
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1
+aws lambda-microvms create-microvm-image --name "$NAME" --description "Task 17 minimal hook image, small" \
+ --code-artifact "uri=$ARTIFACT" --base-image-arn "$BASE_ARN" --base-image-version "$BASE_VER" \
+ --build-role-arn "$BUILD_ROLE_ARN" --cpu-configurations '[{"architecture":"X86_64"}]' \
+ --resources '[{"minimumMemoryInMiB":2048}]' --additional-os-capabilities '["ALL"]' \
+ --hooks "file://$T17/image/hooks.json" --logging "{\"cloudWatch\":{\"logGroup\":\"$LOG_GROUP\"}}" \
+ --tags purpose=$TAGV --client-token "$NAME-create-1" --output json > "$T17/out/3.7-image.json" || exit 1
+rec IMAGE_ARN "$(jq -r .imageArn "$T17/out/3.7-image.json")" && rec VER_SMALL "$(jq -r .imageVersion "$T17/out/3.7-image.json")" || exit 1
+jq '{imageArn,imageVersion,state}' "$T17/out/3.7-image.json"
+```
+
+- Expected: `imageArn` `arn:aws:lambda:eu-west-1:640012953448:microvm-image:equipo-hosted-dev-t17`,
+ an `imageVersion`, state `CREATING`. No `egressNetworkConnectors` is passed, so the build uses the
+ default internet egress to pull the container base image; running VMs get only the connector.
+- Abort if: an error (a `ValidationException` about the architecture or base version included).
+
+### 3.8 Wait for the Small version (spike: about 2 min; bound 20 min)
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1
+for i in $(seq 1 80); do
+ r=$(aws lambda-microvms get-microvm-image-version --image-identifier "$IMAGE_ARN" --image-version "$VER_SMALL" --query '[state,status]' --output text)
+ echo "$(date -u +%T) $r"; case "$r" in SUCCESSFUL*ACTIVE) break;; FAILED*) break;; esac; sleep 15
+done
+aws lambda-microvms get-microvm-image-version --image-identifier "$IMAGE_ARN" --image-version "$VER_SMALL" \
+ --query '{state:state,status:status,reason:stateReason,arch:cpuConfigurations[].architecture,mem:resources[].minimumMemoryInMiB,caps:additionalOsCapabilities,artifact:codeArtifact.uri,hooks:hooks}' --output json
+```
+
+- Expected: `SUCCESSFUL ACTIVE`; `arch` `["X86_64"]`, `mem` `[2048]`, `caps` `["ALL"]`, `artifact`
+ `$ARTIFACT`, the hooks as sent. These are exactly the fields the adapter's image check reads
+ (`runner.go`, `checkImageVersion`).
+- Abort if: `FAILED` (then print the build log tail with
+ `aws logs filter-log-events --log-group-name "$LOG_GROUP" --limit 50 --query 'events[].message' --output text`
+ and stop), not done in 20 min, or any field differs.
+
+### 3.9 Large version (4096 MiB) by one update
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1
+aws lambda-microvms update-microvm-image --image-identifier "$IMAGE_ARN" --description "Task 17 minimal hook image, large" \
+ --code-artifact "uri=$ARTIFACT" --base-image-arn "$BASE_ARN" --base-image-version "$BASE_VER" \
+ --build-role-arn "$BUILD_ROLE_ARN" --cpu-configurations '[{"architecture":"X86_64"}]' \
+ --resources '[{"minimumMemoryInMiB":4096}]' --additional-os-capabilities '["ALL"]' \
+ --hooks "file://$T17/image/hooks.json" --logging "{\"cloudWatch\":{\"logGroup\":\"$LOG_GROUP\"}}" \
+ --client-token "$NAME-update-1" --output json > "$T17/out/3.9-image.json" || exit 1
+rec VER_LARGE "$(jq -r .imageVersion "$T17/out/3.9-image.json")" || exit 1
+[ "$VER_LARGE" != "$VER_SMALL" ] && echo "large version $VER_LARGE"
+```
+
+Then run the 3.8 wait block again with `VER_SMALL` replaced by `VER_LARGE` (expected `mem` `[4096]`),
+and confirm both versions are usable:
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1
+aws lambda-microvms list-microvm-image-versions --image-identifier "$IMAGE_ARN" --query 'items[].[imageVersion,state,status,resources[0].minimumMemoryInMiB]' --output text
+aws lambda-microvms get-microvm-image --image-identifier "$IMAGE_ARN" --query '[state,latestActiveImageVersion]' --output text
+aws lambda-microvms list-tags --resource "$IMAGE_ARN" --output json
+```
+
+- Expected: two versions, both `SUCCESSFUL ACTIVE`, 2048 and 4096; image state `CREATED` or
+ `UPDATED`; tag `purpose=equipo-hosted-dev`. No Large VM is launched in this run; the Large version
+ exists so the config maps both sizes and the adapter's image check can read it.
+- Abort if: the Small version became `INACTIVE` after the update, or any build failed.
+- Record: image ARN, both versions, base image ARN and version, digest, build times.
+
+---
+
+## 4. SNS topic for alerts
+
+The controller requires `sns_topic_arn` and refuses to start if a startup alert cannot be delivered
+(pre-flight concern 1).
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1
+TOPIC_ARN=$(aws sns create-topic --name "$NAME-alerts" --tags Key=purpose,Value=$TAGV --query TopicArn --output text) && rec TOPIC_ARN "$TOPIC_ARN" || exit 1
+aws sns list-tags-for-resource --resource-arn "$TOPIC_ARN" --query 'Tags[].[Key,Value]' --output text
+aws sns list-subscriptions-by-topic --topic-arn "$TOPIC_ARN" --query 'length(Subscriptions)' --output text
+```
+
+- Expected: `arn:aws:sns:eu-west-1:640012953448:equipo-hosted-dev-t17-alerts`; the tag; `0`
+ subscriptions. Alerts are counted in the controller's metrics
+ (`equipo_hosted_alerts_total{kind,result}`) and that is how the run reads them.
+- No subscription is made. If Paul wants email, he writes the address here before approving:
+ `EMAIL=________`; the agent then runs
+ `aws sns subscribe --topic-arn "$TOPIC_ARN" --protocol email --notification-endpoint "$EMAIL" --query SubscriptionArn --output text`
+ and Paul confirms the subscription from his inbox. Blank means skip.
+
+---
+
+## 5. Controller config, keys and TLS
+
+### 5.1 Keys and the self-signed certificate (pre-flight helper, offline)
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" || exit 1
+cd "$REPO" && EQUIPO_HOSTED_KEYGEN_DIR="$T17/keys" go test -tags hostedlive ./cmd/equipo-hosted-controller -run 'TestLiveKeygen$' -count=1 -v || exit 1
+ls -l "$T17/keys"
+openssl x509 -in "$T17/keys/tls.crt" -noout -subject -ext subjectAltName -enddate
+```
+
+- Expected: `controller.key`, `instance.key`, `operator.key`, `tls.key` with mode `-rw-------`;
+ `controller.pub`, `verify_keys.json`, `tls.crt`; SAN `IP Address:127.0.0.1`; valid 7 days.
+- Abort if: the test fails or a key file is readable by group or others.
+
+### 5.2 Ports are free on 127.0.0.1
+
+```sh
+ss -ltn '( sport = :18443 or sport = :18444 )'
+```
+
+- Expected: only the header line.
+- Abort if: either port is in use. (Picking other ports is a change; ask.)
+
+### 5.3 Controller config and live contract config (filled from the ledger)
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" || exit 1
+jq -n --slurpfile vk "$T17/keys/verify_keys.json" \
+ --arg api "$API" --arg met "$METRICS" --arg d "$T17" --arg digest "$DIGEST" --arg arn "$IMAGE_ARN" \
+ --arg small "$VER_SMALL" --arg large "$VER_LARGE" --arg vpc "$VPC" --arg subnet "$SUBNET" --arg sg "$SG" \
+ --arg conn "$CONN_QARN" --arg topic "$TOPIC_ARN" '{
+ listen: $api, metrics_listen: $met,
+ tls_cert_file: ($d + "/keys/tls.crt"), tls_key_file: ($d + "/keys/tls.key"),
+ database: ($d + "/controller.db"), signing_key_file: ($d + "/keys/controller.key"),
+ verify_keys: $vk[0],
+ images: [{digest: $digest, arn: $arn, versions: {small: $small, large: $large}}],
+ region: "eu-west-1", vpc_id: $vpc, vm_subnet_id: $subnet, vm_security_group_id: $sg,
+ connector_arn: $conn, egress: [], sns_topic_arn: $topic}' > "$T17/controller.json" || exit 1
+jq -n --arg digest "$DIGEST" --arg arn "$IMAGE_ARN" --arg small "$VER_SMALL" --arg large "$VER_LARGE" \
+ --arg vpc "$VPC" --arg subnet "$SUBNET" --arg sg "$SG" --arg conn "$CONN_QARN" '{
+ region: "eu-west-1", connector_id: $conn, vpc_id: $vpc, vm_subnet_id: $subnet, vm_security_group_id: $sg,
+ image: $digest, image_arn: $arn, versions: {small: $small, large: $large}, egress: []}' > "$T17/live.json" || exit 1
+cat "$T17/controller.json" "$T17/live.json"
+```
+
+With the ledger filled in, `controller.json` reads like this (angle brackets are ledger values):
+
+```json
+{
+ "listen": "127.0.0.1:18443",
+ "metrics_listen": "127.0.0.1:18444",
+ "tls_cert_file": "<T17>/keys/tls.crt",
+ "tls_key_file": "<T17>/keys/tls.key",
+ "database": "<T17>/controller.db",
+ "signing_key_file": "<T17>/keys/controller.key",
+ "verify_keys": [
+ {"id": "task17-instance", "role": "instance", "public_key": "<base64>"},
+ {"id": "task17-operator", "role": "operator", "public_key": "<base64>"}
+ ],
+ "images": [{"digest": "<DIGEST>", "arn": "<IMAGE_ARN>", "versions": {"small": "<VER_SMALL>", "large": "<VER_LARGE>"}}],
+ "region": "eu-west-1",
+ "vpc_id": "<VPC>",
+ "vm_subnet_id": "<SUBNET>",
+ "vm_security_group_id": "<SG>",
+ "connector_arn": "<CONN_ARN>:<CONN_VERSION>",
+ "egress": [],
+ "sns_topic_arn": "<TOPIC_ARN>"
+}
+```
+
+- Expected: both files print with no empty value; `egress` is `[]` in both (ruling R30).
+- Abort if: any value is empty or `null`.
+
+### 5.4 Build the two controller binaries (offline)
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" || exit 1
+cd "$REPO" && go build -o "$T17/bin/controller" ./cmd/equipo-hosted-controller && \
+ go build -tags hostedlive -o "$T17/bin/controller-crash" ./cmd/equipo-hosted-controller && ls -l "$T17/bin"
+```
+
+- Expected: two binaries. `controller` is the normal build (no crash point); `controller-crash` is
+ only for 7.4.
+- Abort if: a build fails.
+
+---
+
+## 6. Live contract
+
+Runs after 9.A to 9.F, so the client-token behaviour is already known.
+
+### 6.1 Run it
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1
+[ -z "$(live_vms)" ] || { echo "ABORT: live VMs before the contract"; live_vms; exit 1; }
+date -u +%FT%TZ > "$T17/out/6-start"
+cd "$REPO" && EQUIPO_HOSTED_LIVE_CONFIG="$T17/live.json" \
+ go test -tags hostedlive ./internal/isolatedjob/awsjob -run TestLiveContract -count=1 -v -timeout 60m 2>&1 | tee "$T17/out/6-contract.log"
+```
+
+- Expected: `--- PASS: TestLiveContract` with every subtest passing. The contract launches about 7
+ Small VMs, each with a 15-minute maximum duration and stopped by its own cleanup.
+- Pre-approved exceptions (record and continue to 6.2): `StopUnknownRef` fails because AWS answers a
+ malformed ID with a `ValidationException` rather than not found; or `ChangedSpecConflicts` fails
+ only because the error is not mapped to `ErrConflict`, and 9.A showed that a changed request with a
+ used token creates no second VM. Either is a finding for an adapter fix after the run.
+- Abort if: any other subtest fails, or `ChangedSpecConflicts` shows a second VM.
+
+### 6.2 Nothing left running
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1
+for i in $(seq 1 30); do l=$(our_live); [ -z "$l" ] && break; echo "$(date -u +%T) still live:"; echo "$l"; sleep 10; done
+echo "ours live: [$(our_live)]"; echo "any live: [$(live_vms)]"
+aws lambda-microvms list-microvms --query "items[?imageArn=='$IMAGE_ARN'].[microvmId,state,startedAt]" --output text
+```
+
+- Expected: both live lists empty within 5 minutes (TERMINATING may linger briefly); the full list
+ shows this run's VMs as `TERMINATED` (record how many and when, for 9.F).
+- Abort if: a VM is still live after 5 minutes. Terminate it with
+ `aws lambda-microvms terminate-microvm --microvm-identifier <id>`, record it as a leak, then stop.
+- Record: the PASS/FAIL lines, the visibility and List lag the log shows, VM count.
+
+---
+
+## 7. Controller on docs-t1
+
+### 7.1 Start the controller (normal build), launches on
+
+Start it with the Bash tool's `run_in_background`, so it outlives the call:
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1
+[ -z "$(live_vms)" ] || { echo "ABORT: live VMs before the controller starts"; exit 1; }
+cd "$REPO" && echo $$ > "$T17/controller.pid" && \
+ exec env EQUIPO_HOSTED_ENABLED=1 "$T17/bin/controller" -config "$T17/controller.json" >> "$T17/controller.log" 2>&1
+```
+
+Then, in a new call:
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" || exit 1
+ss -ltn '( sport = :18443 or sport = :18444 )'
+for i in $(seq 1 24); do metrics | grep -E 'network_audit_passing|store_readable|reap_last_error' && metrics | grep -q '^equipo_hosted_network_audit_passing 1' && break; sleep 10; done
+grep -E 'API on|launches enabled' "$T17/controller.log"
+```
+
+- Expected: both listeners on `127.0.0.1` only; log line `API on 127.0.0.1:18443, metrics on
+ 127.0.0.1:18444, launches enabled: true`; within 4 minutes
+ `equipo_hosted_network_audit_passing 1`, `equipo_hosted_store_readable 1`,
+ `equipo_hosted_reap_last_error 0`. The audit passing is the live proof that VPC DNS is off, the
+ route table has only the local route, the group has no rules, and the qualified connector ARN
+ matches `VersionArn` (U3).
+- Abort if: the controller exits (read the log), a listener is on another address, or the audit is
+ not passing after 4 minutes (the log names the failed property).
+
+### 7.2 Driver sequence: launch Small, drain, quiescent, suspend, resume, stop with proof
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" || exit 1
+export EQUIPO_HOSTED_LIVE_URL=https://$API EQUIPO_HOSTED_LIVE_CA_FILE="$T17/keys/tls.crt" \
+ EQUIPO_HOSTED_LIVE_KEY_ID=task17-instance EQUIPO_HOSTED_LIVE_KEY_FILE="$T17/keys/instance.key" \
+ EQUIPO_HOSTED_LIVE_CONTROLLER_KEY_FILE="$T17/keys/controller.pub" EQUIPO_HOSTED_LIVE_IMAGE="$DIGEST"
+cd "$REPO" && go test -tags hostedlive ./internal/hostedclient -run 'TestLiveControllerSequence$' -count=1 -v -timeout 30m 2>&1 | tee "$T17/out/7.2-sequence.log"
+grep -E 'attempt |timings:' "$T17/out/7.2-sequence.log"
+. "$TMPDIR/equipo-t17/env.sh" && echo "ours live: [$(our_live)]"
+```
+
+- Expected: `--- PASS`; the `timings:` line (launch call a few seconds; `to_running` up to about a
+ minute, because the controller reads states once per 60 s pass; the resume epoch one above the
+ launch epoch; `stop_to_proof` within about 2 to 3 minutes, since R17 wants two not-found reads 60 s
+ apart or a terminal state). `our_live` empty.
+- Abort if: FAIL. The test's cleanup stops its VM; confirm with `our_live`, then stop.
+- Record: attempt ID, VM ref, the whole `timings:` line, the epoch.
+
+### 7.3 Stop the controller
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" || exit 1
+kill -TERM "$(cat "$T17/controller.pid")"
+for i in $(seq 1 40); do ss -ltn '( sport = :18443 )' | grep -q 18443 || break; sleep 1; done
+tail -3 "$T17/controller.log"; ss -ltn '( sport = :18443 or sport = :18444 )'
+```
+
+- Expected: the listeners close within 40 s (30 s drain). If `kill` cannot see the process (the
+ sandbox can hide processes from later calls), stop the background task with the agent's task-stop
+ tool instead and check the ports the same way.
+- Abort if: the ports stay open.
+
+### 7.4 Crash between the provider call and transaction 2
+
+Start the crash build in the background (`run_in_background`), same database:
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1
+rec CRASH_ATTEMPT "task17-crash-$(openssl rand -hex 4)" || exit 1
+date -u +%FT%T > "$T17/out/7.4-start"
+cd "$REPO" && echo $$ > "$T17/controller.pid" && \
+ exec env EQUIPO_HOSTED_ENABLED=1 EQUIPO_HOSTED_CRASH_AFTER_LAUNCH=1 "$T17/bin/controller-crash" -config "$T17/controller.json" >> "$T17/controller.log" 2>&1
+```
+
+Wait for the audit as in 7.1 (`equipo_hosted_network_audit_passing 1`), then:
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" || exit 1
+grep -c 'CRASH_AFTER_LAUNCH=1' "$T17/controller.log"
+export EQUIPO_HOSTED_LIVE_URL=https://$API EQUIPO_HOSTED_LIVE_CA_FILE="$T17/keys/tls.crt" \
+ EQUIPO_HOSTED_LIVE_KEY_ID=task17-instance EQUIPO_HOSTED_LIVE_KEY_FILE="$T17/keys/instance.key" \
+ EQUIPO_HOSTED_LIVE_CONTROLLER_KEY_FILE="$T17/keys/controller.pub" EQUIPO_HOSTED_LIVE_IMAGE="$DIGEST" \
+ EQUIPO_HOSTED_LIVE_ATTEMPT="$CRASH_ATTEMPT" EQUIPO_HOSTED_LIVE_CRASH_STEP=launch
+cd "$REPO" && go test -tags hostedlive ./internal/hostedclient -run 'TestLiveCrashRecovery$' -count=1 -v -timeout 10m 2>&1 | tee "$T17/out/7.4-launch.log"
+grep 'crash point' "$T17/controller.log" | tail -1
+. "$TMPDIR/equipo-t17/env.sh" && rec CRASH_VM "$(grep -o 'provider launched [^ ]*' "$T17/controller.log" | tail -1 | cut -d' ' -f3)"
+ss -ltn '( sport = :18443 )'; vm_state "$CRASH_VM"
+```
+
+- Expected: the log shows the crash switch is on; the test PASSes (the launch fails in transport);
+ the controller log ends with `crash point: the provider launched <vm> for <attempt>; exiting
+ before the Ref is saved`; port 18443 is closed; the VM is `PENDING` or `RUNNING`. If the launch is
+ refused with "no network audit has passed recently", run the test again after 10 s (pre-flight
+ concern 2); a refused launch creates nothing.
+- Abort if: the controller answered the launch (the test says so), or no VM was launched.
+
+### 7.5 Restart without the crash switch; Replay claims the one VM
+
+Start the normal build in the background (`run_in_background`). The crash variable must not be set
+(pre-flight concern 3):
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1
+cd "$REPO" && echo $$ > "$T17/controller.pid" && \
+ exec env -u EQUIPO_HOSTED_CRASH_AFTER_LAUNCH EQUIPO_HOSTED_ENABLED=1 "$T17/bin/controller" -config "$T17/controller.json" >> "$T17/controller.log" 2>&1
+```
+
+Then:
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" || exit 1
+export EQUIPO_HOSTED_LIVE_URL=https://$API EQUIPO_HOSTED_LIVE_CA_FILE="$T17/keys/tls.crt" \
+ EQUIPO_HOSTED_LIVE_KEY_ID=task17-instance EQUIPO_HOSTED_LIVE_KEY_FILE="$T17/keys/instance.key" \
+ EQUIPO_HOSTED_LIVE_CONTROLLER_KEY_FILE="$T17/keys/controller.pub" EQUIPO_HOSTED_LIVE_IMAGE="$DIGEST" \
+ EQUIPO_HOSTED_LIVE_ATTEMPT="$CRASH_ATTEMPT" EQUIPO_HOSTED_LIVE_CRASH_STEP=recover \
+ EQUIPO_HOSTED_LIVE_OPERATOR_KEY_ID=task17-operator EQUIPO_HOSTED_LIVE_OPERATOR_KEY_FILE="$T17/keys/operator.key"
+cd "$REPO" && go test -tags hostedlive ./internal/hostedclient -run 'TestLiveCrashRecovery$' -count=1 -v -timeout 15m 2>&1 | tee "$T17/out/7.5-recover.log"
+grep -E 'recover:|listed vm|stop:' "$T17/out/7.5-recover.log"
+. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1
+aws lambda-microvms list-microvms --query "items[?imageArn=='$IMAGE_ARN']" --output json \
+ | jq --arg t "$(cat "$T17/out/7.4-start")" '[.[] | select(.startedAt >= $t)] | map({microvmId,state,startedAt})'
+echo "ours live: [$(our_live)]"
+```
+
+- Expected: `--- PASS`; `recover:` shows the job holding `$CRASH_VM` (the same ID as in 7.4);
+ exactly one listed VM for the attempt and no unowned live VM; stop with proof. The CLI list of VMs
+ started since 7.4 began holds exactly one entry, `$CRASH_VM`, now `TERMINATING` or `TERMINATED`.
+ `our_live` empty.
+- Abort if: FAIL, a second VM for the attempt, or a VM ID other than `$CRASH_VM`.
+- Record: the attempt, the VM, the `recover:` and `stop:` lines, how long Replay took after restart.
+
+Leave this controller running for section 8.
+
+---
+
+## 8. Orphan
+
+### 8.1 Plant a VM the controller does not know
+
+The controller is running (from 7.5) with no waiting intent, so R22 deferral does not apply.
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1
+metrics | grep -E 'jobs\{|orphans|alerts_total'
+rec ORPHAN_TOKEN "t17-orphan-$(date +%s)" || exit 1
+date -u +%FT%TZ > "$T17/out/8-planted"
+aws lambda-microvms run-microvm --image-identifier "$IMAGE_ARN" --image-version "$VER_SMALL" --client-token "$ORPHAN_TOKEN" \
+ --ingress-network-connectors "$NO_INGRESS" --egress-network-connectors "$CONN_QARN" \
+ --maximum-duration-in-seconds 1800 --run-hook-payload orphan \
+ --query '[microvmId,state,startedAt]' --output text > "$T17/out/8-orphan.txt" || exit 1
+rec ORPHAN_VM "$(cut -f1 "$T17/out/8-orphan.txt")" && cat "$T17/out/8-orphan.txt" "$T17/out/8-planted"
+```
+
+- Expected: a VM ID, `PENDING`, and its start time. No job row or intent names this token. Its
+ 1800 s maximum duration is the AWS backstop.
+- Abort if: the run fails; or `jobs{state="waiting"}` was above 0 before planting.
+
+### 8.2 Watch the reaper stop it
+
+Expected timeline from the plant time P: the reaper lists every 60 s, so it first sees the VM by
+about P+1:30 (including List lag); it stops an orphan on the first pass at least 10 minutes after
+that first sighting, after rechecking ownership; so the stop comes between about P+11:00 and
+P+12:30, and the VM is `TERMINATED` (or not found) within about a minute after that.
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" || exit 1
+P=$(date -d "$(cat "$T17/out/8-planted")" +%s)
+while :; do
+ now=$(date +%s); s=$(vm_state "$ORPHAN_VM")
+ echo "P+$(( (now-P)/60 )):$(printf %02d $(( (now-P)%60 ))) $s $(metrics | grep -E 'orphans_stopped|orphan_stopped' | tr '\n' ' ')"
+ case "$s" in TERMINATED|*ResourceNotFound*) break;; esac
+ [ $(( now - P )) -ge 900 ] && { echo "ABORT: not stopped by P+15:00"; break; }
+ sleep 30
+done
+grep -i orphan "$T17/controller.log" | tail -5
+```
+
+- Expected: the state stays `RUNNING` until about P+11:00 to P+12:30, then `TERMINATING` and
+ `TERMINATED`; metrics show `equipo_hosted_alerts_total{kind="orphan_stopped",result="sent"} 1`
+ (and `reap_last_orphans_stopped 1` on that pass); the controller log names the VM.
+- Abort if: the VM is stopped before P+10:00 (the grace is not being honoured), or it is still live
+ at P+15:00. In the second case, terminate it:
+ `aws lambda-microvms terminate-microvm --microvm-identifier "$ORPHAN_VM"`, record, stop.
+
+### 8.3 Confirm by Get and List, then stop the controller
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1
+aws lambda-microvms get-microvm --microvm-identifier "$ORPHAN_VM" --query '[state,stateReason,terminatedAt]' --output text 2>&1
+echo "ours live: [$(our_live)]"; echo "any live: [$(live_vms)]"
+```
+
+Then stop the controller with the 7.3 block.
+
+- Expected: `TERMINATED` (or not found); both live lists empty; controller stopped, ports closed.
+- Record: P, first sighting time if logged, stop time, terminated time, the alert and metric lines.
+
+---
+
+## 9. Facts to record (R7)
+
+9.A to 9.F run before section 6 with no controller running, so the reaper never sees these VMs.
+Every VM here uses this run's image, the Small version, `NO_INGRESS`, the qualified connector, and a
+short maximum duration as the AWS backstop; each is terminated as soon as its fact is read.
+
+Helper for this section (paste at the top of each 9 block, after the env line):
+
+```sh
+runvm() { # runvm LABEL TOKEN MAXSECONDS PAYLOADFILE: write the reply to out/9-LABEL.json, the error to .err
+ aws lambda-microvms run-microvm --image-identifier "$IMAGE_ARN" --image-version "$VER_SMALL" --client-token "$2" \
+ --ingress-network-connectors "$NO_INGRESS" --egress-network-connectors "$CONN_QARN" \
+ --maximum-duration-in-seconds "$3" --run-hook-payload "file://$4" --output json > "$T17/out/9-$1.json" 2> "$T17/out/9-$1.err"
+ echo "exit $? $(jq -c '{microvmId,state,startedAt,ingressNetworkConnectors}' "$T17/out/9-$1.json" 2>/dev/null) $(cat "$T17/out/9-$1.err")"
+}
+```
+
+### 9.A Client token: same request, changed request, replay after the end
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1
+# (paste runvm here)
+[ -z "$(live_vms)" ] || { echo "ABORT: live VMs"; exit 1; }
+printf 'task17-a' > "$T17/out/payload-a"; printf 'task17-b' > "$T17/out/payload-b"
+rec TOKEN_A "t17-token-$(openssl rand -hex 4)" || exit 1
+date -u +%FT%T.%3NZ > "$T17/out/9-A1.before"
+runvm A1 "$TOKEN_A" 1200 "$T17/out/payload-a"
+date -u +%FT%T.%3NZ > "$T17/out/9-A1.after"
+rec VM_A "$(jq -r .microvmId "$T17/out/9-A1.json")" || exit 1
+runvm A2 "$TOKEN_A" 1200 "$T17/out/payload-a"
+runvm A3 "$TOKEN_A" 1200 "$T17/out/payload-b"
+A3=$(jq -r '.microvmId // empty' "$T17/out/9-A3.json" 2>/dev/null)
+[ -n "$A3" ] && [ "$A3" != "$VM_A" ] && { rec VM_A3 "$A3"; aws lambda-microvms terminate-microvm --microvm-identifier "$A3"; echo "FINDING: a changed request with a used token made a second VM"; }
+```
+
+- Expected: A1 returns a new VM (`PENDING`). A2 (same token, same request) returns the same
+ `microvmId`. A3 (same token, changed payload) is refused; record the exact error code and message
+ (candidates: `ConflictException` or `ValidationException`).
+- If A3 returns `VM_A` itself: AWS ignores the body on replay; record it.
+- If A3 returns another VM: it is terminated at once; record it; 6.1's `ChangedSpecConflicts`
+ exception no longer applies, so a contract failure there becomes a stop.
+
+Keep `VM_A` for 9.B to 9.D; 9.E terminates it and replays the token.
+
+### 9.B startedAt timing, NO_INGRESS literal and the Date header
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1
+cat "$T17/out/9-A1.before" "$T17/out/9-A1.after"; jq '{state,startedAt}' "$T17/out/9-A1.json"
+for i in $(seq 1 120); do
+ r=$(aws lambda-microvms get-microvm --microvm-identifier "$VM_A" --query '[state,startedAt]' --output text)
+ echo "$(date -u +%T.%3N) $r"; case "$r" in RUNNING*|TERMINAT*) break;; esac; sleep 1
+done
+aws lambda-microvms get-microvm --microvm-identifier "$VM_A" --query '{state:state,startedAt:startedAt,ingress:ingressNetworkConnectors,egress:egressNetworkConnectors,max:maximumDurationInSeconds,role:executionRoleArn,idle:idlePolicy}' --output json
+aws lambda-microvms get-microvm --microvm-identifier "$VM_A" --debug 2>&1 >/dev/null | grep -m1 'Response headers' | grep -o "'[Dd]ate': '[^']*'"
+aws lambda-microvms list-microvms --debug 2>&1 >/dev/null | grep -m1 'Response headers' | grep -o "'[Dd]ate': '[^']*'"
+```
+
+- Expected: `startedAt` is present in the PENDING reply; record how it compares with the local
+ before/after times of the run call and with the time the VM reached RUNNING, and whether it changes
+ between PENDING and RUNNING. The VM reaches RUNNING within about 10 s (spike: first response 2.3 to
+ 3.2 s). The read shows ingress exactly `["arn:aws:lambda:eu-west-1:aws:network-connector:aws-network-connector:NO_INGRESS"]`,
+ egress `[CONN_QARN]`, max 1200, no role, no idle policy. Both Date greps print a `Date` header
+ (record "present" or "absent" for Get and for List; absent means `AgeKnown` is always false and the
+ controller never trusts provider age across a restart).
+- Only the `Date` value is kept from `--debug`; nothing else from the debug output is written down.
+- Abort if: the VM goes from PENDING to TERMINATING (the run hook failed; record `stateReason`), or
+ the ingress literal is echoed differently.
+
+### 9.C Resume on RUNNING; suspend on SUSPENDED; resume twice
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1
+echo "resume RUNNING:"; aws lambda-microvms resume-microvm --microvm-identifier "$VM_A" 2>&1; echo "exit $?"
+date -u +%T.%3N; aws lambda-microvms suspend-microvm --microvm-identifier "$VM_A" 2>&1; echo "exit $?"
+wait_vm "$VM_A" SUSPENDED 180 || exit 1
+echo "suspend SUSPENDED:"; aws lambda-microvms suspend-microvm --microvm-identifier "$VM_A" 2>&1; echo "exit $?"
+date -u +%T.%3N; aws lambda-microvms resume-microvm --microvm-identifier "$VM_A" 2>&1; echo "exit $?"
+echo "second resume at once:"; aws lambda-microvms resume-microvm --microvm-identifier "$VM_A" 2>&1; echo "exit $?"
+wait_vm "$VM_A" RUNNING 180 || exit 1
+```
+
+- Expected: resume on RUNNING fails with `ConflictException` (doc.go, R4); record the exact message.
+ Suspend reaches SUSPENDED in 2 to 4 s (spike). Suspend on SUSPENDED: record the result. The second
+ resume, sent while the first is in progress (the VM stays SUSPENDED while `/resume` runs): record
+ the result. The VM is RUNNING again within a few seconds.
+- If resume on RUNNING is not a `ConflictException`, the adapter's no-op mapping is wrong: record it;
+ 6.1's `ResumeRunningIsNoop` will fail and that is a stop there.
+- Abort if: a wait times out.
+
+### 9.D Payload limit (4096 and 4097 bytes, ASCII)
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1
+# (paste runvm here)
+for n in 4096 4097; do
+ head -c "$n" /dev/zero | tr '\0' x > "$T17/out/payload-$n"; wc -c < "$T17/out/payload-$n"
+ runvm "P$n" "t17-p$n-$(openssl rand -hex 3)" 120 "$T17/out/payload-$n"
+ id=$(jq -r '.microvmId // empty' "$T17/out/9-P$n.json" 2>/dev/null)
+ [ -n "$id" ] && { rec "VM_P$n" "$id"; aws lambda-microvms terminate-microvm --microvm-identifier "$id"; echo "terminated $id"; }
+done
+```
+
+- Expected: 4096 accepted (VM terminated at once); 4097 refused with a `ValidationException` naming
+ the length. Both refusal and acceptance are results; record which.
+- If 4097 is accepted: run the same loop once more for `16384 16385` (the developer guide says 16 KB)
+ and record those two results. Each accepted VM is terminated at once and has a 120 s backstop.
+- Abort if: a terminate fails.
+
+### 9.E Replay the token after the VM has ended
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1
+# (paste runvm here)
+aws lambda-microvms terminate-microvm --microvm-identifier "$VM_A" 2>&1; echo "exit $?"
+wait_vm "$VM_A" TERMINATED 300 || exit 1
+date -u +%FT%TZ > "$T17/out/9-A.terminated"
+echo "terminate again:"; aws lambda-microvms terminate-microvm --microvm-identifier "$VM_A" 2>&1; echo "exit $?"
+runvm E1 "$TOKEN_A" 1200 "$T17/out/payload-a"
+E1=$(jq -r '.microvmId // empty' "$T17/out/9-E1.json" 2>/dev/null)
+[ -n "$E1" ] && [ "$E1" != "$VM_A" ] && { rec VM_E1 "$E1"; aws lambda-microvms terminate-microvm --microvm-identifier "$E1"; echo "FINDING: replay after termination made a new VM"; }
+aws lambda-microvms get-microvm --microvm-identifier "$VM_A" --query '[state,stateReason,terminatedAt]' --output text 2>&1
+```
+
+- Expected: terminate twice succeeds both times (documented idempotent). Record what the replay of
+ the original token and request returns now: `VM_A` again (state `TERMINATED`), a new VM
+ (terminated at once), or an error. This decides how a controller Replay after a long outage
+ behaves.
+
+### 9.F How long TERMINATED VMs stay visible (spans the run)
+
+Run this at the end of 9.E, after 6.2, after 7.5, after 8.3 and at the start of 10:
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1
+for v in $VM_A ${VM_P4096:-}; do echo "$(date -u +%T) $v get: $(vm_state "$v")"; done
+aws lambda-microvms list-microvms --query "items[?state=='TERMINATED'] | length(@)" --output text
+cat "$T17/out/9-A.terminated"
+```
+
+- Expected: record, at each checkpoint, whether Get still answers `TERMINATED` or not found, and
+ how many TERMINATED VMs List still returns. The last checkpoint that sees `VM_A` gives a lower
+ bound on the visibility window; the first that does not gives an upper bound.
+
+### 9.G Final facts (after section 8, controller stopped)
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1
+# (paste runvm here)
+runvm G1 "$TOKEN_A" 1200 "$T17/out/payload-a"
+G1=$(jq -r '.microvmId // empty' "$T17/out/9-G1.json" 2>/dev/null)
+[ -n "$G1" ] && [ "$G1" != "$VM_A" ] && { rec VM_G1 "$G1"; aws lambda-microvms terminate-microvm --microvm-identifier "$G1"; wait_vm "$G1" GONE 300; }
+echo "hours since first use: $(( ( $(date +%s) - $(date -d "$(cat "$T17/out/9-A1.before")" +%s) ) / 3600 ))"
+```
+
+- Expected: the replay of `TOKEN_A`, now 3 to 4 hours after its first use. If it still returns
+ `VM_A`, the token window is at least that long; if it makes a new VM (terminated at once) or errors,
+ the window is shorter. Record which, with the hours.
+- Then run 9.F once more.
+
+**What gets recorded for R7** (copy into the progress file, one line each): client token: A2 result,
+A3 error, E1 result, G1 result with hours; Date header on Get and List; startedAt in PENDING and its
+relation to the call and to RUNNING; resume on RUNNING error; suspend on SUSPENDED result; second
+resume result; payload 4096/4097 (and 16384/16385 if run); the NO_INGRESS literal as echoed; the
+TERMINATED visibility bounds; and, from 6.1, the visibility and List lag the contract measured
+(the pre-flight's 60 s and 30 s are guesses).
+
+---
+
+## 10. Teardown
+
+Runs after 9.G, or on Paul's word after an abort. Dependency order. Every delete names an ID from
+the ledger; nothing else is deleted. Each step's "Expected" is the deletion confirmation; failures
+are a stop, except where a retry is written in.
+
+### 10.1 No VM left, controller stopped
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1
+ss -ltn '( sport = :18443 or sport = :18444 )'
+for v in $(our_live | cut -f1); do echo "terminating $v"; aws lambda-microvms terminate-microvm --microvm-identifier "$v"; done
+for v in $(our_live | cut -f1); do wait_vm "$v" GONE 300; done
+echo "ours live: [$(our_live)]"; echo "any live: [$(live_vms)]"
+```
+
+- Expected: no listener; nothing to terminate (any VM terminated here is a leak and is recorded);
+ both lists empty.
+
+### 10.2 Image (both versions)
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1
+aws lambda-microvms delete-microvm-image --image-identifier "$IMAGE_ARN" --output text 2>&1 | tee "$T17/out/10.2-delete.txt"
+if grep -q ConflictException "$T17/out/10.2-delete.txt"; then
+ for v in "$VER_LARGE" "$VER_SMALL"; do aws lambda-microvms delete-microvm-image-version --image-identifier "$IMAGE_ARN" --image-version "$v"; done
+ sleep 30; aws lambda-microvms delete-microvm-image --image-identifier "$IMAGE_ARN" --output text
+fi
+for i in $(seq 1 40); do r=$(aws lambda-microvms get-microvm-image --image-identifier "$IMAGE_ARN" --query state --output text 2>&1); echo "$(date -u +%T) $r"; case "$r" in DELETED|*ResourceNotFound*) break;; esac; sleep 15; done
+```
+
+- Expected: `DELETING`, then `DELETED` or not found within 10 minutes. The version-by-version
+ fallback runs only if AWS refuses to delete an image that has versions.
+
+### 10.3 Connector, then wait for its network interfaces to go
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1
+aws lambda-core delete-network-connector --identifier "$CONN_ARN" 2>&1; echo "exit $?"
+for i in $(seq 1 60); do r=$(aws lambda-core get-network-connector --identifier "$CONN_ARN" --query State --output text 2>&1); echo "$(date -u +%T) $r"; case "$r" in *ResourceNotFound*) break;; DELETE_FAILED) break;; esac; sleep 15; done
+for i in $(seq 1 80); do n=$(aws ec2 describe-network-interfaces --filters Name=vpc-id,Values="$VPC" --query 'length(NetworkInterfaces)' --output text); echo "$(date -u +%T) ENIs in VPC: $n"; [ "$n" = 0 ] && break; sleep 30; done
+```
+
+- Expected: the connector goes `DELETING`, then not found within 15 minutes; then no network
+ interface is left in the VPC within 40 minutes.
+- Abort if: `DELETE_FAILED`, or interfaces remain after 40 minutes. Do not delete Lambda's
+ interfaces by hand; ask Paul.
+
+### 10.4 Network, in order
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1
+aws ec2 delete-security-group --group-id "$SG" --query Return --output text
+aws ec2 disassociate-route-table --association-id "$RTB_ASSOC"
+aws ec2 delete-route-table --route-table-id "$RTB"
+aws ec2 delete-subnet --subnet-id "$SUBNET"
+aws ec2 delete-vpc --vpc-id "$VPC"
+```
+
+- Expected: each call succeeds (the first prints `True`). The VPC's main route table, default
+ security group and default network ACL go with the VPC.
+- Abort if: a `DependencyViolation`; list what still depends on it with
+ `aws ec2 describe-network-interfaces --filters Name=vpc-id,Values="$VPC"` and ask.
+
+### 10.5 IAM roles
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1
+aws iam detach-role-policy --role-name "$OPERATOR_ROLE" --policy-arn arn:aws:iam::aws:policy/AWSLambdaNetworkConnectorOperatorPolicy
+aws iam delete-role-policy --role-name "$OPERATOR_ROLE" --policy-name t17-eni-extra
+aws iam delete-role --role-name "$OPERATOR_ROLE"
+aws iam delete-role-policy --role-name "$BUILD_ROLE" --policy-name t17-build
+aws iam delete-role --role-name "$BUILD_ROLE"
+```
+
+- Expected: each call succeeds.
+
+### 10.6 S3, logs, SNS
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1
+aws s3api delete-object --bucket "$BUCKET" --key t17/app.zip
+aws s3api list-object-versions --bucket "$BUCKET" --query '[length(Versions || `[]`),length(DeleteMarkers || `[]`)]' --output text
+aws s3api delete-bucket --bucket "$BUCKET"
+aws logs describe-log-groups --log-group-name-prefix "$LOG_GROUP" --query 'logGroups[].logGroupName' --output text
+aws logs delete-log-group --log-group-name "$LOG_GROUP"
+aws sns delete-topic --topic-arn "$TOPIC_ARN"
+```
+
+- Expected: the bucket is empty (`0 0`; it was never versioned) and deleted; the log group list
+ shows only `$LOG_GROUP`, which is deleted. If the list shows any other group under
+ `/aws/lambda-microvms/equipo-hosted-dev-t17`, add it to the ledger with `rec` and delete it the same
+ way (Lambda created it for this image); any other name is a stop. The topic is deleted.
+
+### 10.7 Verify by type, then by tag, then clean local scratch
+
+By type (each must answer "not found" or empty):
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1
+echo "any live VM: [$(live_vms)]"
+aws lambda-microvms get-microvm-image --image-identifier "$IMAGE_ARN" --query state --output text 2>&1 | tail -1
+aws lambda-microvms list-microvm-images --query "items[?starts_with(name, 'equipo-hosted-dev-t17')].name" --output text
+aws lambda-core get-network-connector --identifier "$CONN_ARN" --query State --output text 2>&1 | tail -1
+aws ec2 describe-vpcs --filters Name=tag:purpose,Values=$TAGV --query 'Vpcs[].VpcId' --output text
+aws ec2 describe-vpcs --vpc-ids "$VPC" 2>&1 | tail -1
+aws ec2 describe-subnets --subnet-ids "$SUBNET" 2>&1 | tail -1
+aws ec2 describe-route-tables --route-table-ids "$RTB" 2>&1 | tail -1
+aws ec2 describe-security-groups --group-ids "$SG" 2>&1 | tail -1
+aws ec2 describe-network-interfaces --filters Name=vpc-id,Values="$VPC" --query 'NetworkInterfaces[].NetworkInterfaceId' --output text
+aws iam get-role --role-name "$OPERATOR_ROLE" 2>&1 | tail -1
+aws iam get-role --role-name "$BUILD_ROLE" 2>&1 | tail -1
+aws s3api head-bucket --bucket "$BUCKET" 2>&1 | tail -1
+aws logs describe-log-groups --log-group-name-prefix /aws/lambda-microvms/equipo-hosted-dev-t17 --query 'logGroups[].logGroupName' --output text
+aws sns get-topic-attributes --topic-arn "$TOPIC_ARN" 2>&1 | tail -1
+```
+
+- Expected: no live VM; image not found (or `DELETED`); no image name left; connector not found;
+ no tagged VPC; `InvalidVpcID.NotFound`, `InvalidSubnetID.NotFound`,
+ `InvalidRouteTableID.NotFound`, `InvalidGroup.NotFound`; no interfaces; `NoSuchEntity` twice;
+ `Not Found` (404) for the bucket; no log group; `NotFound` for the topic.
+
+By tag (the Resource Groups Tagging index lags, sometimes by hours, so it can still list deleted
+resources; the direct lookups above decide):
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1
+aws resourcegroupstaggingapi get-resources --tag-filters Key=purpose,Values=$TAGV --query 'ResourceTagMappingList[].ResourceARN' --output text | tr '\t' '\n'
+```
+
+- Expected: empty, or only ARNs already confirmed deleted above. For each ARN listed, check it with
+ its direct lookup above and record "index lag". An ARN that is not in the ledger is not touched and
+ goes to Paul.
+
+Then record everything in the progress file, and remove local scratch:
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" || exit 1
+ss -ltn '( sport = :18443 or sport = :18444 )'
+cat "$T17/ledger.log"
+```
+
+Paste the ledger lines into `HOSTED-SLICE1-PROGRESS.md` (they hold IDs only, no keys), then:
+
+```sh
+. "$TMPDIR/equipo-t17/env.sh" || exit 1
+rm -rf "$T17" && echo "scratch removed"
+```
+
+- Expected: no listener; the ledger is in the progress file; scratch removed (keys, certificate,
+ database, binaries, zip). Nothing started by this run is still running.
+
+### 10.8 Spend record (at least 24 hours later, one call)
+
+Billing data lags. The day after the run:
+
+```sh
+export AWS_PROFILE=kass AWS_PAGER=""
+aws sts get-caller-identity --query Account --output text
+aws ce get-cost-and-usage --time-period Start=2026-11-23,End=2026-11-26 --granularity DAILY --metrics UnblendedCost \
+ --group-by Type=DIMENSION,Key=SERVICE --query 'ResultsByTime[].[TimePeriod.Start,Groups[?Keys[0]==`AWS Lambda`].Metrics.UnblendedCost.Amount|[0]]' --output text
+```
+
+- Expected: account `640012953448`; the Lambda line for the run day. It is the whole account's
+ Lambda spend, so it is an upper bound for this run. Adjust the dates to the actual run day. Record
+ it next to the estimate in section 11.
+
+---
+
+## 11. Expected spend and duration
+
+Rates: Ireland x86_64 compute from spec §10 ($0.155 an hour at 2 GB, $0.310 at 4 GB; pause and resume
+$0.0057 per GB). The Lambda pricing page prints snapshot and image storage rates only for US East
+(write $0.0038 per GB, read $0.00155 per GB, storage $0.08 per GB-month, image storage with a 1-week
+minimum); Ireland may be a little higher. The page lists no charge for image builds or connectors.
+
+| Item | Basis | Expected | Worst case |
+| --- | --- | --- | --- |
+| VM compute, 9.A to 9.G | about 8 Small VMs, about 25 min in all; backstops 1200, 120 and 300 s | $0.07 | $0.11 (0.7 h) |
+| VM compute, contract (6) | about 7 Small VMs, 3 to 6 min each; backstop 15 min each | $0.09 | $0.31 (2 h) |
+| VM compute, controller (7) | 2 Small VMs, about 10 min each; backstop 1 h each | $0.05 | $0.31 (2 h) |
+| VM compute, orphan (8) | 1 Small VM, about 12 min; backstop 30 min | $0.03 | $0.08 (0.5 h) |
+| Use above baseline | idle hook server, so none expected | $0.00 | x4 on all compute: +$2.43 |
+| Pause and resume | 3 cycles (9.C, contract, driver), up to 4 GB each, $0.0057/GB | $0.07 | $0.46 (10 cycles at 8 GB) |
+| Launch snapshot reads | about 20 starts, 2 to 4 GB, $0.00155/GB | $0.12 | $0.37 (30 at 8 GB) |
+| Image storage | 2 versions, assume 3 GB each, 1-week minimum, $0.08/GB-month | $0.11 | $0.37 (20 GB) |
+| Image builds | 2 builds, a few minutes each, if billed as VM time | $0.05 | $0.30 |
+| Connector, VPC, subnet, group, routes | no listed charge; no NAT, internet gateway or Elastic IP | $0.00 | $0.00 |
+| S3 | one object under 10 MB for a few hours, a few requests | $0.01 | $0.01 |
+| SNS | a few publishes, no subscribers | $0.00 | $0.00 |
+| CloudWatch Logs | build logs under 1 MB, 1-day retention | $0.00 | $0.01 |
+| Data transfer | VMs have no route out; S3 to Lambda in-region | $0.00 | $0.01 |
+| Cost Explorer (10.8) | one request at $0.01 | $0.01 | $0.01 |
+| **Total** | | **about $0.60** | **about $4.80** |
+
+**Cap: $10.** No step can reach it: every VM has an AWS maximum duration of at most 1 hour, and the
+largest is the two driver VMs. If any VM is seen live outside its step, the safe stop terminates it.
+
+**Wall-clock:** about 4 to 4.5 hours from 0.1 to the end of 10.7, most of it waiting on the
+connector (up to 15 min), two image builds (up to 20 min each), the contract (about 30 min), the
+controller waits (each state change up to a 60 s reaper pass), the orphan grace (about 12 min) and
+connector interface cleanup in teardown (up to 40 min). 10.8 is one call the next day.
+
+---
+
+## 12. UNCONFIRMED items and pre-flight values
+
+### UNCONFIRMED (written from docs or a secondary source, not confirmed in a model or the docs)
+
+1. **U1. Connector operator role trust.** The networking guide prints the operator role's
+ permissions but not its trust policy. 2.1 uses `lambda.amazonaws.com` with `aws:SourceAccount`,
+ from a third-party walkthrough (dev.classmethod.jp) and the build-role pattern in the security
+ guide.
+2. **U2. Operator role permissions.** The SDK says the role needs `ec2:DeleteNetworkInterface` and
+ describe calls; the managed policy `AWSLambdaNetworkConnectorOperatorPolicy` (v1) holds neither.
+ 2.1 adds them inline. Whether they are needed is unconfirmed.
+3. **U3. Installed CLI is older than the SDK.** AWS CLI 2.36.10's `lambda-core` model has no
+ `LatestVersionArn`, `VersionArn`, `ElasticIpConfiguration` or `list-network-connector-versions`;
+ its `lambda-microvms` model lists only `ARM_64` for `architecture` and drops `status` and
+ `supportedCpuConfigurations` from managed image versions; `list-network-connectors`' output key
+ (`NetworkConnectors`) is read from that older model. The plan relies on the CLI passing
+ `X86_64` through (botocore does not validate enum values) and builds the qualified connector ARN
+ as `<Arn>:<Version>`; the controller's audit confirms the ARN live.
+4. **U4. Base image name and version in eu-west-1.** `al2023-1`, with a version of 3 or later that
+ supports x86_64, is from the guide's us-east-1 examples.
+5. **U5. Container base image.** `public.ecr.aws/lambda/microvms:al2023-minimal` is named in the
+ guide; that it has an x86_64 variant is unconfirmed.
+6. **U6. Hooks.** That the `ready` build hook on port 9000 answered with 200 is enough for the
+ build, and that `runHookPayload` is accepted with the run hook enabled, follow the guide's hook
+ pages; the exact `hooks` JSON is from the model.
+7. **U7. Build log group.** That `logging.cloudWatch.logGroup` accepts a group we pre-create, and
+ that the build writes nowhere else, is unconfirmed (10.6 handles extra groups under the image's
+ prefix).
+8. **U8. Image deletion.** Whether `delete-microvm-image` removes all versions or refuses while
+ versions exist is not documented; 10.2 has the fallback.
+9. **U9. Connector interfaces on delete.** That Lambda deletes the connector's interfaces when the
+ connector is deleted, and how long it takes, is from the SDK text and a secondary source.
+10. **U10. Availability zone.** That a connector accepts a subnet in `eu-west-1a` is unconfirmed.
+11. **U11. Malformed VM ID.** What `terminate-microvm` returns for an ID AWS never issued
+ (`StopUnknownRef`) is undocumented.
+12. **U12. `--debug` format.** That botocore's debug log prints a `Response headers: {...}` line
+ with `'Date'` (9.B) is from botocore's usual logging, not checked here.
+13. **U13. Tagging API coverage.** Whether Resource Groups Tagging lists MicroVM images and network
+ connectors is unconfirmed; direct lookups decide in 10.7.
+14. **U14. Update keeps the first version active.** That `update-microvm-image` leaves the Small
+ version ACTIVE is implied by the guide (new versions are ACTIVE; nothing says older ones change).
+15. **U15. Cost Explorer service name.** That MicroVM charges appear under `AWS Lambda` is
+ unconfirmed.
+16. **U16. Ireland rates.** Snapshot, image storage and launch-read rates for Ireland are not
+ printed; US East rates are used. Image build and connector charges are not listed.
+
+### Pre-flight values
+
+The pre-flight report (`task-17-preflight-report.md`, commits `d94d7454`, `1ebf6e61`, `60a06822`)
+was present when this plan was written, and its values are in the commands above:
+
+- Keygen: `EQUIPO_HOSTED_KEYGEN_DIR`, `TestLiveKeygen`, files `controller.key`, `controller.pub`,
+ `instance.key`, `operator.key`, `verify_keys.json`, `tls.crt`, `tls.key`; key IDs
+ `task17-instance` and `task17-operator`.
+- Contract: `EQUIPO_HOSTED_LIVE_CONFIG`; Visibility 60 s and ListLag 30 s are built in.
+- Controller: `EQUIPO_HOSTED_ENABLED=1`; crash switch `EQUIPO_HOSTED_CRASH_AFTER_LAUNCH=1` in a
+ `-tags hostedlive` build only, exit status 137.
+- Drivers: `EQUIPO_HOSTED_LIVE_URL`, `EQUIPO_HOSTED_LIVE_CA_FILE`, `EQUIPO_HOSTED_LIVE_KEY_ID`,
+ `EQUIPO_HOSTED_LIVE_KEY_FILE`, `EQUIPO_HOSTED_LIVE_CONTROLLER_KEY_FILE`,
+ `EQUIPO_HOSTED_LIVE_IMAGE`, `EQUIPO_HOSTED_LIVE_ATTEMPT`, `EQUIPO_HOSTED_LIVE_CRASH_STEP`
+ (`launch`, `recover`), `EQUIPO_HOSTED_LIVE_OPERATOR_KEY_ID`, `EQUIPO_HOSTED_LIVE_OPERATOR_KEY_FILE`;
+ tests `TestLiveControllerSequence` and `TestLiveCrashRecovery`.
+
+Placeholders left: none. Two choices differ from the report's example on purpose: ports
+`127.0.0.1:18443` and `:18444` instead of `8443` and `9443` (checked free in 5.2, on a shared
+machine), and the config maps both sizes (`small` and `large`), since the image has both versions.