Repository navigation
Fix #1871: Tower persists the cloud's slug, follows renames, reacts to deregistration, adds --claim - #1988
Merged
Conversation
…o deregistration Tower stored and advertised the name the user typed, so when the cloud registered it as <name>-2 every public URL (access URL, success page, IDE x-forwarded-prefix and cookie Path) pointed at the wrong slug. A cloud-side delete left Tower retrying a dead key forever. - redeemToken returns the cloud's slug and display name (falling back to the requested name for an older cloud) and sends claimSlug only when asked. - The OAuth callback and `afx tower connect` persist tower_name = slug plus display_name; the success page and log say when the slug differs. - TunnelClient reports the auth_ok identity; Tower rewrites cloud-config.json when the slug changed, so a cloud rename lands on the next reconnect. - invalid_api_key after this client has connected is a terminal `deregistered` state with no half-open retry. Tower stamps deregistered_at in cloud-config.json (keyed on the same api_key, credentials kept), does not reconnect it at start, on config change, or on smart reconnect, and reports it in /api/tunnel/status, the Tower home page and `afx tower status`. - `afx tower connect --claim` takes the name back from a disconnected tower. - `afx tower status` prints slug, display name and the slug-built access URL. - The callback page now HTML-escapes the names it shows. - Docs (both trees), arch.md and the afx skill (hashes regenerated).
…laim against a fake cloud bugfix-1871-cloud-identity.test.ts drives the real tower-tunnel, cloud-config, token-exchange and TunnelClient against MockTunnelServer (now able to serve redeem and the codev-cloud#17 auth_ok shape) in its own agent-farm dir: a bumped slug lands in cloud-config.json and getPublicAuthority's prefix, auth_ok renames rewrite it, an older cloud's response changes nothing, and invalid_api_key after a connect stamps deregistered_at, keeps the credentials and never retries. Six of its seven tests fail on the pre-fix source; the seventh pins the unchanged older-cloud behaviour. Unit tests pin the TunnelClient state split (deregistered vs the #1372 breaker), the auth_ok identity, updateCloudConfig's key guard, and the CLI (--claim, slug persistence, status output, deregistered re-registration).
The fourth afx skill tree (root .codex/skills) was missed, which failed the skill-parity, spec-1280 and spec-1273 byte-identity tests.
… while connected; prefill the display name CMAP (codex): the config watcher skipped every change while connected, so a re-registration written during a live connection left Tower on the old key; once the cloud rejected it the client sat in terminal `deregistered` with nothing to connect the new registration. The skip now applies only when the live client was built from the same api_key/tower_id/server_url (an identity-only change from auth_ok still skips). The home page Connect dialog now offers the display name rather than the cloud's slug, so re-registering a deregistered `mac-2` asks for `mac` (the dialog normalizes the name before validating it). The regression test now requires Tower to reconnect on the replacement key and never retry the old one; it fails on the previous watcher condition.
…e slug CMAP (claude): tower_name now holds the cloud's routing slug, so the dashboard title (Spec 443, fed by /api/state hostname) silently switched from the name the owner chose to the slug. Use display_name, falling back to tower_name for configs written before #1871.
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.
Summary
Tower stored and advertised the tower name the user typed, not the slug the cloud assigned. When the cloud registered a Tower as
<name>-2, every public URL Tower built pointed at the wrong slug and the IDE's assets 502'd. A cloud-side delete also left Tower retrying a dead key forever. This is the Tower half of codev-cloud#17: persist and show the canonical slug, follow a cloud-side rename, react to deregistration, and add an explicit name takeover.Fixes #1871
Root Cause
lib/token-exchange.tsredeemTokenparsed onlytowerId/apiKeyand dropped theslug/namethe cloud returns. The OAuth callback (servers/tower-tunnel.ts) andafx tower connect(commands/tower-cloud.ts) both persisted the typed name astower_name. The access URL, the success page, and the IDEx-forwarded-prefixand cookie Path all derive fromtower_name.lib/tunnel-client.tsread onlytowerIdfromauth_ok, so a rename made in the cloud never reached Tower.handleAuthError('invalid_api_key')could not tell a key that never worked from a key that worked and then died, so both got the tunnel-client: wedges after sustained uplink flap — instant-fail loop, then a hung connect attempt with no timeout; never self-recovers without manual reconnect #1372 15-minute half-open retry indefinitely. Nothing recorded or surfaced that the Tower had been deregistered.Fix
redeemTokenreturnsslugandname. When either is absent (an older cloud) it falls back to the requested name, which is today's behaviour. The callback and the CLI writetower_name: slugplus a new optionaldisplay_name. The success page and log line name the slug and say when it differs from the requested name.TunnelClient.onAuthOk(identity)reports{towerId, slug?, name?}, and Tower rewritescloud-config.jsonwhen the slug or name changed. Anauth_okwithout a slug leaves the stored identity alone.invalid_api_keyafter the client has beenconnectedis a new terminalTunnelStatederegistered, with no half-open retry.deregistered_atintocloud-config.jsonand keeps the credentials. The write is guarded on the sameapi_key, so it cannot clobber a re-registration written since./api/tunnel/statusreportsstate: deregistered,registered: falseandderegisteredAt. The Tower home page shows it with a Connect button, andafx tower statussays so and points atafx tower connect.afx tower connect --claimsendsclaimSlug: trueon redeem. Without the flag nothing is sent and the cloud still bumps to<name>-2.afx tower statusprints the slug, the display name and the access URL built from the slug.Small adjacent fix: the callback success page now HTML-escapes the names it shows (it interpolated
pending.nameraw).Docs:
afx towerconnect/status incodev/andcodev-skeleton/resources/commands/agent-farm.md, thearch.mdnote ontower_name, and all four afx skill copies (--claim), withshipped-skill-hashes.tsregenerated.Cloud-side gap (not worked around on the Tower side)
A rename in the cloud UI does not close the live tunnel session. A connected Tower therefore keeps its old slug until its next reconnect, which is when
auth_okdelivers the new one. Closing the session on rename is the cloud's change to make. Note that a tunnel-borne IDE request already uses the relay-stamped prefix (#1914), so only Tower's stored and advertised name lags.Scope notes
apps/web) is unchanged. A deregistered registration reportsregistered: falsethere, so it shows "Cloud: not registered".CMAP review fixes
deregisteredwith nothing to connect the new registration. The watcher now skips only when the live client was built from the sameapi_key/tower_id/server_url; an identity-only change fromauth_okstill skips. The regression test now requires Tower to reconnect on the replacement key and never retry the old one, and it fails on the previous condition.mac, notmac-2). The dialog normalizes names before validating them. Re-checked in the browser./api/statehostname(Spec 443 title) now usesdisplay_name, falling back totower_name, which keeps the title users already saw. Covered by a test with display nameAna's MBPand slugana-s-mbp.markDeregistered. Now covered by the watcher fix: the write of the new registration wakes the watcher, which replaces the parked client.chore(porch): …commit subjects (codex), which porch writes itself.auth_ok.nameand the redeem response'snamego only todisplay_name.Test Plan
Regression test added:
bugfix-1871-cloud-identity.test.tsdrives the real tower-tunnel, cloud-config, token-exchange and TunnelClient against a fake cloud.MockTunnelServernow also serves redeem and the codev-cloud#17auth_okshape. The suite uses its own agent-farm dir. It covers:cloud-config.json, the success page,getPublicAuthority()'s prefix and the statusaccessUrl;slug/namebehaves as today;claimSlugis sent only when asked;auth_okwith a new slug rewrites the config, and one without a slug changes nothing;invalid_api_keyafter a connect stampsderegistered_at, keeps the credentials, makes no auth attempt even past the half-open interval, and survives a Tower restart and smart reconnect;6 of its 7 tests fail on the pre-fix source. The 7th pins the unchanged older-cloud path.
Unit tests:
deregisteredvs the tunnel-client: wedges after sustained uplink flap — instant-fail loop, then a hung connect attempt with no timeout; never self-recovers without manual reconnect #1372 breaker, andauth_okidentity in both shapes;updateCloudConfig's key guard and the optional fields;--claim, slug persistence and the "was taken" message, deregistered re-registration, status output for registered and deregistered.Build passes (porch
build).All tests pass (porch
tests: fullpackages/codevsuite).Browser check of the Tower home page (Playwright, headless). The built Tower ran on a spare port with an isolated
CODEV_AGENT_FARM_DIRseeded with a deregistered config. The page shows a red dot,mac-2 deregistered, a Connect button and an explanatory tooltip, with no page errors.afx tower status -p <port>prints the deregistered block, andafx tower connect --helplists--claim. The live Tower and the realcloud-config.jsonwere not touched.Windows (current head
3baa9f5): https://github.com/cluesmith/codev/actions/runs/45702187250.bugfix-1871-cloud-identityfile, CLI tests, install verification, and both probes (windows-latest, windows-11-arm).src/__tests__/bugfix-1982-update-root-docs.test.ts(5 tests, a CRLF mismatch in its own temporary project). It fails the same way onmain: https://github.com/cluesmith/codev/actions/runs/45703930614. So it was already broken by codev update reports false conflicts on CLAUDE.md and AGENTS.md in an unedited project #1982 before this PR, and it is not flaky. This PR touches nothing incodev updateor root docs.a|bfilter, which vitest does not support.Not exercised: the issue's acceptance steps against the real cloud (register under a taken name, rename in the cloud UI, delete in the cloud UI,
--claim). They need a real registration, which the architect ruled out for this builder. The fake cloud plays the same contract.Existing failures (not flaky)
packages/codev/src/__tests__/bugfix-1982-update-root-docs.test.tsfails 5 tests on native Windows, onmainas well as on this branch: https://github.com/cluesmith/codev/actions/runs/45703930614. Its expected and actual managed-block text differ only in CRLF/LF. It was introduced by codev update reports false conflicts on CLAUDE.md and AGENTS.md in an unedited project #1982 (merged just before this branch point) and is out of scope here, since it belongs to thecodev updatesubsystem.