Skip to content

Fix Human readable IDs in autorouter diagnostics#2091

Open
mohan-bee wants to merge 19 commits intotscircuit:mainfrom
mohan-bee:fix-autorouter-diagnostics
Open

Fix Human readable IDs in autorouter diagnostics#2091
mohan-bee wants to merge 19 commits intotscircuit:mainfrom
mohan-bee:fix-autorouter-diagnostics

Conversation

@mohan-bee
Copy link
Copy Markdown

@mohan-bee mohan-bee commented Apr 1, 2026

The autorouter was spitting out IDs like source_trace_0 and source_port_1 in error messages useful to no one.

This PR replaces those with actual net and component names so that when routing fails, you can tell what failed and where.
AI agents now get clean, readable logs pointing directly to the collapsed net or component.

Also hardened the table lookups with defensive guards and empty-list fallbacks so the autorouter no longer crashes on sparse or incomplete circuit JSON.

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 1, 2026

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

Project Deployment Actions Updated (UTC)
tscircuit-core-benchmarks Ready Ready Preview, Comment Apr 2, 2026 2:12pm

Request Review

Copy link
Copy Markdown
Contributor

@seveibar seveibar left a comment

Choose a reason for hiding this comment

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

@mohan-bee why did you refactor so much? Dont refactor and fix, turn off the linter youre using- otherwise the reviewer cant see or attribute what touve changed

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.

Don't console.log in tests, you can inline snapshot it

@mohan-bee
Copy link
Copy Markdown
Author

@seveibar do i have to fix that timeout issues in the test files ?

@seveibar
Copy link
Copy Markdown
Contributor

seveibar commented Apr 1, 2026

Not unless you caused them! Keep in mind the last person to merge to main have them all passing

@mohan-bee
Copy link
Copy Markdown
Author

@seveibar ready for review !

sourcePort.source_component_id as string,
)
return `${sourceComponent?.name ?? "unknown"}.${sourcePort.name}`
}
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.

import this method from @tscircuit/circuit-json-util instead

const readablePortA = getReadableName(db, portA.pcb_port_id)
console.error(
`(source_port_id: ${portA.source_port_id}) for trace ${trace.source_trace_id} does not have x/y coordinates. Skipping this trace.`,
`(pcb_port_id: ${readablePortA ?? portA.pcb_port_id}) for trace ${
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.

the text is literally wrong, it's not a pcb port id. Also you can commit to the readable name, remove the ??

Copy link
Copy Markdown
Contributor

@seveibar seveibar left a comment

Choose a reason for hiding this comment

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

see comments

@mohan-bee mohan-bee requested a review from seveibar April 2, 2026 03:56
Copy link
Copy Markdown
Contributor

@MustafaMulla29 MustafaMulla29 left a comment

Choose a reason for hiding this comment

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

It should be source_port_id not pcb_ port_id

@mohan-bee mohan-bee requested a review from MustafaMulla29 April 2, 2026 05:36
@MustafaMulla29
Copy link
Copy Markdown
Contributor

No, I think it should be source_port coz every other place it's source_port. Confirm with @seveibar

@mohan-bee
Copy link
Copy Markdown
Author

@MustafaMulla29 Since autorouting is a layout problem, pcb_port_id is more precise than source_port_id, which can map to multiple physical locations.

: "unknown"
console.error(
`(source_port_id: ${portB.source_port_id}) for trace ${trace.source_trace_id} does not have x/y coordinates. Skipping this trace.`,
`(${readablePortB}) for trace ${trace.source_trace_id} does not have x/y coordinates. Skipping this trace.`,
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.

why use the trace id? Trace ids aren't readable- can you use a readable name for the trace?

portB.y === undefined
) {
const readablePortB = portB.pcb_port_id
? getReadableNameForPcbPort(db.toArray(), portB.pcb_port_id)
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.

why aren't you using portB.getReadableName() or whatever

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.

don't use db.toArray()

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.

db.toArray() has a huge performance penalty

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

since they are plain objects from db list they don't have methods.

@MustafaMulla29
Copy link
Copy Markdown
Contributor

@MustafaMulla29 Since autorouting is a layout problem, pcb_port_id is more precise than source_port_id, which can map to multiple physical locations.

It's not about being precise, it's about convention.

Copy link
Copy Markdown
Contributor

@seveibar seveibar left a comment

Choose a reason for hiding this comment

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

This shouldn't even be a console.error, we use circuit json errors for errors, we don't use spys or mocks

@seveibar
Copy link
Copy Markdown
Contributor

seveibar commented Apr 2, 2026

@mohan-bee you're doing good stuff btw, it's just hard to contribute to core

@mohan-bee
Copy link
Copy Markdown
Author

@seveibar yes, i will learn things and reflect on the comments.

This reverts commit 23d19f8.
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.

3 participants