fix(ethercat): prevent slave name collisions across masters [DOPE-281]#754
fix(ethercat): prevent slave name collisions across masters [DOPE-281]#754marconetsf wants to merge 4 commits into
Conversation
- Source slave name from <Type> (short, e.g. "EL1809") instead of the long <Name LcId> descriptor. - Auto-suffix _NN at creation when the base collides with any existing slave in any master. - Reject rename to a name already taken by another slave, matching the pattern used by POU/datatype/master renames. - Re-add the long ESI descriptor as a subtitle below the slave header now that the title shows the short form. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (6)
✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
The helper was misplaced under backend/shared/ethercat/, which made the store import violate the layer rule "Store must not import from Backend Shared". Move it to frontend/utils/ alongside next-name.ts and ethercat-status.ts — the conventional location for pure helpers shared between store and components. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Inline a single-element array literal that exceeded the explicit-wrap heuristic but fits within the 120-char width. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
JoaoGSP
left a comment
There was a problem hiding this comment.
Thanks for tackling this — the fix works end-to-end and the tests are solid. Before approving I want to flag one thing about scope:
The DOPE-281 description identifies the root cause as tabs, editor, and file slices keying by slave.name alone, and the AC reads "Two masters can hold slaves with the same name; clicking each opens its own editor with its own configuration, independently." This PR takes the inverse approach — it makes duplicate names impossible rather than making the slices handle them.
Both approaches close the user-visible bug, and this one is lower-risk. But two things still worry me:
- Legacy projects. A project saved before this fix can still contain duplicate slave names across masters. Opening it will hit the original bug — no migration / load-time de-dup. Is there a known set of in-the-wild projects we should check, or do we want a one-time fixup on project load?
- Other write paths. This guard runs in
ethercatDeviceActions.renameand in the two creation paths inindex.tsx. If anything else ever writes toethercatConfig.devices[].name(paste, import, undo replay), the name-keyed-slice bug returns. Worth a comment oncollectAllSlaveNamessaying "all writes must funnel through here," or moving the check into a lower layer.
If the scope change is intentional, please update DOPE-281's description/AC so a future reviewer (or audit) doesn't trip on it. Otherwise happy to approve once we agree on (1).
| */ | ||
| export function generateUniqueSlaveName(base: string, existing: Iterable<string>): string { | ||
| const taken = new Set(existing) | ||
| let candidate = base |
There was a problem hiding this comment.
Tiny doc nit: "Pad widens past 99 automatically" reads like the pad value changes — it doesn't. The behavior you're describing is that padStart(2, '0') doesn't truncate, so String(100) passes through as "100". Maybe: "Two-digit pad doesn't truncate, so 3+ digit indices pass through unchanged."
| let candidate = base | ||
| let i = 0 | ||
| while (taken.has(candidate)) { | ||
| i++ |
There was a problem hiding this comment.
Minor: when existing is already a Set (which is the hot path inside the scan-bus loop), this copies it on every call. Not a real cost at our scale, but existing instanceof Set ? existing : new Set(existing) is free if you want it. Optional.
| // Prefer the short product code from <Type> (e.g. "EL1809") over the | ||
| // long localized name from <Name LcId="1033"> — the long form is | ||
| // verbose and identical for any two units of the same model. | ||
| const baseName = bestMatch.esiDevice.type.name || bestMatch.esiDevice.name || match.device.name |
There was a problem hiding this comment.
Sanity-check question: is esiDevice.type.name reliably populated as the short product code (EL1809, EK1100, …) across all vendor ESI XMLs we've parsed — not just Beckhoff? If type.name is ever empty for a real ESI, the fallback chain drops back to the long localized name and we lose the readability win this PR is trying to deliver. A one-line confirmation (or a quick grep across the test fixtures) would settle it.
| // Same-name rename is a no-op the UI short-circuits before us, but we | ||
| // still allow it here so the action stays idempotent. | ||
| if (newName !== oldName && collectAllSlaveNames(state.project.data.remoteDevices).has(newName)) { | ||
| return { ok: false, message: `An EtherCAT slave named "${newName}" already exists in this project` } |
There was a problem hiding this comment.
Worth a short comment here noting that this is the only enforcement point for slave-name uniqueness, and that the underlying name-keyed slices (tabs/editor/file) will silently misbehave if a duplicate ever slips through. That way future readers of this file know not to add a sibling write path without the same guard.
Summary
<Type>(short, e.g.EL1809) instead of the long<Name LcId>descriptor._NNat creation when the base name already exists in any master.Linked: DOPE-281
Test plan
EL1809,EL1809_01).EL1809on bus A and on bus B → second becomesEL1809_01.🤖 Generated with Claude Code