Skip to content

feat(naming): client-side unique duplicate names for blocks (standard '<Base> N', normalized collision-safe)#1302

Closed
waleedlatif1 wants to merge 1 commit intostagingfrom
capy/ensure-unique-block--843db4c6
Closed

feat(naming): client-side unique duplicate names for blocks (standard '<Base> N', normalized collision-safe)#1302
waleedlatif1 wants to merge 1 commit intostagingfrom
capy/ensure-unique-block--843db4c6

Conversation

@waleedlatif1
Copy link
Collaborator

@waleedlatif1 waleedlatif1 commented Sep 10, 2025

Summary

Implements client-side unique name generation for duplicated blocks, standardizing to " N" and preventing normalized collisions within a workflow. This keeps resolver/store normalization rules in sync and avoids server-side changes.

Why

  • Avoids confusing name collisions after duplicate, especially across variants that normalize equal (e.g., "My Agent" vs "myagent").
  • Ensures consistent UX across both duplicate entry points (collaborative and local store) with a single source of truth.
  • Honors product decision to rely on client-side uniqueness only; server behavior unchanged.

Changes

  • Added helper at apps/sim/lib/naming.ts:
    • normalizeBlockName(name) – lowercase + strip spaces (parity with resolver/store).
    • generateUniqueBlockDuplicateName(existingNames, sourceName) – produces "Base N"; starts at suffix+1 when source ends with whitespace+digits, otherwise 1; loops until normalized-unique.
  • hooks/use-collaborative-workflow.tscollaborativeDuplicateBlock now uses the helper with current workflow block names.
  • stores/workflows/workflow/store.tsduplicateBlock now uses the helper.
  • updateBlockName in store now imports the shared normalizeBlockName to avoid drift.
  • Tests: apps/sim/lib/naming.test.ts covering base/suffix cases, normalization collisions, gaps, whitespace-heavy names, mixed case, and empty names.

Impact

  • Client-only change; server endpoints and duplication behavior remain unchanged.
  • Rename validation continues to prevent normalized collisions; no regressions expected.

QA

  • Create blocks: "Agent", "Agent 1". Duplicate "Agent" → expect "Agent 2".
  • Create "Agent 3". Duplicate "Agent 2" → expect "Agent 4".
  • Create "agent1" (if allowed). Duplicate "Agent" → should skip to next free beyond normalized collisions.
  • Names with multiple spaces: "My Agent" duplicates to "My Agent 1"; if a normalized collision exists, increments accordingly.

Notes

  • No server behavior changed; resolver normalization remains the source of truth we mirrored.
  • Keeps naming behavior consistent whether duplication originates locally or via collaboration.

… normalized comparison; unify client naming via shared helper and wire into duplicate flows; keep server unchanged

Co-authored-by: Capy <capy@capy.ai>
@waleedlatif1 waleedlatif1 added the capy PR created by Capy label Sep 10, 2025
@vercel
Copy link

vercel bot commented Sep 10, 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 10, 2025 5:54am
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Sep 10, 2025 5:54am

@waleedlatif1 waleedlatif1 removed the capy PR created by Capy label Sep 10, 2025
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 implements a client-side unique name generation system for duplicated workflow blocks, addressing confusing name collisions that can occur when different block names normalize to the same value (e.g., "My Agent" vs "myagent"). The changes introduce a centralized naming utility that standardizes duplicate naming to the pattern " N" and prevents normalized collisions within workflows.

The core implementation adds a new utility library at apps/sim/lib/naming.ts containing two key functions: normalizeBlockName() which performs lowercase conversion and space removal (mirroring server-side resolver logic), and generateUniqueBlockDuplicateName() which generates collision-safe duplicate names by checking against normalized existing names. This utility is integrated into both the collaborative workflow hook (use-collaborative-workflow.ts) and the local workflow store (store.ts), replacing previous regex-based approaches with a more robust solution.

The implementation ensures consistency across both duplication pathways (collaborative real-time and local store operations) by providing a single source of truth for naming logic. The updateBlockName function in the store also adopts the shared normalization function to maintain consistency. The changes are thoroughly tested with comprehensive coverage for various edge cases including whitespace handling, gap filling in numbering sequences, normalized collisions, and fallback scenarios.

This solution honors the product decision to handle uniqueness client-side only, avoiding server-side changes while maintaining synchronization with server-side normalization rules. The standardized naming approach provides predictable user experience and prevents the confusion that could arise from visually different names that would conflict after normalization.

Confidence score: 4/5

  • This PR is safe to merge with minimal risk as it implements well-tested client-side improvements without affecting server behavior
  • Score reflects thorough testing coverage and clear separation of concerns, though the complex normalization logic requires careful attention
  • Pay close attention to the naming utility functions in apps/sim/lib/naming.ts and their integration points in the workflow stores

4 files reviewed, 1 comment

Edit Code Review Bot Settings | Greptile

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