Repository navigation
fix(integrations): validate mongodb, neo4j and upstash #10172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
0647a31
fix(integrations): validate postgresql, mysql, mongodb, neo4j and ups…
waleedlatif1 a852401
fix(integrations): stream neo4j records under the cap, keep mysql pre…
waleedlatif1 08d75c6
fix(integrations): drop the row cap; stream mongodb and neo4j reads a…
waleedlatif1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
apps/sim/lib/internal/tool-operations/response-limits.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import { describe, expect, it } from 'vitest' | ||
| import { isPayloadSizeLimitError } from '@/lib/core/utils/stream-limits' | ||
| import { | ||
| createResponseRowsBudget, | ||
| MAX_TOOL_RESPONSE_BODY_BYTES, | ||
| } from '@/lib/internal/tool-operations/response-limits' | ||
|
|
||
| /** Admits every row, returning the error the budget threw, if any. */ | ||
| function admitAll(rows: unknown[]): unknown { | ||
| const budget = createResponseRowsBudget('test_tool') | ||
| try { | ||
| for (const row of rows) budget.admit(row) | ||
| return undefined | ||
| } catch (error) { | ||
| return error | ||
| } | ||
| } | ||
|
|
||
| describe('response rows budget', () => { | ||
| it('admits any number of rows while their array still fits the response limit', () => { | ||
| expect(admitAll(Array.from({ length: 50_000 }, (_, id) => ({ id })))).toBeUndefined() | ||
| }) | ||
|
|
||
| it('fails exactly where the serialized array passes the response limit', () => { | ||
| const fitting = ['x'.repeat(MAX_TOOL_RESPONSE_BODY_BYTES - 4)] | ||
| expect(Buffer.byteLength(JSON.stringify(fitting))).toBe(MAX_TOOL_RESPONSE_BODY_BYTES) | ||
| expect(admitAll(fitting)).toBeUndefined() | ||
|
|
||
| const error = admitAll(['x'.repeat(MAX_TOOL_RESPONSE_BODY_BYTES - 3)]) | ||
| expect(isPayloadSizeLimitError(error)).toBe(true) | ||
| expect(error).toMatchObject({ | ||
| label: 'test_tool response body', | ||
| maxBytes: MAX_TOOL_RESPONSE_BODY_BYTES, | ||
| }) | ||
| }) | ||
|
|
||
| it('counts UTF-8 bytes, so multibyte text fails on its encoded size', () => { | ||
| const row = '漢'.repeat(MAX_TOOL_RESPONSE_BODY_BYTES / 3) | ||
| expect(row.length).toBeLessThan(MAX_TOOL_RESPONSE_BODY_BYTES) | ||
| expect(isPayloadSizeLimitError(admitAll([row]))).toBe(true) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,28 @@ | ||
| import { PayloadSizeLimitError } from '@/lib/core/utils/stream-limits' | ||
|
|
||
| /** Maximum inline tool response size; binary file outputs use stored descriptors. */ | ||
| export const MAX_TOOL_RESPONSE_BODY_BYTES = 10 * 1024 * 1024 | ||
|
|
||
| /** | ||
| * Fails a streamed result as soon as its serialized rows alone exceed | ||
| * {@link MAX_TOOL_RESPONSE_BODY_BYTES}. Bytes are counted the way the response serializes them | ||
| * (UTF-8, plus the array's brackets and commas), and the body around the rows is larger still, so | ||
| * this fails exactly the results the executor's response limit would reject, but before the rest | ||
| * of the result is read into memory. The error is the same one that limit throws. | ||
| */ | ||
| export function createResponseRowsBudget(toolId: string) { | ||
| let bytes = 1 | ||
| return { | ||
| admit(row: unknown): void { | ||
| const serialized = JSON.stringify(row) | ||
| bytes += (serialized === undefined ? 4 : Buffer.byteLength(serialized, 'utf8')) + 1 | ||
| if (bytes > MAX_TOOL_RESPONSE_BODY_BYTES) { | ||
| throw new PayloadSizeLimitError({ | ||
| label: `${toolId} response body`, | ||
| maxBytes: MAX_TOOL_RESPONSE_BODY_BYTES, | ||
| observedBytes: bytes, | ||
| }) | ||
| } | ||
| }, | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.