From 8a7b6ffad2d7bcc6f5ca60a44e8194b9ffc74464 Mon Sep 17 00:00:00 2001
From: Teknium <127238744+teknium1@users.noreply.github.com>
Date: Mon, 7 Sep 2026 21:42:10 -0700
Subject: [PATCH] fix: preserve newer Ink controls when status hydration
arrives late
---
ui-tui/src/__tests__/agentsHydration.test.tsx | 40 +++++++++++++++++++
ui-tui/src/components/agentsOverlay.tsx | 10 ++++-
2 files changed, 48 insertions(+), 2 deletions(-)
create mode 100644 ui-tui/src/__tests__/agentsHydration.test.tsx
diff --git a/ui-tui/src/__tests__/agentsHydration.test.tsx b/ui-tui/src/__tests__/agentsHydration.test.tsx
new file mode 100644
index 0000000000..88ed88b27f
--- /dev/null
+++ b/ui-tui/src/__tests__/agentsHydration.test.tsx
@@ -0,0 +1,40 @@
+import { PassThrough } from 'node:stream'
+
+import { Box, renderSync } from '@hermes/ink'
+import React from 'react'
+import { expect, it, vi } from 'vitest'
+
+import { $delegationState, resetDelegationState } from '../app/delegationStore.js'
+import { AgentsOverlay } from '../components/agentsOverlay.js'
+import type { GatewayClient } from '../gatewayClient.js'
+import { DEFAULT_THEME } from '../theme.js'
+
+it('does not undo an acknowledged pause when opening status resolves late', async () => {
+ resetDelegationState()
+ let resolveStatus!: (value: unknown) => void
+ const status = new Promise(resolve => { resolveStatus = resolve })
+ const request = vi.fn(async (method: string) => method === 'delegation.status' ? status : { paused: true })
+ const stdout = Object.assign(new PassThrough(), { columns: 80, rows: 16, isTTY: false })
+ const stdin = Object.assign(new PassThrough(), { isTTY: true, setRawMode: () => {}, ref: () => {}, unref: () => {} })
+
+ const view = renderSync( {}} t={DEFAULT_THEME} />, {
+ stdout: stdout as unknown as NodeJS.WriteStream,
+ stdin: stdin as unknown as NodeJS.ReadStream,
+ stderr: new PassThrough() as unknown as NodeJS.WriteStream,
+ patchConsole: false
+ })
+
+ try {
+ await vi.waitFor(() => expect(request).toHaveBeenCalledWith('delegation.status', {}))
+ stdin.write('p')
+ await vi.waitFor(() => expect($delegationState.get().paused).toBe(true))
+ resolveStatus({ paused: false, max_spawn_depth: 4 })
+ await status
+ await new Promise(resolve => setTimeout(resolve, 50))
+ expect($delegationState.get().paused).toBe(true)
+ } finally {
+ view.unmount()
+ view.cleanup()
+ resetDelegationState()
+ }
+})
diff --git a/ui-tui/src/components/agentsOverlay.tsx b/ui-tui/src/components/agentsOverlay.tsx
index 4ee2eb4103..d44bda719d 100644
--- a/ui-tui/src/components/agentsOverlay.tsx
+++ b/ui-tui/src/components/agentsOverlay.tsx
@@ -668,10 +668,16 @@ export function AgentsOverlay({ gw, initialHistoryIndex = 0, onClose, t }: Agent
}, [cursor, historyIndex, mode])
useEffect(() => {
- // Warm caps + paused flag on open.
+ // A control acknowledgement or newer hydration must win over this request.
+ const initial = $delegationState.get()
+ let active = true
gw.request('delegation.status', {})
- .then(r => applyDelegationStatus(asRpcResult(r)))
+ .then(r => {
+ if (active && $delegationState.get() === initial) {applyDelegationStatus(asRpcResult(r))}
+ })
.catch(() => {})
+
+ return () => { active = false }
}, [gw])
useEffect(() => {