Skip to content

[Air #1977] feat: cheap /health/live liveness route with Tower's version - #2001

Merged
waleedkadous merged 9 commits into
mainfrom
builder/air-1977
Nov 27, 2026
Merged

waleedkadous merged 9 commits into
mainfrom
builder/air-1977

Conversation

@waleedkadous

@waleedkadous waleedkadous commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Every CLI command probes Tower before it talks to it (#1901), and that probe hit GET /health, Tower's heaviest read: instance list, process census, global.db read. This adds GET /health/live, which does none of that and reports Tower's version. The probe and afx send's older-Tower check now use it.

Closes #1977

What Changed

  • Tower: GET /health/live (tower-routes.ts). It answers { status: 'healthy', version, startedAt, schemaVersion } from RouteContext plus the GLOBAL_CURRENT_VERSION constant. It has no instance list, no census and no DB read. It is public like /health (isPublicRoute). /health is unchanged, for status, the dashboard and doctor.
  • Wire contract (codev-types): TOWER_LIVENESS_ROUTE and TowerLiveness. The SDK mirrors the route literal the way it mirrors COMMAND_ROUTE, because its zero-runtime-deps boundary test forbids a runtime import from codev-types. A route test pins the two strings equal.
  • SDK probeHealth asks /health/live first. It falls back to /health only when the Tower answers that it has no such route. The running probe now carries liveness instead of health, which nothing read. unresponsive carries the route that went unanswered.
  • The SDK validates the whole liveness body (status, non-empty version, parseable startedAt, positive-integer schemaVersion) before handing it on as TowerLiveness. A 200 with a malformed body is unresponsive from probeHealth, with no fallback, and a failure with neither flag from getLiveness().
  • New SDK getLiveness(): it reports unknownRoute for an older Tower, with or without the key, and unanswered when nothing answered. On a 401 it asks the public /health: a healthy answer there means an older Tower. A refused Host header, the only 401 a current Tower gives this route, refuses /health too.
  • afx send's older-Tower check (Spec 1940) asks getLiveness() instead of fetching the whole address book. The now-unused caller parameter of explainNotFound is gone.
  • Messages name the route that was actually asked: "Tower did not answer /health/live (…)" in checkTower, in send's retry line and in afx tower start. After a fallback against an older Tower they say /health.
  • VS Code: the terminal give-up banner's reachability probe (vscode: terminal reconnect budget exhausts during laptop sleep — permanent 'unable to reconnect' banner while Tower is healthy #1681, terminal-manager.probeTowerHealth) uses isRunning() (the liveness route) instead of getHealth().
  • codev/resources/arch.md: the new route is in the Tower API table and the public-allowlist note.

Key Decisions

  • A new route, not /api/version. /api/version is already cheap, but every Tower since vscode + tower: detect installed-vs-running Tower version divergence; preflight needs an in-memory version probe, not just codev --version #983 has it, v3.3.8 included. The send check has to tell "predates the three-part address form" from "knows it", and only a route newer than Spec 1940 can say that by being missing. Spec 1940 merged after the v3.3.8 tag, so it ships in the same release as this change.
  • The fallback triggers on 404 and on 401. Measured against the live v3.3.8 Tower: /health/live gets 404 with the key and 401 without, because the route isn't on that Tower's public list. VS Code's tower-starter calls isRunning() with a key that can be missing. Without the 401 case, it would read an older Tower as unresponsive.
  • The send check relies on the route being present, not on comparing versions. A future CLI against a Tower from this release or later reports a version there, and that Tower knows the address form, so its not-found stands. A check like tower < cli would wrongly say "older" in that case.
  • schemaVersion is GLOBAL_CURRENT_VERSION, the global.db schema this Tower's code migrates to at boot. It is a constant, so it costs nothing.

Test Plan

  • New route test (air-1977-liveness-route.test.ts): a real HTTP server around the real handleRequest and the real auth gate, and the real SDK client with no key.
    • getInstances, listProcessCensus, getGlobalDb, computeRegisteredShellperPids and isStartupReconcileSettled are spies. None of them is called for /health/live.
    • /health on the same Tower does call them, which proves the spies are wired.
    • It checks the exact body and that the SDK and types route strings are equal.
  • SDK (tower-client.test.ts):
    • probeHealth against the new route: running (one request, never /health), not-running, unresponsive on timeout and on 503, all without falling back.
    • Against a Tower without the route: falls back on the catch-all 404 and on 401, an unanswered /health names /health, and a refusal between the two requests reads as not-running.
    • getLiveness: ok, unknownRoute on a 404, unknownRoute on a keyless 401 when /health answers, no flag when /health also refuses, unanswered, and any other status marked as neither.
  • afx send (spec-1940-older-tower-send, bugfix-1901-send-unresponsive), updated to the new request sequence:
    • An older Tower gives "older Tower, restart".
    • On a current Tower a genuine not-found stands.
    • An unanswered version check reads as busy.
    • Other forms and successful sends ask nothing after the send.
    • The address book is never fetched.
  • Updated the afx: 'Tower is not running' reported under high load while Tower is up; the real probe error is discarded #1901 message tests and isPublicRoute.
  • Against real Towers:
    • The live v3.3.8 Tower (read-only GETs) gave the 404/401 above. The new SDK's probeHealth reads it as running through the fallback, keyed and keyless, and getLiveness() gives unknownRoute keyed and keyless.
    • An isolated Tower built from this branch (own agent-farm dir, DB and sockets; port 14977) answers keyless with the version. probeHealth makes a single request.
    • Latency: /health/live took 0.2–1 ms. The live Tower's /health took 350–460 ms per call (45 workspaces, 13 active, load ~5–8).
  • npm run build passes. The full codev suite passes (460 files, 10,005 tests), as does the SDK suite (452 after the review fixes). Porch's build and test checks passed.
  • VS Code: tsc --noEmit and eslint pass, and terminal-manager and terminal-adapter tests pass (67).
  • Malformed liveness bodies (SDK): bare {status:'healthy'}, non-healthy status, empty version, unparseable startedAt, string or fractional schemaVersion, array, null. Each is unresponsive from probeHealth (naming the field, no fallback) and a flagless failure from getLiveness.
  • Windows: run 45954949863 (suites=true) on e3ed77c9b: green (unit tests, CLI tests, install verification, windows-latest and windows-11-arm probes).
  • CI: all 8 checks pass on e3ed77c9b. The first run failed the /tmp residue check (Spec 1658) because the new route test had two fake paths containing /tmp. Nothing is written to them, so they now use /nonexistent/...; no allowlist entry was needed.

Review Notes

  • Dev-only edge case: a Tower local-installed from main between the Spec 1940 merge and this one knows the address form but lacks the route. On that Tower, a typo'd <ws>:architect:<name> gets "older Tower, restart" instead of the not-found. Restarting fixes it, and no released Tower is in that state.
  • Adjacent fix: the /api/version doc comment had drifted above isLoopbackAddress. It is back on handleVersion.
  • Not changed:
    • db/tower-owner.ts still probes /health for the startup ownership guard. It is not probeHealth, and the issue scopes item 2 to the SDK probe. It could move to the route later; that needs the same fallback.
    • doctor keeps /health for insideCodevSession.
    • VS Code connection-manager.connect() keeps getHealth(). It runs once per connect attempt, with backoff, and logs the payload's uptime.

Integration-review round

After the owner's ruling, one round of fixes from the integration reviews (e3ed77c9b):

  1. The SDK validates the whole liveness body (above), with a malformed-response test for each field.
  2. arch.md's afx send section describes getLiveness() on /health/live. It no longer mentions the address-book route or the old failedForAnOlderTower helper.
  3. The public-route rationale in server-utils.ts and arch.md names both kinds of public route: browser-navigation paths, and keyless SDK/CLI probes (/health, /health/live, /api/version).
  4. The VS Code terminal-adapter comments and test names say "liveness probe", not /health.
  5. The Windows workflow was dispatched on this branch (linked under Test Plan).

CMAP

  • codex: REQUEST_CHANGES → fixed. getLiveness() read only a 404 as unknownRoute, so a keyless client against an older Tower (401) got no flag. Fixed with the /health confirmation above and two tests, then re-measured against the live v3.3.8 Tower.
  • claude: APPROVE. I took its non-blocking items:
    • The VS Code give-up probe now uses the liveness route.
    • The route test positively asserts all five heavy spies on the /health side, so none of the negative assertions is vacuous.
    • schemaVersion is documented as a constant of the running code, not a value read from the database.
    • Its note that getLiveness and probeHealth disagreed about 401 is resolved by the codex fix.
  • gemini: not run. This project's consultation config names codex and claude only.

GET /health/live answers {status, version, startedAt, schemaVersion} from what the
process already holds: no instance list, no process census, no database read. The
SDK's probeHealth asks it first and falls back to /health only when an older Tower
answers 404 (keyed) or 401 (keyless). afx send's older-Tower check asks the liveness
route instead of the whole address book. Unresponsive messages now name the route
that went unanswered. /health keeps its census for status and the dashboard.
- getLiveness: a keyless client's 401 from an older Tower is an unknown route when
  the public /health answers healthy (codex)
- VS Code terminal give-up probe uses isRunning (liveness route), not getHealth
- route test positively asserts every heavy spy on the /health side
- document schemaVersion as a constant of the running code
@waleedkadous
waleedkadous marked this pull request as draft November 26, 2026 23:20
The /tmp residue check (Spec 1658) failed CI: the test's dashboard path and socket
dir are opaque strings that never reach the disk, so they need no /tmp at all.
- SDK validates the whole liveness body (status, version, startedAt, schemaVersion)
  before returning it as TowerLiveness; a malformed 200 is unresponsive from
  probeHealth and a flagless failure from getLiveness, with tests for each field
- arch.md: afx send's older-Tower check is getLiveness() on /health/live, not the
  address-book route or failedForAnOlderTower
- public-route rationale (server-utils.ts, arch.md) names both kinds: browser
  navigation paths and keyless SDK/CLI probes
- VS Code terminal-adapter comments and tests say liveness probe, not /health
@waleedkadous
waleedkadous marked this pull request as ready for review November 27, 2026 07:04
@waleedkadous
waleedkadous merged commit ab0fa50 into main Nov 27, 2026
8 checks passed
waleedkadous added a commit that referenced this pull request Nov 27, 2026
waleedkadous added a commit that referenced this pull request Nov 27, 2026
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.

Tower: a cheap liveness route with the version; /health is too heavy to probe under load

1 participant