Skip to content

[Air #1999] Tower: cheap GET /api/liveness route; CLI probe and afx send use it - #2000

Closed
waleedkadous wants to merge 9 commits into
mainfrom
builder/air-1999
Closed

waleedkadous wants to merge 9 commits into
mainfrom
builder/air-1999

Conversation

@waleedkadous

@waleedkadous waleedkadous commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Implements #1999 (a cheap liveness route, so the CLI's "is Tower up?" probe stops running a process census under load).

Summary

  • New route GET /api/liveness returns { status: 'alive', version, schemaVersion, startedAt } (wire type TowerLiveness in codev-types). It does no work: no instance list, no process census, no database read. Every field is fixed at boot, and schemaVersion is the GLOBAL_CURRENT_VERSION constant. The route is public like /health and sits behind the boot readiness gate like every route.
  • SDK probeHealth asks /api/liveness. It asks /health only when the liveness route gets the catch-all 404 a Tower gives a route it does not have. A 401 also triggers it: that is what an older Tower gives a client without the key, because the route is not public there (a VS Code client with no key, for example). A probe that goes unanswered (timeout, reset) or is refused never falls back, so a starved Tower is not handed the heavy route. TowerHealthProbe's running variant now carries liveness: TowerLiveness | null, where null means an older Tower. Nothing read the old .health field.
  • /health is unchanged for afx status and the dashboard.
  • afx send's older-Tower check (explainNotFound) calls the new getLiveness() in place of the address-book probe. If the route answers, the Tower knows the <workspace>:architect:<name> form and its not-found stands. The catch-all 404 means an older Tower. No HTTP answer at all means busy, and the message says so.
  • Messages that said "did not answer /health" now say "did not answer its liveness probe", because /health is no longer what was asked (tower-check.ts, send.ts, tower.ts).
  • Docs: arch.md gets a liveness-probe bullet and an updated public-allowlist entry, and the isPublicRoute comment names the keyless probes.

Why a new route and not /api/version

/api/version (#983) already does no work, but it predates Spec 1940, so whether it exists says nothing about the address form. The issue asks for a route whose 404 is itself the answer. /api/version is left exactly as the VS Code preflight reads it.

Testing

  • air-1999-liveness-route.test.ts spies on getInstances, listProcessCensus, getGlobalDb, getDb, db.prepare and getShellperManager. A control test asks /health first and requires all of them to fire, so a spy that isn't wired to what the routes really call fails the control rather than passing the liveness test by accident. The liveness request then calls none of them. The file also pins the body and the public, GET-only route.
  • SDK tower-client.test.ts covers the probe against the new route: running, not-running and unresponsive (timeout, a 200 that isn't a liveness body, a partial body, a 404 that carries a code). An unanswered probe makes exactly one request and never asks /health. Against an older Tower it covers the fallback on the catch-all 404 and on a 401, plus /health classified as before (healthy, timeout, 503, degraded, refused). It also covers getLiveness()'s classification.
  • spec-1940-older-tower-send.test.ts and bugfix-1901-send-unresponsive.test.ts drive the real command over a fake transport. An older Tower makes the requests GET /api/liveness, GET /health, POST /api/send, GET /api/liveness, followed by the restart message. The address book is never asked. Against a current Tower, /health is never asked.
  • Windows (on-demand, since afx tower start uses this probe): https://github.com/cluesmith/codev/actions/runs/45909504370 passed. Install verification, CLI tests, unit tests and both probes (x64 and ARM) succeeded; install guard and targeted tests were skipped.
  • Results: packages/codev unit suite 10003 passed, 116 skipped (460 files), and porch build/tests checks green, SDK 455 passed, VS Code 1981 passed (1 skipped), and the build passes.

Review (AIR: in place of a review file)

Consultation: codex returned COMMENT and claude returned APPROVE, both HIGH confidence. Gemini isn't in this repo's porch consultation config.

  • Acted on. Both reviewers noted that isTowerLiveness checked only status and version, but narrowed to a type whose schemaVersion and startedAt are required. It now checks all four fields, and a test pins the partial-body case. Claude noted that the public-route docs said every entry exists for a browser navigation, which /api/liveness doesn't. The wording is fixed in server-utils.ts and arch.md. Codex flagged a stale test header comment, which is fixed.
  • Not acted on, with reasons:
    • Dev-build window. The older-Tower check reads route presence, as the issue prescribes. A Tower built from main after Spec 1940 but before this PR would be called "older" by mistake. No release is affected: v3.3.8 has neither change, and both ship in the next release. If a release were cut between the two, that would stop being true.
    • The probe is still held by the boot readiness gate, exactly as /health is today, so "running" still means "can serve". Exempting it would make the probe a pure event-loop signal, but it is a behaviour change outside this issue.

Lessons

Possible follow-ups (left alone, other call sites):

  • db/tower-owner.ts probeTowerHealth still sends a raw /health request, though only on the owner-lock conflict path.
  • The VS Code connection-manager calls getHealth() on connect, for uptime only.

Flaky Tests

None seen.

@waleedkadous
waleedkadous marked this pull request as draft November 26, 2026 23:12
@waleedkadous
waleedkadous marked this pull request as ready for review November 27, 2026 00:03
@waleedkadous

Copy link
Copy Markdown
Contributor Author

Closing unmerged. This PR and PR #2001 (the GET /health/live liveness route) were two implementations of the same issue, and only one could merge. The owner chose PR #2001, which merged as ab0fa50a9. Nothing was wrong with this one: reviewers found the two equal in quality. The branch is kept.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant