fix(cli): make agent wait unlimited by default

This commit is contained in:
Mohamed Boudra
2026-02-23 20:51:42 +07:00
parent b167abfda5
commit 3f06063b4b
7 changed files with 98 additions and 25 deletions
@@ -1740,4 +1740,72 @@ describe('DaemonClient', () => {
},
])
})
test('waitForFinish with timeout=0 omits timeoutMs and has no client deadline', async () => {
vi.useFakeTimers()
try {
const logger = createMockLogger()
const mock = createMockTransport()
const client = new DaemonClient({
url: 'ws://test',
clientId: 'clsk_unit_test',
logger,
reconnect: { enabled: false },
transportFactory: () => mock.transport,
})
clients.push(client)
const connectPromise = client.connect()
mock.triggerOpen()
await connectPromise
const waitPromise = client.waitForFinish('agent-wait-zero-timeout', 0)
expect(mock.sent).toHaveLength(1)
const request = JSON.parse(String(mock.sent[0])) as {
type: 'session'
message: {
type: 'wait_for_finish_request'
requestId: string
agentId: string
timeoutMs?: number
}
}
expect(request.message.type).toBe('wait_for_finish_request')
expect(request.message.agentId).toBe('agent-wait-zero-timeout')
expect(request.message).not.toHaveProperty('timeoutMs')
const settled = vi.fn()
void waitPromise.then(
() => settled('resolved'),
() => settled('rejected')
)
await vi.advanceTimersByTimeAsync(5 * 60 * 1000)
expect(settled).not.toHaveBeenCalled()
mock.triggerMessage(
wrapSessionMessage({
type: 'wait_for_finish_response',
payload: {
requestId: request.message.requestId,
status: 'idle',
final: null,
error: null,
lastMessage: null,
},
})
)
await expect(waitPromise).resolves.toEqual({
status: 'idle',
final: null,
error: null,
lastMessage: null,
})
} finally {
vi.useRealTimers()
}
})
})
+3 -2
View File
@@ -2426,17 +2426,18 @@ export class DaemonClient {
async waitForFinish(agentId: string, timeout = 60000): Promise<WaitForFinishResult> {
const requestId = this.createRequestId()
const hasTimeout = Number.isFinite(timeout) && timeout > 0
const message = SessionInboundMessageSchema.parse({
type: 'wait_for_finish_request',
requestId,
agentId,
timeoutMs: timeout,
...(hasTimeout ? { timeoutMs: timeout } : {}),
})
const payload = await this.sendCorrelatedRequest({
requestId,
message,
responseType: 'wait_for_finish_response',
timeout: timeout + 5000,
timeout: hasTimeout ? timeout + 5000 : 0,
options: { skipQueue: true },
})
return {
+9 -5
View File
@@ -5497,10 +5497,12 @@ export class Session {
}
const abortController = new AbortController()
const effectiveTimeoutMs = timeoutMs ?? 600_000 // 10 minutes default
const timeoutHandle = setTimeout(() => {
abortController.abort('timeout')
}, effectiveTimeoutMs)
const hasTimeout = typeof timeoutMs === 'number' && timeoutMs > 0
const timeoutHandle = hasTimeout
? setTimeout(() => {
abortController.abort('timeout')
}, timeoutMs)
: null
try {
let result = await this.agentManager.waitForAgentEvent(agentId, {
@@ -5553,7 +5555,9 @@ export class Session {
payload: { requestId, status: 'timeout', final, error: null, lastMessage: null },
})
} finally {
clearTimeout(timeoutHandle)
if (timeoutHandle) {
clearTimeout(timeoutHandle)
}
}
}