Skip to content

Tower keeps a dead shellper row forever when its pid is reused after reboot (start-time mismatch ignored by the sweep) #1877

Closed

Description

@waleedkadous

Problem

After a machine reboot, a persisted terminal_sessions row whose shellper_pid has been reused by an unrelated process is never cleaned up. Tower retries the reconnect on every reconcile pass and logs two lines each time, forever.

Observed on this machine (Tower 3.3.6 and 3.3.7): the writing workspace's guidebook architect row fea2d3f9… (created 2026-10-19, shellper_start_time = 2026-10-13) has shellper_pid 2217. After the 2026-10-24 reboot, pid 2217 is /usr/libexec/diagnosticextensionsd. The socket file is gone. Tower logged 12k–41k lines/day about it from Oct 28 to Nov 4 and tower.log reached 354 MB.

Root cause

Two code paths disagree about what "alive" means:

  • shellperManager.reconnectSession() already detects the reuse and says so: Session fea2d3f9… reconnect failed: PID 2217 reused (start time mismatch).
  • The Phase-2 sweep in dist/agent-farm/servers/tower-terminals.js (near the a live pid is never signaled WARN, ~line 854 and ~1164 in 3.3.7) then checks only processExists(session.shellper_pid) and, because the pid number is alive, leaves the row untouched (unconfirmed++).

So the Bugfix #1686 safety rule (never signal / never delete a live shellper) is applied to a pid that the reconnect code has just proven is not our shellper.

Fix (prescribed)

In the Phase-2 sweep, treat "pid reused (start time mismatch)" as pid dead: when reconnectSession() fails specifically because the recorded shellper_start_time does not match the live process's start time, the row is stale and must be deleted (without signaling the pid, which belongs to someone else). Keep the #1686 behaviour for every other reconnect failure (socket refused, transient fd error) where the start time does match.

Suggested shape: have reconnectSession() return (or throw) a distinguishable reason (pid-reused), surface it to the sweep, and gate the shellperAlive check on !pidReused. The same check should apply to the on-the-fly reconnect path that emits On-the-fly reconnect for … failed but pid … is alive.

Acceptance

Notes

  • Never hand-edit global.db; this is the in-band fix. The stale row on this machine will clear itself on the next Tower restart after the fix lands.
  • DELETE /api/terminals/:id cannot clean it either: killTerminalWithShellper returns false because the session was never reconnected into the manager, so the route 404s before deleteTerminalSession.

Activity

  1. added
    area/tower
    on Nov 4, 2026
  2. waleedkadous commented on Nov 4, 2026

    @waleedkadous
    ContributorAuthor

    On it! Working on a fix now.

  3. added 3 commits that reference this issue on Nov 4, 2026
    617b834
    b646c37
    c3c0195
  4. added 2 commits that reference this issue on Nov 9, 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