Skip to content
Merged
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
2 changes: 1 addition & 1 deletion apps/docs/content/docs/cli/reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10129,7 +10129,7 @@ sim workspaces source apply [options]

</CommandTable>

Exit codes: 0 applied (or a clean dry run); 1 the source has errors (each printed as file:line:column with its frame and hint), or every change it would write was held back because it uses a declared secret the workspace has no value for or a declared credential key nothing binds to (nothing was written; a dry run of such an apply exits 1 too), the directory was read from another workspace than the one --workspace or SIM_WORKSPACE names (SOURCE_OTHER_WORKSPACE: drop it, or promote it with --to; without either an apply targets the workspace the directory was read from), its base records binary files no get downloaded (SOURCE_BLOBS_NOT_FETCHED: get again first), a --run test run did not complete (the apply is written; deployments/ was not applied), or the command failed; 5 a resource changed or was deleted on the server since the directory was read (SOURCE_STALE: get it again into a fresh directory, reapply the edit, retry); 6 a resource (a workflow or its folder, a table) is locked (a locked block exits 1, E_APPLY_LOCKED_BLOCK); 7 the directory is too large; 8 the apply stopped part-way on a server failure: what was written is saved into the directory, and applying again continues. An apply a resource refused part-way (stale, locked, forbidden) saves what was written too, and exits as that refusal: 5, 6 or 1; 9 rate limited (HTTP 429) after the CLI's retries, before anything was written: wait a minute and apply again (binary files already uploaded are not sent again); 10 another apply is writing the workspace (SOURCE_BUSY), or another command is using the directory (SOURCE_DIR_BUSY): nothing was written, run the command again once the other finished; 13 not logged in, the login expired, or the server refused the credential (AUTH_REQUIRED): nothing was sent, run `sim login` (or fix or unset SIM_API_KEY when the key comes from it) and the command again; 14 without --yes and with no terminal to ask: the plan was printed with no errors and nothing was written (run the same command with --yes to apply it); 15 written in part: changes that use a declared secret the workspace has no value for, or a declared credential key nothing binds to, were held back and the rest was applied and saved (set the secret or connect the credential, then apply again); a dry run that would do so exits 15 too, having written nothing; 130 interrupted (Ctrl-C): a write already sent is finished and saved into the directory first, waiting up to 60s for its answer, and a second Ctrl-C, or no answer by then, stops at once and prints that it may have been written and how to check.
Exit codes: 0 applied (or a clean dry run); 1 the source has errors (each printed as file:line:column with its frame and hint), or every change it would write was held back because it uses a declared secret the workspace has no value for or a declared credential key nothing binds to (nothing was written; a dry run of such an apply exits 1 too), the directory was read from another workspace than the one --workspace or SIM_WORKSPACE names (SOURCE_OTHER_WORKSPACE: drop it, or promote it with --to; without either an apply targets the workspace the directory was read from), its base records binary files no get downloaded (SOURCE_BLOBS_NOT_FETCHED: get again first), a --run test run did not complete (the apply is written; deployments/ was not applied), or the command failed; 5 a resource changed or was deleted on the server since the directory was read (SOURCE_STALE: get it again into a fresh directory, reapply the edit, retry); 6 a resource (a workflow or its folder, a table) is locked (a locked block exits 1, E_APPLY_LOCKED_BLOCK); 7 the directory is too large (apply part of it with --only); 8 the apply stopped part-way on a server failure: what was written is saved into the directory, and applying again continues. An apply a resource refused part-way (stale, locked, forbidden) saves what was written too, and exits as that refusal: 5, 6 or 1; 9 rate limited (HTTP 429) after the CLI's retries, before anything was written: wait a minute and apply again (binary files already uploaded are not sent again); 10 another apply is writing the workspace (SOURCE_BUSY), or another command is using the directory (SOURCE_DIR_BUSY): nothing was written, run the command again once the other finished; 13 not logged in, the login expired, or the server refused the credential (AUTH_REQUIRED): nothing was sent, run `sim login` (or fix or unset SIM_API_KEY when the key comes from it) and the command again; 14 without --yes and with no terminal to ask: the plan was printed with no errors and nothing was written (run the same command with --yes to apply it); 15 written in part: changes that use a declared secret the workspace has no value for, or a declared credential key nothing binds to, were held back and the rest was applied and saved (set the secret or connect the credential, then apply again); a dry run that would do so exits 15 too, having written nothing; 130 interrupted (Ctrl-C): a write already sent is finished and saved into the directory first, waiting up to 60s for its answer, and a second Ctrl-C, or no answer by then, stops at once and prints that it may have been written and how to check.

API request and response schemas: [applyWorkspaceSource](/api-reference/workflows/applyWorkspaceSource), [findMissingWorkspaceSourceBlobs](/api-reference/workflows/findMissingWorkspaceSourceBlobs), [stageWorkspaceSourceBlobs](/api-reference/workflows/stageWorkspaceSourceBlobs), [getWorkspaceSource](/api-reference/workflows/getWorkspaceSource), [getSourceCatalog](/api-reference/catalog/getSourceCatalog), [getWorkflowDeployment](/api-reference/workflows/getWorkflowDeployment), [executeWorkflow](/api-reference/workflows/executeWorkflowV2).

Expand Down
2 changes: 1 addition & 1 deletion apps/docs/content/docs/cli/workspaces.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ sim workspaces source apply [options]

</CommandTable>

Exit codes: 0 applied (or a clean dry run); 1 the source has errors (each printed as file:line:column with its frame and hint), or every change it would write was held back because it uses a declared secret the workspace has no value for or a declared credential key nothing binds to (nothing was written; a dry run of such an apply exits 1 too), the directory was read from another workspace than the one --workspace or SIM_WORKSPACE names (SOURCE_OTHER_WORKSPACE: drop it, or promote it with --to; without either an apply targets the workspace the directory was read from), its base records binary files no get downloaded (SOURCE_BLOBS_NOT_FETCHED: get again first), a --run test run did not complete (the apply is written; deployments/ was not applied), or the command failed; 5 a resource changed or was deleted on the server since the directory was read (SOURCE_STALE: get it again into a fresh directory, reapply the edit, retry); 6 a resource (a workflow or its folder, a table) is locked (a locked block exits 1, E_APPLY_LOCKED_BLOCK); 7 the directory is too large; 8 the apply stopped part-way on a server failure: what was written is saved into the directory, and applying again continues. An apply a resource refused part-way (stale, locked, forbidden) saves what was written too, and exits as that refusal: 5, 6 or 1; 9 rate limited (HTTP 429) after the CLI's retries, before anything was written: wait a minute and apply again (binary files already uploaded are not sent again); 10 another apply is writing the workspace (SOURCE_BUSY), or another command is using the directory (SOURCE_DIR_BUSY): nothing was written, run the command again once the other finished; 13 not logged in, the login expired, or the server refused the credential (AUTH_REQUIRED): nothing was sent, run `sim login` (or fix or unset SIM_API_KEY when the key comes from it) and the command again; 14 without --yes and with no terminal to ask: the plan was printed with no errors and nothing was written (run the same command with --yes to apply it); 15 written in part: changes that use a declared secret the workspace has no value for, or a declared credential key nothing binds to, were held back and the rest was applied and saved (set the secret or connect the credential, then apply again); a dry run that would do so exits 15 too, having written nothing; 130 interrupted (Ctrl-C): a write already sent is finished and saved into the directory first, waiting up to 60s for its answer, and a second Ctrl-C, or no answer by then, stops at once and prints that it may have been written and how to check.
Exit codes: 0 applied (or a clean dry run); 1 the source has errors (each printed as file:line:column with its frame and hint), or every change it would write was held back because it uses a declared secret the workspace has no value for or a declared credential key nothing binds to (nothing was written; a dry run of such an apply exits 1 too), the directory was read from another workspace than the one --workspace or SIM_WORKSPACE names (SOURCE_OTHER_WORKSPACE: drop it, or promote it with --to; without either an apply targets the workspace the directory was read from), its base records binary files no get downloaded (SOURCE_BLOBS_NOT_FETCHED: get again first), a --run test run did not complete (the apply is written; deployments/ was not applied), or the command failed; 5 a resource changed or was deleted on the server since the directory was read (SOURCE_STALE: get it again into a fresh directory, reapply the edit, retry); 6 a resource (a workflow or its folder, a table) is locked (a locked block exits 1, E_APPLY_LOCKED_BLOCK); 7 the directory is too large (apply part of it with --only); 8 the apply stopped part-way on a server failure: what was written is saved into the directory, and applying again continues. An apply a resource refused part-way (stale, locked, forbidden) saves what was written too, and exits as that refusal: 5, 6 or 1; 9 rate limited (HTTP 429) after the CLI's retries, before anything was written: wait a minute and apply again (binary files already uploaded are not sent again); 10 another apply is writing the workspace (SOURCE_BUSY), or another command is using the directory (SOURCE_DIR_BUSY): nothing was written, run the command again once the other finished; 13 not logged in, the login expired, or the server refused the credential (AUTH_REQUIRED): nothing was sent, run `sim login` (or fix or unset SIM_API_KEY when the key comes from it) and the command again; 14 without --yes and with no terminal to ask: the plan was printed with no errors and nothing was written (run the same command with --yes to apply it); 15 written in part: changes that use a declared secret the workspace has no value for, or a declared credential key nothing binds to, were held back and the rest was applied and saved (set the secret or connect the credential, then apply again); a dry run that would do so exits 15 too, having written nothing; 130 interrupted (Ctrl-C): a write already sent is finished and saved into the directory first, waiting up to 60s for its answer, and a second Ctrl-C, or no answer by then, stops at once and prints that it may have been written and how to check.

API request and response schemas: [applyWorkspaceSource](/api-reference/workflows/applyWorkspaceSource), [findMissingWorkspaceSourceBlobs](/api-reference/workflows/findMissingWorkspaceSourceBlobs), [stageWorkspaceSourceBlobs](/api-reference/workflows/stageWorkspaceSourceBlobs), [getWorkspaceSource](/api-reference/workflows/getWorkspaceSource), [getSourceCatalog](/api-reference/catalog/getSourceCatalog), [getWorkflowDeployment](/api-reference/workflows/getWorkflowDeployment), [executeWorkflow](/api-reference/workflows/executeWorkflowV2).

Expand Down
2 changes: 2 additions & 0 deletions apps/docs/content/docs/platform/self-hosting/networking.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ A reverse-proxy limit of at least 250 MB clears these configured defaults; use t

Most `/api` requests also pass through Next.js Proxy. The current app configuration leaves its `proxyClientMaxBodySize` at 10 MiB. Larger bodies are truncated to that buffer rather than automatically rejected by Next.js; the route may then fail to parse them. Receiving larger custom-route bodies requires changing `experimental.proxyClientMaxBodySize` in the app build, which increases per-request memory use. The shared JSON parser separately clamps contract-validated bodies to 10 MiB, so raising the Next.js buffer alone does not increase their limit. See [Next.js proxy body buffering](https://nextjs.org/docs/app/api-reference/config/next-config-js/proxyClientMaxBodySize).

Workspace source apply and plan requests (`POST /api/v2/workspaces/{workspaceId}/source` and `/source/plan`) skip Next.js Proxy and accept bodies up to 58 MB, so your reverse proxy must allow that size for large table rows to apply.

**With object storage configured**, regular file uploads do not flow through the proxy — the browser `PUT`s them directly to the bucket using a presigned URL, so the proxy limits matter only for chat attachments, API payloads, and webhook bodies. On the default local-disk storage there is no presigned path and every upload goes through the proxy, so its body limit applies to all of them.

## Outbound connectivity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,63 @@ describe('POST /api/v2/workspaces/{workspaceId}/source/plan', () => {
expect(data.diagnostics).toHaveLength(1_001)
expect(data.diagnostics.at(-1)).toMatchObject({ code: 'I_FINDINGS_TRUNCATED' })
})

it('reads a body past the 10 MiB proxy ceiling whole, as a large table rows file sends', async () => {
const rows = `${'{"code":"a","note":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}\n'.repeat(160_000)}`

const response = await plan({ 'tables/leads.rows.jsonl': rows })

expect(response.status).toBe(200)
expect(mocks.plan.mock.calls[0][0].input.files['tables/leads.rows.jsonl']).toBe(rows)
})

it('refuses a body unread with 429 once the plans in flight hold as many bodies as their slots, and frees the room of every answered request', async () => {
const result = await mocks.plan()
const finish: Array<() => void> = []
mocks.plan.mockImplementation(
() => new Promise((resolve) => finish.push(() => resolve(result)))
)
// No declared length, so each reserves a body at the cap.
const running = Array.from({ length: 4 }, () => plan({ 'workflows/a/workflow.ts': WORKFLOW }))
await vi.waitFor(() => expect(finish).toHaveLength(4))

let read = false
const unread = await POST(
new NextRequest(`http://localhost:3000/api/v2/workspaces/${WORKSPACE_ID}/source/plan`, {
method: 'POST',
headers: { 'x-api-key': 'key', 'content-type': 'application/json', 'content-length': '2' },
body: new ReadableStream(
{
pull(controller) {
read = true
controller.enqueue(new TextEncoder().encode('{}'))
controller.close()
},
},
{ highWaterMark: 0 }
),
duplex: 'half',
}),
{ params: Promise.resolve({ workspaceId: WORKSPACE_ID }) }
)
expect(unread.status).toBe(429)
expect(read).toBe(false)

for (const done of finish) done()
await Promise.all(running)
mocks.plan.mockResolvedValue(result)
// More malformed bodies one after another than the lane holds at once: each frees its room.
for (let attempt = 0; attempt < 5; attempt++) {
const malformed = await POST(
new NextRequest(`http://localhost:3000/api/v2/workspaces/${WORKSPACE_ID}/source/plan`, {
method: 'POST',
headers: { 'x-api-key': 'key', 'content-type': 'application/json' },
body: '{',
}),
{ params: Promise.resolve({ workspaceId: WORKSPACE_ID }) }
)
expect(malformed.status).toBe(400)
}
expect((await plan({ 'workflows/a/workflow.ts': WORKFLOW })).status).toBe(200)
})
})
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { WORKSPACE_SOURCE_REQUEST_MAX_BYTES } from '@sim/workspace-code/limits'
import { v2PlanWorkspaceSourceContract } from '@/lib/api/contracts/v2/workspace-source'
import { defineV2JsonRoute, v2ApiKeyAuth, v2RateLimits } from '@/lib/api/server/routes'
import { withSourceSlot } from '@/lib/workflows/api'
import { reserveWorkspaceSourceBody, withSourceSlot } from '@/lib/workflows/api'
import {
presentWorkspaceApply,
v2WorkspaceSourceErrorPolicy,
Expand All @@ -27,7 +27,8 @@ export const POST = defineV2JsonRoute({
operation: workspaceSourceOperations.plan,
rateLimit: v2RateLimits.sourcePlan,
errorPolicy: v2WorkspaceSourceErrorPolicy,
parseOptions: { maxBodyBytes: WORKSPACE_SOURCE_REQUEST_MAX_BYTES },
parseOptions: { maxBodyBytes: WORKSPACE_SOURCE_REQUEST_MAX_BYTES, bypassesProxy: true },
reserveBody: reserveWorkspaceSourceBody('plan'),
mapInput: ({ params, body }) => ({
workspaceId: params.workspaceId,
files: body.files,
Expand Down
19 changes: 19 additions & 0 deletions apps/sim/app/api/v2/workspaces/[workspaceId]/source/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,25 @@ describe('POST /api/v2/workspaces/{workspaceId}/source', () => {
expect(data.diagnostics).toHaveLength(1_001)
expect(data.diagnostics.at(-1)).toMatchObject({ code: 'I_FINDINGS_TRUNCATED' })
})

it('reads a body past the 10 MiB proxy ceiling whole, as a large table rows file sends', async () => {
mocks.apply.mockResolvedValue({
workspaceId: WORKSPACE_ID,
dryRun: false,
plan: [],
applied: [],
needBlobs: [],
files: {},
base: { version: 1, workspaceId: WORKSPACE_ID, resources: {} },
diagnostics: [],
})
const rows = `${'{"code":"a","note":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}\n'.repeat(160_000)}`

const response = await apply('', { 'tables/leads.rows.jsonl': rows })

expect(response.status).toBe(200)
expect(mocks.apply.mock.calls[0][0].input.files['tables/leads.rows.jsonl']).toBe(rows)
})
})

/** `count` warnings, one per workflow, as a stored workspace whose tables are gone reads. */
Expand Down
10 changes: 8 additions & 2 deletions apps/sim/app/api/v2/workspaces/[workspaceId]/source/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import {
v2GetWorkspaceSourceContract,
} from '@/lib/api/contracts/v2/workspace-source'
import { defineV2JsonRoute, v2ApiKeyAuth, v2RateLimits } from '@/lib/api/server/routes'
import { applyOrDryRunLane, withSourceSlot } from '@/lib/workflows/api'
import {
applyOrDryRunLane,
applyOrDryRunRequestLane,
reserveWorkspaceSourceBody,
withSourceSlot,
} from '@/lib/workflows/api'
import {
presentWorkspaceApply,
v2WorkspaceSourceErrorPolicy,
Expand Down Expand Up @@ -55,7 +60,8 @@ export const POST = defineV2JsonRoute({
operation: workspaceSourceOperations.apply,
rateLimit: v2RateLimits.sourceApply,
errorPolicy: v2WorkspaceSourceErrorPolicy,
parseOptions: { maxBodyBytes: WORKSPACE_SOURCE_REQUEST_MAX_BYTES },
parseOptions: { maxBodyBytes: WORKSPACE_SOURCE_REQUEST_MAX_BYTES, bypassesProxy: true },
Comment thread
waleedlatif1 marked this conversation as resolved.
Resolved
reserveBody: reserveWorkspaceSourceBody(applyOrDryRunRequestLane),
mapInput: ({ params, query, body }) => ({
workspaceId: params.workspaceId,
files: body.files,
Expand Down
Loading
Loading