Skip to content

Conversation

@Sg312
Copy link
Contributor

@Sg312 Sg312 commented Jan 3, 2026

Summary

Fix missing blocks in import if undefined keys exist

Type of Change

  • Bug fix

Testing

Manual

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 3, 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 3, 2026 10:30pm

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 3, 2026

Greptile Summary

This PR fixes a bug where workflow imports would fail due to malformed subBlocks with key "undefined", missing id fields, or type: "unknown". The fix applies defensive filtering at both export (credential-extractor.ts) and import (importer.ts) stages to remove these malformed entries before they cause validation errors.

Key changes:

  • Added removeMalformedSubBlocks() function in credential-extractor.ts to strip out invalid subBlocks during export/sanitization
  • Enhanced normalizeSubblockValues() in importer.ts to skip malformed subBlocks during import with debug logging
  • Both implementations use identical validation logic (checks for "undefined" keys, missing id, type: "unknown", and null/non-object values)
  • Prevents downstream Zod validation errors and missing blocks in imported workflows

Confidence Score: 4/5

  • This PR is safe to merge with minor considerations around edge case handling
  • The fix properly addresses the root issue with defensive validation at both export and import boundaries. Logic is consistent across both files and follows established patterns. Score is 4/5 (not 5) due to a minor edge case: arrays would pass the typeof !== 'object' check, though this is unlikely to occur in practice
  • No files require special attention - both implementations are straightforward and defensive

Important Files Changed

Filename Overview
apps/sim/lib/workflows/credentials/credential-extractor.ts Added removeMalformedSubBlocks function to filter out subBlocks with key "undefined", missing id, type "unknown", or invalid structure during export/sanitization
apps/sim/stores/workflows/json/importer.ts Enhanced normalizeSubblockValues to skip malformed subBlocks during import with the same validation logic, adding logging for debugging

Sequence Diagram

sequenceDiagram
    participant User
    participant Export as Export/Sanitize
    participant CE as credential-extractor.ts
    participant Import as importer.ts
    participant Store as Workflow Store

    Note over User,Store: Export Flow
    User->>Export: Export workflow
    Export->>CE: sanitizeWorkflowForSharing()
    CE->>CE: removeMalformedSubBlocks()
    Note over CE: Filter out:<br/>- key === "undefined"<br/>- !subBlock or typeof !== object<br/>- type === "unknown"<br/>- !subBlock.id
    CE->>CE: Delete malformed subBlocks
    CE-->>Export: Clean workflow state
    Export-->>User: JSON file

    Note over User,Store: Import Flow
    User->>Import: Import workflow JSON
    Import->>Import: parseWorkflowJson()
    Import->>Import: normalizeSubblockValues()
    Note over Import: Skip (with logging):<br/>- subBlockId === "undefined"<br/>- !subBlock or typeof !== object<br/>- type === "unknown"<br/>- !subBlock.id
    Import->>Import: Build normalizedSubBlocks
    Import-->>Store: Clean workflow state
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.

2 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Comment on lines +34 to +37
if (!subBlock || typeof subBlock !== 'object') {
logger.warn(`Skipping invalid subBlock ${subBlockId} in block ${blockId}: not an object`)
return
}
Copy link
Contributor

Choose a reason for hiding this comment

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

style: In JavaScript, arrays pass the typeof !== 'object' check since typeof [] === 'object'. Consider adding !Array.isArray(subBlock) to explicitly reject arrays

Suggested change
if (!subBlock || typeof subBlock !== 'object') {
logger.warn(`Skipping invalid subBlock ${subBlockId} in block ${blockId}: not an object`)
return
}
// Skip subBlocks that are null or not objects
if (!subBlock || typeof subBlock !== 'object' || Array.isArray(subBlock)) {
logger.warn(`Skipping invalid subBlock ${subBlockId} in block ${blockId}: not an object`)
return
}
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/sim/stores/workflows/json/importer.ts
Line: 34:37

Comment:
**style:** In JavaScript, arrays pass the `typeof !== 'object'` check since `typeof [] === 'object'`. Consider adding `!Array.isArray(subBlock)` to explicitly reject arrays

```suggestion
        // Skip subBlocks that are null or not objects
        if (!subBlock || typeof subBlock !== 'object' || Array.isArray(subBlock)) {
          logger.warn(`Skipping invalid subBlock ${subBlockId} in block ${blockId}: not an object`)
          return
        }
```

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +184 to +187
if (!subBlock || typeof subBlock !== 'object') {
keysToRemove.push(key)
return
}
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Arrays pass the typeof !== 'object' check since typeof [] === 'object'. Consider adding !Array.isArray(subBlock) to explicitly reject arrays

Suggested change
if (!subBlock || typeof subBlock !== 'object') {
keysToRemove.push(key)
return
}
// Flag subBlocks that are null or not objects
if (!subBlock || typeof subBlock !== 'object' || Array.isArray(subBlock)) {
keysToRemove.push(key)
return
}
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/sim/lib/workflows/credentials/credential-extractor.ts
Line: 184:187

Comment:
**style:** Arrays pass the `typeof !== 'object'` check since `typeof [] === 'object'`. Consider adding `!Array.isArray(subBlock)` to explicitly reject arrays

```suggestion
    // Flag subBlocks that are null or not objects
    if (!subBlock || typeof subBlock !== 'object' || Array.isArray(subBlock)) {
      keysToRemove.push(key)
      return
    }
```

How can I resolve this? If you propose a fix, please make it concise.

@Sg312 Sg312 merged commit 356b473 into staging Jan 3, 2026
11 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/import-export-undefined branch January 4, 2026 20:50
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