Skip to content

Conversation

@icecrasher321
Copy link
Collaborator

Summary

Fix race condition with respect to deployment check status rendering.

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 7, 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 7, 2026 6:39pm

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 7, 2026

Greptile Summary

Fixed race conditions in deployment check status rendering by improving state synchronization across workflow navigation.

Key improvements:

  • use-deployed-state.ts: Enhanced race condition protection by reading fresh deployment status from registry at fetch time using useCallback, ensuring the hook always validates against current workflow state rather than stale props
  • use-change-detection.ts: Removed debounce logic that caused timing issues with state updates, and simplified subBlock value merging to eliminate race conditions when comparing current vs deployed state
  • deploy.tsx: Simplified by removing unnecessary useCallback wrapper and redundant error handling wrapper

The changes ensure deployment status UI accurately reflects the current workflow state even when users rapidly switch between workflows.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The changes are well-focused on fixing specific race conditions through improved state synchronization. The modifications follow React best practices by using useCallback for stable function references and checking fresh state from the registry. The removal of debounce logic and simplification of error handling reduces complexity without introducing new issues. All changes are defensive and improve robustness.
  • No files require special attention

Important Files Changed

Filename Overview
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/deploy/deploy.tsx Simplified deploy component by removing unnecessary useCallback wrapper and error handling wrapper for refetch function
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/deploy/hooks/use-change-detection.ts Removed debounce logic and simplified subBlock value merging to eliminate race conditions in change detection
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/deploy/hooks/use-deployed-state.ts Enhanced race condition protection by reading fresh deployment status from registry at fetch time instead of relying on stale props

Sequence Diagram

sequenceDiagram
    participant User
    participant Deploy
    participant useDeployedState
    participant Registry
    participant API
    participant useChangeDetection

    Note over User,useChangeDetection: Workflow Deployment Status Flow

    User->>Deploy: Navigate to workflow
    Deploy->>useDeployedState: Initialize with workflowId
    useDeployedState->>Registry: Get fresh activeWorkflowId & deployment status
    
    alt Workflow is deployed
        useDeployedState->>API: GET /api/workflows/{id}/deployed
        useDeployedState->>Registry: Check if activeWorkflowId still matches
        
        alt Workflow changed during fetch
            useDeployedState->>useDeployedState: Ignore response (race condition prevented)
        else Workflow still active
            API-->>useDeployedState: Return deployed state
            useDeployedState->>Registry: Verify activeWorkflowId again
            useDeployedState->>Deploy: Update deployedState
        end
    end

    Deploy->>useChangeDetection: Compare current vs deployed
    useChangeDetection->>useChangeDetection: Build current state (no debounce)
    useChangeDetection->>useChangeDetection: Compare states
    useChangeDetection->>Deploy: Return changeDetected

    Deploy->>User: Render UI (Live/Update/Deploy)

    User->>Deploy: Switch to different workflow
    Deploy->>useDeployedState: New workflowId
    useDeployedState->>Registry: Get fresh activeWorkflowId
    Note over useDeployedState,Registry: Race condition check prevents<br/>stale state updates
Loading

@icecrasher321 icecrasher321 merged commit 833825f into staging Jan 7, 2026
11 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/deploy-check-race-condition branch January 8, 2026 18:38
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