Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop-app): stop time-nudges escalating during approval waits
Diego Zacarias31bd83d2bcc3
diff --git a/desktop-app/package-lock.json b/desktop-app/package-lock.jsonindex 4d8260240..3fbb72e4d 100644--- a/desktop-app/package-lock.json+++ b/desktop-app/package-lock.json@@ -1,12 +1,12 @@{"name": "evenfire",- "version": "0.1.316",+ "version": "0.1.317","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "evenfire",- "version": "0.1.316",+ "version": "0.1.317","license": "MPL-2.0","dependencies": {"@tanstack/react-query": "5.100.10",diff --git a/desktop-app/package.json b/desktop-app/package.jsonindex b1139fe31..81ab5c880 100644--- a/desktop-app/package.json+++ b/desktop-app/package.json@@ -1,7 +1,7 @@{"name": "evenfire","productName": "Evenfire",- "version": "0.1.316",+ "version": "0.1.317","private": true,"license": "MPL-2.0","description": "Evenfire desktop client for secure agent and workflow access",diff --git a/desktop-app/ui/src/components/agents/NudgeArea.tsx b/desktop-app/ui/src/components/agents/NudgeArea.tsxindex 4bca3ed0d..ee4412225 100644--- a/desktop-app/ui/src/components/agents/NudgeArea.tsx+++ b/desktop-app/ui/src/components/agents/NudgeArea.tsx@@ -30,6 +30,16 @@ function MiniSummary({ steps }: { steps: ProgressStep[] }) {* step away — closing the "fire & forget + come back" loop. Renders nothing for* T1/T2 (short waits) and for no/terminal task. Covers both locally-started and* rejoined tasks (rendered as a sibling of the thread, not inside the placeholder).+ *+ * Suspended tasks render NO nudge at all. Every T3+ nudge asserts the agent is+ * working ("still working", "taking longer than usual", "might be stuck") — all+ * false while the task is parked on an approval gate, where the blocker is the+ * user, not the agent. §AC3 freezes the tier timer at `pausedAt` so the wait+ * itself can't escalate, but a task that genuinely ran >2min BEFORE suspending+ * still enters the gate already at T3/T4/T5, so the freeze alone can't suppress+ * the misleading copy — this guard does. No replacement "waiting for your+ * approval" banner: the approval card rendered above is already that affordance,+ * and duplicating it would just add noise under it.*/export function NudgeArea({ agentRef, chatId, onStartNewChat, onRefreshState }: Props) {const tracker = useAgentTaskTracker()@@ -50,6 +60,12 @@ export function NudgeArea({ agentRef, chatId, onStartNewChat, onRefreshState }:if (!state) return nullif (state.status === 'completed' || state.status === 'cancelled' || state.status === 'failed')return null+ // Approval gate open → the approval card owns the surface (see the block+ // above). Also guard on `pendingApproval` alone: after a rejoin the FSM+ // projection can paint the gate before the sticky `suspended` replay flips+ // this tracker entry's status, and the nudge must stay out through that+ // window too.+ if (state.status === 'suspended' || state.pendingApproval) return nullif (tier === 'T1' || tier === 'T2') return nullif (tier === 'T3') {diff --git a/desktop-app/ui/src/components/agents/__tests__/nudgeArea.test.tsx b/desktop-app/ui/src/components/agents/__tests__/nudgeArea.test.tsxindex dab373ccc..d4d336119 100644--- a/desktop-app/ui/src/components/agents/__tests__/nudgeArea.test.tsx+++ b/desktop-app/ui/src/components/agents/__tests__/nudgeArea.test.tsx@@ -125,6 +125,20 @@ describe('NudgeArea (D.5b)', () => {expect(container.firstChild).toBeNull()})+ it('renders nothing while suspended even if the computed tier is T3+', () => {+ // Genuinely worked 2.5–16min BEFORE suspending (T3/T4/T5), so §AC3's freeze+ // at `pausedAt` still lands on a nudge tier — but "your agent is still+ // working" is false at an approval gate. The approval card is the+ // affordance; the nudge stays out.+ for (const ageMs of [150_000, 400_000, 1_000_000]) {+ const { container, unmount } = renderNudge(+ task(ageMs, { status: 'suspended', pausedAt: Date.now() })+ )+ expect(container.firstChild).toBeNull()+ unmount()+ }+ })+it('stops showing a nudge after switching to a chat with no task', () => {// Key-aware fake: agent-x::c1 has a long-running (T3) task; c2 has none.const byKey = new Map<string, TaskState>([['agent-x::c1', task(150_000)]])diff --git a/desktop-app/ui/src/contexts/AgentTaskTrackerContext/__tests__/taskTracker.test.ts b/desktop-app/ui/src/contexts/AgentTaskTrackerContext/__tests__/taskTracker.test.tsindex fe87970d1..698e3680f 100644--- a/desktop-app/ui/src/contexts/AgentTaskTrackerContext/__tests__/taskTracker.test.ts+++ b/desktop-app/ui/src/contexts/AgentTaskTrackerContext/__tests__/taskTracker.test.ts@@ -243,6 +243,73 @@ describe('TaskTracker', () => {expect(onSuspended).toHaveBeenCalledTimes(1)})+ it('a replayed suspended (already suspended) does NOT re-stamp pausedAt (§AC3)', async () => {+ // Advance the clock WITHOUT fake timers: the 5s connect timeout and 30s idle+ // watchdog are irrelevant to this invariant and would just fail the task.+ let clock = Date.now()+ vi.spyOn(Date, 'now').mockImplementation(() => clock)+ tracker.setCallbacks({ onTerminal: vi.fn(), onSuspended: vi.fn() })+ tracker.start(KEY, 'task-1', 'um-1')+ const suspend = () =>+ rpc.emit({+ type: 'suspended',+ data: {+ taskId: 'task-1',+ requestId: 'req-1',+ displayName: 'Shell Execute',+ reason: 'approval',+ },+ })+ await suspend()+ const firstPausedAt = tracker.get(KEY)?.pausedAt+ expect(firstPausedAt).toBeTypeOf('number')++ // The bridge reconnects (the 300s RPC token lapsed) and mcp-host replays its+ // sticky `suspended` to the new subscriber. The freeze must survive it —+ // otherwise the frozen age becomes full wall-clock and D.5b escalates the+ // nudges to T3/T4/T5 while the task just sits at the approval gate.+ clock += 600_000+ await suspend()+ clock += 600_000+ await suspend()++ expect(tracker.get(KEY)?.pausedAt).toBe(firstPausedAt)+ expect(tracker.get(KEY)?.status).toBe('suspended')+ expect(tracker.get(KEY)?.pendingApproval?.requestId).toBe('req-1')+ })++ it('a genuine re-suspension after a resume DOES re-stamp pausedAt', async () => {+ let clock = Date.now()+ vi.spyOn(Date, 'now').mockImplementation(() => clock)+ tracker.setCallbacks({ onTerminal: vi.fn(), onSuspended: vi.fn() })+ tracker.start(KEY, 'task-1', 'um-1')+ await rpc.emit({+ type: 'suspended',+ data: { taskId: 'task-1', requestId: 'req-1', displayName: 'Shell', reason: 'approval' },+ })+ const firstPausedAt = tracker.get(KEY)?.pausedAt+ expect(firstPausedAt).toBeTypeOf('number')++ // Approval decided → execution resumes (status back to 'streaming').+ clock += 60_000+ await rpc.emit({+ type: 'tool_start',+ data: { taskId: 'task-1', toolCallId: 'tc-1', toolName: 'shell', iteration: 2 },+ })+ expect(tracker.get(KEY)?.status).toBe('streaming')+ expect(tracker.get(KEY)?.pendingApproval).toBeUndefined()++ // A SECOND tool needs approval → real transition, so the freeze point moves.+ clock += 60_000+ await rpc.emit({+ type: 'suspended',+ data: { taskId: 'task-1', requestId: 'req-2', displayName: 'Shell', reason: 'approval' },+ })++ expect(tracker.get(KEY)?.pausedAt).toBe(firstPausedAt! + 120_000)+ expect(tracker.get(KEY)?.pendingApproval?.requestId).toBe('req-2')+ })+it('subscribe returns an unsubscribe that stops further notifications', async () => {const fn = vi.fn()const unsubscribe = tracker.subscribe(KEY, fn)diff --git a/desktop-app/ui/src/contexts/AgentTaskTrackerContext/taskTracker.ts b/desktop-app/ui/src/contexts/AgentTaskTrackerContext/taskTracker.tsindex 7e1ad5863..e31c9614e 100644--- a/desktop-app/ui/src/contexts/AgentTaskTrackerContext/taskTracker.ts+++ b/desktop-app/ui/src/contexts/AgentTaskTrackerContext/taskTracker.ts@@ -539,9 +539,23 @@ export class TaskTracker implements AgentTaskTracker {case 'suspended': {const sd = event.data+ // Stamp `pausedAt` ONLY on the TRANSITION into suspended (§AC3 freezes the+ // D.5b tier timer at `pausedAt` so an approval wait can't escalate the+ // nudges). This event is NOT once-per-suspension: mcp-host keeps the last+ // `suspended` as a sticky event and replays it to every new subscriber, and+ // the main-process bridge (`appService.startTaskProgressStream`) reconnects+ // the SSE transparently whenever the 300s RPC token lapses mid-stream+ // (`auth-expired`) — i.e. roughly every 5 min on a long approval wait. Each+ // replay re-entering this branch used to re-stamp `pausedAt = now`, turning+ // the "frozen" age (`pausedAt - startedAt`) back into full wall-clock and+ // escalating the task to T3/T4/T5 while it sat suspended. Guarding on the+ // PREVIOUS status keeps a genuine RE-suspension correct: a decided approval+ // routes through `tool_start`/`llm_in_progress`, which set status back to+ // 'streaming', so the next `suspended` is a real transition and re-stamps.+ const wasSuspended = state.status === 'suspended'this.mutate(key, s => {s.status = 'suspended'- s.pausedAt = Date.now()+ if (!wasSuspended) s.pausedAt = Date.now()s.pendingApproval = sd.requestId? {requestId: sd.requestId,