Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion apps/controller/src/BaseController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ import {
sql,
} from '@roomote/db/server';
import { dequeueTaskRun } from '@roomote/cloud-agents/server';
import { finishRun } from '@roomote/sdk/server';
import { finishRun, reportTaskPlatformIssue } from '@roomote/sdk/server';
import { isModalConcurrentSandboxLimitError } from '@roomote/compute-providers';

import { getOrphanedTaskRun } from './orphaned-task-runs';
import {
Expand Down Expand Up @@ -597,6 +598,30 @@ export abstract class BaseController {
`[BaseController] ❌ Error spawning ${taskRun.payloadKind} worker for task run #${taskRun.id}: ${errorMessage}`,
);

if (isModalConcurrentSandboxLimitError(error)) {
try {
await reportTaskPlatformIssue({
taskId: taskRun.taskId,
runId: taskRun.id,
report: {
title: 'Concurrent sandbox limit reached',
summary:
'A task could not start because the Modal workspace reached its concurrent sandbox limit.',
},
});
} catch (alertError) {
captureControllerException(alertError, {
runId: taskRun.id,
payloadKind: taskRun.payloadKind,
provider: taskRun.vendor,
phase: 'concurrent_sandbox_limit_alert',
});
console.error(
`[BaseController] Failed to report concurrent sandbox limit for task run #${taskRun.id}: ${alertError instanceof Error ? alertError.message : String(alertError)}`,
);
}
}

await this.finishFailedTaskRun(taskRun, errorMessage, errorCode);

throw reportError;
Expand Down
97 changes: 97 additions & 0 deletions apps/controller/src/__tests__/BaseController.test.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions packages/compute-providers/src/modal/rpc-diagnostics.test.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions packages/compute-providers/src/modal/rpc-diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ const MODAL_RPC_SIGNATURE_REGEX =
/\/(?<service>modal\.[A-Za-z0-9_.]+)\/(?<method>[A-Za-z][A-Za-z0-9_]*)\s+(?<status>[A-Z_]+):/;
const MODAL_STATUS_CODE_REGEX = /status\s*=\s*StatusCode\.(?<status>[A-Z_]+)/;
const MODAL_ERROR_CODE_REGEX = /\(Error code:\s*(?<code>[A-Z0-9]+)\)/;
const MODAL_CONCURRENT_SANDBOX_LIMIT_PATTERNS = [
/\bconcurrent(?:ly)?\b[^\n]*\bsandbox(?:es)?\b[^\n]*\blimit\b/i,
/\bsandbox(?:es)?\b[^\n]*\bconcurrent(?:ly)?\b[^\n]*\blimit\b/i,
/\bmaximum (?:allowed )?(?:number of )?(?:active |running |concurrent )?sandbox(?:es)?\b/i,
/\b(?:active|running) sandbox(?:es)?\b[^\n]*\blimit\b/i,
/\blimit\b[^\n]*\b(?:active|running) sandbox(?:es)?\b/i,
] as const;

export interface ModalRpcErrorEnrichment {
fingerprint: string[];
Expand Down Expand Up @@ -79,6 +86,19 @@ export function getModalRpcErrorMetadata(
return error instanceof ModalRpcError ? error.metadata : undefined;
}

export function isModalConcurrentSandboxLimitError(error: unknown): boolean {
const metadata = getModalRpcErrorMetadata(error);

return Boolean(
error instanceof Error &&
metadata?.operation === 'create_instance' &&
metadata.grpcStatus === 'RESOURCE_EXHAUSTED' &&
MODAL_CONCURRENT_SANDBOX_LIMIT_PATTERNS.some((pattern) =>
pattern.test(error.message),
),
);
}

export function buildModalRpcErrorEnrichment(
metadata: ModalRpcErrorMetadata,
options: ModalRpcErrorEnrichmentOptions = {},
Expand Down
1 change: 1 addition & 0 deletions packages/sdk/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export {
export { recordComputeProviderUsage } from './lib/task-runs/record-compute-provider-usage';
export {
recordTaskMessageEnvelope,
reportTaskPlatformIssue,
refreshTaskTitleOnCompletion,
} from './lib/task-runs/record-task-message-envelope';
export { ensureSnapshotResumeGitHubFollowUpFallback } from './lib/task-runs/ensure-snapshot-resume-github-follow-up-fallback';
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading