Skip to content

Conversation

@icecrasher321
Copy link
Collaborator

Summary

Persist subblock values in batch add handler.

Type of Change

  • Bug fix

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link

vercel bot commented Jan 14, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Review Updated (UTC)
docs Skipped Skipped Jan 14, 2026 8:56pm

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 14, 2026

Greptile Summary

This PR fixes a bug where subblock values were not persisted to the database during batch add operations. The fix consolidates subblock merging logic into a new utility file (apps/sim/lib/workflows/subblocks.ts) and ensures that when blocks are batch-added via the socket handler, their subblock values are properly merged before database insertion.

Key Changes:

  • Created centralized mergeSubBlockValues and mergeSubblockStateWithValues functions
  • Updated BATCH_ADD_BLOCKS handler to merge subBlockValues into block structures before DB insert
  • Refactored existing code to use the new consolidated utilities, reducing duplication
  • Fixed duplicateBlock to retrieve activeWorkflowId before merging subblock state
  • Removed unnecessary empty object parameter in webhook execution

The change follows a clear pattern where subblock values are now properly merged at the database layer, ensuring consistency between the client state and persisted data.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The changes consolidate duplicated logic into a well-structured utility module, fix a clear data persistence bug, and maintain backward compatibility. The refactoring reduces code duplication and improves maintainability without introducing breaking changes.
  • No files require special attention

Important Files Changed

Filename Overview
apps/sim/lib/workflows/subblocks.ts New utility file consolidating subblock merging logic with two helper functions
apps/sim/socket/database/operations.ts Updated BATCH_ADD_BLOCKS to merge subBlockValues into blocks before database insert
apps/sim/stores/workflows/utils.ts Refactored multiple functions to use centralized subblock merging utilities

Sequence Diagram

sequenceDiagram
    participant UI as UI/Frontend
    participant Hook as useCollaborativeWorkflow
    participant Store as WorkflowStore
    participant SubStore as SubBlockStore
    participant Socket as Socket Handler
    participant DB as Database Operations
    participant Utils as Subblock Utils

    Note over UI,Utils: Batch Add Blocks Flow
    
    UI->>Hook: batchAddBlocks(blocks, edges, subBlockValues)
    Hook->>Store: batchAddBlocks(blocks, edges, subBlockValues)
    Store->>Store: Add blocks to local state
    
    alt subBlockValues provided
        Store->>SubStore: Update workflowValues with subBlockValues
    end
    
    Hook->>Socket: BATCH_ADD_BLOCKS operation
    Note over Hook,Socket: payload includes subBlockValues
    
    Socket->>DB: handleBlocksOperationTx(BATCH_ADD_BLOCKS)
    
    loop For each block
        DB->>Utils: mergeSubBlockValues(block.subBlocks, subBlockValues[blockId])
        Utils-->>DB: merged subBlocks with values
    end
    
    DB->>DB: Insert blocks with merged subBlocks to database
    
    Note over UI,Utils: Subblock values now persisted in DB
Loading

@icecrasher321
Copy link
Collaborator Author

@greptile

@icecrasher321 icecrasher321 merged commit 3f1dccd into staging Jan 14, 2026
11 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/batch-add-pers branch January 15, 2026 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants