Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(minikube): validate T2 lease children against the pinned origin/dev
Alfredo Lopez6ca44cbebb02
diff --git a/AGENTS.md b/AGENTS.mdindex b17c24fca..c281fe11a 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -18,7 +18,8 @@ ambiguous ownership metadata must fail closed instead of regenerating ports.Before reusing a profile, record and compare all of the following:-- active worktree path, branch, `HEAD`, and `origin/dev`;+- active worktree path, branch, `HEAD`, and `origin/dev` (the value the T2+ lease owner pinned at lane start, not a later re-read of the ref);- target Minikube profile and explicit Kubernetes context;- the pre-gate state marker: `worktreeId`, `gitHead`, `clusterFingerprint`,and the exact `imagesGeneratedAt` value from the image manifest;diff --git a/docs/testing/minikube-t2-runbook.md b/docs/testing/minikube-t2-runbook.mdindex 3459e6f70..97103dfb3 100644--- a/docs/testing/minikube-t2-runbook.md+++ b/docs/testing/minikube-t2-runbook.md@@ -7,7 +7,8 @@ URLs, DSNs, credentials, customer data, or raw runtime logs.## Scope and entry pointsThe contract is local-development-only. It requires a clean development-branch descended from the current `origin/dev`, a generated profile owned by+branch descended from the current `origin/dev` (the commit pinned when the lane+takes its profile lease; see Ownership and concurrency), a generated profile owned bythat canonical worktree path plus branch, and an explicit Kubernetes contextfor that profile. Exact-HEAD freshness is proved by the deployed marker andgate evidence, not by reallocating a profile after every commit.@@ -156,6 +157,17 @@ serialize through the atomic sibling directoryconcurrent loser fails closed and never removes either the stale directory orthe winner's replacement lock.+The lease owner also pins `origin/dev`. It records the commit it resolved as+`ORIGIN_DEV` in the lock record and exports it as `T2_PINNED_ORIGIN_DEV`; every+child of the lease validates ancestry against that pin instead of re-reading+the remote-tracking ref, which a `git fetch` in any worktree of the repository+moves. A move is reported as `origin/dev moved during the lane` and does not+invalidate the lane. The pin is honored only under an inherited lease, must be+a full commit SHA present in the repository, and must still be an ancestor of+the local `origin/dev`: a force-push of `dev` during the lane, a lease child+without a pin, or a pin that differs from the owner's record fails with+`DEVELOPMENT_SCOPE_REQUIRED` or `PROFILE_OWNERSHIP_MISMATCH`.+The pre-gate marker must contain the current worktree identifier, exact `HEAD`,cluster fingerprint, image coordinate, and the exact `imagesGeneratedAt` valuefrom the image manifest. A mismatch—including a new image acquisition at the@@ -176,8 +188,8 @@ in the final preflight after optional journeys; planner mode does not certify itHealth and Playwright commands inherit the parent's opaque lease token,profile, explicit context, repository, and lock root for that invocation only.A nested mutation wrapper revalidates the full repository/branch/HEAD/profile/-context/worktree/lock-key binding and live owner before using the lease. A-missing token or mismatched binding fails; the journey cannot acquire a second+context/worktree/lock-key/`origin/dev` binding and live owner before using the+lease. A missing token or mismatched binding fails; the journey cannot acquire a secondlease or redirect an inherited lease to another profile. Hermetic coverage is`bash scripts/tests/test-minikube-t2-proxy-runtime.sh`.@@ -464,7 +476,7 @@ failure still uses the full target.Each run writes a sanitized `evidence.json` below the ignored local path`.local-notes/infra/runs/<timestamp>-<sha>/`. It contains branch/`HEAD`,-`origin/dev`, merge-base, worktree path, profile/context identifiers,+the `origin/dev` pinned at lane start, merge-base, worktree path, profile/context identifiers,fingerprint and image-manifest references, phase timestamps, lane statuses,test counts, and references to local log files. It never contains Secretvalues, DSNs, tokens, kubeconfig data, private URLs, user data, screenshots, ordiff --git a/scripts/minikube/t2-common.sh b/scripts/minikube/t2-common.shindex 131814f8e..2e613f407 100755--- a/scripts/minikube/t2-common.sh+++ b/scripts/minikube/t2-common.sh@@ -224,6 +224,56 @@ t2_canonical_path() {(cd -- "$1" 2>/dev/null && pwd -P)}+# refs/remotes/origin/dev is shared by every worktree of this repository, so a+# fetch from any of them moves it while a lane runs. The lease owner reads it+# once (t2_lock_acquire exports T2_PINNED_ORIGIN_DEV) and every child of that+# lease validates against the pin. The pin is honored only under an inherited+# lease: an exported pin cannot certify a branch against an older dev, and a+# lease child that lost the pin fails instead of re-reading the moved ref.+t2_resolve_origin_dev() {+ local pin="${T2_PINNED_ORIGIN_DEV:-}" current+ current="$(git -C "$T2_PROJECT_DIR" rev-parse --verify origin/dev 2>/dev/null || true)"+ if [ "${T2_SKIP_LOCK:-}" != true ]; then+ if [ -n "$pin" ]; then+ T2_NEXT_COMMAND='unset T2_PINNED_ORIGIN_DEV; the lease owner pins origin/dev for its children'+ t2_fail DEVELOPMENT_SCOPE_REQUIRED 'T2_PINNED_ORIGIN_DEV is only honored under an inherited T2 lease'+ return 1+ fi+ T2_ORIGIN_DEV="$current"+ return 0+ fi+ if [ -z "$pin" ]; then+ T2_NEXT_COMMAND='run this child from the T2 lease owner, which exports T2_PINNED_ORIGIN_DEV'+ t2_fail DEVELOPMENT_SCOPE_REQUIRED 'an inherited T2 lease carries no pinned origin/dev'+ return 1+ fi+ if [[ ! "$pin" =~ ^[0-9a-f]{40}$ ]]; then+ T2_NEXT_COMMAND='run this child from the T2 lease owner, which exports the full origin/dev SHA'+ t2_fail DEVELOPMENT_SCOPE_REQUIRED 'T2_PINNED_ORIGIN_DEV is not a full commit SHA'+ return 1+ fi+ if ! git -C "$T2_PROJECT_DIR" cat-file -e "$pin^{commit}" 2>/dev/null; then+ T2_NEXT_COMMAND='run this child from the T2 lease owner of this repository'+ t2_fail DEVELOPMENT_SCOPE_REQUIRED 'T2_PINNED_ORIGIN_DEV is not a commit in this repository'+ return 1+ fi+ if [ -z "$current" ]; then+ T2_NEXT_COMMAND='fetch origin/dev and run from a named development branch'+ t2_fail DEVELOPMENT_SCOPE_REQUIRED 'branch, HEAD, or origin/dev could not be resolved'+ return 1+ fi+ if ! git -C "$T2_PROJECT_DIR" merge-base --is-ancestor "$pin" "$current"; then+ T2_NEXT_COMMAND='origin/dev was rewritten during the lane; merge the current origin/dev, then re-run T2'+ t2_fail DEVELOPMENT_SCOPE_REQUIRED 'the pinned origin/dev is not an ancestor of the current origin/dev'+ return 1+ fi+ if [ "$current" != "$pin" ]; then+ printf '[minikube-t2] origin/dev moved during the lane: pinned %s, local ref now %s; validating against the pin\n' \+ "$pin" "$current" >&2+ fi+ T2_ORIGIN_DEV="$pin"+}+t2_repo_metadata() {local actual_root remote_urlactual_root="$(git -C "$T2_PROJECT_DIR" rev-parse --show-toplevel 2>/dev/null || true)"@@ -243,7 +293,7 @@ t2_repo_metadata() {fiT2_BRANCH="$(git -C "$T2_PROJECT_DIR" branch --show-current 2>/dev/null || true)"T2_HEAD="$(git -C "$T2_PROJECT_DIR" rev-parse --verify HEAD 2>/dev/null || true)"- T2_ORIGIN_DEV="$(git -C "$T2_PROJECT_DIR" rev-parse --verify origin/dev 2>/dev/null || true)"+ t2_resolve_origin_dev || return 1if [ -z "$T2_BRANCH" ] || [ -z "$T2_HEAD" ] || [ -z "$T2_ORIGIN_DEV" ]; thenT2_NEXT_COMMAND='fetch origin/dev and run from a named development branch't2_fail DEVELOPMENT_SCOPE_REQUIRED 'branch, HEAD, or origin/dev could not be resolved'@@ -1200,6 +1250,11 @@ t2_lock_process_matches() {t2_lock_acquire() {local process_start reclaim_dir=""t2_lock_profile_id_check || return 1+ if [ -z "${T2_ORIGIN_DEV:-}" ]; then+ T2_NEXT_COMMAND='resolve repository metadata (t2_repo_metadata) before acquiring the profile lock'+ t2_fail DEVELOPMENT_SCOPE_REQUIRED 'the lease owner has no origin/dev to pin'+ return 1+ fimkdir -p "$T2_LOCK_ROOT"T2_LOCK_DIR="$T2_LOCK_ROOT/$T2_PROFILE.lock"T2_LOCK_KEY="$(t2_lock_key)"@@ -1273,6 +1328,7 @@ PROFILE=$T2_PROFILECONTEXT=$T2_CONTEXTWORKTREE_ID=$T2_WORKTREE_IDLOCK_KEY=$T2_LOCK_KEY+ORIGIN_DEV=$T2_ORIGIN_DEVTOKEN=$T2_LOCK_TOKENPID=$$PROCESS_START=$process_start@@ -1281,6 +1337,9 @@ EOFif [ -n "$reclaim_dir" ]; thenrmdir "$reclaim_dir" 2>/dev/null || truefi+ # Children of this lease validate against the origin/dev read here, not+ # against the shared remote-tracking ref (see t2_resolve_origin_dev).+ export T2_PINNED_ORIGIN_DEV="$T2_ORIGIN_DEV"T2_LOCK_HELD=trueT2_LOCK_RELEASED=false}@@ -1302,7 +1361,7 @@ t2_lock_validate_inherited() {t2_fail PROFILE_LOCK_REQUIRED 'inherited profile lock token is missing or does not match'return 1fi- for owner_key in REPOSITORY BRANCH HEAD PROFILE CONTEXT WORKTREE_ID LOCK_KEY; do+ for owner_key in REPOSITORY BRANCH HEAD PROFILE CONTEXT WORKTREE_ID LOCK_KEY ORIGIN_DEV; docase "$owner_key" inREPOSITORY) expected_pid="$T2_PROJECT_DIR" ;;BRANCH) expected_pid="$T2_BRANCH" ;;@@ -1311,8 +1370,12 @@ t2_lock_validate_inherited() {CONTEXT) expected_pid="$T2_CONTEXT" ;;WORKTREE_ID) expected_pid="$T2_WORKTREE_ID" ;;LOCK_KEY) expected_pid="$T2_LOCK_KEY" ;;+ ORIGIN_DEV) expected_pid="${T2_PINNED_ORIGIN_DEV:-}" ;;esac- if [ "$(t2_lock_owner_value "$owner_key" || true)" != "$expected_pid" ]; then+ # An empty pin never matches, even against a lock written before the+ # owner recorded ORIGIN_DEV.+ if [ -z "$expected_pid" ] && [ "$owner_key" = ORIGIN_DEV ] ||+ [ "$(t2_lock_owner_value "$owner_key" || true)" != "$expected_pid" ]; thenT2_NEXT_COMMAND='re-run the operation from the worktree/profile that owns the T2 lock't2_fail PROFILE_OWNERSHIP_MISMATCH "profile lock owner does not match $owner_key"return 1