Skip to content

afx: 'Tower is not running' reported under high load while Tower is up; the real probe error is discarded #1901

Done

Description

@waleedkadous

Problem

Under high machine load (load average 31 to 43), afx send and afx status intermittently print [error] Tower is not running. Start it with: afx tower start while Tower is up: same pid for days, and /health on port 4100 answers 200 in 0.6 to 1.1 s. The same command succeeds on a retry seconds later. Reported by an adopter, seen by two architects within two minutes.

Effects: a message relay fails unless the sender reads the last line, and the wording invites starting a second Tower.

What is known

The reporter suspected a ~1 s probe timeout. That is not it: REQUEST_TIMEOUT_MS in packages/sdk/src/tower-client.ts is 10,000.

TowerClient.isRunning() returns result.ok && result.data?.status === 'healthy', a bare boolean. Every failure of the /health request (connection refused or reset, timeout, non-200, a failed auth-key read, a JSON parse error) collapses to false, and the callers (send.ts, interrupt.ts, reset.ts, ide.ts, rename.ts, others) all print the same "Tower is not running". The actual error is thrown away, so the root cause of the false negative is not yet identified. Candidates: a transient connect failure when the accept queue is saturated, or an event-loop stall on the Tower side.

Fix

  1. Reproduce under load and capture the discarded error first. Do not guess the cause.
  2. Make the probe report why it failed: distinguish "nothing listening on the port" from "listening but did not answer / answered badly". Only the first should say "Tower is not running" and suggest afx tower start.
  3. For the second case, retry once after a short pause, then fail with the real reason, e.g. "Tower did not answer /health () after N ms; it appears to be up, retry".
  4. Apply through one shared helper so every caller gets the same behaviour, rather than patching each command.

Testing

Unit tests with an injected fetch: connection refused gives the "not running" message; a reset or timeout followed by success passes silently; two failures give the "did not answer" message with the underlying error and no suggestion to start Tower.

Activity

  1. added
    area/tower
    on Nov 15, 2026
  2. waleedkadous commented on Nov 16, 2026

    @waleedkadous
    ContributorAuthor

    On it! Working on a fix now.

  3. waleedkadous commented on Nov 16, 2026

    @waleedkadous
    ContributorAuthor

    Constraint from the owner (2026-11-16): do not reproduce this with synthetic machine load. A first attempt with CPU-burner processes pushed load average to 76 and slowed the whole machine. Reproduce with an injected slow or failing fetch in a unit test, or a single stalled local HTTP server standing in for Tower.

  4. added a commit that references this issue on Nov 17, 2026
  5. added 10 commits that reference this issue on Nov 24, 2026
  6. added a commit that references this issue on Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/tower

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions