Repository navigation
Description
Problem
Tower's side of the Codev Cloud tower lifecycle is incomplete. Observed 2026-11-02 during the Windows manual pass for #1658 (review finding M5): after a reconnect, the cloud registered the Tower under a deduplicated name (<name>-2), Tower kept advertising and stamping the name the user typed, and every IDE asset under the cloud URL 502'd. The stranded <name> row could not be removed from the cloud UI either. The cloud side is tracked as codev-cloud#17 (delete reachable from the towers list, delete closes a live tunnel, rename endpoint, explicit name takeover, name in the redeem response). This issue is codev's half of the same contract.
Root cause (codev side), verified in source
redeemToken(lib/token-exchange.ts) parses onlytowerIdandapiKey; the cloud's redeem response already carriesslug, the server-derived routing identity. The OAuth callback inservers/tower-tunnel.tspersiststower_name: pending.name, the user's requested name. Every public URL Tower builds (accessUrl, the connect success page, thex-forwarded-prefixstamped byide-forward.ts) derives from that stored name, so Tower and cloud disagree whenever the cloud bumps or renames.- On
auth_errorwithinvalid_api_key,lib/tunnel-client.tsre-parks and retries forever with a failed-marker log line. After a cloud-side delete the tunnel closes and the key is dead, but Tower keeps itscloud-config.jsonand keeps retrying;afx tower statusdoes not say the Tower was deregistered. POST /api/tunnel/disconnectalready callsDELETE /api/towers/:idwith the Bearer key (best effort), so codev can delete its own live registration today. A stranded row whose key was rotated by a later re-registration can only be deleted from the cloud UI (codev-cloud#17).
Fix (Tower only; the cloud's protocol does not change for these)
- Persist the canonical identity.
redeemTokenreturnsslugandnamealongsidetowerIdandapiKey(fallback: requested name when absent, for older cloud deployments). The callback persiststower_name: slugand a newdisplay_name: name. The success page and the log line show the slug, and say so when it differs from the typed name ("registered as<name>-2;<name>was taken"). - Re-read the slug on every reconnect. Once the cloud's
auth_okcarriesslug(requested from codev-cloud), updatecloud-config.jsonwhen it differs so a rename made in the cloud UI takes effect on the next reconnect without re-registering. - React to deregistration. On
auth_error: invalid_api_keyafter a previously successful connection, stop retrying, mark the registration deregistered incloud-config.json(do not silently delete credentials the user may want to inspect), surface it inafx tower statusand on the Tower home page, and point atafx tower connect. - Explicit takeover.
afx tower connect --claimsendsclaimSlug: trueon redeem, so a user re-registering a machine whose old row is not connected gets the name back instead of<name>-2. Default stays the bump. - Show the canonical name.
afx tower statusprints slug, display name and the access URL built from the slug. - Tests: redeem response with a different slug yields
cloud-config.jsoncarrying the slug andgetPublicAuthority()building the prefix from it;auth_okwith a new slug rewrites the config;invalid_api_keyafter a successful connect moves to the deregistered state and stops the retry loop;--claimsets the flag; a response withoutslug/namebehaves as today.
Acceptance
- Register under a name the cloud already has:
afx tower statusshows the bumped slug, the connect page names it, andhttps://<cloud>/t/<bumped>/ide/?folder=…loads the workbench with every asset under the bumped prefix. - Rename the tower in the cloud UI, let Tower reconnect: status shows the new slug and the IDE loads under it.
- Delete the tower in the cloud UI: Tower logs the close, status says deregistered, no retry storm.
afx tower connect --claimon a machine whose old row is disconnected takes the old name.- Register under a free name: behaviour unchanged.
Cloud contract (settled with the codev-cloud workspace, tracked as codev-cloud#17)
auth_ok→{ towerId, slug, name }- redeem →
{ towerId, slug, name, apiKey };claimSlug: truetakes over a not-connected tower of the same user PATCH /api/towers/:id { name }→200 { towerId, slug, name }or409on slug conflict; old slug 404s immediately- delete closes the live tunnel session;
/t/<slug>/answers 410 for a tombstone window, then 404
Steps 1, 3 and 5 can land before the cloud ships; steps 2 and 4 are tested against the cloud's staging once codev-cloud#17 is deployed there. Source: #1658 review finding M5.
Activity
[Spec 1658] Review: owner pass results A to H (15 pending on the bran…
amrmelsayed commentedon Nov 17, 2026
Cloud half is on staging (note from the codev-cloud architect, 2026-11-18)
The cloud side of this work (codev-cloud#17, merged to develop via its PR #18) is deployed to STAGING. What a builder on this issue can test against there:
auth_oknow carries{towerId, slug, name}; the redeem response carries{towerId, slug, name, apiKey}andclaimSlug.PATCH /api/towers/:id {name}renames; 409 on a name conflict.DELETEderegisters and closes the live session./t/<old-slug>/answers 410 (owner-scoped, for one hour) and then 404 after a rename or deregistration; the towers list links to the detail page.Production follows when the owner merges develop to main on the cloud side. Tower must persist and display the slug the cloud returns, never the typed name, and must handle the rename and takeover cases above. Related: #1914 builds its IDE link relative to the page so a slug change cannot strand it.
amrmelsayed commentedon Nov 17, 2026
Cloud half is now in PRODUCTION (codev-cloud architect, 2026-11-18)
Supersedes the staging note above. The tower lifecycle contract is live on the cloud:
auth_okcarries{towerId, slug, name}.{towerId, slug, name, apiKey};claimSlug: truetakes over a not-connected tower of the same user. A connected holder is bumped rather than answered 409, so the token is not burned.PATCH /api/towers/:id {name}returns{towerId, slug, name}or 409 on conflict.DELETEcloses the live tunnel;/t/<slug>/answers 410 to the deleting user for one hour, then 404.A builder on this issue can develop and verify against production. Staging equals production for now.
waleedkadous commentedon Nov 25, 2026
On it! Working on a fix now.
[Bugfix #1871] Fix: persist the cloud's slug, follow renames, react t…
[Bugfix #1871] Test: slug persistence, rename, deregistration and --c…
[Bugfix #1871] Fix: add --claim to the self-hosted .codex afx skill copy
[Bugfix #1871] Builder thread: investigation and fix notes
[Bugfix #1871] Fix: replace the tunnel client when credentials change…
[Bugfix #1871] Fix: title the dashboard with the display name, not th…
[Bugfix #1871] Builder thread: CMAP rounds and Windows results