Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/de/self-hosted/configuration/observability-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ Fehler, die auf keinen Defekt in Tale hinweisen, meldet der Browser nicht:
- Anfragen, die die Seite selbst abgebrochen hat, etwa weil du sie vor dem vollständigen Laden verlassen hast
- Anfragen, die das Backend mit einem Status unter 500 ablehnt, etwa bei fehlender Berechtigung oder einem bereits vergebenen Namen
- Anfragen, die gar keine Antwort erhalten, zum Beispiel weil das Gerät offline ist
- Anfragen, die fehlschlagen, während die Plattform oder ihre Datenbank neu startet: `UPSTREAM_UNAVAILABLE` vom Proxy während eines Deployments oder Neustarts und `503 DATABASE_UNAVAILABLE` von der Plattform

Serverfehler ab Status 500 meldet er weiterhin.
Andere Serverfehler ab Status 500 meldet er weiterhin.

## Aggregierte Nutzungsstatistik mit Umami

Expand Down
3 changes: 2 additions & 1 deletion docs/en/self-hosted/configuration/observability-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ The browser leaves out errors that do not indicate a defect in Tale:
- requests the page cancelled itself, for example because you left the page before it finished loading
- requests the backend refused with a status below 500, such as a missing permission or a name that is already taken
- requests that got no response at all, for example while the device was offline
- requests that fail while the platform or its database restarts: the proxy's `UPSTREAM_UNAVAILABLE` during a deployment or restart, and the platform's `503 DATABASE_UNAVAILABLE`

Server errors, with a status of 500 or above, are still reported.
Other server errors, with a status of 500 or above, are still reported.

## Aggregate analytics with Umami

Expand Down
3 changes: 2 additions & 1 deletion docs/fr/self-hosted/configuration/observability-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ Le navigateur ne signale pas les erreurs qui ne révèlent aucun défaut de Tale
- les requêtes que la page annule elle-même, par exemple quand tu la quittes avant la fin de son chargement
- les requêtes que le backend refuse avec un statut inférieur à 500, par exemple faute d’autorisation ou parce qu’un nom est déjà pris
- les requêtes restées sans aucune réponse, par exemple quand l’appareil est hors ligne
- les requêtes qui échouent pendant que la plateforme ou sa base de données redémarre : `UPSTREAM_UNAVAILABLE` du proxy pendant un déploiement ou un redémarrage, et `503 DATABASE_UNAVAILABLE` de la plateforme

Les erreurs serveur, de statut 500 ou plus, restent signalées.
Les autres erreurs serveur, de statut 500 ou plus, restent signalées.

## Statistiques agrégées avec Umami

Expand Down
106 changes: 106 additions & 0 deletions services/platform/app/lib/backend/platform-unavailable.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// @vitest-environment node
import { Hono } from 'hono';
import { describe, expect, it, vi } from 'vitest';

import { appErrorHandler } from '@/backend/error-reporting';

import {
BackendApiError,
backendApiErrorFromBody,
readBackendApiError,
} from './api-client';
import { isPlatformUnavailable } from './platform-unavailable';

/** The edge's envelope as `services/proxy/Caddyfile` writes it for a machine
* door while the platform does not answer, with the status of the error it
* stands for. */
const EDGE_UNAVAILABLE = {
error:
'The platform is not answering right now — a deployment may be rolling; retry with backoff',
code: 'UPSTREAM_UNAVAILABLE',
requestId: '9d607850-ceb6-4990-b1e8-2e8d27199ffd',
};

/** What a real app door answers while its database restarts. */
async function databaseRestartAnswer(): Promise<Response> {
const app = new Hono();
app.onError(appErrorHandler);
app.get('/api/app/tasks', () => {
throw Object.assign(new Error('terminating connection'), {
code: '57P01',
});
});
return app.request('http://localhost/api/app/tasks');
}

describe('isPlatformUnavailable', () => {
it.each([502, 503, 504])(
"reads the edge's %i while the platform does not answer",
(status) => {
expect(
isPlatformUnavailable(
backendApiErrorFromBody(status, EDGE_UNAVAILABLE),
),
).toBe(true);
},
);

it("reads the platform's own answer while its database restarts", async () => {
const warn = vi.spyOn(console, 'warn').mockImplementation(() => undefined);
try {
const error = await readBackendApiError(await databaseRestartAnswer());
expect(error.status).toBe(503);
expect(error.code).toBe('DATABASE_UNAVAILABLE');
expect(isPlatformUnavailable(error)).toBe(true);
} finally {
warn.mockRestore();
}
});

it('is false for every other failure', () => {
// The backend's own fault: a text 500 the app reads by status alone.
expect(
isPlatformUnavailable(
backendApiErrorFromBody(500, 'Internal Server Error'),
),
).toBe(false);
// A 502 from something other than the edge's rule: no code at all.
expect(isPlatformUnavailable(backendApiErrorFromBody(502, null))).toBe(
false,
);
// A dependency the platform answers for, not the platform itself.
expect(
isPlatformUnavailable(
new BackendApiError(
503,
'Object store unavailable',
'OBJECT_STORE_UNAVAILABLE',
),
),
).toBe(false);
// Either code at a status it never comes with.
expect(
isPlatformUnavailable(
new BackendApiError(
500,
'Database unavailable',
'DATABASE_UNAVAILABLE',
),
),
).toBe(false);
expect(
isPlatformUnavailable(
new BackendApiError(
400,
'Upstream unavailable',
'UPSTREAM_UNAVAILABLE',
),
),
).toBe(false);
// Not a backend answer at all.
expect(isPlatformUnavailable(new Error(EDGE_UNAVAILABLE.error))).toBe(
false,
);
expect(isPlatformUnavailable(undefined)).toBe(false);
});
});
30 changes: 30 additions & 0 deletions services/platform/app/lib/backend/platform-unavailable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { BackendApiError } from './api-client';

/**
* The answers that say the platform is briefly not there — restarting, or a
* deployment rolling — and to retry after `Retry-After`, by code and the
* statuses each comes with:
* - `UPSTREAM_UNAVAILABLE` (502, 503 or 504), which the edge answers for the
* platform when it cannot reach it (`services/proxy/Caddyfile`);
* - `DATABASE_UNAVAILABLE` (503), which the platform answers while its
* database restarts (`backend/error-reporting.ts`) and does not report
* itself.
*/
const PLATFORM_UNAVAILABLE: ReadonlyMap<string, readonly number[]> = new Map([
['UPSTREAM_UNAVAILABLE', [502, 503, 504]],
['DATABASE_UNAVAILABLE', [503]],
]);

/**
* Whether a request failed because the platform, or its database, was
* briefly gone. Every request in flight meets such an answer at once, so the
* browser reports none of them as a defect (`app/lib/sentry-normalize.ts`).
* Any other 5xx stays a fault, and so does either code at another status.
*/
export function isPlatformUnavailable(error: unknown): boolean {
return (
error instanceof BackendApiError &&
error.code !== undefined &&
PLATFORM_UNAVAILABLE.get(error.code)?.includes(error.status) === true
);
}
80 changes: 76 additions & 4 deletions services/platform/app/lib/sentry-normalize.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { describe, expect, it } from 'vitest';

import { toBackendError } from '@/app/lib/backend/adapters';
import { BackendApiError } from '@/app/lib/backend/api-client';
import {
BackendApiError,
backendApiErrorFromBody,
} from '@/app/lib/backend/api-client';
import { AppError } from '@/lib/shared/errors/app-error';

import {
Expand Down Expand Up @@ -350,15 +353,15 @@ describe('prepareSentryEvent', () => {
it('keeps a 5xx, even one carrying structured data', () => {
const fault = new BackendApiError(
503,
'Database unavailable',
'DATABASE_UNAVAILABLE',
'Object store unavailable',
'OBJECT_STORE_UNAVAILABLE',
{ retryAfterMs: 5000 },
);
// The adapter lane passes a 5xx through untouched.
expect(toBackendError(fault)).toBe(fault);
expect(
prepareSentryEvent(
thrown('BackendApiError', 'Database unavailable', APP_SCRIPT),
thrown('BackendApiError', 'Object store unavailable', APP_SCRIPT),
{ originalException: fault },
),
).not.toBeNull();
Expand Down Expand Up @@ -410,6 +413,75 @@ describe('prepareSentryEvent', () => {
});
});

describe('an unavailable platform', () => {
// What the mutation hooks and the error boundaries log while the platform
// restarts — one event per failed request, from every open tab (GlitchTip
// tale/tale #109).
const EDGE =
'The platform is not answering right now — a deployment may be rolling; retry with backoff';
const DATABASE =
'The platform’s database is not answering right now — it may be restarting; retry with backoff';

it.each([502, 503, 504])(
"drops the edge's UPSTREAM_UNAVAILABLE at %i",
(status) => {
expect(
prepareSentryEvent(thrown('BackendApiError', EDGE, APP_SCRIPT), {
originalException: backendApiErrorFromBody(status, {
error: EDGE,
code: 'UPSTREAM_UNAVAILABLE',
requestId: 'edge-1',
}),
}),
).toBeNull();
},
);

it("drops the platform's DATABASE_UNAVAILABLE", () => {
expect(
prepareSentryEvent(thrown('BackendApiError', DATABASE, APP_SCRIPT), {
originalException: backendApiErrorFromBody(503, {
error: DATABASE,
code: 'DATABASE_UNAVAILABLE',
requestId: 'req-1',
}),
}),
).toBeNull();
});

it('keeps the backend’s own fault and a 502 the edge did not word', () => {
expect(
prepareSentryEvent(
thrown(
'BackendApiError',
'Request failed with status 500',
APP_SCRIPT,
),
{ originalException: backendApiErrorFromBody(500, null) },
),
).not.toBeNull();
expect(
prepareSentryEvent(
thrown(
'BackendApiError',
'Request failed with status 502',
APP_SCRIPT,
),
{ originalException: backendApiErrorFromBody(502, null) },
),
).not.toBeNull();
});

it('judges the thrown value, never the text an event carries', () => {
expect(
prepareSentryEvent(thrown('BackendApiError', EDGE, APP_SCRIPT)),
).not.toBeNull();
expect(
prepareSentryEvent({ message: `Mutation failed: ${EDGE}` }),
).not.toBeNull();
});
});

it('normalizes the events it keeps', () => {
const event = prepareSentryEvent({ message: RAW_ACTION_FAILURE });
expect(event?.message).toBe(
Expand Down
22 changes: 16 additions & 6 deletions services/platform/app/lib/sentry-normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Prepare browser events before they leave for Sentry/GlitchTip: drop what is
* not ours to fix, and normalize what is.
*
* `prepareSentryEvent`, the app's `beforeSend`, drops four kinds of event:
* `prepareSentryEvent`, the app's `beforeSend`, drops five kinds of event:
* - a cancelled request (`isAbortErrorEvent`), which reports no failure at
* all;
* - an error a browser extension threw, told by its innermost frame. One
Expand All @@ -11,7 +11,13 @@
* - an expected refusal: a 4xx the surface already explains, which the
* mutation and action hooks still log through `console.error`;
* - a transport failure: the TypeError the browser raises for a request that
* got no answer at all, which the offline overlay already reports.
* got no answer at all, which the offline overlay already reports;
* - a request the platform was briefly gone for (`isPlatformUnavailable`):
* the edge's `UPSTREAM_UNAVAILABLE` while it restarts or a deployment
* rolls, the platform's `DATABASE_UNAVAILABLE` while its database
* restarts. Every open tab meets one at once, and the failed write's toast
* or the list's error state already tells the person; one restart used to
* open an error event per failed request.
*
* What stays is normalized. Convex composes every client-visible failure as
* `[CONVEX A(agents/actions:listAgents)] [Request ID: 018f2a…] Server Error
Expand All @@ -25,6 +31,7 @@
*/

import { isBackendRefusal } from '@/app/lib/backend/adapters';
import { isPlatformUnavailable } from '@/app/lib/backend/platform-unavailable';
import { TRANSPORT_FAILURE_RE } from '@/app/lib/backend/transport-failure';
import { isAbortError } from '@/lib/utils/abort-error';

Expand Down Expand Up @@ -201,10 +208,12 @@ function isTransportFailure(event: NormalizableSentryEvent): boolean {

/**
* The app's `beforeSend`: drop a cancelled request, an extension's error, an
* expected refusal and a transport failure (`null` tells the SDK not to
* send), and normalize every event that stays. A refusal is judged on the
* expected refusal, a transport failure and a request the platform was
* briefly gone for (`null` tells the SDK not to send), and normalize every
* event that stays. A refusal and an unavailable platform are judged on the
* thrown value itself, which the SDK hands over as `hint.originalException`:
* a `BackendApiError` keeps its status there, so a 5xx still reports.
* a `BackendApiError` keeps its status and code there, so every other 5xx
* still reports.
*/
export function prepareSentryEvent<Event extends NormalizableSentryEvent>(
event: Event,
Expand All @@ -214,7 +223,8 @@ export function prepareSentryEvent<Event extends NormalizableSentryEvent>(
isAbortErrorEvent(event, hint) ||
isFromBrowserExtension(event) ||
isBackendRefusal(hint?.originalException) ||
isTransportFailure(event)
isTransportFailure(event) ||
isPlatformUnavailable(hint?.originalException)
) {
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions services/platform/tests/manual/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ tale-project standard ([`AGENTS.md`](../../../../AGENTS.md) "Manual tests"), and

## The suites

1062 boxes across 21 suites. Every suite declares the ID prefix its
1063 boxes across 21 suites. Every suite declares the ID prefix its
boxes carry, in its header blockquote; a box ID is unique across this whole
directory and greppable as one token.

Expand All @@ -49,7 +49,7 @@ directory and greppable as one token.
| [navigation](suites/navigation.md) | `NAV-` | side-nav rail + the Home panel, section panels, breadcrumbs, command palette, changelog, page-loads | 66 |
| [notifications](suites/notifications.md) | `NOTIF-` | the notification bell + panel | 32 |
| [origins](suites/origins.md) | `ORIGIN-` | one deployment on several origins: sessions, file links, sign-in doors, an external TLS terminator | 12 |
| [performance](suites/performance.md) | `PERF-` | cold load, chat TTFT, thread switch, pagination | 18 |
| [performance](suites/performance.md) | `PERF-` | cold load, chat TTFT, thread switch, pagination | 19 |
| [projects](suites/projects.md) | `PROJ-` | projects, agents, tasks (attachments, comments), files, secrets, threads, Home's projects section | 59 |
| [responsive](suites/responsive.md) | `RESP-` | mobile viewport, bottom tab bar, the phone's Home list, mobile save bar, the narrow page column, short viewports | 34 |
| [settings](suites/settings.md) | `SET-` | account, personalization, usage, org, teams, branding, connectors, API, providers | 114 |
Expand Down
Loading
Loading