🧍 fix: Accommodate BYOM Queue and Execution Budgets (#15750)

This commit is contained in:
Danny Avila 2026-09-08 16:37:04 -04:00 • committed by GitHub
parent fd229fe478
commit 1a6410a72c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 56 additions and 2 deletions

View file

@ -1,7 +1,55 @@
import type { WorkspaceToolRequest } from './workspace';
import type { CodeBridgeFetch } from './bridge';
import { executeWorkspaceTool } from './workspace';
describe('executeWorkspaceTool', () => {
test.each<[WorkspaceToolRequest, number]>([
[
{ protocolVersion: 1, operation: 'read_file', workspaceId: 'primary', path: 'README.md' },
65_000,
],
[
{
protocolVersion: 1,
operation: 'execute_command',
workspaceId: 'primary',
command: 'echo ready',
},
70_000,
],
[
{
protocolVersion: 1,
operation: 'execute_command',
workspaceId: 'primary',
command: 'echo ready',
timeoutMs: 300_000,
},
340_000,
],
])('allows admission, execution and delivery time for %j', async (request, budget) => {
const timeout = jest.spyOn(AbortSignal, 'timeout');
const fetchImpl = jest
.fn()
.mockResolvedValue(
new Response(
JSON.stringify({ error: 'Older server deadline exceeded', code: 'ASSIGNMENT_EXPIRED' }),
{ status: 504 },
),
);
await expect(
executeWorkspaceTool({
baseURL: 'https://code.example.com/v1',
authHeaders: {},
request,
fetchImpl,
}),
).rejects.toMatchObject({ upstreamStatus: 504 });
expect(timeout).toHaveBeenCalledWith(budget);
expect(fetchImpl.mock.calls[0][1].body).toBe(JSON.stringify(request));
expect(fetchImpl).toHaveBeenCalledTimes(1);
});
test('sends an authenticated bounded read to the selected attached worker', async () => {
const fetchImpl = jest.fn().mockResolvedValue(
new Response(

View file

@ -17,6 +17,9 @@ const DEFAULT_COMMAND_OUTPUT_BYTES = 256 * 1024;
const MAX_COMMAND_OUTPUT_BYTES = 1024 * 1024;
const MAX_COMMAND_SIGNAL_LENGTH = 32;
const WORKSPACE_COMMAND_TRANSPORT_GRACE_MS = 5_000;
/** Matches Code API's bounded admission wait and command settlement allowance. */
const WORKSPACE_QUEUE_TIMEOUT_MS = 30_000;
const WORKSPACE_COMMAND_SETTLEMENT_GRACE_MS = 5_000;
const MAX_RESPONSE_BYTES = 4 * 1024 * 1024;
const MAX_ERROR_BODY_BYTES = 4096;
const ERROR_BODY_TIMEOUT_MS = 1000;
@ -653,8 +656,11 @@ function isValidResult(
}
function getWorkspaceToolTimeoutMs(request: WorkspaceToolRequest): number {
if (request.operation !== 'execute_command') return WORKSPACE_TOOL_TIMEOUT_MS;
return (request.timeoutMs ?? DEFAULT_COMMAND_TIMEOUT_MS) + WORKSPACE_COMMAND_TRANSPORT_GRACE_MS;
const executionBudgetMs =
request.operation === 'execute_command'
? (request.timeoutMs ?? DEFAULT_COMMAND_TIMEOUT_MS) + WORKSPACE_COMMAND_SETTLEMENT_GRACE_MS
: WORKSPACE_TOOL_TIMEOUT_MS;
return WORKSPACE_QUEUE_TIMEOUT_MS + executionBudgetMs + WORKSPACE_COMMAND_TRANSPORT_GRACE_MS;
}
export async function executeWorkspaceTool({