-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Workflow persistence error #3938
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
Open
Siddhartha-singh01
wants to merge
3
commits into
simstudioai:main
Choose a base branch
from
Siddhartha-singh01:workflow-persistence-error
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+25
−12
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
160dc1c
fix(persistence): chunk block and edge inserts to prevent sql variabl…
Siddhartha-singh01 2e63582
docs(persistence): add comments for chunk size math
Siddhartha-singh01 079b113
Merge staging into fix/workflow-persistence-error to resolve conflict…
Siddhartha-singh01 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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -463,9 +463,9 @@ export async function loadWorkflowFromNormalizedTables( | |||||
| if (subflow.type === SUBFLOW_TYPES.LOOP) { | ||||||
| const loopType = | ||||||
| (config as Loop).loopType === 'for' || | ||||||
| (config as Loop).loopType === 'forEach' || | ||||||
| (config as Loop).loopType === 'while' || | ||||||
| (config as Loop).loopType === 'doWhile' | ||||||
| (config as Loop).loopType === 'forEach' || | ||||||
| (config as Loop).loopType === 'while' || | ||||||
| (config as Loop).loopType === 'doWhile' | ||||||
| ? (config as Loop).loopType | ||||||
| : 'for' | ||||||
|
|
||||||
|
|
@@ -502,7 +502,7 @@ export async function loadWorkflowFromNormalizedTables( | |||||
| distribution: (config as Parallel).distribution ?? '', | ||||||
| parallelType: | ||||||
| (config as Parallel).parallelType === 'count' || | ||||||
| (config as Parallel).parallelType === 'collection' | ||||||
| (config as Parallel).parallelType === 'collection' | ||||||
| ? (config as Parallel).parallelType | ||||||
| : 'count', | ||||||
| enabled: finalBlocks[subflow.id]?.enabled ?? true, | ||||||
|
|
@@ -545,6 +545,9 @@ export async function saveWorkflowToNormalizedTables( | |||||
| tx.delete(workflowSubflows).where(eq(workflowSubflows.workflowId, workflowId)), | ||||||
| ]) | ||||||
|
|
||||||
| const CHUNK_SIZE = 50 | ||||||
|
|
||||||
| // Insert blocks | ||||||
| if (Object.keys(state.blocks).length > 0) { | ||||||
| const blockInserts = Object.values(state.blocks).map((block) => ({ | ||||||
| id: block.id, | ||||||
|
|
@@ -566,9 +569,15 @@ export async function saveWorkflowToNormalizedTables( | |||||
| locked: block.locked ?? false, | ||||||
| })) | ||||||
|
|
||||||
| await tx.insert(workflowBlocks).values(blockInserts) | ||||||
| // SQLite limits bound parameters to 999 per statement. | ||||||
| // workflowBlocks has 17 fields -> max safe chunk = floor(999/17) = 58. | ||||||
| // Using 50 for a conservative margin. | ||||||
| for (let i = 0; i < blockInserts.length; i += CHUNK_SIZE) { | ||||||
| await tx.insert(workflowBlocks).values(blockInserts.slice(i, i + CHUNK_SIZE)) | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| // Insert edges | ||||||
| if (state.edges.length > 0) { | ||||||
| const edgeInserts = state.edges.map((edge) => ({ | ||||||
| id: edge.id, | ||||||
|
|
@@ -579,7 +588,9 @@ export async function saveWorkflowToNormalizedTables( | |||||
| targetHandle: edge.targetHandle || null, | ||||||
| })) | ||||||
|
|
||||||
| await tx.insert(workflowEdges).values(edgeInserts) | ||||||
| for (let i = 0; i < edgeInserts.length; i += CHUNK_SIZE) { | ||||||
| await tx.insert(workflowEdges).values(edgeInserts.slice(i, i + CHUNK_SIZE)) | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| const subflowInserts: SubflowInsert[] = [] | ||||||
|
|
@@ -603,7 +614,9 @@ export async function saveWorkflowToNormalizedTables( | |||||
| }) | ||||||
|
|
||||||
| if (subflowInserts.length > 0) { | ||||||
| await tx.insert(workflowSubflows).values(subflowInserts) | ||||||
| for (let i = 0; i < subflowInserts.length; i += CHUNK_SIZE) { | ||||||
| await tx.insert(workflowSubflows).values(subflowInserts.slice(i, i + CHUNK_SIZE)) | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -806,11 +819,11 @@ export function regenerateWorkflowStateIds(state: RegenerateStateInput): Regener | |||||
| blockIdMapping.set(oldId, crypto.randomUUID()) | ||||||
| }) | ||||||
|
|
||||||
| // Map edge IDs | ||||||
| // Map edge IDs | ||||||
|
|
||||||
| ;(state.edges || []).forEach((edge: Edge) => { | ||||||
| edgeIdMapping.set(edge.id, crypto.randomUUID()) | ||||||
| }) | ||||||
| ; (state.edges || []).forEach((edge: Edge) => { | ||||||
| edgeIdMapping.set(edge.id, crypto.randomUUID()) | ||||||
| }) | ||||||
|
|
||||||
| // Map loop IDs | ||||||
| Object.keys(state.loops || {}).forEach((oldId) => { | ||||||
|
|
@@ -884,7 +897,7 @@ export function regenerateWorkflowStateIds(state: RegenerateStateInput): Regener | |||||
| newBlocks[newId] = newBlock | ||||||
| }) | ||||||
|
|
||||||
| // Regenerate edges with updated source/target references | ||||||
| // Regenerate edges with updated source/target references | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This comment was shifted to 4-space indentation, but the
Suggested change
|
||||||
|
|
||||||
| ;(state.edges || []).forEach((edge: Edge) => { | ||||||
| const newId = edgeIdMapping.get(edge.id)! | ||||||
|
|
||||||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "Map edge IDs" block (comment +
forEach) has been re-indented to 4 spaces, while every other statement at the same scope level uses 2-space indentation (see lines 817–820, 828–836). This makes the block visually appear nested inside the previousforEach, which it is not.