Skip to content

fix(platform): word lapsed-session failures and guard the rule - #3763

Merged
yannickmonney merged 8 commits into
mainfrom
fix/session-lapse-failure-detail
Sep 28, 2026
Merged

yannickmonney merged 8 commits into
mainfrom
fix/session-lapse-failure-detail

Conversation

@yannickmonney

Copy link
Copy Markdown
Contributor

Follow-up to #3685 (a lapsed session shows its sentence, not the payload), from its review. I re-checked each finding on main (88d74c6) before coding. The branch is rebased on 300bcf0.

What changed

Environment tab (high). On main, saving or removing a project secret after the session ended toasted Couldn't save environment above the serialized refusal ({"code":"UNAUTHORIZED",…}). The write hook's default toast also reported the same failure.

  • The tab's onSet/onDelete now reject with failureDetail(err) ?? common.errors.generic.
  • useSetProjectSecret/useDeleteProjectSecret pass errorToast: false, so a failed save raises one toast: Couldn't save environment above Your session has ended. Sign in again., localized.
  • In @tale/ui, EnvVarListEditor (inline) and EditorActions read the thrown value through a new readableErrorMessage (@tale/ui/error-message). It returns a plain error's sentence, and nothing for an error carrying data, an empty message or a non-error. Where it returns nothing, the toast shows the package's own "Something went wrong. Try again." The JSON editor's save toast reads it the same way.

A guard for the rule (medium). tests/guards/error-message-description.guard.test.ts walks every non-test source under services/platform/app and packages/ui/src. It fails on a toast/Alert description or title built from an error's message:

  • the x instanceof Error ? x.message ternary, on one line or across several;
  • description={err.message} and description: err.message;
  • an (x as Error).message cast;
  • String(err).

The guard also tests its own patterns against samples. It keeps an allowlist that needs a reason per entry and must stay live; it is empty today. Against main it flags the four sites the review named, plus json-input.tsx's toast title. Two of the flagged sites are Better Auth paths, the owner sign-up step and the forced password change's sign-out; both now read through failureDetail, so none needed allowlisting. The rule is written next to failureDetail and in .agents/repo.md.

  • Because the guard reads packages/ui/src as text, services/platform/turbo.json now hashes $TURBO_ROOT$/packages/ui/src/** for test. That entry subsumes main's new globals.css input; both readers stay in OUTSIDE_READS. The turbo-inputs guard holds it.
  • As a side effect, a design-system change now re-runs @tale/platform#test, its i18n suite included. test:ui and test:browser still replay; .agents/repo.md says so.

The seven failureDetail surfaces now have lapsed-session tests (medium). Each runs in en/de/fr, and each fails if its surface goes back to .message: Chat health's Alert, the document-history comparison toast (a new dialog test on the real hook and adapter row), the Google Drive and Microsoft 365 import toasts, and team create/edit/delete. The AUTH-B13 automation row lists them.

Team dialogs (low). authClientError (app/lib/auth/auth-client-error.ts) reads a Better Auth { error } the way the app reads a backend answer:

  • A 401 UNAUTHORIZED, or a bare 401, is the localized session sentence and is reported to the recovery flow. create-team really answers a bare 401 with an empty body, observed below.
  • Another refusal keeps the library's words.
  • A refusal without words shows only the title, so the English "Failed to create team"/"Failed to update team" fallbacks are gone.
  • "Team ID not returned" is now a fault with no detail.
  • A change of members alone that an ended session refuses also says so, instead of "1 membership change was refused".

Document comparison (low).

  • The hook stores a refusal's words or the localized history.compareFailed.
  • A body of the wrong shape is a fault, not a developer string.
  • The hook leaves the toast to the dialog, so it is one toast instead of two.
  • The lane's own refusal (COMPARISON_OFFLINE, which every comparison meets today) was English in every language. It now carries documents.history.compareOffline in en/de/fr.

"Failed to fetch" (the decision asked for). failureDetail now reads a request that got no answer as the localized common.errors.connectionLost. That covers Chromium's "Failed to fetch", Safari's "Load failed" and Firefox's wording, using the matcher the Sentry filter already had, now in app/lib/backend/transport-failure.ts. Any other runtime error (TypeError, SyntaxError, RangeError, …) yields no detail. No app code throws those types for display, and their messages are developer text.

Standing notice (low).

  • In the dashboard shell, the notice after Stay here now sits in the shell's alert stack, above the header, like the other shell alerts. It no longer floats over the header, so nothing is covered at any width.
  • On a narrow or short viewport it keeps to its title and Sign in; the sentence stays for screen readers. It pads the notch itself.
  • A dashboard page outside the shell (create-organization, changelog) keeps the floating notice.
  • AUTH-B14 and the member preferences page (en/de/fr) say where it is.

Stacking test (low). session-lapse-recovery.browser.test.tsx now renders the real StickyHeader and PanelHeader at 375×740, 900×400 (short) and 1280×800. It checks every header control and Sign in by hit-test, and checks that the notice stays under an open dialog. It also keeps the floating fallback's over-the-header check. dashboard-layout.test.tsx pins that the shell shows the notice once, above the page.

How I verified it

Every new test was run against main's code (the impl files checked out from origin/main, or the surface reverted to .message), and every one failed:

  • ui floor: 3 tests.
  • Environment tab: 6 tests; and 2 more when only the hook's toast was restored, which count 2 toasts.
  • Team dialogs: 14 tests.
  • Comparison: 13 tests.
  • Chat health and the imports: 9 tests.
  • The notice with the floating version in the shell: 4 browser tests.
  • The layout test when the shell does not mount the notice: 1 test.

The turbo guard fails without the new input.

Real browser (local backend, Vite dev SPA, Chromium 1194; the session signed out through the same cookie jar; toasts recorded as they mount):

Flow main this branch
Environment → add a variable → Save (en) Couldn't save environment {"code":"UNAUTHORIZED","message":"Your session has ended. Sign in again.",…} one toast: Couldn't save environment / Your session has ended. Sign in again.
same, de / fr, and removing a variable (en, de, fr) — Umgebung konnte nicht gespeichert werden / Deine Sitzung ist beendet. Melde dich erneut an.; Impossible d'enregistrer l'environnement / Ta session a pris fin. Reconnecte-toi.
Settings → Teams → Create team (de); Better Auth answered 401 with an empty body Team konnte nicht erstellt werden / Failed to create team Team konnte nicht erstellt werden / Deine Sitzung ist beendet. Melde dich erneut an.
Edit team → rename (en, fr); Better Auth answered 401 {"message":"Unauthorized","code":"UNAUTHORIZED"} Couldn't update team / Unauthorized Couldn't update team / Your session has ended. Sign in again. (fr: Échec de la mise à jour de l'équipe / Ta session a pris fin. Reconnecte-toi.)
Stay here on a 375 px phone, controls in the top 220 px hit-tested all 8 header controls covered by the notice (back, project switcher, account menu, every tab) notice is a static 49 px row above the header; all 8 header controls and Sign in pressable
same at 1280 px — full-width shell alert with title, sentence and Sign in; every control pressable

visual-aspect-analyzer was embedded and signed in, over the notice flow, before and after:

  • The scores are the same: desktop 68 → 68 and phone 53 → 53.
  • The defects are the same on main: the error toast's slide-in jank, page-load CLS 0.013–0.022, the added row's shift, and the phone capsule's flicker during auto-scroll.
  • On the phone, the six header flickers main showed are gone. They came from the tab strip being occluded by the floating notice.
  • The shell content moving down when the notice appears is the intended change; it happens right after the Stay here press.

Checks run locally, all passing:

  • Type-aware oxlint on all 39 changed TS files.
  • Scoped tsc over the changed platform files, and tsc for @tale/ui.
  • vitest for the changed files and what renders them: 37 UI files and 271 tests after the rebase, plus the platform files that render EditorActions/EnvVarListEditor, @tale/ui's env editor, JSON input and editor tests, and the browser tests of both workspaces.
  • lib/i18n/messages.test.ts, the docs suite (35 files), lint:manual, check-guide on auth.md, oxfmt --check on the repo.
  • knip reports only the existing oidcOrganizationClaims.

The whole platform suite and workspace-wide tsc are left to CI (the sandbox's 4 GB limit).

Left open

  • Double toasts elsewhere. Other surfaces still toast in their own catch while the hook's default toast is on: the Drive/OneDrive imports, team delete and team membership changes, and more. With TOAST_LIMIT 1 the person sees the last toast, but two fire. It's a separate sweep.
  • Other Better Auth surfaces. Organization settings, API keys, two-factor and passkeys can adopt authClientError; this PR moves the team dialogs only.
  • The comparison lane is still offline by design. Whether to keep offering Compare selected is a product decision; its refusal now reads in the person's language.
  • Notch on an installed iPhone app. The notice pads the notch, and the header below it still pads it too, so there is a blank band only in the lapsed state. The existing shell banners do not pad the notch at all.

The inline env editor and the header Save cluster described a failed save
with the thrown error's message. A backend refusal rethrown as-is carries
its payload on `data` and serializes it into `message` for logs, so the
toast read {"code":"UNAUTHORIZED",...} under its title.

Both now read the message through readableErrorMessage, which returns a
plain error's sentence and nothing for an error carrying `data`, an empty
message or a thrown non-error; the generic "Something went wrong" line
takes its place. The JSON editor's save toast reads it the same way.
Saving or removing a project secret after the session ended toasted the
refusal's serialized payload ({"code":"UNAUTHORIZED",...}) under "Couldn't
save environment", and the write hook's default toast reported the same
failure a second time.

The tab's writes now reject with the refusal's own words through
failureDetail, so a lapsed session reads as its localized sentence and a
fault as the generic line. The secrets hooks leave the failure toast to
the editor. The member preferences page says that saving an Environment
tab that was already open shows the session sentence, in all three
languages, and AUTH-B13 walks it.
failureDetail passed any plain error's message through, so a request that
got no answer showed the browser's own English ("Failed to fetch", "Load
failed" on Safari) under a German or French title, and a runtime fault
showed its developer text ("Cannot read properties of undefined").

A request that got no answer now reads as the localized
common.errors.connectionLost sentence, and an error the JavaScript runtime
raises (TypeError, SyntaxError, RangeError and the rest) yields no detail,
so the surface keeps its own title or fallback. The fetch-failure matcher
moves out of the Sentry filter into one module both read.
The rule that a surface shows a failure's words and never its payload had
no guard outside the chat feature. A new guard walks every non-test source
under the platform app and the design system and fails on a description or
title built from an error's message: the instanceof ternary on one line or
several, err.message as a prop or a property, an Error cast and a
stringified error. It checks its own shapes against samples, and keeps an
allowlist, empty today, whose entries must still match.

The last two offenders, the owner sign-up toast and the forced password
change's sign-out toast, read the failure through failureDetail. Because the
guard reads packages/ui/src as text, the platform's test task now hashes
it, and the turbo-inputs guard holds that. The rule is written down beside
failureDetail and in the repo contract.
The team dialogs call Better Auth directly and threw its refusal as a plain
error, so after the session ended the toast under the localized title read
"Unauthorized" for a rename, or the English fallback "Failed to create
team" for the bare 401 create-team answers. The developer string "Team ID
not returned" reached the toast the same way, and a change of members alone
was counted as refused instead of saying the session ended.

authClientError reads a Better Auth refusal the way the app reads a backend
answer. A 401 UNAUTHORIZED, or a bare 401, is the localized "session ended"
sentence and is reported to the recovery flow. Another refusal keeps the
library's words, and one without words shows only the title. The dialogs
throw it, an answer without a team id counts as a fault, and a membership
change refused by an ended session says so.
The version comparison answered every attempt with an English refusal
("Document comparison is offline while the platform AI backend is
rewritten"), showed "Comparison failed" in English for a fault and the
developer's "Invalid comparison response" for a body of the wrong shape.
It reported each failure three times: the action's default toast, the
dialog's toast and the line under the version picker.

The offline refusal now carries a localized sentence. The hook stores a
refusal's own words or the localized "Couldn't compare versions" line,
treats a malformed body as a fault, and leaves the toast to the dialog.
…ssion

The Chat health Alert and the Google Drive and Microsoft 365 import toasts
read a refusal through failureDetail, but nothing failed if one went back
to printing the error's message: their tests fed only plain strings. Each
now meets the session door's own refusal in English, German and French,
and must show the localized sentence and no serialized payload.

The AUTH-B13 automation row lists these tests with the other surfaces'.
After Stay here the standing notice floated over the top of the window.
Below about 536 px it spanned the full width and covered the page header,
its navigation trigger and actions included, until the person signed in,
which defeated staying to copy work.

In the dashboard shell the notice now sits in the alert stack above the
page, like the other shell alerts, so it covers nothing at any width. On a
narrow or short viewport it keeps to its title and Sign in, and it pads the
notch itself. A dashboard page without the shell keeps the floating notice.
The browser test now renders the real StickyHeader and PanelHeader at a
phone's, a short window's and a desktop's size, and the layout test pins
where the shell shows it. AUTH-B14 and the member preferences page say
where the notice is.
@yannickmonney
yannickmonney merged commit 9ae3127 into main Sep 28, 2026
50 checks passed
@yannickmonney
yannickmonney deleted the fix/session-lapse-failure-detail branch September 28, 2026 21:07
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.

1 participant