Skip to content

Router: make tool-collision suffixes deterministic across server remove/re-add #356

Description

@tsouth89

Problem

The router assigns collision suffixes (_2, _3, ...) to tools whose exposed names would otherwise collide, but it does so in add order. exposed_name (src-tauri/src/router.rs) allocates names against a seen set as each server is indexed, so the first tool to a given name keeps the base and later ones get _2, _3, and so on.

That's stable across a refresh (same servers, same order), which refresh_keeps_collision_suffixes_stable covers. It is not stable across a server being removed and re-added, or servers being added in a different order: a tool exposed as foo can come back as foo_2, or two colliding tools can swap suffixes.

When that happens, a client that cached the old exposed name calls it, route_of returns None, and the call fails with "no route" even though the tool is still present.

Fix

Make the collision-suffix assignment deterministic and independent of add/remove order:

  • Derive the suffix from a stable key (for example, sort the colliding (server_id, original_tool_name) pairs and assign suffixes in that order) instead of insertion order, so the same set of tools always yields the same exposed names.
  • Keep the routes reverse-map consistent with whatever scheme you pick.
  • Preserve the existing guarantee that toggling or blocking one tool never renumbers its siblings (see the "Allocate the exposed name regardless of policy" comment in index).

Tests

Add coverage for the remove/re-add case (extend the pattern in refresh_keeps_collision_suffixes_stable): build a router with tools that collide across servers, record the exposed names, then remove and re-add a server (and/or add servers in a different order) and assert the exposed names are unchanged.

Files: src-tauri/src/router.rs.

Metadata

Metadata

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions