Skip to content

fix(naming): client-side unique duplicate names for blocks#1273

Merged
waleedlatif1 merged 1 commit intomainfrom
capy/ensure-unique-block--843db4c6
Sep 10, 2025
Merged

fix(naming): client-side unique duplicate names for blocks#1273
waleedlatif1 merged 1 commit intomainfrom
capy/ensure-unique-block--843db4c6

Conversation

@waleedlatif1
Copy link
Copy Markdown
Collaborator

@waleedlatif1 waleedlatif1 commented Sep 6, 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.

@waleedlatif1 waleedlatif1 added the capy PR created by Capy label Sep 6, 2025
@vercel
Copy link
Copy Markdown

vercel Bot commented Sep 6, 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 6, 2025 6:49pm
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Sep 6, 2025 6:49pm

@waleedlatif1 waleedlatif1 removed the capy PR created by Capy label Sep 6, 2025
@waleedlatif1 waleedlatif1 changed the title feat: client-side unique duplicate names for blocks (standard '<Base> N', normalized collision-safe) fix(naming): client-side unique duplicate names for blocks Sep 6, 2025
Copy link
Copy Markdown
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 centralized client-side unique naming system for duplicated workflow blocks. The core change introduces two new utility functions in apps/sim/lib/naming.ts: normalizeBlockName() which converts names to lowercase and removes spaces (mirroring server-side normalization), and generateUniqueBlockDuplicateName() which creates unique names using the standardized " N" format.

The implementation addresses a UX issue where block duplication could create confusing name collisions, particularly when different naming variants normalize to the same string (e.g., "My Agent" vs "myagent"). The solution ensures consistency across both collaborative workflows (use-collaborative-workflow.ts) and local workflows (stores/workflows/workflow/store.ts) by replacing their separate naming logic with the shared utility.

The naming algorithm intelligently handles numeric suffixes - if a source name ends with whitespace and digits, it increments from that number; otherwise it starts from 1. It then loops through candidates until finding one that doesn't create a normalized collision. The updateBlockName function in the workflow store also now uses the shared normalizeBlockName to prevent drift between client and server validation rules.

Comprehensive test coverage validates edge cases including existing numeric suffixes, normalized collisions, gap filling in numbering sequences, whitespace handling, mixed case scenarios, and fallback behavior for empty names. This change maintains the product decision to handle uniqueness client-side only while keeping server behavior unchanged.

Confidence score: 4/5

  • This PR is safe to merge with low risk of production issues
  • Score reflects well-structured implementation with comprehensive tests, but complexity in naming logic warrants careful review
  • Pay close attention to the naming utility functions in apps/sim/lib/naming.ts for potential edge cases

4 files reviewed, no comments

Edit Code Review Bot Settings | Greptile

…d comparison; unify client naming via shared helper and wire into duplicate flows; keep server unchanged
@waleedlatif1 waleedlatif1 force-pushed the capy/ensure-unique-block--843db4c6 branch from 7959958 to 3be69ab Compare September 6, 2025 18:44
@vercel vercel Bot temporarily deployed to Preview – docs September 6, 2025 18:44 Inactive
@waleedlatif1 waleedlatif1 merged commit e25214f into main Sep 10, 2025
6 checks passed
@waleedlatif1 waleedlatif1 deleted the capy/ensure-unique-block--843db4c6 branch September 10, 2025 05:46
@waleedlatif1 waleedlatif1 restored the capy/ensure-unique-block--843db4c6 branch September 10, 2025 05:46
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