Skip to content

fix(platform): name the refused field at the app doors and in forms - #3538

Merged
yannickmonney merged 20 commits into
mainfrom
fix/app-door-refusals-name-field
Sep 28, 2026
Merged

yannickmonney merged 20 commits into
mainfrom
fix/app-door-refusals-name-field

Conversation

@yannickmonney

@yannickmonney yannickmonney commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

T26 (TALE-84, with TALE-162 and TALE-103 as its duplicates): about 190 app-door routes answered a body their schema refused with a bare { error: 'invalid body' }. The dialog could only say "invalid body", and GlitchTip got the same opaque AppError. On 0.5.55 the Products, Contacts and Data residency forms still let through values the server refuses.

What changed

Every app door names the field (services/platform/backend/lib/invalid-body-response.ts)

  • All 157 bare sites in 37 route files now answer through invalidBodyResponse(c, zodError). That helper came in fix(platform): close the 2026-09-26 platform evaluation's S3 findings #3498; until now only products and contacts used it. The answer keeps the invalid body code and adds a field: reason message and data.issues. The inline describeIssues copy in knowledge entries is gone too.
  • One refusal lists at most 20 issues, the same bound the REST door uses, so a hostile body is never echoed back at length.
  • New invalidBodyIssuesResponse(c, issues) gives the same shape for a refusal that no schema raised: a share body or embedding body that is not JSON, or an automation save without document.
  • The email reply and compose refinement is refused at content ("must not be empty unless files are attached"). It used to show up as an unnamed "Invalid input" on the whole body.
  • A guard in invalid-body-response.test.ts fails on any bare error: 'invalid body' left under backend/. A second case makes sure the scan can't pass without matching anything.

The SPA shows the reason

  • invalidBodyReason(err) in lib/utils/backend-error.ts returns the sentence of an invalid body refusal. For any other code it returns nothing, because another code's message is not a display contract.
  • The default toasts of useBackendMutation / useBackendAction, plus the two task toasts that override them, now show that sentence instead of "Try again". Sending the same body again would only fail again.
  • The contact create and edit toasts carry backendRefusalReason the way the product dialogs already did.

Client validation now matches the server

  • Contacts (TALE-162). The form trims each field and caps it with the caps the door uses: Name 300, Email 320 with at most 64 characters before the @, Phone 50, Locale 20. Those caps moved next to the contact patterns in lib/shared/schemas/common.ts. The OpenAPI spec and the door read them from there too.
  • Products (TALE-84). A pasted image address has to be an absolute http(s) URL or the app path an upload returned (utils/product-image-url-schema.ts). The parity test checks that the door refuses the same values. The error now shows under Image URL when that field is visible. Whether a host is public is still the door's decision, because it depends on deployment policy, and its reason is shown on the toast.
  • Data residency (TALE-103). Test connection sent the form without checking it, so an empty host came back as invalid body on the result line. Save and Test now go through one check per section, which marks the fields and focuses the first one without sending anything. Required fields are judged after trimming, the way they are sent: a database made of spaces passed === '' and came back as a 400. Every field has the door's length cap. The sources are PG_HOST_PATTERN and KNOWLEDGE_CONNECTION_PASSWORD_MAX in @tale/shared/schemas/knowledge, which replace the form's mirrored regex, and OBJECT_STORAGE_CONNECTION_MAX in lib/shared/schemas/object_storage.ts.
  • New key products.edit.validation.imageUrl in en, de and fr. de-CH needs no override. The docs (platform/knowledge/structured-data, self-hosted/configuration/data-residency) now say what the forms check, in EN, DE and FR.

Manual layer: added KNOW-B13 and DATA-B8, plus one reference/automation.md row that names the owning specs. I checked the IDs against #3524 (KNOW-F30) and #3527 (DATA-F12).

Verification

  • Regression proof: I swapped each changed source back to origin/main, one at a time. Every new test failed and passed again with the fix:
    • invalid-body-response.test.ts guard (with feedback/routes.ts from main)
    • conversations routes 7/7 (sentAt path, empty-reply content path)
    • automations ask-answer 4/4 (answer path)
    • contact dialog 5/5 (the four caps and the toast reason)
    • product create + edit 2/2 (image URL)
    • data-residency 4/4 (knowledge Test with an empty form, database of spaces, storage Test with a blank region, bucket over the cap)
    • useBackendMutation / useBackendAction 2/2 (toast reason)
  • These pass on main too, and pin existing behaviour: "values at the caps, trimmed", the invalidBodyReason unit cases, and the image-URL parity cases.
  • Local runs (shared box, scoped):
    • vitest server project over every changed backend domain, backend/lib, lib/utils and scripts/openapi: 260 files, 2234 tests passed.
    • vitest client project over app/features/{contacts,products,settings/data-residency,tasks/hooks} and both hooks: 263 passed.
    • lib/i18n: 185 passed, with no report-mode finding on the new key. @tale/shared knowledge.test.ts: 24 passed. services/docs suite: 166 passed.
    • oxlint --type-aware and oxfmt --check on every changed file: clean. A scoped tsc --noEmit over the changed files and their imports: clean.
    • bun run lint:manual is ok, and check-guide.ts is OK on both touched suites.
  • Not observed: I didn't drive these in a real browser. The component tests render the dialogs and sections, and the two manual boxes cover the rest.

Left open

  • Clearing a contact's phone in Edit does nothing. The dialog sends phone: ''. The door's blankAsAbsent reads that as "not sent", so the old number stays behind a success toast. This is a silent no-op, not a 400, so it's out of scope here. The fix is to send null and widen the contract's phone?: string to allow it.
  • The import dialogs don't check the 1,000-row cap. A contacts or products file with more than 1,000 rows is refused as a whole body. The toast now names contacts/products and the cap, but the dialogs don't split the file or check its size first.
  • The messages are zod's English. The app-door sentences use zod's default wording ("Too big: expected string to have <=300 characters"), not the REST door's house wording, which needs a per-parse error map at each of the ~190 parse sites. The forms show localized messages before anything is sent, so these sentences reach a person only for refusals a form doesn't know.
  • Query and other refusals are still bare. invalid query (8 sites) and a few other codes (invalid email, invalid purpose, invalid status) still give no field. They were outside this task.

yannickmonney and others added 20 commits September 27, 2026 19:39
About 190 app doors answered a body their schema refused with a bare
`{ error: 'invalid body' }`: the dialog could only say "invalid body",
and the error report carried the same opaque code, so nobody could tell
which field the form had let through.

Every door now answers through `backend/lib/invalid-body-response.ts`:
the same `invalid body` code, a `field: reason` message and the issues
under `data.issues`. `invalidBodyIssuesResponse` covers a refusal no
schema raised (a body that is not JSON, the automation save's missing
`document`). An email with neither body nor files is refused at
`content`. A guard test fails any bare literal left under `backend/`.

The caps a form has to mirror now live where the app can read them:
the contact caps beside the contact patterns in `lib/shared`, the
object-storage connection caps in its shared schema, and the Postgres
host rule and password cap in `@tale/shared/schemas/knowledge`.
The UI evaluations kept hitting `invalid body` on Products, Contacts and
Data residency (TALE-84, TALE-162, TALE-103): each form let through a
value the door refuses.

- Contacts: the form trims and caps Name (300), Email (320, at most 64
  characters before the `@`), Phone (50) and Locale (20) with the
  shared caps, and both dialogs put a refused body's reason on the toast.
- Products: a pasted image address must be an absolute http(s) URL (or
  the app path an upload returned); the error sits under Image URL.
- Data residency: Test connection checks the fields the way Save does
  and names what it would refuse instead of sending it; required fields
  are judged trimmed, as they are sent, and every field has the door's
  length cap.
- The default mutation and action toasts (and the task toasts) show an
  `invalid body` refusal's field-naming sentence instead of "Try again".

New `products.edit.validation.imageUrl` in en, de and fr; the product
and self-hosted data-residency docs say what the forms check, in all
three languages. Manual boxes KNOW-B13 and DATA-B8, with the owning
specs in the automation register.
The workspace-tool bridge kept only the code of a domain refusal. An
agent's task_create with a description over 20,000 code units or a label
over 50 came back as "TASK_DESCRIPTION_INVALID: the domain refused these
arguments.", so the model could not tell which limit it broke. The domain
threw one "Invalid title" for an empty and an over-long title on the human
create and edit paths, and the tasks app door dropped the domain's message
altogether.

- core/tasks/helpers.ts now holds the refusal sentences beside the limits.
  Each names the cap, the unit every cap is measured in (UTF-16 code
  units, where most emoji count as 2) and the length measured, never the
  value. validateTitle tells an empty title from an over-long one, and the
  description, label count, label name and comment caps are named.
- toolResultFromError relays the domain's sentence beside the code, and
  nothing else from the refusal's payload.
- The agent-comment writer moves into the coded write shim, so an
  over-long comment answers invalid_args instead of error.
- workspace_status states every cap of task_create, task_comment and
  task_upsert_by_external_ref from the shared constants, in code units.
- The tasks app door answers a domain refusal with its message, and an
  empty title on create reaches the domain instead of a bare invalid body.

Closes #3155
asAppError translated every error carrying a string code and a numeric
status, so a MentionDirectoryError (503) on an agent comment reached the
model as invalid_args and was audited so. Only a 4xx refusal is
translated now; a coded 5xx stays a plain error and answers `error`.
…ence

A blank or whitespace-only title at the tool door still answered the
generic 'needs a non-empty "title" string', naming neither the range nor
its unit. It now answers taskTitleRefusal's empty sentence, the one the
domain's validateTitle throws; a missing or non-string title keeps the
generic text.
The tasks door's schema carried caps of its own above the domain's (a
title up to 500, a description up to 50,000, up to 100 labels, a comment
min(1)), and anything it refused answered a bare `invalid body` that
could not tell an empty title or comment from an over-long one. The
title, description, label count and comment body are now checked with
the domain's own refusal helpers and answer `{error: <code>, message}`,
before a rate-limit slot is spent.
A task refusal's sentence now reaches the app door and an agent's tool
result, yet SETUP_FOLDER_MISSING echoed the setup folder name it was
sent. The sentence names the rule instead, and a guard reads every
TaskError, TaskReviewError and task-domain ProjectError message so a new
interpolated value fails until it is made static or reviewed.
The REST reference and the house schema messages said "characters" for
the task title, description, label, comment and translation caps, which
count UTF-16 code units like the domain's refusals. The schema messages
and the en/de/fr reference now name the unit.
The row for named task limits now covers the app door's schema, the
empty task_create title, a coded outage staying `error`, the value-free
setup-folder refusal with its guard, and REST's unit wording.
@yannickmonney
yannickmonney merged commit df5bc92 into main Sep 28, 2026
57 checks passed
@yannickmonney
yannickmonney deleted the fix/app-door-refusals-name-field branch September 28, 2026 06:47
yannickmonney added a commit that referenced this pull request Sep 28, 2026
Merge 066d510 pulled the head of the still-open #3538
(fix/app-door-refusals-name-field) into this branch, so the squash of
#3554 would have landed that PR's field-naming work under the reviewer
title. This reverts the merge against its first parent, leaving the
tree exactly as the reviewer fixes had it at 4d2cf36. #3538 lands on
its own.
yannickmonney added a commit that referenced this pull request Sep 28, 2026
Takes main up to 9662e8a, which now carries #3538 on its own.
yannickmonney added a commit that referenced this pull request Sep 28, 2026
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