fix(routes): report an upstream routing outage as unavailable

When the OSRM routing service failed (a 5xx, a 403 block, a 404), answered
with a body that was not JSON, or did not answer at all (timeout, network
error), /api/route returned HTTP 200 with 'no route found' or 'route proxy
error'. plan_route turned that into invalid_arguments ("No walk route from
...: no route found"), blaming the caller for an outage, and the directions
layer reported "No route found between A and B".

The proxy now answers all of these with 502 {ok:false, error:'routing
service unavailable'}: a rejected upstream fetch, any failure status but
400, a non-JSON content type, and a body read that fails or does not parse.
An exception in the proxy's own code after that point is still a 200 'route
proxy error'. createRouteService throws for a 5xx before reading the body's
ok:false, so plan_route reports unavailable, and the directions source
treats any 5xx as "Routing unavailable (HTTP n)", also when the failure
page in front of the proxy is not JSON. OSRM's own refusal (a 400 such as
NoRoute, or a 200 without a route) still reads "no route found".

The 12 s upstream timeout now starts when the request leaves rather than
before it waits for an outbound slot, so a wait in the proxy's own queue
(up to about 8 s at the 1 s spacing) is not reported as an outage.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
quanticsoul4772andClaude Opus 5.5 committed 2026-11-02 08:42:57 -08:00
1 parent ebd8439868
commit f8795ff426
7 files changed
+223 -34

No files matched your search

+4 -1
View File
@@ -189,7 +189,10 @@ export function createRouteService({
} catch {
/* the status below is authoritative */
}
if (response.status === 429) throw httpFailure(response, 'Routing');
// A rate limit or an outage (5xx) is the routing service's failure, not
// a missing route, whatever the body says.
if (response.status === 429 || response.status >= 500)
throw httpFailure(response, 'Routing');
if (payload?.ok === false || response.status === 400)
return { ok: false, error: payload?.error || 'no route found' };
if (!response.ok) throw httpFailure(response, 'Routing');
+36
View File
@@ -1,6 +1,7 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { composeCatalog, coreTools } from '../index.js';
import { createMcpServer } from '../mcp/index.js';
import { createPlaceSearchService, createRouteService } from '../places.js';
const place = (id, latitude, longitude, extra = {}) => ({
@@ -249,6 +250,41 @@ test('the place and route services read the app routes and translate failures',
);
});
test('a routing outage is reported as unavailable, not as invalid arguments', async () => {
for (const fetchImpl of [
async () =>
Response.json(
{ ok: false, error: 'routing service unavailable' },
{ status: 502 },
),
async () => {
throw new TypeError('fetch failed');
},
]) {
const catalog = composeCatalog({
tools: coreTools,
services: { routing: createRouteService({ fetchImpl }), places },
});
const server = createMcpServer({
catalog,
name: 'test',
version: '1.0.0',
});
const { result } = await server.handle({
jsonrpc: '2.0',
id: 1,
method: 'tools/call',
params: {
name: 'plan_route',
arguments: { from: { place: 'Austin' }, to: { place: 'Dallas' } },
},
});
assert.equal(result.isError, true);
assert.equal(result.structuredContent.error, 'unavailable');
assert.doesNotMatch(result.content[0].text, /No walk route/);
}
});
test('place answers say when the search limits may have left places out', async () => {
const five = Array.from({ length: 5 }, (_, index) =>
place(`p${index}`, 30.27, -97.74),