Skip to content

fix: merge subblock values in auto-layout to prevent losing router context#4055

Merged
waleedlatif1 merged 1 commit intostagingfrom
fix/auto-layout-subblock-merge
Apr 8, 2026
Merged

fix: merge subblock values in auto-layout to prevent losing router context#4055
waleedlatif1 merged 1 commit intostagingfrom
fix/auto-layout-subblock-merge

Conversation

@waleedlatif1
Copy link
Copy Markdown
Collaborator

@waleedlatif1 waleedlatif1 commented Apr 8, 2026

Summary

  • Auto-layout was reading from getWorkflowState() without merging subblock store values, then persisting stale data to the database via PUT /api/workflows/[id]/state
  • This caused runtime-edited values (e.g. router_v2 context) to be silently overwritten with their initial/empty values whenever auto-layout was triggered
  • Added mergeSubblockState() call (the same pattern used by every other persistence path) to preserve current subblock values during auto-layout

Test plan

  • Set a router_v2 block's context field to a non-empty value
  • Trigger auto-layout
  • Verify the context value is preserved after layout completes
  • Reload the page and verify the context value persists from the database

@cursor
Copy link
Copy Markdown

cursor bot commented Apr 8, 2026

PR Summary

Medium Risk
Touches workflow state update/persistence for auto-layout; while the change is small, it affects what gets written to the store and database and could impact runtime-edited block data if incorrect.

Overview
Auto-layout now merges live subblock values into the blocks returned from the layout API via mergeSubblockState() before updating the workflow store and persisting state.

On save failure rollback, it also merges subblock state when restoring the previous blocks, preventing runtime-edited subblock fields (e.g. router context) from being overwritten by stale/empty values during auto-layout.

Reviewed by Cursor Bugbot for commit aac05b6. Configure here.

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 8, 2026

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Apr 8, 2026 8:02pm

Request Review

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 8, 2026

Greptile Summary

This PR fixes a data-loss bug where auto-layout was persisting stale subblock values to the database. The fix adds mergeSubblockState(layoutedBlocks, workflowId) before writing to the store and the database, matching the pattern used on every other persistence path. The revert path on save failure also correctly applies the same merge. The previous concern about using activeWorkflowId from the registry instead of the workflowId parameter has been addressed — both call sites now use the function argument.

Confidence Score: 5/5

Safe to merge — the fix is minimal, correct, and follows the established persistence pattern used everywhere else in the codebase.

The prior P1 concern (using activeWorkflowId from the registry instead of the scoped workflowId parameter) has been resolved. Both the happy path and the revert path now call mergeSubblockState with workflowId. No new issues were found.

No files require special attention.

Vulnerabilities

No security concerns identified.

Important Files Changed

Filename Overview
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/utils/auto-layout-utils.ts Adds mergeSubblockState on both the happy path (lines 113–114) and the revert path (line 173), using the scoped workflowId parameter throughout — correctly prevents auto-layout from overwriting runtime-edited subblock values.

Sequence Diagram

sequenceDiagram
    participant U as User
    participant ALU as applyAutoLayoutAndUpdateStore
    participant API as /api/workflows/[id]/autolayout
    participant SBS as SubBlockStore
    participant WFS as WorkflowStore
    participant DB as /api/workflows/[id]/state

    U->>ALU: trigger auto-layout
    ALU->>WFS: getState() → blocks, edges, loops, parallels
    ALU->>API: POST (blocks + layout options)
    API-->>ALU: layoutedBlocks (positions updated)
    ALU->>SBS: mergeSubblockState(layoutedBlocks, workflowId)
    SBS-->>ALU: mergedBlocks (positions + current subblock values)
    ALU->>WFS: replaceWorkflowState(mergedBlocks)
    ALU->>DB: PUT (mergedBlocks with subblock values preserved)
    alt Save succeeds
        DB-->>ALU: 200 OK
        ALU-->>U: { success: true }
    else Save fails
        DB-->>ALU: error
        ALU->>SBS: mergeSubblockState(originalBlocks, workflowId)
        SBS-->>ALU: revertBlocks
        ALU->>WFS: replaceWorkflowState(revertBlocks)
        ALU-->>U: { success: false, error }
    end
Loading

Reviews (2): Last reviewed commit: "fix: merge subblock values in auto-layou..." | Re-trigger Greptile

@waleedlatif1 waleedlatif1 force-pushed the fix/auto-layout-subblock-merge branch from 0b31cce to c2765fa Compare April 8, 2026 19:59
…ntext

Auto-layout was reading from getWorkflowState() without merging subblock
store values, then persisting stale subblock data to the database. This
caused runtime-edited values (e.g. router_v2 context) to be overwritten
with their initial/empty values whenever auto-layout was triggered.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@waleedlatif1 waleedlatif1 force-pushed the fix/auto-layout-subblock-merge branch from c2765fa to aac05b6 Compare April 8, 2026 20:01
@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit aac05b6. Configure here.

@waleedlatif1 waleedlatif1 merged commit 694f4a5 into staging Apr 8, 2026
12 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/auto-layout-subblock-merge branch April 8, 2026 20:25
TheodoreSpeaks pushed a commit that referenced this pull request Apr 8, 2026
…ntext (#4055)

Auto-layout was reading from getWorkflowState() without merging subblock
store values, then persisting stale subblock data to the database. This
caused runtime-edited values (e.g. router_v2 context) to be overwritten
with their initial/empty values whenever auto-layout was triggered.
TheodoreSpeaks added a commit that referenced this pull request Apr 8, 2026
* fix(billing): skip billing on streamed workflows with byok

* Simplify logic

* Address comments, skip tokenization billing fallback

* Fix tool usage billing for streamed outputs

* fix(webhook): throw webhook errors as 4xxs (#4050)

* fix(webhook): throw webhook errors as 4xxs

* Fix shadowing body var

---------

Co-authored-by: Theodore Li <[email protected]>

* feat(enterprise): cloud whitelabeling for enterprise orgs (#4047)

* feat(enterprise): cloud whitelabeling for enterprise orgs

* fix(enterprise): scope enterprise plan check to target org in whitelabel PUT

* fix(enterprise): use isOrganizationOnEnterprisePlan for org-scoped enterprise check

* fix(enterprise): allow clearing whitelabel fields and guard against empty update result

* fix(enterprise): remove webp from logo accept attribute to match upload hook validation

* improvement(billing): use isBillingEnabled instead of isProd for plan gate bypasses

* fix(enterprise): show whitelabeling nav item when billing is enabled on non-hosted environments

* fix(enterprise): accept relative paths for logoUrl since upload API returns /api/files/serve/ paths

* fix(whitelabeling): prevent logo flash on refresh by hiding logo while branding loads

* fix(whitelabeling): wire hover color through CSS token on tertiary buttons

* fix(whitelabeling): show sim logo by default, only replace when org logo loads

* fix(whitelabeling): cache org logo url in localstorage to eliminate flash on repeat visits

* feat(whitelabeling): add wordmark support with drag/drop upload

* updated turbo

* fix(whitelabeling): defer localstorage read to effect to prevent hydration mismatch

* fix(whitelabeling): use layout effect for cache read to eliminate logo flash before paint

* fix(whitelabeling): cache theme css to eliminate color flash before org settings resolve

* fix(whitelabeling): deduplicate HEX_COLOR_REGEX into lib/branding and remove mutation from useCallback deps

* fix(whitelabeling): use cookie-based SSR cache to eliminate brand flash on all page loads

* fix(whitelabeling): use !orgSettings condition to fix SSR brand cache injection

React Query returns isLoading: false with data: undefined during SSR, so the
previous brandingLoading condition was always false on the server — initialCache
was never injected into brandConfig. Changing to !orgSettings correctly applies
the cookie cache both during SSR and while the client-side query loads, eliminating
the logo flash on hard refresh.

* fix(editor): stop highlighting start.input as blue when block is not connected to starter (#4054)

* fix: merge subblock values in auto-layout to prevent losing router context (#4055)

Auto-layout was reading from getWorkflowState() without merging subblock
store values, then persisting stale subblock data to the database. This
caused runtime-edited values (e.g. router_v2 context) to be overwritten
with their initial/empty values whenever auto-layout was triggered.

* fix(whitelabeling): eliminate logo flash by fetching org settings server-side (#4057)

* fix(whitelabeling): eliminate logo flash by fetching org settings server-side

* improvement(whitelabeling): add SVG support for logo and wordmark uploads

* skelly in workspace header

* remove dead code

* fix(whitelabeling): hydration error, SVG support, skeleton shimmer, dead code removal

* fix(whitelabeling): blob preview dep cycle and missing color fallback

* fix(whitelabeling): use brand-accent as color fallback when workspace color is undefined

* chore(whitelabeling): inline hasOrgBrand

---------

Co-authored-by: Theodore Li <[email protected]>
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.

1 participant