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(agents): retain concurrent approvals after picker answers

reviewda5b45888928
diff --git a/CLAUDE.md b/CLAUDE.md
index c8e5bb4e4..afd8d50fe 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -4876,3 +4876,6 @@ recording before the child transcript-association guard in both shells.
A held parent question can overlap child permissions: retain its question card and waiting
state while publishing each approval ticket separately. Approval replies resolve only their
own ticket; the picker stays pending until its correlated answer or explicit reset.
+When the parent answers first, retain concurrent approval tickets and blocked attention until
+their own replies; ordinary tool activity cannot settle them. Explicit turn/session resets
+still cancel both kinds of pending attention.
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index d01c820bb..aaa94f7e1 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -789,3 +789,6 @@ recording before the child transcript-association guard in both shells.
A held parent question can overlap child permissions: retain its question card and waiting
state while publishing each approval ticket separately. Approval replies resolve only their
own ticket; the picker stays pending until its correlated answer or explicit reset.
+When the parent answers first, retain concurrent approval tickets and blocked attention until
+their own replies; ordinary tool activity cannot settle them. Explicit turn/session resets
+still cancel both kinds of pending attention.
diff --git a/src/core/agent-status-mirror.ts b/src/core/agent-status-mirror.ts
index def5466e8..81932660c 100644
--- a/src/core/agent-status-mirror.ts
+++ b/src/core/agent-status-mirror.ts
@@ -38,6 +38,8 @@ export const EXPIRE_MS = 6 * 60 * 60_000
export const WRITE_DEBOUNCE_MS = 300
export interface MirrorEntry {
+ /** Tickets introduced concurrently with a picker, retained until reply or explicit reset. */
+ concurrentApprovalIds?: string[]
/** Live question identity, independent of the short-lived display stash. */
pendingQuestion?: { sessionId: string; toolUseId: string }
/** working/waiting/blocked/done; undefined = idle/unknown (e.g. after a session reset). */
@@ -479,6 +481,19 @@ function reduceEffectiveEntry(
}
// Unrelated tool hooks (including untagged child hooks) are not answers. Keep both
// the state and its original evidence/identity until a correlated result or explicit reset.
+ const resetApprovals = (ev.kind === 'session' && ev.sessionPhase === 'start') ||
+ (ev.sessionId === prev?.sessionId && (ev.kind === 'session' || ev.newTurn || ev.interrupted))
+ if (resetApprovals) delete next.concurrentApprovalIds
+ else {
+ if (ev.pendingId && ev.state === 'blocked' && ev.askKind === 'approval' &&
+ (prev?.pendingQuestion || prev?.concurrentApprovalIds?.length)) {
+ next.concurrentApprovalIds = [...new Set([...(prev?.concurrentApprovalIds ?? []), ev.pendingId])]
+ }
+ if (ev.pendingId && ev.state === 'working' && next.concurrentApprovalIds) {
+ next.concurrentApprovalIds = next.concurrentApprovalIds.filter(id => id !== ev.pendingId)
+ if (!next.concurrentApprovalIds.length) delete next.concurrentApprovalIds
+ }
+ }
const ask = prev?.pendingQuestion
if (ask) {
const sameSession = ev.sessionId === ask.sessionId
@@ -488,6 +503,11 @@ function reduceEffectiveEntry(
if (!reset && !answered) return next
delete next.pendingQuestion
}
+ if (next.concurrentApprovalIds?.length) {
+ // The picker answer and unrelated parent tool activity cannot answer child permissions.
+ commitState('blocked', !!ev.verified)
+ return next
+ }
if (ev.questionId && ev.sessionId) {
next.pendingQuestion = { sessionId: ev.sessionId, toolUseId: ev.questionId }
}
@@ -1419,6 +1439,28 @@ export function recordAgentEvent(rawEvent: NormalizedAgentEvent): NormalizedAgen
const prevState = prev?.state
const next = reduceEffectiveEntry(prev, ev, now)
state.set(nodeId, next)
+ const questionAnswered = !!prev?.pendingQuestion && !next.pendingQuestion &&
+ ev.sessionId === prev.pendingQuestion.sessionId && ev.answeredQuestionId === prev.pendingQuestion.toolUseId
+ if (questionAnswered || (ev.pendingId && ev.state === 'working')) {
+ for (const card of inboxEvents) {
+ if (card.nodeId !== nodeId) continue
+ if ((questionAnswered && card.kind === 'question') ||
+ (ev.pendingId && card.kind === 'approval' && card.pendingId === ev.pendingId)) card.resolved = true
+ }
+ }
+ if (next.concurrentApprovalIds?.length && !next.pendingQuestion) {
+ if (ev.pendingId && ev.state === 'blocked' && ev.askKind === 'approval') {
+ produceInboxFromState(nodeId, ev, prevState, 'blocked', now, true)
+ }
+ const pendingId = next.concurrentApprovalIds[next.concurrentApprovalIds.length - 1]
+ const card = inboxEvents.find(e => e.nodeId === nodeId && e.pendingId === pendingId && !e.resolved)
+ if (questionAnswered || (ev.pendingId && ev.state === 'working')) {
+ fireNodeStateChange({ nodeId, agentId: ev.agentId, sessionId: next.sessionId, ts: now,
+ event: 'update', state: 'needsYou', kind: 'approval', pendingId, message: card?.title ?? 'Needs approval' })
+ }
+ scheduleWrite()
+ return { ...ev, kind: 'state', state: 'blocked', sessionId: next.sessionId, askKind: 'approval', pendingId }
+ }
// reduceEntry held an unanswered `request_user_input` through its turn-end `done` — rewrite
// the broadcast to what the reducer decided, so every consumer (canvas store, notch, phone)
// agrees the node is still waiting rather than each re-deriving it from the raw done.
@@ -1432,14 +1474,7 @@ export function recordAgentEvent(rawEvent: NormalizedAgentEvent): NormalizedAgen
scheduleWrite()
return { ...ev, state: next.state, sessionId: next.sessionId }
}
- if (ev.pendingId && ev.state === 'working') {
- for (const card of inboxEvents) {
- if (card.nodeId === nodeId && card.kind === 'approval' && card.pendingId === ev.pendingId) {
- card.resolved = true
- }
- }
- scheduleWrite()
- }
+ scheduleWrite()
// Broadcast the same held state to Desktop, Server, canvas/board and the phone.
return { ...ev, kind: 'state', state: next.state, sessionId: next.sessionId,
verified: ev.verified, newTurn: undefined, interrupted: undefined,
diff --git a/src/core/pending-question.test.ts b/src/core/pending-question.test.ts
index 0c3723de9..05519a3c7 100644
--- a/src/core/pending-question.test.ts
+++ b/src/core/pending-question.test.ts
@@ -121,6 +121,37 @@ describe('subagent attention forwarding (W2)', () => {
expect(_inboxSnapshot().events.every(e => e.resolved)).toBe(true)
})
+ it.each(['allow', 'deny'])('keeps approval tickets actionable when the parent answers first (%s)', decision => {
+ ask()
+ const approval = { agent_id: 'child', session_id: 'child-session', tool_name: 'Bash',
+ tool_input: { command: 'echo child' }, nodeterm_pending_id: 'ticket-1' }
+ hook('PermissionRequest', approval)
+ hook('PermissionRequest', { ...approval, nodeterm_pending_id: 'ticket-2' })
+ expect(recordQuestionResult('node', 'parent', 'ask-1')).toMatchObject({
+ state: 'blocked', askKind: 'approval', pendingId: 'ticket-2' })
+ expect(_snapshot().node.pendingQuestion).toBeUndefined()
+ expect(_inboxSnapshot().events.find(e => e.kind === 'question')?.resolved).toBe(true)
+ expect(_inboxSnapshot().events.filter(e => e.kind === 'approval' && !e.resolved)).toHaveLength(2)
+ expect(hook('PreToolUse', { tool_name: 'Read' })).toMatchObject({ state: 'blocked', pendingId: 'ticket-2' })
+ expect(hook('PermissionRequest', { ...approval, nodeterm_answered: decision })).toMatchObject({
+ state: 'blocked', askKind: 'approval', pendingId: 'ticket-2' })
+ expect(_inboxSnapshot().events.find(e => e.pendingId === 'ticket-1')?.resolved).toBe(true)
+ expect(_inboxSnapshot().events.find(e => e.pendingId === 'ticket-2')?.resolved).not.toBe(true)
+ expect(hook('PermissionRequest', { ...approval, nodeterm_pending_id: 'ticket-2', nodeterm_answered: decision }))
+ .toMatchObject({ state: 'working' })
+ expect(_inboxSnapshot().events.every(e => e.resolved)).toBe(true)
+ expect(_snapshot().node.concurrentApprovalIds).toBeUndefined()
+ })
+
+ it.each(['UserPromptSubmit', 'SessionEnd', 'SessionStart', 'Stop'])('resets overlapping approvals on explicit %s', event => {
+ ask()
+ hook('PermissionRequest', { agent_id: 'child', tool_name: 'Bash', nodeterm_pending_id: 'ticket' })
+ recordQuestionResult('node', 'parent', 'ask-1')
+ hook(event, { is_interrupt: true, ...(event === 'SessionStart' ? { session_id: 'new' } : {}) })
+ expect(_snapshot().node.concurrentApprovalIds).toBeUndefined()
+ expect(_inboxSnapshot().events.filter(e => e.kind !== 'done').every(e => e.resolved)).toBe(true)
+ })
+
it('does not turn the held picker own permission into an approval', () => {
ask()
expect(hook('PermissionRequest', { tool_name: 'AskUserQuestion', nodeterm_pending_id: 'picker' }))