Skip to content

Conversation

@icecrasher321
Copy link
Collaborator

Summary

Refactor loading state tracking for workflows to be based on simple state machine.

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 Nov 20, 2025

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

1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Nov 20, 2025 3:04am

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Nov 20, 2025

Greptile Summary

  • Refactored workflow loading to use a state machine pattern with explicit phases (idle, metadata-loading, metadata-ready, state-loading, ready, error)
  • Implemented race condition prevention using request IDs to discard stale workflow hydration results
  • Removed boolean isLoading flag in favor of comprehensive HydrationState tracking across workspace and workflow contexts

Confidence Score: 4/5

  • Safe to merge with minor areas requiring attention in race condition edge cases
  • Well-structured state machine refactoring with proper race condition handling via request IDs, though the completeMetadataLoad transition logic could be more explicit about handling concurrent state loads
  • apps/sim/stores/workflows/registry/store.ts - verify the state transition logic in completeMetadataLoad when phase is state-loading

Important Files Changed

Filename Overview
apps/sim/stores/workflows/registry/store.ts Refactored loading state to use state machine pattern with request IDs for race condition prevention
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/workflow.tsx Replaced local state with computed isWorkflowReady based on hydration phase and removed redundant effect

Sequence Diagram

sequenceDiagram
    participant User
    participant WorkflowHook as "useWorkflows Hook"
    participant Registry as "Workflow Registry"
    participant API as "API /workflows"
    participant Store as "Workflow Store"

    User->>WorkflowHook: Navigate to workspace
    WorkflowHook->>Registry: beginMetadataLoad(workspaceId)
    Registry->>Registry: Set phase='metadata-loading'
    WorkflowHook->>API: GET /api/workflows?workspaceId
    API-->>WorkflowHook: Return workflow list
    WorkflowHook->>Registry: completeMetadataLoad(workspaceId, workflows)
    Registry->>Registry: Set phase='metadata-ready'
    User->>Registry: setActiveWorkflow(workflowId)
    Registry->>Registry: loadWorkflowState(workflowId)
    Registry->>Registry: Set phase='state-loading', create requestId
    Registry->>API: GET /api/workflows/:id
    API-->>Registry: Return workflow state
    Registry->>Registry: Validate requestId matches
    Registry->>Store: setState(workflowState)
    Registry->>Registry: Set phase='ready'
    Registry-->>User: Workflow ready
Loading

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.

5 files reviewed, no comments

Edit Code Review Agent Settings | Greptile
React with 👍 or 👎 to share your feedback on this new summary format

@icecrasher321 icecrasher321 merged commit e5cb6e3 into staging Nov 20, 2025
9 checks passed
@waleedlatif1 waleedlatif1 deleted the improvment/hydration-state-machine branch November 20, 2025 19:20
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