Skip to content

fix(dsn): surface conflicting physical-pin assignments instead of exporting unreadable JSON - #328

Closed
Huyvux12 wants to merge 1 commit into
IntelligentElectron:mainfrom
Huyvux12:fix/327-conflicting-pin-export
Closed

Huyvux12 wants to merge 1 commit into
IntelligentElectron:mainfrom
Huyvux12:fix/327-conflicting-pin-export

Conversation

@Huyvux12

Copy link
Copy Markdown

Summary

A DSN design that assigns one physical pin to two nets used to export successfully and then fail to reload: the net assembler kept the pin in both net membership lists while the component-side map recorded only the last assignment, so the writer emitted JSON with a valid content hash that the same release's reader rejects. The export now surfaces the unresolved conflict instead of reporting success.

Changes

  • src/parsers/cadence/dsn/net-assembly.ts: addPinToNet throws when a pin already has an assignment to a different net, naming the pin and both nets. Re-assigning the same net stays idempotent.
  • docs/decision-tables/dsn-net-assignment/pin-conflict.{csv,spec.json,rules.json,rules.md}: new golden table for the rule (9 cells: prior assignment x incoming net, including NC).
  • src/parsers/cadence/dsn/net-assignment.table.test.ts: replay block for the new table, one test per cell.

No physical-connectivity decision is made here: which assignment is correct, and whether the source should be rejected, corrected, or reconciled, remains unverified (see #294). No schema change, no net selection, no bus merging.

Related Issues

Fixes #327

Decision tables

New logic with interacting conditions and no table, so the table was built first and is attached as part of this fix (bug fix):

New table docs/decision-tables/dsn-net-assignment/pin-conflict, 9 cells, replayed by src/parsers/cadence/dsn/net-assignment.table.test.ts ("pin-conflict: one physical pin, one net"):

| # | When | Outcome | Next | Cells |
|---|---|---|---|---|
| 1 | prior_net = none | assign the pin to the incoming net |  | 3 |
| 2 | prior_net = NET_A; new_net = NET_A | keep the existing assignment |  | 1 |
| 3 | prior_net = NC; new_net = NC | keep the existing assignment |  | 1 |
| else | everything else | reject the conflicting assignment |  | |

9 cells became 3 rules plus a default

The replay passes (72/72 in net-assignment.table.test.ts, 9 of them the new cells). NC counts as a net name here: a pin recorded unconnected and also connected is the same conflict. That differs from mergeRepeatedSections, which tolerates NC when folding twin copies of a repeated section — a cross-key fold, not a same-key assignment — so it is unaffected.

Verification

Built the packaged binary from this branch (scripts/build-binary.sh host <dir>/universal-netlist packaged, Bun 1.4.4) and drove the CLI and the MCP server over stdio. Verdict: PASS.

Control — CLI export of a real golden design still succeeds and reloads:

$ universal-netlist export_design test/golden/cadence/BEAGLEBONEBLK_C3.netlist.json --output /tmp/verify-export2.netlist.json
{"design":".../test/golden/cadence/BEAGLEBONEBLK_C3.netlist.json","design_variant":"<Default>","output":"/tmp/verify-export2.netlist.json"}
# exit 0; reloaded output parses: 335 nets, 413 components

Off the happy path — CLI export of the conflicting document generated by the released v1.16.0 code now fails loudly instead of writing a file:

$ universal-netlist export_design same-pin-different-nets.netlist.json --output /tmp/verify-conflict.netlist.json
{"error":"same-pin-different-nets.netlist.json: net 'NET_A' lists U1.OUT4, but U1.OUT4 is on 'NET_B'"}
# exit 1; no output file written

MCP over stdio — list_nets on the golden design returns its nets; on the conflicting document it returns the same reader error as an error result, not a crash:

control-golden list_nets -> {"design_variant": "<Default>", "nets": ["12M_LOOP", "12MHZ", "AIN0", ...]}
conflict-doc list_nets -> {"error": "same-pin-different-nets.netlist.json: net 'NET_A' lists U1.OUT4, but U1.OUT4 is on 'NET_B'"}

The fix itself was verified against the issue's 6-case reproduction (assembleNets + buildComponents + writer + reader round-trip), before and after:

Before (released v1.16.0 and local main @ 60d3ef7): 3 controls readable; 3 conflict cases produce valid-hash JSON the reader rejects (net 'NET_A' lists U1.OUT4, but U1.OUT4 is on 'NET_B'), and reversing the records reverses the selected net.

After (this branch): the 3 conflict cases throw at assembly — Pin U1.OUT4 is assigned to both 'NET_A' and 'NET_B'; a physical pin belongs to one net, so the netlist cannot be built until the conflicting assignments are resolved. — and the 3 controls still export and reload.

Why the throw lives in the assembler rather than the writer: the assembled graph is already incoherent before serialization — queries read both sides (componentPins vs nets) and would return contradictory answers — so serving it is silently wrong, and the writer cannot name the cause as precisely. The alternative (validate in serializeUniversalNetlist) would confine the failure to export only; if the maintainer prefers that, the fallback is a small validation reusing the same message. No in-repo design hits the throw: all 21 golden Cadence netlists are inverse-consistent, and #247's two remaining duplicate-refdes designs are renamed apart by separateDuplicateRefdes before assembly.

Testing

  • Added/updated tests

  • npm run type-check passes

  • npm run lint passes

  • npm test passes (see scope note below)

  • Base SHA on upstream: 60d3ef7 (reproduced and fixed on this commit).

  • Repro commands: node reproduce.mjs ./runtime/node_modules/@intelligentelectron/universal-netlist (v1.16.0, 6 cases as in Export/reload inconsistency: conflicting physical pin assignments produce unreadable JSON #327) and the same script against the local build; post-fix check node verify-fix.mjs ./upstream (3 conflicts surface at assembly, 3 controls export and reload).

  • Regression scope: npm run type-check (0 errors), npm run lint (0 warnings/errors), npm test with the Cadence fixtures checked out: 2882 passed / 18 failed / 231 skipped. All 18 failures were triaged and none is an assertion failure or caused by this change: 8 are timeouts on this 1.5-CPU VM (the same files pass in isolation, including the golden suite 92/92 and the DSN suite), 9 need the Altium/KiCad fixtures (this checkout fetched Cadence only; CI runs the full corpus), and 1 is the known root-user DiskCacheStore artifact. The pre-existing failures were verified identical on the clean tree by running the affected files with the fix stashed.

  • Diff scope: 2 source/test files changed (+16 in net-assembly.ts, +43 in the table test) and 4 new table files. No CHANGELOG.md or version change, per CONTRIBUTING.

  • Risks checked and ruled out: legitimate duplicate pins (every duplicate path — duplicate refdes, repeated sections, multi-root drawings — is renamed apart before assembly, and same-net repeats stay idempotent); cache poisoning (a throwing parse is never cached: store.set runs only after produce succeeds); Altium/KiCad paths (out of scope for Export/reload inconsistency: conflicting physical pin assignments produce unreadable JSON #327; they build nets without this component-side map, and KiCad groups each pin under one net by construction).

…orting unreadable JSON

addPinToNet now throws when one physical pin is assigned to two nets, instead of keeping both net memberships while the component-side map records only the last assignment. A successful export then either round-trips through the reader or fails loudly; it no longer emits valid-hash JSON the same release rejects. Same-net re-assignment stays idempotent. Adds the pin-conflict decision table (9 cells) and its replay tests. Fixes IntelligentElectron#327.

Copy link
Copy Markdown
Contributor

Thanks for the PR and for reproducing the issue so carefully, @Huyvux12.

We tested the throw on real designs before deciding. BeagleBone AI, which is public, hits it on its main processor, and with this change the whole design stops loading for every tool. The conflict there comes from a parser bug (the wrong pin map for sections numbered -1, -2, ...), so the design is fixable.

We opened #331. It fixes that lookup and a second one (the same part name in several libraries), and it moves the refusal to export_design: it names the pins and both nets, as your message does, and queries keep working on the design.

We need to run more tests on our private corpus before merging #331. Give us until next week, and we'll come back to this PR then.


Generated by Claude Code

@valentinozegna

Copy link
Copy Markdown
Contributor

Closing this one, @Huyvux12: #331 is merged and ships in v1.16.1, and it covers the case this PR was after.

Your work is in there. The reproduction you confirmed is what pointed us at the assembler, and the refusal message in export_design names the pin and both nets the way yours does. The difference is where it sits: at export, so a design with a conflict still loads and answers queries, and the two parser lookups that caused most real conflicts are fixed at the source.

Thanks for the careful PR. You are credited in the release notes :)


Generated by Claude Code

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.

Export/reload inconsistency: conflicting physical pin assignments produce unreadable JSON

2 participants