fix(tmux,run,hooks): the four pre-existing bugs the #37 evaluation found

- tmux targets are exact (`=name`, `=name:` for panes/options): a bare
  `-t agenthub-lane-1` resolves by prefix to agenthub-lane-12 once lane 1
  is gone, so killing a finished lane could kill another.
- getRun/killRun refuse ids that are not `agenthub-lane-<n>`, so
  DELETE /api/run/main can no longer kill a user's own tmux session.
- router/apply reports restart_required only for a running pane; getRun
  returns a `gone` handle, so it was always true.
- needs_action is cleared only by the session that raised it (new nullable
  lanes.needs_action_session); a second session in the same cwd used to
  clear it on its second hook.
This commit is contained in:
2026-09-23 13:13:16 +07:00
parent 04b6b98d97
commit 99a2a8277c
18 changed files with 134 additions and 33 deletions
+11 -3
View File
@@ -210,10 +210,18 @@ function touchLaneFromHook(hookType, data) {
if (data.session_id && lane.session_id !== data.session_id) patch.session_id = data.session_id;
if (hookType === "Notification" && !idleNudge) {
patch.needs_action = data.message || "needs you";
} else if (lane.needs_action && data.session_id === lane.session_id) {
// Clear only when the hook comes from the session currently bound to the lane
// (evaluated before any rebinding, so a rebinding hook never clears in the same pass)
patch.needs_action_session = data.session_id || null;
} else if (
lane.needs_action &&
data.session_id &&
data.session_id === (lane.needs_action_session || lane.session_id)
) {
// Clear only from the session that raised it: another session sharing the
// cwd rebinds session_id on every hook but is not the one waiting. A flag
// with no recorded raiser falls back to the bound session (evaluated
// before any rebinding, so a rebinding hook never clears in the same pass).
patch.needs_action = null;
patch.needs_action_session = null;
}
// Only idle↔running is mirrored: provisioning and failed are lifecycle
+1 -1
View File
@@ -690,7 +690,7 @@ router.post("/:id/router/apply", sameOriginGuard, (req, res) => {
// outside; the pane has to be restarted. Report it instead of letting the
// switch look clean and then fail on the user's next prompt.
const runId = runs.runIdForLane(lane.id);
const live = !!runs.getRun(runId);
const live = runs.getRun(runId)?.status === "running";
// Every other mutating lane route broadcasts; without it the client's
// cached row keeps the OLD router_profile, and the next lane switch
// re-reads that stale row and flips the picker back.