Skip to content

fix(rehydration): consolidate store rehydration code#1249

Merged
icecrasher321 merged 2 commits intostagingfrom
fix/rehydration-consolidation
Sep 5, 2025
Merged

fix(rehydration): consolidate store rehydration code#1249
icecrasher321 merged 2 commits intostagingfrom
fix/rehydration-consolidation

Conversation

@icecrasher321
Copy link
Collaborator

Summary

Consolidate store rehydration and make registry source of truth for active workflow.

Type of Change

  • Bug fix

Testing

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 Sep 5, 2025

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

Project Deployment Preview Comments Updated (UTC)
sim Ready Ready Preview Comment Sep 5, 2025 2:40am
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Sep 5, 2025 2:40am

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Greptile Summary

This PR consolidates duplicated store rehydration logic in the socket context by extracting common functionality into a shared rehydrateWorkflowStores function. Previously, two socket event handlers ('copilot-workflow-edit' and 'workflow-state') contained nearly 70 lines of identical code for rehydrating workflow and subblock stores. The refactoring eliminates this duplication by creating a centralized function that handles the rehydration process with proper validation checks.

The consolidation also strengthens the application architecture by making the workflow registry the authoritative source for determining the active workflow. Instead of relying on URL parameters to check if a workflow is active, the code now uses useWorkflowRegistry.getState().activeWorkflowId as the single source of truth. This change reduces potential race conditions and ensures consistent workflow state management across the application.

The new rehydrateWorkflowStores function includes two key validation checks: active workflow verification to ensure rehydration only occurs for the currently active workflow, and pending operations checking to prevent data races during concurrent operations. This fits well with the existing state management pattern in the codebase, which already uses Zustand stores for workflow registry management as seen in the /stores/workflows/registry directory structure.

Confidence score: 4/5

  • This PR is safe to merge with minimal risk as it consolidates existing logic without changing core functionality
  • Score reflects solid refactoring practices that eliminate code duplication while improving architectural consistency through centralized workflow state management
  • Pay close attention to the socket event handler integration points to ensure all rehydration scenarios are properly covered

1 file reviewed, no comments

Edit Code Review Bot Settings | Greptile

@vercel vercel bot temporarily deployed to Preview – docs September 5, 2025 02:35 Inactive
@icecrasher321 icecrasher321 merged commit 47da5eb into staging Sep 5, 2025
6 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/rehydration-consolidation branch September 5, 2025 05:50
arenadeveloper02 pushed a commit to arenadeveloper02/p2-sim that referenced this pull request Sep 19, 2025
* fix(rehydration): consolidate store rehydration code

* fix stale closure
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