research-tui-supervisor-coexistence

Research: TUI-vs-supervisor session lock coexistence — single-owner vs cooperative-handoff

Metadata

Statusdone
Assignedagent-1786
Agent identity3184716484e6f0ea08bb13539daf07686ee79d440505f1fdf2de0357707034c3
Created2026-05-02T23:53:33.105711085+00:00
Started2026-05-03T00:53:31.477531250+00:00
Completed2026-05-03T00:59:55.752739473+00:00
Tagsresearch,nex,chat,tui,supervisor,bug, eval-scheduled
Eval score0.94
└ blocking impact0.90
└ completeness1.00
└ coordination overhead0.95
└ correctness0.95
└ downstream usability0.85
└ efficiency0.90
└ intent fidelity0.85
└ style adherence0.95

Description

Description

src/tui/viz_viewer/state.rs:13696-13753 has a forced-takeover path: when the user opens a chat tab in the TUI, it requests release of the session lock, waits 300ms, SIGTERMs the supervisor's nex handler if still alive, re-acquires. This is racy when combined with the supervisor restart-loop (see research-supervisor-lock-churn): even after SIGTERM, a new supervisor handler can spawn into the lock between the TUI's takeover wait and the TUI's wg nex --resume invocation. End result: sometimes TUI wins, sometimes supervisor wins, sometimes neither.

Investigation scope (READ ONLY — no source mods)

  • src/tui/viz_viewer/state.rs:13696-13770 (TUI takeover dance + spawn wg nex --resume)
  • src/commands/service/coordinator_agent.rs:660-743 (supervisor pre-flight + register_coordinator_session)
  • src/session_lock.rs (request_release / clear_release_marker / wait_for_release)
  • src/executor/native/agent.rs:1363 + src/executor/native/chat_surface.rs:176 (release-marker observation in the running handler)
  • Two design choices to evaluate:
    • Single-owner: only ONE handler ever runs — supervisor stops respawning when TUI takes over (sentinel file chat-N/.user-driven); supervisor resumes when TUI exits or sentinel removed
    • Cooperative-handoff: supervisor and TUI handlers cooperate via a tighter protocol (e.g. supervisor enters "observer mode" while TUI is connected, doesn't try to spawn its own nex)

Deliverable (via wg log)

  • Compare both options: pros/cons, blast radius, complexity
  • Recommend ONE
  • Patch shape for the recommended option (file:line, not full diff)
  • Note: design-chat-agent / implement-tmux-wrapped already shipped tmux wrapping. Verify whether the supervisor's nex handler today is itself tmux-wrapped — if yes, takeover semantics differ (supervisor's nex lives inside a detached tmux session, surviving SIGTERM at the wrapper level). Document.

Validation

  • Both options analyzed
  • Recommendation made with rationale
  • Patch shape concrete enough to drive impl task
  • tmux-wrapping interaction documented
  • No source modifications in this task

Depends on

Required by

Log