fix(agents): honor embedded ollama timeouts (#66418)

This commit is contained in:
Vincent Koc
2026-04-14 09:21:22 +01:00
committed by GitHub
parent 900681751d
commit 38de896419
4 changed files with 56 additions and 3 deletions

View File

@@ -47,6 +47,8 @@ type AttemptSpawnWorkspaceHoisted = {
createAgentSessionMock: UnknownMock;
sessionManagerOpenMock: UnknownMock;
resolveSandboxContextMock: UnknownMock;
ensureGlobalUndiciEnvProxyDispatcherMock: UnknownMock;
ensureGlobalUndiciStreamTimeoutsMock: UnknownMock;
buildEmbeddedMessageActionDiscoveryInputMock: UnknownMock;
subscribeEmbeddedPiSessionMock: Mock<SubscribeEmbeddedPiSessionFn>;
acquireSessionWriteLockMock: Mock<AcquireSessionWriteLockFn>;
@@ -71,6 +73,8 @@ const hoisted = vi.hoisted((): AttemptSpawnWorkspaceHoisted => {
const createAgentSessionMock = vi.fn();
const sessionManagerOpenMock = vi.fn();
const resolveSandboxContextMock = vi.fn();
const ensureGlobalUndiciEnvProxyDispatcherMock = vi.fn();
const ensureGlobalUndiciStreamTimeoutsMock = vi.fn();
const buildEmbeddedMessageActionDiscoveryInputMock = vi.fn((params: unknown) => params);
const installToolResultContextGuardMock = vi.fn(() => () => {});
const flushPendingToolResultsAfterIdleMock = vi.fn(async () => {});
@@ -135,6 +139,8 @@ const hoisted = vi.hoisted((): AttemptSpawnWorkspaceHoisted => {
createAgentSessionMock,
sessionManagerOpenMock,
resolveSandboxContextMock,
ensureGlobalUndiciEnvProxyDispatcherMock,
ensureGlobalUndiciStreamTimeoutsMock,
buildEmbeddedMessageActionDiscoveryInputMock,
subscribeEmbeddedPiSessionMock,
acquireSessionWriteLockMock,
@@ -209,8 +215,10 @@ vi.mock("../../../infra/machine-name.js", () => ({
}));
vi.mock("../../../infra/net/undici-global-dispatcher.js", () => ({
ensureGlobalUndiciEnvProxyDispatcher: () => {},
ensureGlobalUndiciStreamTimeouts: () => {},
ensureGlobalUndiciEnvProxyDispatcher: (...args: unknown[]) =>
hoisted.ensureGlobalUndiciEnvProxyDispatcherMock(...args),
ensureGlobalUndiciStreamTimeouts: (...args: unknown[]) =>
hoisted.ensureGlobalUndiciStreamTimeoutsMock(...args),
}));
vi.mock("../../bootstrap-files.js", async () => {
@@ -683,6 +691,8 @@ export function resetEmbeddedAttemptHarness(
hoisted.createAgentSessionMock.mockReset();
hoisted.sessionManagerOpenMock.mockReset().mockReturnValue(hoisted.sessionManager);
hoisted.resolveSandboxContextMock.mockReset();
hoisted.ensureGlobalUndiciEnvProxyDispatcherMock.mockReset();
hoisted.ensureGlobalUndiciStreamTimeoutsMock.mockReset();
hoisted.buildEmbeddedMessageActionDiscoveryInputMock
.mockReset()
.mockImplementation((params) => params);

View File

@@ -0,0 +1,42 @@
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import {
cleanupTempPaths,
createContextEngineAttemptRunner,
getHoisted,
resetEmbeddedAttemptHarness,
} from "./attempt.spawn-workspace.test-support.js";
const hoisted = getHoisted();
describe("runEmbeddedAttempt undici timeout wiring", () => {
const tempPaths: string[] = [];
beforeEach(() => {
resetEmbeddedAttemptHarness();
});
afterEach(async () => {
await cleanupTempPaths(tempPaths);
});
it("forwards the configured run timeout into global undici stream tuning", async () => {
await createContextEngineAttemptRunner({
sessionKey: "agent:main:ollama-timeout-test",
tempPaths,
contextEngine: {
assemble: async ({ messages }) => ({
messages,
estimatedTokens: 1,
}),
},
attemptOverrides: {
timeoutMs: 123_456,
},
});
expect(hoisted.ensureGlobalUndiciEnvProxyDispatcherMock).toHaveBeenCalledOnce();
expect(hoisted.ensureGlobalUndiciStreamTimeoutsMock).toHaveBeenCalledWith({
timeoutMs: 123_456,
});
});
});

View File

@@ -361,7 +361,7 @@ export async function runEmbeddedAttempt(
// Proxy bootstrap must happen before timeout tuning so the timeouts wrap the
// active EnvHttpProxyAgent instead of being replaced by a bare proxy dispatcher.
ensureGlobalUndiciEnvProxyDispatcher();
ensureGlobalUndiciStreamTimeouts();
ensureGlobalUndiciStreamTimeouts({ timeoutMs: params.timeoutMs });
log.debug(
`embedded run start: runId=${params.runId} sessionId=${params.sessionId} provider=${params.provider} model=${params.modelId} thinking=${params.thinkLevel} messageChannel=${params.messageChannel ?? params.messageProvider ?? "unknown"}`,