Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

fix(relay): a team tab node's Esc / Ctrl-C interrupt guess writes its session store

reviewfabdecfc9385
diff --git a/src/renderer/nodes/TerminalNode.tsx b/src/renderer/nodes/TerminalNode.tsx
index e0a565282..e453402da 100644
--- a/src/renderer/nodes/TerminalNode.tsx
+++ b/src/renderer/nodes/TerminalNode.tsx
@@ -276,7 +276,7 @@ import { announceUserClosedSession } from '../lib/lastSessionClose'
import { useSettings } from '../state/settings'
import { useCodexIdentity, codexSharedIdentity, codexFallbackText } from '../state/codexIdentity'
import { ensureCodexLaunchCaps } from '../state/codexCli'
-import { useAgentStatus, inferInterruptAfterSettle } from '../state/agentStatus'
+import { useAgentStatus } from '../state/agentStatus'
import { useLaunchDelivery } from '../state/launchDelivery'
import { erroredDeps, firstOpenInFlight as isFirstOpenInFlight, handedOverDeps, holdReason, interruptedDeps, launchTooltip } from '../lib/pendingLaunch'
import { useStationHandovers } from '../state/stationHandovers'
@@ -1368,19 +1368,21 @@ export function TerminalNode({
*
* What reads and writes it: the badge (`status`) and everything derived from it, every focus mark
* (`setActive` / `clearUnread`: the dwell, a click, a "go to node" focus, selection, a file
- * insert, the lifecycle teardown), the OSC session-title chip, and the memory levers that must
- * not kill live work (`readAgentState`, `readAgentProcess`, the park's `readSessionEnded`). A
- * relay node's own status thereby also protects its park — `persistent:false` can arrive from a
- * tmux-less relay HOST, i.e. a plain-shell agent session on someone else's machine. The
- * status-driven readers that would act on THIS machine are switched off for a relay node by
- * `gates` below (`relayStatusGates`).
+ * insert, the lifecycle teardown), the OSC session-title chip, the Esc / Ctrl-C interrupt
+ * inference (`agentStatusSession.inferInterruptAfterSettle`, bound to this same store), and the
+ * memory levers that must not kill live work (`readAgentState`, `readAgentProcess`, the park's
+ * `readSessionEnded`). A relay node's own status thereby also protects its park —
+ * `persistent:false` can arrive from a tmux-less relay HOST, i.e. a plain-shell agent session on
+ * someone else's machine. The status-driven readers that would act on THIS machine are switched
+ * off for a relay node by `gates` below (`relayStatusGates`).
*
* Deliberately still on the default store (`useAgentStatus`): Eco / hibernation, restart, pause,
* the liveness check, the cold restore and the pending-launch deps. Those features are refused on
* relay sessions, so their reads only ever concern a local node. Stable for the session's
* lifetime (memoized by api identity), so the once-mounted lifecycle effect may close over it.
*/
- const agentStatusStore = useSessionStores().agentStatus.store
+ const agentStatusSession = useSessionStores().agentStatus
+ const agentStatusStore = agentStatusSession.store
const readAgentState = useCallback(
(): AgentState | undefined => agentStatusStore.getState().byId[id]?.state,
[agentStatusStore, id]
@@ -4049,7 +4051,9 @@ export function TerminalNode({
// Lone Esc / Ctrl-C while the agent works: Claude Code fires NO hook on a user
// interrupt, so probe the cancelled turn (still-silent working → done). Exact
// match — arrow keys etc. arrive as multi-byte \x1b[… sequences.
- if (showStatus && (input === '\x1b' || input === '\x03')) inferInterruptAfterSettle(id)
+ // On THIS node's session store (the default one for a local node): a relay node's guess
+ // must never flip the entry a handed-off SSH project holds under the same node id.
+ if (showStatus && (input === '\x1b' || input === '\x03')) agentStatusSession.inferInterruptAfterSettle(id)
// While a wake is in flight, HOLD this input rather than write it: the resume line is
// sitting un-submitted in the pane and a keystroke would splice into it. The buffer is
// bounded — a `queueFull`/`buffered` verdict means "held, do not write". Flushed (or
diff --git a/src/renderer/nodes/terminal-agent-status.source.test.ts b/src/renderer/nodes/terminal-agent-status.source.test.ts
index bc41e834b..f64b0a366 100644
--- a/src/renderer/nodes/terminal-agent-status.source.test.ts
+++ b/src/renderer/nodes/terminal-agent-status.source.test.ts
@@ -25,7 +25,7 @@ function between(text: string, start: string, end: string): string {
describe('TerminalNode reads its own session store', () => {
it('the node badge reads the session store, not the default one', () => {
- expect(src).toMatch(/const agentStatusStore = useSessionStores\(\)\.agentStatus\.store/)
+ expect(src).toMatch(/const agentStatusSession = useSessionStores\(\)\.agentStatus\n\s*const agentStatusStore = agentStatusSession\.store/)
expect(src).not.toMatch(/useAgentStatus\(\(s\) => s\.byId\[id\]\)/)
expect(src).toMatch(/agentStatusStore\(\(s\) => s\.byId\[id\]\)/) // the bound store is its own hook
expect(src).toMatch(/const status = agentStatusStore\(\(s\) => s\.byId\[id\]\)/)
@@ -56,6 +56,17 @@ describe('TerminalNode reads its own session store', () => {
expect(insertFiles).toContain('agentStatusStore.getState().setActive(id, true)')
})
+ it('the Esc / Ctrl-C interrupt inference writes the session store, not the default one', () => {
+ // The default instance's bound helper must not be reachable from the node at all.
+ expect(src).not.toMatch(/import \{[^}]*\binferInterruptAfterSettle\b[^}]*\} from '\.\.\/state\/agentStatus'/)
+ expect(src).not.toMatch(/useAgentStatus[^\n]*inferInterruptAfterSettle/)
+ const calls = src.match(/inferInterruptAfterSettle\(id\)/g) ?? []
+ expect(calls).toHaveLength(1)
+ expect(src).toMatch(
+ /if \(showStatus && \(input === '\\x1b' \|\| input === '\\x03'\)\) agentStatusSession\.inferInterruptAfterSettle\(id\)/
+ )
+ })
+
it('Approve/Deny, title sync, transcript search and the chat view are gated', () => {
expect(src).toContain('relayStatusGates(session.source)')
expect(src).toMatch(/const gates = relayStatusGates\(session\.source\)/)
diff --git a/src/renderer/session/agent-status-for-project.test.ts b/src/renderer/session/agent-status-for-project.test.ts
index 4a19fead4..13416dfca 100644
--- a/src/renderer/session/agent-status-for-project.test.ts
+++ b/src/renderer/session/agent-status-for-project.test.ts
@@ -118,6 +118,31 @@ describe('agentStatusForProject', () => {
})
})
+describe('the interrupt inference of a project session', () => {
+ it("writes only that session's store, never the default one under a shared node id", () => {
+ vi.useFakeTimers()
+ try {
+ const relay = createSession('relay', RELAY_API, 'Team')
+ bindProjectToSession(TEAM_PROJECT, relay.id)
+ defaultAgentStatus.store.getState().setState(NODE, 'working', 'claude')
+ agentStatusForProject(TEAM_PROJECT).store.getState().setState(NODE, 'working', 'claude')
+
+ // A lone Esc typed into the team tab's node: its session's own helper, bound to its store.
+ agentStatusForProject(TEAM_PROJECT).inferInterruptAfterSettle(NODE, 1000)
+ vi.advanceTimersByTime(1000)
+ expect(agentStatusForProject(TEAM_PROJECT).store.getState().byId[NODE]?.state).toBe('done')
+ expect(agentStatusForProject(TEAM_PROJECT).store.getState().byId[NODE]?.lastTurnInterrupted).toBeDefined()
+ // The handed-off SSH project's entry under the same id is untouched.
+ expect(agentStatusForProject(SSH_PROJECT).store.getState().byId[NODE]?.state).toBe('working')
+
+ // And the local node's helper is the default one, exactly as before.
+ expect(agentStatusForProject(SSH_PROJECT).inferInterruptAfterSettle).toBe(defaultAgentStatus.inferInterruptAfterSettle)
+ } finally {
+ vi.useRealTimers()
+ }
+ })
+})
+
describe('the session registry signal', () => {
it('the registry version moves on create, bind, offline and dispose', () => {
const heard: number[] = []