Skip to content

Add empty-connections early-return guards to all pipeline solvers#659

Open
chengdazhi wants to merge 1 commit into
tscircuit:mainfrom
chengdazhi:fix/empty-connections-guards
Open

Add empty-connections early-return guards to all pipeline solvers#659
chengdazhi wants to merge 1 commit into
tscircuit:mainfrom
chengdazhi:fix/empty-connections-guards

Conversation

@chengdazhi

Copy link
Copy Markdown

Problem

Passing an input problem with no connections (directConnections: [] / netConnections: [], which yields no MSP pairs and no traces) caused solvers to run their step loops over empty work queues, and a fully empty input (chips: []) crashed outright: TraceCleanupSolver, AvailableNetOrientationSolver, and NetLabelNetLabelCollisionSolver build a Flatbush-backed ChipObstacleSpatialIndex, and Flatbush throws Unexpected numItems value: 0 when constructed with zero chips.

Note: the issue mentions CapacityMeshSolver.ts / DirectLineSolver.ts; those files don't exist in this repo, so I applied the guard to every solver in the actual pipeline (SchematicTracePipelineSolver's stages).

Fix

Add an early-return guard to each pipeline solver: when there are no connections / connection pairs / traces / labels to process, the solver marks itself solved in the constructor and returns an empty result (empty traces / labels maps) instead of stepping:

  • MspConnectionPairSolver — no directConnections and no netConnections
  • SchematicTraceLinesSolver — no MSP connection pairs
  • LongDistancePairSolver — no candidate pairs
  • TraceOverlapShiftSolver — no input traces
  • NetLabelPlacementSolver — no connection-net groups to label
  • TraceLabelOverlapAvoidanceSolver — no traces (still runs the final MergedNetLabelObstacleSolver so downstream stages can read labelMergingSolver.getOutput())
  • TraceCleanupSolver — no traces (also avoids building the spatial index that crashed on chips: [])
  • Example28Solver — no traces
  • AvailableNetOrientationSolver — no labels (skips the spatial index construction)
  • RailNetLabelCornerPlacementSolver — no labels needing corner placement
  • TraceAnchoredNetLabelOverlapSolver — no labels
  • NetLabelTraceCollisionSolver — no traces or no labels
  • NetLabelNetLabelCollisionSolver — no labels (skips the spatial index construction)

Tests

Added tests/solvers/SchematicTracePipelineSolver/SchematicTracePipelineSolver_emptyConnections.test.ts covering the pipeline and each solver with empty connections (and the pipeline with chips: []), asserting the solver solves without failing and returns empty traces/labels.

  • Full suite: bun test — 117 pass, 4 skip, 0 fail
  • tsc --noEmit and biome format clean
  • Verified stage-by-stage that solver outputs for a normal input (example19) are byte-identical before/after this change

This PR was prepared with assistance from an AI coding agent.

Closes #657

Each solver now marks itself solved immediately when there are no
connections, traces, or labels to process, returning an empty result
instead of running its step loop. This also fixes crashes when the
input problem has no chips, where building a Flatbush-backed chip
obstacle spatial index with zero items threw inside
TraceCleanupSolver, AvailableNetOrientationSolver, and
NetLabelNetLabelCollisionSolver.
@vercel

vercel Bot commented Jul 13, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
schematic-trace-solver Ready Ready Preview, Comment Jul 13, 2026 7:32am

Request Review

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.

[BUG] Router crashes on empty connections array

1 participant