fix(cli): bound orchestration ask timeouts (#10689)

* fix(cli): bound orchestration ask timeouts

* fix(cli): harden remote timeout boundaries
This commit is contained in:
Jinjing
2026-07-26 12:50:05 -07:00
committed by GitHub
parent 8b25cfc0f8
commit 76b2a3b44d
19 changed files with 765 additions and 268 deletions
+22
View File
@@ -4,6 +4,7 @@ import { join } from 'node:path'
import { createServer, type Socket } from 'node:net'
import { afterEach, describe, expect, it } from 'vitest'
import type { RuntimeMetadata } from '../../shared/runtime-bootstrap'
import { MAX_TIMER_DELAY_MS } from '../../shared/timer-delay'
import { sendRequest } from './transport'
const servers = new Set<ReturnType<typeof createServer>>()
@@ -25,6 +26,27 @@ afterEach(async () => {
servers.clear()
})
describe('runtime transport timeout validation', () => {
it.each([-1, 1.5, MAX_TIMER_DELAY_MS + 1, Number.MAX_SAFE_INTEGER + 1])(
'rejects invalid timer delay %s before transport discovery',
async (timeoutMs) => {
const metadata: RuntimeMetadata = {
runtimeId: 'runtime-1',
pid: 123,
transports: [],
authToken: 'token',
startedAt: 1
}
await expect(sendRequest(metadata, 'status.get', undefined, timeoutMs)).rejects.toMatchObject(
{
code: 'invalid_argument'
}
)
}
)
})
// Why: these tests create Unix domain socket servers in temp directories.
// Windows does not support Unix domain sockets in the same way.
describe.skipIf(process.platform === 'win32')('runtime transport', () => {
+7
View File
@@ -3,6 +3,7 @@ import { randomUUID } from 'node:crypto'
import { findTransport, type RuntimeMetadata } from '../../shared/runtime-bootstrap'
import { isKeepaliveFrame, RuntimeRpcEnvelopeSchema } from './envelope-schema'
import { RuntimeClientError, type RuntimeRpcResponse } from './types'
import { MAX_TIMER_DELAY_MS, isSafeTimerDelayMs } from '../../shared/timer-delay'
export async function sendRequest<TResult>(
metadata: RuntimeMetadata,
@@ -10,6 +11,12 @@ export async function sendRequest<TResult>(
params: unknown,
timeoutMs: number
): Promise<RuntimeRpcResponse<TResult>> {
if (!isSafeTimerDelayMs(timeoutMs)) {
throw new RuntimeClientError(
'invalid_argument',
`Runtime request timeout must be an integer between 0 and ${MAX_TIMER_DELAY_MS}ms.`
)
}
return await new Promise((resolve, reject) => {
const transport = findTransport(metadata, 'unix', 'named-pipe')
if (!transport) {