Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

🪑 fix: Explain Workspace Capacity Timeouts (#16016)

Danny Avila3012a205b2a5
diff --git a/packages/api/src/code/workspace.spec.ts b/packages/api/src/code/workspace.spec.ts
index 2f81b0afde..c19c2efd1f 100644
--- a/packages/api/src/code/workspace.spec.ts
+++ b/packages/api/src/code/workspace.spec.ts
@@ -1,6 +1,45 @@
import type { WorkspaceToolRequest } from './workspace';
import type { CodeBridgeFetch } from './bridge';
-import { executeWorkspaceTool } from './workspace';
+import { executeWorkspaceTool, WorkspaceToolHttpError } from './workspace';
+
+describe('workspace admission feedback', () => {
+ test('identifies definite pre-execution expiry without retrying the operation', async () => {
+ const fetchImpl = jest.fn().mockResolvedValue(
+ new Response(JSON.stringify({ code: 'WORKSPACE_QUEUE_TIMEOUT' }), {
+ status: 503,
+ headers: { 'Retry-After': '1' },
+ }),
+ );
+ await expect(
+ executeWorkspaceTool({
+ baseURL: 'https://code.example/v1',
+ authHeaders: {},
+ fetchImpl,
+ request: {
+ protocolVersion: 1,
+ operation: 'execute_command',
+ workspaceId: 'primary',
+ command: 'echo test',
+ },
+ }),
+ ).rejects.toThrow('The operation was not started');
+ expect(fetchImpl).toHaveBeenCalledTimes(1);
+ });
+
+ test.each([
+ [504, '{"code":"ASSIGNMENT_EXPIRED"}', false],
+ [503, '<html>Gateway unavailable</html>', false],
+ [503, '{"code":"WORKSPACE_QUEUE_TIMEOUT"}', true],
+ [503, 'null', false],
+ ] as const)(
+ 'does not infer non-execution from an ambiguous response',
+ (status, body, truncated) => {
+ expect(new WorkspaceToolHttpError('rejected', status, body, truncated).message).not.toContain(
+ 'not started',
+ );
+ },
+ );
+});
describe('executeWorkspaceTool', () => {
test.each<[WorkspaceToolRequest, number]>([
diff --git a/packages/api/src/code/workspace.ts b/packages/api/src/code/workspace.ts
index c461ca71e0..d043fde185 100644
--- a/packages/api/src/code/workspace.ts
+++ b/packages/api/src/code/workspace.ts
@@ -258,7 +258,10 @@ export class WorkspaceToolHttpError extends Error {
public readonly upstreamBodyTruncated = false,
) {
super(
- `Workspace tool request ${reason}` +
+ (reason === 'rejected' &&
+ isWorkspaceAdmissionTimeout(upstreamStatus, upstreamBody, upstreamBodyTruncated)
+ ? 'Workspace capacity was unavailable before the queue deadline. The operation was not started. Wait for active work to finish or select an independent workspace on a machine with available capacity.'
+ : `Workspace tool request ${reason}`) +
(upstreamStatus == null ? '' : ` (upstreamStatus: ${upstreamStatus})`) +
(upstreamBody ? `; upstreamBody: ${JSON.stringify(upstreamBody)}` : '') +
(upstreamBodyTruncated ? ' [body truncated or incomplete]' : ''),
@@ -267,6 +270,18 @@ export class WorkspaceToolHttpError extends Error {
}
}
+function isWorkspaceAdmissionTimeout(status?: number, body?: string, truncated = false): boolean {
+ if (status !== 503 || !body || truncated || body.length > MAX_ERROR_BODY_BYTES) {
+ return false;
+ }
+ try {
+ const parsed: { code?: string } | null = JSON.parse(body);
+ return parsed?.code === 'WORKSPACE_QUEUE_TIMEOUT';
+ } catch {
+ return false;
+ }
+}
+
/** Keep a received HTTP status even if reading its diagnostic body fails or stalls. */
async function readErrorBody(
response: Response,