The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
fix(agent): an approval wait is timed as a wait, a tool as its own run
purple08a2204f37a5
diff --git a/src/api/agents/__tests__/tool-executor.test.ts b/src/api/agents/__tests__/tool-executor.test.tsindex accacb5e..5afff009 100644--- a/src/api/agents/__tests__/tool-executor.test.ts+++ b/src/api/agents/__tests__/tool-executor.test.ts@@ -331,3 +331,27 @@ describe('tool-executor — applyResultToToolCall', () => {expect(call.cacheHit).toBe(true)})})++describe('the duration is the tool\'s own time, not the approval wait (Gegenprobe 01.10.2026)', () => {+ it('a call that sat on the approval card reports only its run time', async () => {+ const runtime = makeRuntime({+ tools: { file_write: { executor: async () => { await sleep(5); return 'ok' } } },+ awaitApproval: async () => { await sleep(150); return true },+ })+ const [out] = await executeParallel([req('1', 'file_write')], runtime)+ expect(out.status).toBe('completed')+ expect(out.durationMs).toBeLessThan(100)+ // The start stays the moment the call was scheduled (the audit trail).+ expect(out.completedAt - out.startedAt).toBeGreaterThanOrEqual(150)+ })++ it('a rejected call reports no wait as its duration either', async () => {+ const runtime = makeRuntime({+ tools: { file_write: { executor: async () => 'ok' } },+ awaitApproval: async () => { await sleep(150); return false },+ })+ const [out] = await executeParallel([req('1', 'file_write')], runtime)+ expect(out.status).toBe('rejected')+ expect(out.durationMs).toBeLessThan(100)+ })+})diff --git a/src/api/agents/tool-executor.ts b/src/api/agents/tool-executor.tsindex 08260fd5..b2111220 100644--- a/src/api/agents/tool-executor.ts+++ b/src/api/agents/tool-executor.ts@@ -235,6 +235,10 @@ async function runSingle(opts: ExecutorOptions): Promise<ExecutionResult> {const startedAt = Date.now()+ // What the duration counts from. Moves to the end of the approval wait: the+ // time a call sat on the user's card is not the tool's time, and a 20 ms+ // file_write read "21.6s" next to its tick (Gegenprobe 01.10.2026).+ let clockFrom = startedAtconst argsHash = stableArgsHash(req.args ?? {})opts.onStart?.(req)@@ -250,7 +254,7 @@ async function runSingle(const finalize = (partial: Omit<ExecutionResult, 'completedAt' | 'durationMs'>): ExecutionResult => {const completedAt = Date.now()- const durationMs = completedAt - startedAt+ const durationMs = completedAt - clockFromconst result: ExecutionResult = { ...partial, completedAt, durationMs }runtime.recordAudit?.({kind: 'complete',@@ -349,6 +353,7 @@ async function runSingle(// User approval. Unconditional: a runtime that does not want a prompt says// so with APPROVE_ALL, it does not get there by forgetting the field.const approved = await runtime.awaitApproval(req, tool)+ clockFrom = Date.now()if (!approved) {return finalize({id: req.id,diff --git a/src/components/chat/WorkingAnchor.tsx b/src/components/chat/WorkingAnchor.tsxindex 3ddff550..223c1f90 100644--- a/src/components/chat/WorkingAnchor.tsx+++ b/src/components/chat/WorkingAnchor.tsx@@ -17,6 +17,16 @@ interface Props {conversationId?: string | null}+/**+ * When the explicit label of a conversation's run appeared, so the clock next+ * to "Waiting for your approval" says how long the card has been waiting, not+ * how long the run has been going ("Waiting for your approval 6s" the moment+ * the card came up, Gegenprobe 01.10.2026). Module scope, like the run's+ * booked start, so a tab switch does not start the wait at 0 again.+ */+const labelSince = new Map<string, number>()+const labelKey = (conversationId: string, label: string) => `${conversationId}\u0000${label}`+/*** THE bottom-of-run status line (G14-6, David 2026-08-07): the word "Working"* carrying the same shimmer as a live tool name, with the elapsed clock@@ -39,23 +49,41 @@ export function WorkingAnchor({ isRunning, label, conversationId }: Props) {// lands AFTER paint — so the first quarter second of a new run showed the// previous run's time. React's documented "adjust state while rendering"// shape re-runs only this component, before anything paints.+ // Same render-time reset when the clock switches between the run and an+ // explicit label, so the old count never paints under the new word.const [wasRunning, setWasRunning] = useState(isRunning)- if (wasRunning !== isRunning) {+ const [wasLabel, setWasLabel] = useState(label)+ if (wasRunning !== isRunning || wasLabel !== label) {setWasRunning(isRunning)+ setWasLabel(label)setElapsed(0)}useEffect(() => {+ // A label that is gone (or a run that ended under it) gives its start up,+ // so the next approval of this conversation counts from its own start.+ if (conversationId && (!isRunning || !label)) {+ for (const k of labelSince.keys()) if (k.startsWith(`${conversationId}\u0000`)) labelSince.delete(k)+ }if (!isRunning) return- // The run's booked start when there is one; otherwise the start belongs- // to this mount, in the effect's own closure, with nothing left over from- // the previous run to read back.- const start = bookedAt ?? Date.now()+ // An explicit label counts from when it appeared; otherwise the run's+ // booked start; otherwise the start belongs to this mount, in the effect's+ // own closure, with nothing left over from the previous run to read back.+ let start: number+ if (label && conversationId) {+ const key = labelKey(conversationId, label)+ if (!labelSince.has(key)) labelSince.set(key, Date.now())+ start = labelSince.get(key)!+ } else if (label) {+ start = Date.now()+ } else {+ start = bookedAt ?? Date.now()+ }const interval = setInterval(() => {setElapsed(Math.max(0, Math.floor((Date.now() - start) / 1000)))}, 250)return () => clearInterval(interval)- }, [isRunning, bookedAt])+ }, [isRunning, bookedAt, label, conversationId])if (!isRunning) return nulldiff --git a/src/components/chat/__tests__/the-approval-clock-counts-the-wait.test.ts b/src/components/chat/__tests__/the-approval-clock-counts-the-wait.test.tsnew file mode 100644index 00000000..9c794b83--- /dev/null+++ b/src/components/chat/__tests__/the-approval-clock-counts-the-wait.test.ts@@ -0,0 +1,71 @@+/**+ * @vitest-environment jsdom+ *+ * Gegenprobe on the real build, 01.10.2026: the approval card had just come up+ * and the status line already read "Waiting for your approval 6s", the run's+ * time, not the wait. An explicit label now counts from when it appeared, and+ * the run's own clock comes back when the wait ends.+ */+import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'+import { createElement } from 'react'+import { render, screen, act, cleanup } from '@testing-library/react'+import { WorkingAnchor } from '../WorkingAnchor'+import { useGenerationStore } from '../../../stores/generationStore'++const T0 = new Date('2026-10-01T09:00:00Z').getTime()+const WAIT = 'Waiting for your approval'++beforeEach(() => {+ vi.useFakeTimers()+ vi.setSystemTime(T0)+ useGenerationStore.setState({ runs: {}, generating: {}, aborters: {} })+ useGenerationStore.getState().bookRun('c1', 'cloud', Symbol('run'))+})+afterEach(() => {+ cleanup()+ vi.useRealTimers()+})++const line = () => screen.getByTestId('working-anchor').textContent ?? ''+const props = (label?: string) => ({ isRunning: true, conversationId: 'c1', label })++describe('the clock next to an approval wait', () => {+ it('starts at the card, then the run clock comes back', () => {+ const view = render(createElement(WorkingAnchor, props()))+ act(() => { vi.advanceTimersByTime(6_000) })+ expect(line()).toContain('6s')++ view.rerender(createElement(WorkingAnchor, props(WAIT)))+ act(() => { vi.advanceTimersByTime(300) })+ expect(line()).toContain(WAIT)+ expect(line()).not.toContain('6s')+ act(() => { vi.advanceTimersByTime(4_000) })+ expect(line()).toContain('4s')++ view.rerender(createElement(WorkingAnchor, props()))+ act(() => { vi.advanceTimersByTime(300) })+ expect(line()).toContain('10s')+ })++ it('a tab switch during the wait keeps the wait time', () => {+ const first = render(createElement(WorkingAnchor, props(WAIT)))+ act(() => { vi.advanceTimersByTime(20_000) })+ first.unmount()+ act(() => { vi.advanceTimersByTime(5_000) })+ render(createElement(WorkingAnchor, props(WAIT)))+ act(() => { vi.advanceTimersByTime(300) })+ expect(line()).toContain('25s')+ })++ it('the next approval of a later run counts from its own start', () => {+ const view = render(createElement(WorkingAnchor, props(WAIT)))+ act(() => { vi.advanceTimersByTime(30_000) })+ // The run ends while the card is open (Stop), then a new run asks again.+ view.rerender(createElement(WorkingAnchor, { ...props(WAIT), isRunning: false }))+ act(() => { vi.advanceTimersByTime(60_000) })+ view.rerender(createElement(WorkingAnchor, props(WAIT)))+ act(() => { vi.advanceTimersByTime(2_300) })+ expect(line()).toContain('2s')+ expect(line()).not.toContain('1m')+ })+})