# Route order conflict with a path parameter: a 200 that lied

> A route order conflict with a path parameter let /profiles/:id/stop read 'bulk' as an id and answer 200. Our build now fails on any shadowed route.

Source: https://mosaicbrowser.com/blog/route-pattern-swallowed-a-path

## POST /profiles/bulk/stop answered 200 and stopped nothing

A route order conflict with a path parameter let /profiles/:id/stop read 'bulk' as an id and answer 200. Our build now fails on any shadowed route.

![A documented route, typed correctly, that did nothing](https://mosaicbrowser.com/covers/route-pattern-swallowed-a-path.webp)

A route order conflict happens when a router that takes the first match meets a path parameter registered above a literal path of the same shape. Ours had `/profiles/:id/stop` above `/profiles/bulk/stop`, so the parameter caught the word `bulk` as a profile id. The literal route was registered, documented and unreachable, and the request that should have reached it got a `200`.

## What the two calls returned

Mosaic's local [REST API](https://mosaicbrowser.com/features/rest-api) can start and stop a selection of profiles in one call. Both bulk routes sat in the file below the single-profile routes they resemble. These are the two answers we measured before the routes were moved:

```
POST /profiles/bulk/start   404  {"error":"Profile bulk not found"}
POST /profiles/bulk/stop    200  {"stopped":true}

```

The first is a nuisance. A caller gets an error, reads it, and wonders why the API is looking for a profile called `bulk`. The second is the one that matters. A caller who typed the documented path correctly got a success for an operation that never ran. Send it forty profile ids and all forty browsers stay open, while the script that asked for them to close moves on.

## How a route order conflict with a path parameter happens

Our router is small on purpose. It splits the path into segments and walks the routes in the order they were added. For each route with the same method and segment count, a segment starting with `:` matches anything and a literal segment must be equal. The first route where every segment passes wins.

`/api/v1/profiles/:id/stop` and `/api/v1/profiles/bulk/stop` are both five segments. The first was added earlier. Its `:id` accepts `bulk`, its `stop` equals `stop`, so it matched and the loop returned. The bulk handler was never consulted.

This is not peculiar to hand-written routers. FastAPI's tutorial has a section called "Order matters" for the same case: path operations "are evaluated in order", so `/users/me` has to be declared before `/users/{user_id}`. Some routers rank a literal segment above a parameter whatever the order. Ours did not, and nothing told us.

Mosaic is a desktop app

Email yourself the link and open it on your computer.

[How it works: REST API](https://mosaicbrowser.com/features/rest-api)

## Why the wrong route said yes

Shadowing explains why the bulk handler did not run. It does not explain the `200`. That came from a second fault in the single-profile handler: it never checked that the profile existed. Stopping an id the launcher had never seen resolved quietly, so the route answered `{"stopped":true}` for any string at all. We measured it on a uuid that had never existed and on the literal `bulk`, with the same answer for both.

The start route had the opposite habit. It looked the profile up, failed, and said so, which is why `bulk/start` came back as a readable 404. Same shadowing, same router, and only one of the two routes could tell a typo from a real id.

The fix for the second fault is one line. The stop handler looks the profile up first, and an unknown id is a 404. Stopping a profile that exists and is not running is still a success, because the caller asked for an end state and has it. Stopping a profile that does not exist is a mistake in the request.

## The fix, and why it is a build check

Moving the two bulk routes above `/profiles/:id/start` fixed them. The other `bulk/*` routes had been safe only by luck: nothing declares `/profiles/:id/edit` or `/profiles/:id/delete`, so nothing could shadow them. Somebody adding `/profiles/:id/<word>` next year would break them again in the same silent way.

So `npm run check:api`, which already failed the build when a route was missing from the API reference, also reads the routes in registration order. For every pair with the same method and segment count, it asks whether the earlier one matches the later one with at least one parameter doing the work:

```
for k in segments:
  earlier[k] is :param and later[k] is :param  -> different route, no conflict
  earlier[k] is :param                         -> eats later[k]
  earlier[k] != later[k]                       -> no conflict
conflict if every segment passed and a param was used

```

A hit fails the build with both routes named and one instruction: register the literal path above the one with the parameter. The check could not have been written on the old data. Its first version kept the routes in a set, which proved that `bulk/stop` existed and was documented the whole time it was broken. A set has no order, and order was the whole question.

The same check now guards three more literals our comments call out by name. `GET /providers/vendors` would otherwise answer `Provider vendors not found`, `GET /proxies/checking` would answer `Proxy checking not found`, and `/proxies/export` would be read as a proxy id.

## What a caller should do about it

If an API answers a bulk or literal route with something that looks like a single-item reply, suspect shadowing first. Two signs give it away. The error names your literal as an id, as `Profile bulk not found` did. Or the response has the single-item shape (`{"stopped":true}`) where the bulk route documents counts and failures by id: ours answers `ok`, `skipped` and a `failures` list naming each profile.

Mosaic's [local API guide](https://mosaicbrowser.com/guides/anti-detect-browser-local-api) lists every route as it is registered, and the reference and the router are held to each other by the same check. Our [tally that counted rows nobody could read](https://mosaicbrowser.com/blog/tally-counted-declarations) is the same lesson from the detector side: a claim that something exists is not a measurement that it ran.

## Sources

1. [FastAPI tutorial: Path Parameters, Order matters](https://fastapi.tiangolo.com/tutorial/path-params/), read November 3, 2026

## Questions

### Why does my literal route never get called?

In a router that takes the first match, a pattern such as /profiles/:id/stop registered earlier also matches /profiles/bulk/stop, with id set to bulk. Register the literal route above the pattern, or use a router that ranks literal segments first.

### Does route order matter in FastAPI?

Yes. FastAPI's tutorial says path operations are evaluated in order, so /users/me has to be declared before /users/{user_id}, or the second one receives me as a user id.

### How can I catch route shadowing automatically?

Walk the routes in registration order and, for each pair with the same method and segment count, flag an earlier route whose parameters line up with a later route's literals and whose literals all agree. Ours runs in the build and names both routes.

### Why did the shadowed stop route return 200 instead of 404?

The stop handler never checked that the profile existed. Stopping an id the launcher had never seen resolved quietly, so any string, including bulk, got stopped: true. The handler now looks the profile up first and answers 404 for an unknown id.

## Related

[Anti-detect browser REST API: profiles from your scripts](https://mosaicbrowser.com/features/rest-api): Mosaic's anti-detect browser REST API runs on 127.0.0.1 with API keys. Create and start profiles, then attach Puppeteer or Playwright over CDP.

[Anti-detect browser local API: what it is and what to check](https://mosaicbrowser.com/guides/anti-detect-browser-local-api): An anti-detect browser local API is an HTTP server on 127.0.0.1 that creates, starts and stops profiles and hands your script a DevTools endpoint.

[Our detector tally counted rows nobody could read](https://mosaicbrowser.com/blog/tally-counted-declarations): Our docs said 34 automatic detectors while 3 had no extractor. The tally counted labels, not results, so every run now checks claim against outcome.

[Three MCP tool descriptions that told a model something untrue](https://mosaicbrowser.com/blog/tool-description-is-the-contract): Auditing 47 MCP tools found a field that did not exist, a trash called irreversible and a device list with no phones. A description is the model's contract.









[A regex that lost its backslashes inside a template literal](https://mosaicbrowser.com/blog/regex-in-template-literal): A template literal turns \s into s, so a regex shipped inside one matches nothing and throws nothing. It hid five of our detector rows as unread.

[Thirty tabs open: why a test suite needs a fresh tab per site](https://mosaicbrowser.com/blog/one-tab-per-detector): Captcha popups and ad windows left about 30 tabs open in our detector runner. Now each test gets its own tab, and a sweep closes every stray when it ends.

## Mosaic, on your own computer

The browser this blog is about: its own Chromium, fingerprints from real machines and a proxy IP per profile. Free covers 3 profiles with no card, and Pro is $25 a month for any number of them.

Mosaic is a desktop app

Email yourself the link and open it on your computer.
