Skip to content

The open-source agent harness - the runtime layer that turns an LLM into a working agent.

fix: map Daytona sandbox secret sync HTTP 4xx failures to 422 (#1012)

Sujai Kumar Gupta6a38bc1811a8
diff --git a/.changeset/daytona-secret-sync-4xx.md b/.changeset/daytona-secret-sync-4xx.md
new file mode 100644
index 000000000..bd488c479
--- /dev/null
+++ b/.changeset/daytona-secret-sync-4xx.md
@@ -0,0 +1,5 @@
+---
+'@truefoundry/trueforge': patch
+---
+
+Map Daytona sandbox-environment secret sync HTTP 4xx failures to 422 instead of 502.
diff --git a/.github/fern/openapi/openapi.json b/.github/fern/openapi/openapi.json
index 0b6d0e1b9..1e51b16ff 100644
--- a/.github/fern/openapi/openapi.json
+++ b/.github/fern/openapi/openapi.json
@@ -8567,7 +8567,7 @@
}
}
},
- "description": "Sandbox provider is missing or its credentials are invalid."
+ "description": "Sandbox provider is missing, credentials are invalid, or rejected the secret."
},
"502": {
"content": {
@@ -8660,7 +8660,7 @@
}
}
},
- "description": "Sandbox provider is missing or its credentials are invalid."
+ "description": "Sandbox provider is missing, credentials are invalid, or rejected secret deletion."
},
"502": {
"content": {
diff --git a/docs/openapi.json b/docs/openapi.json
index 0b6d0e1b9..1e51b16ff 100644
--- a/docs/openapi.json
+++ b/docs/openapi.json
@@ -8567,7 +8567,7 @@
}
}
},
- "description": "Sandbox provider is missing or its credentials are invalid."
+ "description": "Sandbox provider is missing, credentials are invalid, or rejected the secret."
},
"502": {
"content": {
@@ -8660,7 +8660,7 @@
}
}
},
- "description": "Sandbox provider is missing or its credentials are invalid."
+ "description": "Sandbox provider is missing, credentials are invalid, or rejected secret deletion."
},
"502": {
"content": {
diff --git a/packages/trueforge/src/apis/sandboxEnvironments.ts b/packages/trueforge/src/apis/sandboxEnvironments.ts
index 26021c118..88397c817 100644
--- a/packages/trueforge/src/apis/sandboxEnvironments.ts
+++ b/packages/trueforge/src/apis/sandboxEnvironments.ts
@@ -3,6 +3,7 @@
* Snapshot builds are not started here — versions land in `pending` for a future controller.
* Networking secrets sync to Daytona on PUT (plaintext is never persisted).
*/
+import { DaytonaError } from '@daytona/sdk';
import { OpenAPIHono, type RouteHandler } from '@hono/zod-openapi';
import { InvalidPageTokenError } from '@truefoundry/trueforge-core/agent-session';
import type { Context } from 'hono';
@@ -71,9 +72,14 @@ function sandboxEnvironmentSecretHttpError(error: unknown): { status: 422 | 502;
return undefined;
}
const authorizationMessage = getDaytonaAuthorizationErrorMessage(error.cause);
- return authorizationMessage === undefined
- ? { status: 502, message: error.message }
- : { status: 422, message: authorizationMessage };
+ if (authorizationMessage !== undefined) {
+ return { status: 422, message: authorizationMessage };
+ }
+ const statusCode = error.cause instanceof DaytonaError ? error.cause.statusCode : undefined;
+ if (statusCode !== undefined && statusCode >= 400 && statusCode < 500) {
+ return { status: 422, message: error.message };
+ }
+ return { status: 502, message: error.message };
}
/** CRUD for sandbox environments. */
diff --git a/packages/trueforge/src/routes/sandboxEnvironmentRoutes.ts b/packages/trueforge/src/routes/sandboxEnvironmentRoutes.ts
index 29e0c1d69..3e1738011 100644
--- a/packages/trueforge/src/routes/sandboxEnvironmentRoutes.ts
+++ b/packages/trueforge/src/routes/sandboxEnvironmentRoutes.ts
@@ -123,7 +123,7 @@ export const putSandboxEnvironmentRoute = createRoute({
},
422: {
content: { 'application/json': { schema: RequestErrorResponseSchema } },
- description: 'Sandbox provider is missing or its credentials are invalid.',
+ description: 'Sandbox provider is missing, credentials are invalid, or rejected the secret.',
},
502: {
content: { 'application/json': { schema: RequestErrorResponseSchema } },
@@ -162,7 +162,7 @@ export const deleteSandboxEnvironmentRoute = createRoute({
},
422: {
content: { 'application/json': { schema: RequestErrorResponseSchema } },
- description: 'Sandbox provider is missing or its credentials are invalid.',
+ description: 'Sandbox provider is missing, credentials are invalid, or rejected secret deletion.',
},
502: {
content: { 'application/json': { schema: RequestErrorResponseSchema } },