Skip to content

Preserve imported trace topology during subcircuit circuit-json inflation and reroute reproduction fixes#2443

Open
rushabhcodes wants to merge 7 commits into
tscircuit:mainfrom
rushabhcodes:update-kicadts
Open

Preserve imported trace topology during subcircuit circuit-json inflation and reroute reproduction fixes#2443
rushabhcodes wants to merge 7 commits into
tscircuit:mainfrom
rushabhcodes:update-kicadts

Conversation

@rushabhcodes

@rushabhcodes rushabhcodes commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes a core trace-inflation bug in tscircuit/core where imported subcircuit circuitJson could lose or distort source-trace/pcb-trace relationships during inflation, especially for multi-segment imported traces and rerouted Arduino Uno regions.

This PR keeps one logical source_trace mapped to all of its imported physical pcb_trace segments, preserves imported trace metadata during runtime trace creation, and updates reroute expectations to validate the runtime board state correctly.

Why this matters

This was a subtle but important core data-modeling bug:

  • imported traces with multiple physical pcb_trace segments were not represented correctly after inflation
  • rerouting imported regions could produce invalid or misleading source-trace associations
  • subcircuit trace inflation could fail to recreate the expected runtime source_trace records
  • repro116 Arduino Uno reroute scenarios exposed real topology mismatches between imported geometry and runtime traces

The fix improves correctness in tscircuit/core rather than only adjusting fixtures.

What changed

  • refactored subcircuit trace inflation to create one logical Trace per imported source_trace
  • attached all imported physical pcb_trace segments and vias to that logical trace
  • reused imported trace metadata when creating runtime source_trace entries
  • avoided forcing imported ids into the runtime DB model
  • updated reroute verification to compare against the runtime pre-reroute board state
  • refreshed affected PCB snapshots for repro116 reroute coverage

Tests

Reproduced and fixed with coverage including:

  • tests/features/subcircuit-circuit-json/subcircuit-circuit-json06.test.tsx
  • tests/repros/repro116-arduino-uno.test.tsx
  • tests/repros/repro116-arduino-uno-reroute.test.tsx
  • tests/repros/repro116-arduino-uno-reroute-center.test.tsx
  • tests/repros/repro116-arduino-uno-reroute-lower-mid.test.tsx
  • tests/repros/repro116-arduino-uno-reroute-invalid-source-ids.test.tsx

Impact

This is a bug reproduction + fix in tscircuit/core with direct improvements to trace data modeling, imported subcircuit correctness, and reroute stability.

@vercel

vercel Bot commented Jun 14, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
tscircuit-core-benchmarks Ready Ready Preview, Comment Jun 14, 2026 4:53pm

Request Review

@rushabhcodes rushabhcodes changed the title update kicadts Preserve imported trace topology during subcircuit circuit-json inflation and reroute reproduction fixes Jun 14, 2026
@rushabhcodes rushabhcodes requested review from a team, ShiboSoftwareDev, imrishabh18 and seveibar and removed request for ShiboSoftwareDev, imrishabh18 and seveibar June 14, 2026 13:17

@seveibar seveibar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cc @MustafaMulla29

Why is source trace storing a pcb trace? Does it need to?

Im afk and not really able to review this, but we should try to eliminate the hacky behavior in multiple stages- the FIRST PR should make sure source traces properly manage multiple pcb traces without misleading properties

trace._portsRoutedOnPcb = ports
trace.pcb_trace_id = pcb_trace.pcb_trace_id
trace._insertErrorIfTraceIsOutsideBoard(pcb_trace.route, ports)
trace.pcb_trace_id = firstPcbTraceId

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hmm that doesnt seem right

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