Skip to content

Prevent demo requests from silently targeting Mexico - #65

Merged
simongonzalezdc merged 1 commit into
mainfrom
production-dialect-contract-fix
Apr 23, 2026
Merged

simongonzalezdc merged 1 commit into
mainfrom
production-dialect-contract-fix

Conversation

@simongonzalezdc

Copy link
Copy Markdown
Member

Summary

  • Fix /api/translate so missing dialect no longer silently defaults to es-MX.
  • Accept common target aliases: dialect, targetDialect, targetLocale, locale.
  • Return a 400 client error for missing target dialect before calling providers.
  • Refresh stale 16-tool / 737-test / package-count docs after the research MCP release.

Root cause

Live/browser testing with dialect: "es-PR" works for Puerto Rico examples, but API-style requests using targetLocale: "es-PR" were ignored and silently routed as es-MX. That made the system look like it was failing regional semantics when the real bug was an unsafe endpoint default.

Verification

  • node --test scripts/__tests__/demo-server.test.mjs
  • pnpm build
  • pnpm test
  • pnpm audit --audit-level low

The public demo endpoint defaulted any request without a dialect field to es-MX. That made alternate client contracts such as targetLocale look like model failures and produced Mexican/neutral output for Puerto Rican test cases. The server now accepts common target-dialect aliases and rejects missing dialects with a client error before touching providers.

Documentation counts were also refreshed after the research MCP tool and new regression tests.

Constraint: Browser UI already sends dialect, but external/API testers commonly send targetLocale or targetDialect.
Rejected: Keep es-MX fallback | hides contract mistakes and misdiagnoses dialect quality.
Confidence: high
Scope-risk: narrow
Directive: Do not reintroduce default dialects on public translation endpoints; force explicit target dialects or aliases.
Tested: node --test scripts/__tests__/demo-server.test.mjs
Tested: pnpm build
Tested: pnpm test
Tested: pnpm audit --audit-level low
@simongonzalezdc
simongonzalezdc force-pushed the production-dialect-contract-fix branch from a9a0960 to fd7940a Compare April 23, 2026 02:19

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a9a09607bb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread scripts/demo-server.mjs
Comment on lines +58 to +60
const candidate = body?.dialect ?? body?.targetDialect ?? body?.targetLocale ?? body?.locale;
if (candidate === undefined || candidate === null || String(candidate).trim() === "") {
throw new Error("Target dialect is required. Send dialect, targetDialect, or targetLocale, for example es-PR.");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Treat blank dialect as missing before alias fallback

readDialect uses nullish coalescing (??), so a present-but-empty dialect value short-circuits alias lookup and causes a 400 even when targetDialect/targetLocale/locale is valid. A request like { "dialect": "", "targetLocale": "es-PR" } now fails with “Target dialect is required” instead of using the alias, which breaks clients that always send an empty dialect field.

Useful? React with 👍 / 👎.

Comment thread scripts/demo-server.mjs
const status = /No provider configured|No translation providers|Provider not available/i.test(message)
? 503
: /Invalid|No input|too large/i.test(message)
: /Invalid|No input|required|too large/i.test(message)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid classifying all 'required' errors as HTTP 400

The new /required/ check in the status mapper turns unrelated server-side failures into client errors. In this codebase, translation failures can include messages like Missing required semantic trait... (from the quality-judge path), so valid requests are now returned as 400 instead of 5xx/503, which misclassifies provider/output failures and can break client retry and alerting behavior.

Useful? React with 👍 / 👎.

@simongonzalezdc
simongonzalezdc merged commit 353f5e4 into main Apr 23, 2026
5 of 6 checks passed
@simongonzalezdc
simongonzalezdc deleted the production-dialect-contract-fix branch April 23, 2026 02:23
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