Repository navigation
Description
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 thea live pid is never signaledWARN, ~line 854 and ~1164 in 3.3.7) then checks onlyprocessExists(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
- A row with a reused pid is deleted on the first reconcile after Tower start, with one INFO line, and never retried.
- A row whose pid is a genuinely live shellper with a matching start time is still never signaled or deleted (regression test for tower reconcile: failed reconnect triggers delete + SIGTERM without verifying the shellper is dead (destroyed 53 live sessions in the #1629 incident) #1686).
- Unit test: fake
processExiststrue + start-time mismatch → row deleted, nokill; start-time match → row kept.
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/:idcannot clean it either:killTerminalWithShellperreturns false because the session was never reconnected into the manager, so the route 404s beforedeleteTerminalSession.
Activity
waleedkadous commentedon Nov 4, 2026
On it! Working on a fix now.
Fix #1877: delete a shellper row whose pid was reused, without signal…
[Bugfix #1877] Thread: PR + CMAP results
[Bugfix #1877] Review: share PID_REUSE_TOLERANCE_MS; document the two…
[Spec 1658] Merge main (v3.3.7, #1869 Open IDE, #1877 pid-reuse row d…
[Spec 1658] Windows tests after the main merge: #1877 start-time help…