Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
MUL-8775 fix(dev-env): report a stale API or busy web instead of a foreign listener (#10127)
Jiayuan Zhang741bb5790a66
diff --git a/scripts/dev-env.sh b/scripts/dev-env.shindex fb7dd1727d..eb47598c6a 100755--- a/scripts/dev-env.sh+++ b/scripts/dev-env.sh@@ -921,13 +921,21 @@ stop_component() {component_state() {case "$1" inapi)- local health+ local health expected_commit reported_commithealth="$(health_json || true)"- if [ -n "$health" ] && api_identity_matches "$health" "$(checkout_commit)"; then+ expected_commit="$(checkout_commit)"+ reported_commit="$(json_field "$health" commit || true)"+ if [ -n "$health" ] && api_identity_matches "$health" "$expected_commit"; thenprintf 'running|http://localhost:%s|pid %s commit %s started %s' "$BACKEND_PORT" \"$(json_field "$health" pid || echo '?')" \- "$(json_field "$health" commit || echo '?')" \+ "$reported_commit" \"$(json_field "$health" started_at || echo '?')"+ elif [ -n "$health" ] && health_belongs_to_api "$health" \+ && [ "$reported_commit" != "$expected_commit" ]; then+ # Same process this environment launched; only the checkout moved on.+ # `make up` restarts it, so this is not an external conflict.+ printf 'stale|http://localhost:%s|running %s, checkout at %s; run make up to restart' \+ "$BACKEND_PORT" "${reported_commit:-?}" "$expected_commit"elif [ -n "$health" ]; thenprintf 'mismatch|http://localhost:%s|health responder is not this checkout/process' "$BACKEND_PORT"else@@ -935,13 +943,20 @@ component_state() {fi;;web)- if curl -sf --max-time 10 "http://localhost:${FRONTEND_PORT}" >/dev/null 2>&1 \- && listener_belongs_to_component web "$FRONTEND_PORT"; then- printf 'running|http://localhost:%s|pid %s' "$FRONTEND_PORT" "$(port_listener_pid "$FRONTEND_PORT")"- elif [ -n "$(port_listener_pid "$FRONTEND_PORT")" ]; then- printf 'mismatch|http://localhost:%s|listener is not owned by this environment' "$FRONTEND_PORT"- else+ local listener+ listener="$(port_listener_pid "$FRONTEND_PORT")"+ if [ -z "$listener" ]; thenprintf 'stopped|http://localhost:%s|' "$FRONTEND_PORT"+ elif ! listener_pid_belongs_to_component web "$listener"; then+ printf 'mismatch|http://localhost:%s|listener pid %s is not owned by this environment' \+ "$FRONTEND_PORT" "$listener"+ elif curl -sf --max-time 10 "http://localhost:${FRONTEND_PORT}" >/dev/null 2>&1; then+ printf 'running|http://localhost:%s|pid %s' "$FRONTEND_PORT" "$listener"+ else+ # Next dev serializes compiles, so a probe can time out behind a slow+ # route compile even though the listener is ours.+ printf 'busy|http://localhost:%s|pid %s is ours but not responding (likely compiling); re-run make status' \+ "$FRONTEND_PORT" "$listener"fi;;daemon)diff --git a/scripts/dev-env.test.sh b/scripts/dev-env.test.shindex 1d045c32ec..927e6624a7 100644--- a/scripts/dev-env.test.sh+++ b/scripts/dev-env.test.sh@@ -172,6 +172,44 @@ assert_stop_handles_listener() {)}+# Launcher 100 owns listener 200; listener 999 is someone else's.+assert_component_state() {+ local case_name=$1 component=$2 listener=$3 reported_commit=$4 probe_ok=$5+ local expected_state=$6 expected_detail=$7+ (+ # shellcheck disable=SC1090+ source "$root_dir/scripts/dev-env.sh"+ STATE_DIR="$tmp_dir/state-$case_name"+ mkdir -p "$STATE_DIR"+ BACKEND_PORT=18080+ FRONTEND_PORT=13000+ TEST_LISTENER=$listener+ TEST_COMMIT=$reported_commit+ TEST_PROBE_OK=$probe_ok++ component_pid() { printf '100'; }+ port_listener_pid() { printf '%s' "$TEST_LISTENER"; }+ process_group_id() { [ "$1" = 200 ] && printf '100' || printf '%s' "$1"; }+ process_parent_id() { printf '1'; }+ checkout_commit() { printf 'bbb2222'; }+ health_json() {+ printf '{"pid":%s,"commit":"%s","started_at":"2026-01-01T00:00:00Z"}' "$TEST_LISTENER" "$TEST_COMMIT"+ }+ curl() { [ "$TEST_PROBE_OK" = 1 ]; }++ local row state detail+ row="$(component_state "$component")"+ state="${row%%|*}"+ detail="${row##*|}"+ [ "$state" = "$expected_state" ] \+ || fail "$case_name state = $state, want $expected_state ($row)"+ case "$detail" in+ *"$expected_detail"*) ;;+ *) fail "$case_name detail = $detail, want it to contain: $expected_detail" ;;+ esac+ )+}+# ---------------------------------------------------------------------------# An empty registry is a normal state, not an error.# ---------------------------------------------------------------------------@@ -289,6 +327,18 @@ assert_nested_listener_is_recordedassert_stop_handles_listener nested 420 310 200 "" 420assert_stop_handles_listener external 999 999 1 888+# Status separates "ours but out of date or busy" from "not ours". Only the+# latter means inspecting the port for an external listener; a commit after+# `make up` or a slow Next compile must not read like a hijacked port.+assert_component_state api-current api 200 bbb2222 1 running "commit bbb2222"+assert_component_state api-stale api 200 aaa1111 1 stale "running aaa1111, checkout at bbb2222; run make up"+assert_component_state api-foreign api 999 bbb2222 1 mismatch "not this checkout/process"+assert_component_state api-foreign-old api 999 aaa1111 1 mismatch "not this checkout/process"+assert_component_state web-running web 200 - 1 running "pid 200"+assert_component_state web-busy web 200 - 0 busy "pid 200 is ours but not responding"+assert_component_state web-foreign web 999 - 1 mismatch "listener pid 999 is not owned"+assert_component_state web-foreign-silent web 999 - 0 mismatch "listener pid 999 is not owned"+# ---------------------------------------------------------------------------# Unknown names and components fail loudly instead of doing something else.# ---------------------------------------------------------------------------