Skip to content

Tower SIGTERMs a reused shellper pid in the reconcile pre-filter (workspace missing / temp dir) #1879

Open

Description

@waleedkadous

Problem

Follow-up to #1877 (PR #1878, which deletes a reused-pid shellper row without signaling it). The same hazard remains on paths that PR did not touch.

In _reconcileTerminalSessionsInner() (packages/codev/src/agent-farm/servers/tower-terminals.ts), the Phase 1 pre-filter handles a shellper row whose workspace path no longer exists, or lives in a temp dir, like this:

if (dbSession.shellper_pid && processExists(dbSession.shellper_pid)) {
  try { process.kill(dbSession.shellper_pid, 'SIGTERM'); killed++; } catch {}
}

There is no start-time check. After a reboot, shellper_pid can belong to an unrelated process (in #1877 it was /usr/libexec/diagnosticextensionsd). If that row's workspace is also gone, Tower SIGTERMs that unrelated process. That is worse than #1877, which only spammed the log.

Fix (suggested)

Gate both pre-filter kills on !(await isShellperPidReused(shellper_pid, shellper_start_time)). The helper is added in PR #1878 (terminal/session-manager.ts). The row is still deleted either way.

Related, same class (lower priority)

  • liveSessionsForWorkspace() (Never activate Codev inside a builder worktree; hide the Agents view there #1809 prune) counts a row as live when processExists(shellper_pid) is true. A reused pid therefore reads as a live stray session.
  • shellper-husk-sweep.ts declares its own PID_REUSE_TOLERANCE_MS = 2000, and its comment points at a stale line. It could import the constant from session-manager.ts.
  • shellper_start_time comes from the shellper's own Date.now(), while the guard reads ps -o lstart on macOS (one-second resolution) or the /proc/<pid> ctime on Linux. Only the 2s tolerance reconciles the two. Recording getProcessStartTime(pid) at spawn would put both sides on one clock.

Raised by the Claude CMAP review of PR #1878.

Activity

  1. added
    area/tower
    on Nov 4, 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