8000 PTY lock admission is too blunt: surface a locked state with recovery · Issue #244 · simon-inkie/inkie-deck · GitHub
[go: up one dir, main page]

Skip to content

PTY lock admission is too blunt: surface a locked state with recovery #244

Open

Description

@simon-inkie

Summary

handlesTerminal in packages/deck/app/lib/runner/registry.server.ts treats an existing .runner.lock, or any lstatSync error on it, as "a PTY session owns this agent", whatever the instance flag says. This is deliberate fail-closed behaviour (it prevents two writers on one conversation), but it is blunt. Follow-up to #241.

Situations wrongly blocked

  • The PTY flag is off on purpose (MC_PTY_RUNNER=0 or unset) and a lock is left from a prior run: tmux is blocked, but with the flag off Deck also refuses PTY start, recovery and controls.
  • A stale lock after a crash, before recovery has run.
  • A filesystem error (EACCES, EPERM, ELOOP) on the lock path is treated as an active PTY session.

What the user sees

A blank terminal viewport, refused compose sends ("The PTY session is not running or no longer opted in"), wake and push silently dropped, and no Start or Stop controls. There is no recovery route in the UI.

Proposed behaviour

  1. Flag-aware and liveness-checked: with the flag off, block tmux only while a live child holds the lock. If the lock is provably stale, allow recovery.
  2. A distinct "locked" state with a reason and a recovery action, not a blank viewport.
  3. A filesystem error on the lock path must not claim PTY ownership by itself. Show an error state instead.
  4. Align .runtime handling: agent_opts_into_pty in packages/base/bin/runtime-launch.sh checks .runner and .runner.lock but not .runtime, while Deck's opt-in requires .runtime to be unset or claude. An agent with another runtime and a .runner file is skipped by the base scripts while Deck refuses to start it, stranding it.

Guardrails

  • Never allow a second writer. "Provably stale" must meet the spec's recovery rule (reclaim only when recovery proves there was no spawn or confirms the group is gone), and flock failures stay fail-closed. The change is to surface a state with a recovery action, not to loosen admission.
  • The current spec defines the existing behaviour as intended, so this needs a spec amendment before code.

Activity

  1. simon-inkie commented on Nov 22, 2026

    @simon-inkie
    OwnerAuthor

    Two minor, fail-safe follow-ups from reviewing the recovery fix in #241 (both fail closed, neither risks a second writer):

    • packages/deck/app/lib/runner/lock.server.ts: the readFileSync of /proc/<pid>/environ during the leaderless-group scan is not wrapped. If a descendant exits mid-scan it throws ENOENT, which aborts a recovery that would otherwise have succeeded. Treat a vanished member as gone and carry on.
    • packages/deck/app/lib/runner/lock.server.ts: if the recorded leader PID is recycled by an unrelated process, the birth-time mismatch makes verification return false immediately and skips the leaderless-descendant scan, leaving the agent locked until manual cleanup. Safe, but worth a recovery path in the same locked-state work.
  2. simon-inkie commented on Nov 22, 2026

    @simon-inkie
    OwnerAuthor

    Two more items from Devin's review of the recovery fix in #241:

    • Restricted procfs (hidepid=1): verifyGroup reads /proc entries for unrelated users, and one denied read aborts leaderless recovery even when every group member is readable. Same fix as the vanished-descendant case: skip unreadable non-members, refuse only if a member cannot be verified.
    • Add a real process-group test for leaderless recovery (spawn leader and descendant, kill the leader, assert the survivor is verified through the inherited session marker and the claim is removed only after the group is gone), since the current tests mock /proc and process.kill.
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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0