Skip to content

fix(platform): name every refused limit in task tools and doors - #3546

Merged
yannickmonney merged 11 commits into
mainfrom
fix/task-tools-name-every-limit
Sep 27, 2026
Merged

yannickmonney merged 11 commits into
mainfrom
fix/task-tools-name-every-limit

Conversation

@yannickmonney

@yannickmonney yannickmonney commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

What changed

Follow-up to #3529. toolResultFromError in workspace_domain_tools.ts kept only the code of a domain refusal. Every other refused limit therefore reached the agent without its number. This is what /api/tools/execute answered on origin/main (Postgres, checkAutomationRunToolLane):

{"status":"invalid_args","message":"TASK_DESCRIPTION_INVALID: the domain refused these arguments."}
{"status":"invalid_args","message":"TASK_LABELS_INVALID: the domain refused these arguments."}
{"status":"error","message":"Invalid comment body"}

The comment answered error, which reads as "try again": the agent-comment writer was the one write-shim handler outside the coded translation. On the human side, validateTitle threw the same Invalid title for an empty title and an over-long one. The tasks app door also dropped the domain's message and answered {"error":"TASK_TITLE_INVALID"} alone.

The same calls on this branch:

{"status":"invalid_args","message":"TASK_DESCRIPTION_INVALID: The task description is capped at 20,000 UTF-16 code units (most emoji count as 2); this one has 20,001."}
{"status":"invalid_args","message":"TASK_LABELS_INVALID: A label name is capped at 50 UTF-16 code units (most emoji count as 2); this one has 56."}
{"status":"invalid_args","message":"TASK_COMMENT_INVALID: The comment is capped at 10,000 UTF-16 code units (most emoji count as 2); this one has 10,001."}
  • Refusal sentences (core/tasks/helpers.ts, where the limits already live):
    • One pure function per limit: title, description, label count, label name, comment.
    • Each sentence names the cap, its unit and the length measured. It never contains the value.
    • An empty title reads The task title is empty — it takes 1 to 200 UTF-16 code units. An over-long one reads The task title is capped at 200 UTF-16 code units (most emoji count as 2); this one has 201.
  • Domain:
    • validateTitle, validateDescription and normalizeLabelNames (domains/tasks/service.ts) throw these sentences under their existing codes, so no code changes.
    • The comment post and edit (comments.ts) do the same.
  • Agent tool door:
    • toolResultFromError answers invalid_args as <CODE>: <domain sentence>. Only the sentence travels, capped at 400 characters, and never any other field of the refusal. A refusal that carries no sentence keeps the old generic text.
    • agentAddComment moves from sandbox/shim.ts into workspace-write-shim.ts behind coded(), like its sibling writers.
    • coded() translates only a 4xx refusal. A coded 5xx stays a plain error and answers error, not invalid_args. An example is a MENTION_DIRECTORY_UNAVAILABLE 503 on a comment.
    • An empty or whitespace-only task_create title answers the domain's empty sentence (… is empty — it takes 1 to 200 UTF-16 code units.). A missing or non-string title keeps the generic text.
    • fix(platform): name the title limit when task_create refuses #3529's title pre-check builds its message from the same taskTitleRefusal, so the tool door and the domain cannot drift apart.
  • Signatures (workspace_tools_bridge.ts):
    • workspace_status states every cap, built from the shared constants:
      • task_create: title ≤ 200, description ≤ 20,000, and labels (the first 20 are kept, each ≤ 50).
      • task_comment: body ≤ 10,000, and at most 16 locales in bodyByLocale.
      • task_upsert_by_external_ref: says an over-long title is cut to 200, ending in "…". It is not refused, which is intended.
    • The bodyByLocale refusal names both of its caps from constants. TASK_COMMENT_LOCALES_MAX is new, in lib/shared/schemas/task-comment.ts.
  • Counting: every enforcement point already counts String.length, which is UTF-16 code units: the dialog's maxLength, the REST zod schemas and the domain. So this PR names that unit instead of "characters", as the REST chat content cap already does (evaluation J2-1). No limit changes.
  • App door (/api/app/tasks):
    • handleError answers TaskError / ProjectError as {error: <code>, message, data?}. That is the shape the same function already used for TaskReviewError and AutomationError, and the one appErrorResponse documents. The sentences are the domain's own prose.
    • The door's schema checks the title, description, label count and comment body with the domain's own refusal helpers. Its old caps sat above the domain's (title ≤ 500, description ≤ 50,000, ≤ 100 labels, comment .min(1)), and they answered a bare invalid body. An empty or over-long value now answers {error: <code>, message}, however far past the cap. The check runs before a rate-limit slot is spent.
  • No value in a refusal: SETUP_FOLDER_MISSING no longer repeats the folder name that was sent. domains/tasks/errors.test.ts reads every TaskError, TaskReviewError and task-domain ProjectError message with the TypeScript AST. A new interpolated value fails the test until it is made static or reviewed onto its list.
  • REST wording: the task title, description, label, comment and translation caps say must be at most 200 UTF-16 code units, not "characters". The en/de/fr API reference names the unit for the title and comment caps.

#3155's acceptance holds on the public tree:

  • "", whitespace-only and over-long titles each get a structured refusal naming the constraint.
  • The refusal is returned as a tool result, with nothing thrown or logged at error level.
  • Its fix direction 1 (a message-carrying refusal distinguishing empty from over-long) is now in the domain.
  • The Convex overlay the issue's stack trace names has been retired.

How I verified it

  • Unit tests (--project server, --maxWorkers=2): 71 files, 841 tests, all green. They are every test under domains/tasks, domains/sandbox and core/tasks, the bridge, and each test that imports a changed module (v1-tasks, error-codes, platform-tasks, task-store, spec, …). New tests:
    • core/tasks/helpers.test.ts: the sentences. Also emoji measured in code units (100 🎯 fit, 101 report 202), and a decomposed label measured NFC-composed as the catalog stores it.
    • domains/tasks/service.limits.test.ts: createTask / updateTask / agentCreateTaskTrusted. An empty vs over-long title, a description over the cap, and a label over 50, with no write.
    • domains/tasks/comments.limits.test.ts: the comment post and edit.
    • domains/tasks/routes.limits.test.ts: the app door runs the real domain on a stub connection. "" and " " both answer the empty sentence, and 201 characters answer the over-long one, on create and on edit.
    • domains/sandbox/workspace-write-shim.test.ts: the real writers behind the shim. Each answers {code, message} for a description, a label and a comment over the cap.
    • workspace_tools_bridge.test.ts: the relay itself, including "no payload beside the sentence" and "generic text when there is no sentence". Also the signatures, which must never say "characters".
  • Unit negative control: with origin/main's eight implementation files and the new tests kept, 26 tests fail. The only new or changed tests that pass there should pass on both sides: the fallback-sentence guard, and the pure helper tests, whose module the control keeps.
  • backend:integration, filtered run on a local PG 16 + pg_search + pgvector cluster (ITEST_LANES=checkAutomationRunToolLane,checkTasks,checkTasksCollabIntegrity): 42 pass.
    • The new check sends a description, a label and a comment over the cap through /api/tools/execute. It gets the three answers above, and no card, label or comment is written.
    • On origin/main both checks fail. The three calls answer the "before" block above, and the title refusal still says "capped at 200 characters".
    • Two checks fail identically on origin/main and here: automation-run tool lane and document_create authority. document_create needs an S3 endpoint (ITEST_S3_ENDPOINT), which this sandbox does not have.
  • Static checks:
    • tsc on a scoped config over every changed file plus dispatch-routes.ts and integration-check.ts: clean.
    • oxlint --type-aware and oxfmt --check on the changed files: clean.
    • tools/opengrep/run.sh: 0 findings.
    • bun run lint:manual: passes.
    • knip --workspace services/platform: only the existing oidcOrganizationClaims.
  • The workspace-wide gates (full tsc, bun run check, the full suites) are left to CI. The sandbox's 4 GB cap cannot run them.
  • Review round 1 (after merging origin/main):
    • --project server over domains/{sandbox,tasks}, core/tasks, core/node_only/sandbox, rest, lib/connectors/natives, lib/shared/schemas and scripts/openapi: 123 files, 2,159 tests, all green.
    • Full platform tsc --noEmit: clean. oxlint --type-aware on the changed files: clean. bun run lint:manual: passes.
    • Negative controls: the shim's outage test fails without the 4xx range check. The refusal guard fails when the old interpolated SETUP_FOLDER_MISSING message is put back.

Left open

  • Upsert description: task_upsert_by_external_ref stores a description of any length. upsertTaskByExternalRef has no cap, while the REST intake refuses one over 20,000. Refusing it, or cutting it like the imported title, is a product call, so the signature states no cap for it.
  • Task dialog: the dialog shows a generic toast for these refusals, and its description field has no maxLength. Showing the limit needs localized copy (en/de/fr), not the server's English sentence.
  • Label components: label-editor.tsx and label-manage-dialog.tsx declare their own MAX_LABEL_LENGTH = 50 instead of importing TASK_LABEL_CHARS_MAX.

Closes #3155

yannickmonney and others added 11 commits September 27, 2026 19:18
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 6548bcc into main Sep 27, 2026
57 checks passed
@yannickmonney
yannickmonney deleted the fix/task-tools-name-every-limit branch September 27, 2026 22:50
yannickmonney added a commit that referenced this pull request Sep 28, 2026
Follow-up to #3546. A blank task_comment body or task_upsert_by_external_ref
title now answers the shared empty sentence at the tool door. The app's
label create/rename and from-external-issue schemas answer the domain's
sentences instead of their own caps.

The upsert cuts an over-long description to 20,000 UTF-16 code units
ending in "…", as it cuts a title; the signature says so. The refusal
guard also reads the ProjectErrors a task door reaches. The REST
reference names the description, label and comment-body caps in that unit.
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.

Bug: agent task_create crashes uncaught on invalid title — code-only TASK_TITLE_INVALID gives the calling agent nothing actionable (1 event, 09-02)

1 participant