Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix: background the T1 port-forward as a direct kubectl child

Alfredo Lopezdd755abe2f41
diff --git a/.cursor/rules/minikube-t2-harness.mdc b/.cursor/rules/minikube-t2-harness.mdc
index 1ecd6f67c..3119de28f 100644
--- a/.cursor/rules/minikube-t2-harness.mdc
+++ b/.cursor/rules/minikube-t2-harness.mdc
@@ -64,6 +64,11 @@ Invariants that must never regress:
PIDs recorded in the profile cache or legacy `/tmp/pf-<profile>-*.pid`.
awk is a loose pre-filter: `kubectl` as argv0/path token and a later
standalone `port-forward` token (flags may sit between them).
+- T1 backgrounds its control-postgres port-forward as a direct `kubectl`
+ child (never through the `t2_kc` function): a backgrounded function forks
+ a subshell whose argv is the script, `$!` records that subshell, cleanup's
+ `*port-forward*` guard never matches, and the orphaned real kubectl fails
+ the final exact-head preflight with `PORT_FORWARD_CONFLICT`.
- Stable failure codes (`BOOTSTRAP_REQUIRED`, `HEAD_MARKER_MISMATCH`,
`PORT_FORWARD_CONFLICT`, `PROFILE_BUSY`, ...) keep their meanings.
diff --git a/scripts/e2e/minikube-real-postgres.sh b/scripts/e2e/minikube-real-postgres.sh
index 293624f68..66faa8f91 100755
--- a/scripts/e2e/minikube-real-postgres.sh
+++ b/scripts/e2e/minikube-real-postgres.sh
@@ -377,7 +377,13 @@ main() {
T1_REDACT_PASSWORD="$PG_PASSWORD"
LOCAL_PORT="$(choose_local_port)"
- t2_kc -n "$PG_NAMESPACE" port-forward --address=127.0.0.1 svc/"$PG_SERVICE" "$LOCAL_PORT:5432" \
+ # Launch kubectl directly, not through the t2_kc function: backgrounding a
+ # function forks a subshell whose argv is this script, so $! would record
+ # the subshell, the cleanup guard (*port-forward*svc/control-postgres*)
+ # would never match, and the orphaned real kubectl port-forward would fail
+ # the final exact-head preflight with PORT_FORWARD_CONFLICT.
+ kubectl --context="$T2_CONTEXT" -n "$PG_NAMESPACE" port-forward \
+ --address=127.0.0.1 svc/"$PG_SERVICE" "$LOCAL_PORT:5432" \
>"$T1_TMP_DIR/port-forward.log" 2>&1 &
PORT_FORWARD_PID=$!
if ! wait_for_tcp "$LOCAL_PORT"; then
diff --git a/scripts/tests/test-minikube-t2-contract.sh b/scripts/tests/test-minikube-t2-contract.sh
index 8360f97bd..717c11aaf 100755
--- a/scripts/tests/test-minikube-t2-contract.sh
+++ b/scripts/tests/test-minikube-t2-contract.sh
@@ -75,6 +75,14 @@ fi
grep -Fq 'pending_tests' "$T1"
grep -Fq 'numTotalTests' "$T1"
grep -Fq 'port-forward' "$T1"
+# The pf must be a direct kubectl child: backgrounding the t2_kc function
+# records the subshell PID, cleanup never matches *port-forward*, and the
+# orphaned kubectl fails the final preflight with PORT_FORWARD_CONFLICT.
+if grep -Eq 't2_kc[^|]*port-forward' "$T1"; then
+ echo 'FAIL: T1 backgrounds the control-postgres port-forward through the t2_kc function' >&2
+ exit 1
+fi
+grep -Fq 'kubectl --context="$T2_CONTEXT" -n "$PG_NAMESPACE" port-forward' "$T1"
grep -Fq 'set +x' "$T1" "$PREFLIGHT" "$T2"
# T1 must restore the branch-profile GFS credentials on the way out with the
diff --git a/scripts/tests/test-minikube-t2-scenarios.sh b/scripts/tests/test-minikube-t2-scenarios.sh
index 9444e0eed..c4ac168ef 100755
--- a/scripts/tests/test-minikube-t2-scenarios.sh
+++ b/scripts/tests/test-minikube-t2-scenarios.sh
@@ -272,6 +272,8 @@ grep -Fq 'GFS_RESTORE_ACTIVE_NOLOGIN=true' "$ROOT/scripts/e2e/minikube-real-post
grep -Fq 'GFS_RECOVER_ABANDONED_STATE=true' "$ROOT/scripts/e2e/minikube-real-postgres.sh" || fail 'T1 GFS restore must resume an interrupted gfsc-reader rollout claim'
grep -Fq 'settle-gfs-reader-rollout.sh' "$ROOT/scripts/e2e/minikube-real-postgres.sh" || fail 'T1 GFS restore must settle a Ready gfsc-reader leftover rollout claim first'
grep -Fq 'gfs-rollout-shim' "$ROOT/scripts/e2e/minikube-real-postgres.sh" || fail 'T1 GFS restore must use the HCC-safe reader rollout wait'
+grep -Eq 't2_kc[^|]*port-forward' "$ROOT/scripts/e2e/minikube-real-postgres.sh" && fail 'T1 must background the port-forward as a direct kubectl child, not through the t2_kc function'
+grep -Fq 'kubectl --context="$T2_CONTEXT" -n "$PG_NAMESPACE" port-forward' "$ROOT/scripts/e2e/minikube-real-postgres.sh" || fail 'T1 must launch the control-postgres port-forward with an explicit kubectl context'
grep -Fq 'GFS_RESTORE_ACTIVE_NOLOGIN=true' "$ROOT/scripts/minikube/pre-gate-sync.sh" || fail 'pre-gate-sync must restore a NOLOGIN GFS role from the committed Secret DSN'
grep -Fq 'GFS_RECOVER_ABANDONED_STATE=true' "$ROOT/scripts/minikube/pre-gate-sync.sh" || fail 'pre-gate-sync must resume an interrupted gfsc-reader rollout claim'
grep -Fq 'settle-gfs-reader-rollout.sh' "$ROOT/scripts/minikube/pre-gate-sync.sh" || fail 'pre-gate-sync must settle a Ready gfsc-reader leftover rollout claim before reconcile'