Skip to content

tower owner-lock robustness: surface refusal in the CLI, graceful-shutdown same-address overlap, clear-owner escape hatch (follow-up to #1629) #1690

Open

Description

@amrmelsayed

Follow-up to #1629's owner-lock guard (PR #1689), split per the gate ruling: the guard resolves the incident class (different-port second Tower hijacking a live production DB); three robustness items remain, deliberately deferred to keep the guard's scope bounded.

  1. Surface the refusal in the CLI (most urgent). afx tower start daemonizes, so the guard's loud "another Tower owns this DB (pid X, port Y — did you mean CODEV_AGENT_FARM_DIR?)" error today reaches only tower.log; the user sees the generic 30s "failed to respond" timeout — indistinguishable from tower startup can hang unbounded and unlogged in killOrphanedShellpers, tripping the 30s launcher timeout (field report on 3.3.3) #1685's hang class. The launcher should detect the fast-exit + read the refusal out of the log (or a status file) and print it verbatim.
  2. Graceful-shutdown same-address overlap (codex's remaining RC on Fix #1629: refuse a second Tower against a live global.db (owner lock) #1689): between the old Tower closing its listener and process.exit, a same-host:port restart passes the bindHost-matched shortcut and claims while the old owner lives. Low severity (graceful shutdown never deletes rows — the overlap is a transient handoff to a legitimate successor), but closing it correctly needs a pid-is-actually-a-tower identity check — and doing that without the opposite failure (claude's warning: refusing on a recycled pid wedges startup on a phantom owner) is why this is its own design item, coupled with:
  3. An escape hatch: afx tower start --clear-owner (or afx tower clear-owner) for a wedged/phantom owner record, with the teaching error naming it.

Items 2+3 ship together or not at all — a stricter refusal without the hatch converts a rare overlap into a rare lockout.

Activity

  1. added
    area/tower
    on Sep 16, 2026
  2. amrmelsayed commented on Sep 16, 2026

    @amrmelsayed
    CollaboratorAuthor

    Addition from PR #1689's lock-file rewrite (builder's recommendation, endorsed): item 2's real fix should explicitly evaluate a native flock lifetime-lock — a kernel-held lock on an open fd is released automatically on process death, which simultaneously solves (a) the stale-takeover unlink race (the residual accepted on #1689 — no dep-free filesystem CAS exists), (b) the graceful-shutdown same-address overlap (lock held until true process exit), and (c) the phantom-pid wedge (no stale files to wedge on). The cost is a native/optional dependency decision (node has no built-in flock) — which is the owner's call, and why it lives in this follow-up rather than the shipped guard.

  3. amrmelsayed commented on Sep 16, 2026

    @amrmelsayed
    CollaboratorAuthor

    Trivial rider for whichever lane takes this: tower-owner.ts:355's docstring still says "the active global.db's .lock sibling" — the code correctly returns .tower-owner (renamed for the SQLite dotfile-VFS collision). Doc-only, one line.

  4. added 2 commits that reference this issue on Sep 16, 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