Repository navigation
Fix #1901: tell "Tower not running" from "Tower not answering"; tower start never stops a busy Tower - #1976
Merged
Conversation
Under load a live Tower accepts the connection at once but its starved event loop misses the 10 s request timeout. isRunning() collapsed that (and resets) to false, so commands said "Tower is not running. Start it with: afx tower start" while Tower was up. - sdk: TowerClient.probeHealth() classifies one /health probe as running / not-running (connection refused) / unresponsive (with the reason). A localhost refusal counts only when every address refused. Generic failures keep the cause code (fetch failed: ECONNRESET). requestTimeoutMs option (default 10 000). - cli: lib/tower-check.ts checkTower() is the one gate: refused reads "not running"; anything else is retried once after 1 s, then reported with the underlying error and no advice to start Tower. - send, interrupt, reset, self-refresh, sweep-husks, add/remove-architect and status go through it. workspace start/stop stop on an unresponsive Tower instead of starting a second one or clearing live runtime state. - rename, shell and open say "not running" only for a refused connection. - afx tower start no longer SIGTERMs a port holder that did not answer: it exits non-zero naming the PID and command line, and leaves replacing it to afx tower stop. Stop is unchanged and still stops a hung Tower.
…nning"; start never stops a stalled holder - bugfix-1901-tower-check: injected fetch through the real CLI client. Refused gives "not running"; a reset or timeout followed by success passes silently; two failures give "did not answer" with the error and no suggestion to start Tower. - bugfix-1901-tower-start-unresponsive: a real child process that accepts and never answers, on an ephemeral port. Start signals nothing, exits non-zero and names the PID and command line; a refused port starts normally; stop still kills the stalled holder. The first test fails on the pre-fix tower.ts (start SIGTERMed the holder). - sdk probeHealth cases, including a refused ::1 not masking another failure on 127.0.0.1 (fails without the every-address rule). - Existing Tower mocks gain probeHealth mapped from their isRunning mock. The #1691 and windows-launch towerStart tests stub the probe, which otherwise would reach the live Tower on 4100.
…d deactivation; IPv6-unreachable still reads as refused From PR review (CMAP round 1): - workspace stop guarded only the health probe. A healthy probe followed by a deactivation request Tower never answered fell into the legacy cleanup and clearRuntime(), wiping the registry of builders that may still be running. deactivateWorkspace() now passes status and connectionRefused through, and stop aborts with "nothing was cleared" when Tower took the request and never answered. Answered errors still fall back to local cleanup. - A localhost refusal counts when at least one attempt was refused and every attempt failed before reaching a server (EHOSTUNREACH, ENETUNREACH, EADDRNOTAVAIL). On a machine with broken IPv6, an unreachable ::1 plus a refused 127.0.0.1 is a down Tower, so workspace start starts one instead of exiting. A reached-then-reset 127.0.0.1 is still not masked. - open always reports the API error line instead of exiting silently when a failed request carries no error text.
…broken-IPv6 refusal
- bugfix-1901-workspace-start-stop:
- start on an unresponsive Tower exits and never calls towerStart;
- a refused connection still starts Tower;
- stop aborts without clearRuntime() when /health is not answered and
when the deactivation request is not answered;
- an answered error still falls back to local cleanup.
The start and stop guards each fail their test when removed.
- sdk: an unreachable ::1 plus a refused 127.0.0.1 reads as not-running.
- Thread: CMAP round 1 notes.
…r as a not-found; status --json tells busy from down Architect round, after merging PR #1957 (Spec 1940, named architects): - A <workspace>:architect:<name> send that came back NOT_FOUND asks the address book, to tell an older Tower. When Tower did not answer that check at all, the bare not-found was reported, though nobody could judge it. getAddressBook() now marks a failure with no HTTP answer as unanswered, and send says the check went unanswered and to retry. An answered failure of the check still leaves the not-found. - checkTower() takes a retries option (default 1). send --retry N passes 0, so its budget owns the retrying: N + 1 health probes instead of 2(N + 1). Without --retry the gate's single retry still applies. - status --json: tower is {running, state, error}. running is unchanged for existing scripts; state is running, not-running or unresponsive; error is the reason when unresponsive, otherwise null.
… ownership; status --json state
- bugfix-1901-send-unresponsive: the real send command and SDK client
over a scripted Tower.
- A three-part address against an unanswered /health, an unanswered
address-book check, and an unanswered send each read as unresponsive
or a timeout, never "older Tower" and never a bare not-found.
- Total probes pinned: 2 without --retry, N + 1 with --retry N.
- bugfix-1901-status-json: tower is {running, state, error} for running,
not-running and unresponsive.
- Each fails without its change.
- Thread: architect-round notes.
…requestTimeoutMs PR #1971 (merged from main) added requestBinary() with the module's fixed REQUEST_TIMEOUT_MS. The requestTimeoutMs option this PR added is the timeout for every request, and the other three request paths use it. The default is unchanged (10 000 ms), so only a client that sets the option sees a difference.
waleedkadous
added a commit
that referenced
this pull request
Nov 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Under heavy load (load average 31 to 43),
afx send,afx statusand other commands printedTower is not running. Start it with: afx tower startwhile Tower was up and answering/healthon a retry seconds later. That wording invites starting a second Tower. Worse, two commands acted on the false negative:afx workspace startwent on to kill the live Tower (below), andafx workspace stopcleared the runtime state of builders that were still running.Fixes #1901
Root Cause
Reproduced first, with the discarded error captured:
TimeoutErrorat the 10 s abort.curlshowed connect always completing in under 8 ms while time-to-first-byte reached 29 s. Tower was listening; its event loop was starved past the timeout. There was no accept-queue or connect failure.isRunning() === false.TowerClient.isRunning()returns a bare boolean, so every/healthfailure (refused, timeout, reset, error status, unreadable body) collapsed into "not running" in every caller. TheECONNREFUSEDmessage check that could have told them apart was dead under Node's fetch, because the code lives onerr.cause. AIR #1950 (afx send--retry, merged meanwhile) fixed that check and addedconnectionRefused, and this PR builds on it. One gap remained: overlocalhost, Node's AggregateError copies the code of the first attempt only. Tower binds IPv4, so that first attempt is always a refused::1, which would mask a127.0.0.1that failed another way.Fix
TowerClient.probeHealth()classifies one/healthprobe asrunning,not-running(connection refused) orunresponsive(with the reason).localhostrefusal counts when at least one attempt was refused and every attempt failed before reaching a server (EHOSTUNREACH,ENETUNREACH,EADDRNOTAVAIL). So a broken-IPv6::1plus a refused127.0.0.1still reads as down, while a refused::1cannot mask a127.0.0.1that was reached and then reset.fetch failed: ECONNRESET).requestTimeoutMsoption (default 10 000), used by the stalled-server test.isRunning()now delegates toprobeHealth().lib/tower-check.tscheckTower().Tower did not answer /health (<error>) after N ms; it appears to be up, retry, with no advice to start Tower.retries: 0, so the two do not stack.checkTower():send,interrupt,reset,self-refresh,tower sweep-husks,workspace add-architectandworkspace remove-architect.status: its human output shows "not answering" with the reason.status --jsonkeepstower.runningas it was (false for down and busy alike, so existing scripts read the same) and addstower.state(running/not-running/unresponsive) andtower.error(the reason when unresponsive, otherwisenull).workspace startandworkspace stopnow exit with the message when Tower is unresponsive.workspace startused to treat it as "start one" and fall into the kill below.workspace stopused to clear runtime state of builders that were still running. It also aborts, clearing nothing, when the health probe passes but Tower never answers the deactivation request itself (from review).deactivateWorkspace()now passesstatusandconnectionRefusedthrough.rename,shellandopenprinted "not running" for any failed request; now they do only for a refused connection.openreports the API error for anything else and no longer prints "not running" for HTTP errors either.send --retry Nowns the retrying. With--retrythe gate probes once per attempt, so an unanswering Tower gets N + 1 probes, not the 2(N + 1) it would get if the gate's own retry stacked inside each attempt. Without--retry, the gate's single retry applies (two probes).ide.tsneeded no change. It useshttp.request, soerr.codeis reliable, and it already reports timeouts separately.Merged with Spec 1940 (named architects, PR #1957)
Main moved during review, and PR #1957 changed
send.tsand the SDK client too. Both PRs change whatsenddoes when something fails. When a<workspace>:architect:<name>send comes back NOT_FOUND, theirs asks the address book, to tell an older Tower that cannot parse the form. I read the merged code as one piece:/healthstops at the gate, before any send or address-book question, and reads as unresponsive.getAddressBook()now marks a failure with no HTTP answer asunanswered.sendthen says Tower did not answer the check that tells a missing address from an older Tower, and that it appears to be up and should be retried.Behaviour change:
afx tower startno longer replaces a hung Tower by itselfBefore,
towerStartprobed/api/statuswith a 2 s timeout. If that missed and the port was in use, it decided the holder was a zombie, SIGTERMed every PID on the port and started a new Tower. Under load that PID is the live Tower, and runningafx tower start(which the old error message told people to do) killed it.Now
towerStartuses the same probe. A refused port starts as before, and a healthy Tower gets "already running" as before. A holder that accepted the connection but did not answer is left alone: start exits non-zero, prints the PID and command line so the reader can see whether it is a Tower, says to wait and retry if the machine is busy, and says to runafx tower stop, thenafx tower start, to replace it deliberately. Stopping a Tower is now always a human's decision.afx tower stopis unchanged: it kills the PIDs listening on the port without a health probe, so it still stops a hung Tower.Testing
bugfix-1901-tower-check(injected fetch through the real CLI client):bugfix-1901-tower-start-unresponsive: a real child process that accepts and never answers, on an ephemeral port, so the tests never reach Tower on 4100.tower.ts, where start SIGTERMed the holder.bugfix-1901-workspace-start-stop:workspace starton an unresponsive Tower exits and never callstowerStart, and a refused connection still starts Tower.workspace stopaborts withoutclearRuntime()when/healthor the deactivation request goes unanswered, and an answered error still falls back to local cleanup.bugfix-1901-send-unresponsive(the real command and SDK client over a scripted Tower, the harness from Spec 1940's test):/health, an unanswering address-book check, and an unanswering send each report unresponsive or timeout, never "older Tower" and never a bare not-found;--retry, N + 1 with--retry N.bugfix-1901-status-json:toweris{running, state, error}for running, not-running and unresponsive, witherrorpresent asnullwhen there is no error. It fails without the change.probeHealthcases: a refused::1does not mask a reset on127.0.0.1(this one fails without the rule), and an unreachable::1plus a refused127.0.0.1reads as not running.HOME, stalled holder on a spare port:afx tower start --port Pexited 1 after 21 s with the message, and the holder survived;afx tower stop --port Pkilled it.probeHealthmapped from theirisRunningmock. The afx tower start: surface the owner-guard refusal in the CLI instead of the generic 30s timeout (split from #1690 item 1) #1691 and windows-launchtowerStarttests now stub the probe. They used to fake a refusal by stubbingnode:http, and with the probe on fetch they would have reached the live Tower.packages/codevsuite passed (123.6 s), with the 3-worker cap from PR Fix #1956: cap packages/codev vitest at 3 workers (singleFork was dead since Vitest 4) #1965.npm testinpackages/codev, load 15.8): 432 files passed and 14 skipped; 9071 tests passed and 116 skipped; 170 s.porch.checks.tests.timeout_ms = 900000, set first in this worktree's.codev/config.local.jsonper the architect's instruction and since made the workspace setting (main-42). It only lengthens the limit.Review
workspace stopdeactivation-timeout path; fixed with a test.openexit, and tests for the start/stop guards.send --retrystacking on the gate's retry, andstatus --jsonnot telling busy from down: done in this PR at the architect's request (above)./healthis too heavy to probe under load (getInstancesplus a fullpscensus): filed as Tower: a cheap liveness route with the version; /health is too heavy to probe under load #1977, a cheap liveness route that carries the version. That is a Tower server change, out of scope here.Size: 283 insertions and 96 deletions in source; 631 insertions in tests.