From 5c9417896d38ab25f32d6abc7a45b90c32468f97 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 19 Nov 2026 22:10:48 +0000 Subject: [PATCH 1/4] fix(i18n, mcp): a translation fault serves untranslated text with a warning An i18n service that resolves but whose getLocales/getTranslations throws is now a translation fault, answered at the shared translator (translationBundleOf) as no bundle: the text is served untranslated, the server log says so at warn, and an optional reportTranslationFault hands the same sentence to a door that carries a warning on its answer. REST /meta list and by-name reads answer 200 untranslated (was 500); the MCP object tools serve the authored labels; list_datasets keeps its datasets, partial with the fault's warning (was datasets: []); and query_dataset answers (was 503), on both MCP transports. The pins that held the degraded answer are flipped in place. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_016WV4d1k1GRsQbF3vCPKxhz --- .../34993-translation-fault-untranslated.md | 15 ++++ .../stdio-data-bridge.dataset-locale.test.ts | 74 ++++++++-------- packages/mcp/src/stdio-data-bridge.ts | 20 +++-- packages/rest/src/meta-item-read-gate.ts | 45 ++++++++-- .../src/meta-translation-fault-34993.test.ts | 86 +++++++++++++++++++ packages/runtime/src/domains/mcp.ts | 13 +-- .../src/mcp-dataset-tools-bridge.test.ts | 50 ++++------- .../service-analytics/src/dataset-tools.ts | 8 +- 8 files changed, 218 insertions(+), 93 deletions(-) create mode 100644 .changeset/34993-translation-fault-untranslated.md create mode 100644 packages/rest/src/meta-translation-fault-34993.test.ts diff --git a/.changeset/34993-translation-fault-untranslated.md b/.changeset/34993-translation-fault-untranslated.md new file mode 100644 index 00000000000..69e8671c355 --- /dev/null +++ b/.changeset/34993-translation-fault-untranslated.md @@ -0,0 +1,15 @@ +--- +'@objectstack/rest': patch +'@objectstack/runtime': patch +'@objectstack/mcp': patch +'@objectstack/service-analytics': patch +--- + +Clause-②: yes (widening) +Metadata-protocol: none + +fix(i18n, mcp): a translation fault serves the untranslated text with a warning instead of failing the read + +When the i18n service resolves but its `getLocales` or `getTranslations` throws, the shared `/meta` translator (`translationBundleOf`, `@objectstack/rest`) now answers it as no bundle: the text is served untranslated and the server log says so at `warn` (`The translations could not be read (…), so labels and descriptions are served untranslated.`). Before, the translation rejected, so `GET /meta/:type` and `GET /meta/:type/:name` answered 500, the MCP object tools failed, `list_datasets` answered `datasets: []` with `partial: true`, and `query_dataset` refused 503 on both MCP transports. + +Now `list_datasets` keeps every dataset, in its authored text, with `partial: true` and that sentence as its `warning`; `query_dataset` answers. A dataset host's `loadDatasets` may return `{ items, warning }` without `partial`: a whole read the tools say something about, which `query_dataset` does not refuse. The translator's sources take an optional `reportTranslationFault(warning)` to carry the sentence on an answer. diff --git a/packages/mcp/src/stdio-data-bridge.dataset-locale.test.ts b/packages/mcp/src/stdio-data-bridge.dataset-locale.test.ts index 746735d66a4..7d37180946f 100644 --- a/packages/mcp/src/stdio-data-bridge.dataset-locale.test.ts +++ b/packages/mcp/src/stdio-data-bridge.dataset-locale.test.ts @@ -23,8 +23,8 @@ * - an i18n service the host cannot resolve (its resolver throws), or none: * the untranslated list, never an error; * - an i18n service that resolves but whose `getLocales` / `getTranslations` - * throws, over the REAL executor: a degraded read on both dataset tools - * (seat ruling A, its own describe below). + * throws, over the REAL executor: the datasets untranslated, with a warning, + * on both dataset tools and the object tools (#34993, its own describe below). */ import { describe, it, expect } from 'vitest'; @@ -35,7 +35,12 @@ import { type AnalyticsService, type MatchableMember, } from '@objectstack/service-analytics'; -import { createStdioDataBridge, type StdioDataBridgeDeps, type StdioDatasetToolsService } from './stdio-data-bridge.js'; +import { + createStdioDataBridge, + servedLocaleObjectView, + type StdioDataBridgeDeps, + type StdioDatasetToolsService, +} from './stdio-data-bridge.js'; const PRINCIPAL = { userId: 'u_key', tenantId: 'org_1' }; @@ -151,21 +156,16 @@ describe('[ADR-0149 D2] stdio list_datasets is localized for the workspace defau }); /** - * [ADR-0149 D2] An i18n service that RESOLVES but whose reads throw is not the - * unresolvable service above. `translationBundleOf` calls `getLocales` and - * `getTranslations` unguarded, so `translateMetaList` rejects with the i18n - * error, and `loadDatasets` leaves that rejection to throw. The executor here - * is the REAL one (the analytics service `AnalyticsServicePlugin` registers, - * admission wired), so the answer is the executor's own degraded-read - * contract: `list_datasets` lists nothing, says `partial` and names the error; - * `query_dataset` refuses 503 `SERVICE_UNAVAILABLE` for a server-side fault. - * The control case lists the dataset over the same harness, so the empty - * catalogue is the failed read's doing, not the harness's. + * [ADR-0149 D2 · #34993] An i18n service that RESOLVES but whose reads throw + * is a translation fault, which the shared translator (`translationBundleOf`) + * answers as no bundle and says. The executor here is the REAL one (the + * analytics service `AnalyticsServicePlugin` registers, admission wired): + * `list_datasets` keeps the dataset, in its authored text, `partial` with the + * fault's warning; `query_dataset` answers; the object tools serve the + * authored labels. The control case lists the dataset in the bundle labels. * - * Pinned on purpose under seat ruling A: the catalogue degrades and says so. - * A follow-up (B: serve the untranslated text on a translation fault, inside - * the shared translator) would flip these expectations deliberately, on both - * transports at once. + * Flipped on purpose by #34993 (seat ruling B) from #34876's ruling-A pin + * (`datasets: []` + `partial`, and a 503), on both transports at once. */ describe('[ADR-0149 D2] stdio dataset tools when the i18n service resolves but its reads throw', () => { /** @@ -239,32 +239,28 @@ describe('[ADR-0149 D2] stdio dataset tools when the i18n service resolves but i expect(answer.datasets.map((d) => [d.name, d.label])).toEqual([['opp_metrics', '商机指标']]); }); - it.each(CASES)('$read throwing: list_datasets lists nothing, says partial and names the i18n error', async ({ read, message }) => { + it.each(CASES)('$read throwing: list_datasets keeps the dataset untranslated, partial, naming the i18n error', async ({ read, message }) => { const bridge = await bridgeOverRealExecutor(() => i18nWhoseReadThrows(read, message)); const answer = await bridge.listDatasets!({ terms: TERMS }); - // [#34919] Terms were sent, so the degraded answer also carries `nextStep`: - // nothing listed reads `no_measure` for every word, and the note says the - // catalogue was incomplete and to repeat the warning. - expect(answer).toEqual({ - datasets: [], - partial: true, - warning: expect.stringContaining(message), - nextStep: { decision: 'no_measure', terms: TERMS, note: expect.stringContaining('warning') }, - }); - expect(answer.warning).toMatch(/^The dataset catalogue could not be read: /); + expect(answer.datasets.map((d) => [d.name, d.label])).toEqual([['opp_metrics', 'Opportunity Metrics']]); + expect(answer).toMatchObject({ partial: true, warning: expect.stringContaining(message) }); }); - it.each(CASES)('$read throwing: query_dataset refuses 503 SERVICE_UNAVAILABLE, naming the failed read', async ({ read, message }) => { + it.each(CASES)('$read throwing: query_dataset answers, in the authored labels', async ({ read, message }) => { const bridge = await bridgeOverRealExecutor(() => i18nWhoseReadThrows(read, message)); - const refused = await bridge - .queryDataset!({ datasetName: 'opp_metrics', selection: { measures: ['total_amount'] } }, { maxRows: 10 }) - .then( - () => undefined, - (e: unknown) => e as { code?: unknown; status?: unknown; message?: unknown }, - ); - expect(refused).toMatchObject({ code: 'SERVICE_UNAVAILABLE', status: 503 }); - // The failed read's own 503 (naming the i18n error), not the executor's - // "not available on this deployment" one. - expect(refused?.message).toContain(`the dataset read failed (${message})`); + const answer = await bridge.queryDataset!({ datasetName: 'opp_metrics', selection: { measures: ['total_amount'] } }, { maxRows: 10 }); + expect(answer.rowCount).toBe(1); + expect(answer.provenance.dataset).toEqual({ name: 'opp_metrics', label: 'Opportunity Metrics' }); + }); + + it.each(CASES)('$read throwing: the object tools serve the authored labels', async ({ read, message }) => { + const deal = { name: 'crm_opportunity', label: 'Opportunity', fields: { stage: { type: 'text', label: 'Stage' } } }; + const view = servedLocaleObjectView( + { listObjects: async () => [deal], getObject: async () => deal } as any, + { i18n: () => i18nWhoseReadThrows(read, message) }, + ); + const [listed] = (await view.listObjects()) as Array; + expect([listed.label, listed.fields.stage.label]).toEqual(['Opportunity', 'Stage']); + expect(((await view.getObject('crm_opportunity')) as typeof deal).label).toBe('Opportunity'); }); }); diff --git a/packages/mcp/src/stdio-data-bridge.ts b/packages/mcp/src/stdio-data-bridge.ts index 88696ab488c..54373cf951e 100644 --- a/packages/mcp/src/stdio-data-bridge.ts +++ b/packages/mcp/src/stdio-data-bridge.ts @@ -286,7 +286,7 @@ export interface StdioDataBridgeDeps { */ export interface StdioDatasetToolsService { datasetTools(deps: { - loadDatasets: (context: unknown) => Promise; + loadDatasets: (context: unknown) => Promise; diagnoseDelegation?: (object: string, context: unknown) => Promise<{ narrowed: boolean; statement?: string } | undefined>; maxQueryLimit?: number; }): { @@ -1703,12 +1703,12 @@ export function createStdioDataBridge(deps: StdioDataBridgeDeps): McpDataBridge // carries no request, so the locale is the i18n service's default (what // `metaRequestLocale` answers with no header), the workspace default the // stdio principal speaks. An i18n service this host cannot resolve leaves the - // list untranslated, as there. The stdio bridge has no delegation probe (an - // API key is not delegated), so none is passed, as `query_records` here - // carries none. + // list untranslated, as there. [#34993] So does a translation fault, whose + // sentence the rows carry as their `warning`. The stdio bridge has no delegation probe (an API key is not delegated), so + // none is passed, as `query_records` here carries none. if (deps.datasetTools) { const service = deps.datasetTools; - const loadDatasets = async (): Promise => { + const loadDatasets = async () => { const protocolService = protocol?.(); let merged: StdioProtocolObjectReads | undefined; let items: readonly unknown[]; @@ -1718,8 +1718,14 @@ export function createStdioDataBridge(deps: StdioDataBridgeDeps): McpDataBridge } else { items = (await metadataService.list('dataset')) ?? []; } - const translated = await translateMetaList(defaultLocaleSources(deps.i18n, async () => merged), 'dataset', items); - return Array.isArray(translated) ? translated : items; + let warning: string | undefined; + const translated = await translateMetaList( + { ...defaultLocaleSources(deps.i18n, async () => merged), reportTranslationFault: (w: string) => { warning = w; } }, + 'dataset', + items, + ); + const rows = Array.isArray(translated) ? translated : items; + return warning === undefined ? rows : { items: rows, warning }; }; const executor = (maxQueryLimit?: number) => service.datasetTools({ loadDatasets, ...(maxQueryLimit !== undefined ? { maxQueryLimit } : {}) }); diff --git a/packages/rest/src/meta-item-read-gate.ts b/packages/rest/src/meta-item-read-gate.ts index e52e82e503c..942e763f99b 100644 --- a/packages/rest/src/meta-item-read-gate.ts +++ b/packages/rest/src/meta-item-read-gate.ts @@ -3250,23 +3250,47 @@ export async function isTranslatableMetaType(type: string): Promise { return translatableMetaTypes.has(type); } +/** + * [#34993] The sentence a translation fault is said in, on every door that + * says one: the i18n service resolved, but its translations could not be read. + */ +export function metaTranslationFaultWarning(error: unknown): string { + const reason = error instanceof Error ? error.message : String(error); + return `The translations could not be read (${reason}), so labels and descriptions are served untranslated.`; +} + /** * Build a `TranslationBundle` (`Record`) from an * `II18nService` instance. `undefined` when no locales are registered, so * callers can avoid translation work. (`RestServer.buildTranslationBundle` * delegates here.) + * + * [#34993] A service whose `getLocales` or `getTranslations` throws is a + * translation fault, not a failed read: the answer is `undefined` (the text is + * served untranslated, as with no bundle), the server log says so at `warn` + * (a functional degradation), and `reportFault` hands the same sentence + * ({@link metaTranslationFaultWarning}) to a door that carries a warning on + * its answer. One locale failing fails the whole bundle, so an answer never + * mixes the locales that read with the fallback for the one that did not. */ -export function translationBundleOf(i18n: unknown): any | undefined { +export function translationBundleOf(i18n: unknown, reportFault?: (warning: string) => void): any | undefined { const service: any = i18n; if (!service || typeof service.getLocales !== 'function' || typeof service.getTranslations !== 'function') { return undefined; } - const locales: string[] = service.getLocales(); - if (!locales.length) return undefined; const bundle: Record = {}; - for (const locale of locales) { - const data = service.getTranslations(locale); - if (data && typeof data === 'object') bundle[locale] = data; + try { + const locales: string[] = service.getLocales(); + if (!locales.length) return undefined; + for (const locale of locales) { + const data = service.getTranslations(locale); + if (data && typeof data === 'object') bundle[locale] = data; + } + } catch (error) { + const warning = metaTranslationFaultWarning(error); + logWarn(`[meta] ${warning}`); + reportFault?.(warning); + return undefined; } return Object.keys(bundle).length ? bundle : undefined; } @@ -3579,6 +3603,11 @@ export interface MetaListTranslationSources { * last fallback; without it, only the request's own preference counts. */ requestLocale(i18n?: unknown): string | undefined; + /** + * [#34993] Told the sentence of a translation fault ({@link translationBundleOf}), + * for a door that says it on its answer. Optional: the server log says it either way. + */ + reportTranslationFault?(warning: string): void; } /** @@ -3611,7 +3640,7 @@ export async function translateMetaList( : (raw && typeof raw === 'object' && Array.isArray(raw.items) ? raw.items : null); if (!arr) return items; const i18n = await sources.resolveI18nService(); - const bundle = translationBundleOf(i18n); + const bundle = translationBundleOf(i18n, (warning) => sources.reportTranslationFault?.(warning)); const locale = sources.requestLocale(i18n); if (!locale) return items; const { translateMetadataDocument } = await import('@objectstack/spec/system'); @@ -3687,7 +3716,7 @@ export async function translateMetaDocument( if (!document || typeof document !== 'object') return document; if (!(await isTranslatableMetaType(metaType))) return document; const i18n = await sources.resolveI18nService(); - const bundle = translationBundleOf(i18n); + const bundle = translationBundleOf(i18n, (warning) => sources.reportTranslationFault?.(warning)); const locale = sources.requestLocale(i18n); if (!locale) return document; if (metaType === 'view') { diff --git a/packages/rest/src/meta-translation-fault-34993.test.ts b/packages/rest/src/meta-translation-fault-34993.test.ts new file mode 100644 index 00000000000..924f0acf27b --- /dev/null +++ b/packages/rest/src/meta-translation-fault-34993.test.ts @@ -0,0 +1,86 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * [#34993] REST `/meta` on a translation fault: an i18n service that resolves + * but whose `getLocales` / `getTranslations` throws. The shared translator + * (`translationBundleOf`) answers it as no bundle, so the list and the by-name + * read serve the authored text (200, not 500), and the server log says so at + * `warn` — this door carries no warning on its answer. The control serves the + * bundle label over the same harness, so the authored text is the fault's doing. + */ + +import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest'; +import { RestServer } from './rest-server.js'; + +const ACCOUNT = { name: 'showcase_account', label: 'Account', fields: { industry: { name: 'industry', type: 'text', label: 'Industry' } } }; +const ZH_CN = { objects: { showcase_account: { label: '客户', fields: { industry: { label: '行业' } } } } }; + +function i18nWhoseReadThrows(read: 'getLocales' | 'getTranslations' | undefined, message = 'bundle offline') { + return { + getLocales: () => { + if (read === 'getLocales') throw new Error(message); + return ['en', 'zh-CN']; + }, + getTranslations: (locale: string) => { + if (read === 'getTranslations') throw new Error(message); + return locale === 'zh-CN' ? ZH_CN : {}; + }, + getDefaultLocale: () => 'en', + }; +} + +function restOver(i18n: unknown) { + const protocol = { + getDiscovery: vi.fn().mockResolvedValue({ version: 'v0', routes: { data: '', metadata: '', ui: '', auth: '/auth' } }), + getMetaTypes: vi.fn().mockResolvedValue([]), + getMetaItems: vi.fn(async ({ type }: any) => (type === 'object' ? [ACCOUNT] : [])), + getMetaItem: vi.fn(async ({ type, name }: any) => ({ type, name, item: ACCOUNT, lock: 'none', editable: true })), + findData: vi.fn().mockResolvedValue([]), + }; + const server = { get: vi.fn(), post: vi.fn(), put: vi.fn(), delete: vi.fn(), patch: vi.fn(), use: vi.fn() }; + const rest = new RestServer( + server as any, protocol as any, { api: { requireAuth: false } } as any, + undefined, undefined, undefined, undefined, undefined, + undefined, undefined, undefined, undefined, undefined, + async () => i18n as any, + ); + (rest as any).resolveExecCtx = async () => ({ userId: 'u1', systemPermissions: [] }); + rest.registerRoutes(); + return rest; +} + +async function read(rest: RestServer, path: string, params: Record) { + const route = (rest as any).getRoutes().find((r: any) => r.method === 'GET' && r.path === path); + const res = { json: vi.fn(), status: vi.fn().mockReturnThis(), header: vi.fn(), send: vi.fn() }; + await route.handler({ method: 'GET', params, query: {}, body: {}, headers: { 'accept-language': 'zh-CN' } }, res); + const status = res.status.mock.calls.length ? res.status.mock.calls[res.status.mock.calls.length - 1][0] : 200; + const body = res.json.mock.calls[res.json.mock.calls.length - 1]?.[0]; + const doc = path.endsWith(':name') ? body?.item : (Array.isArray(body) ? body : body?.items)?.[0]; + return { status, label: doc?.label, field: doc?.fields?.industry?.label }; +} + +beforeAll(() => { vi.stubEnv('OS_REST_LOG', 'info'); }); +afterAll(() => { vi.unstubAllEnvs(); }); + +describe('[#34993] REST /meta serves the authored text on a translation fault', () => { + it('control: the reads answering, the list serves the bundle label', async () => { + expect(await read(restOver(i18nWhoseReadThrows(undefined)), '/api/v1/meta/:type', { type: 'object' })) + .toEqual({ status: 200, label: '客户', field: '行业' }); + }); + + it.each(['getLocales', 'getTranslations'] as const)('%s throwing: list and by-name read answer 200 untranslated, and the log says why', async (failing) => { + const warn = vi.spyOn(console, 'warn').mockImplementation(() => {}); + try { + const rest = restOver(i18nWhoseReadThrows(failing)); + expect(await read(rest, '/api/v1/meta/:type', { type: 'object' })) + .toEqual({ status: 200, label: 'Account', field: 'Industry' }); + expect(await read(rest, '/api/v1/meta/:type/:name', { type: 'object', name: 'showcase_account' })) + .toEqual({ status: 200, label: 'Account', field: 'Industry' }); + expect(warn.mock.calls.map((c) => String(c[0]))).toEqual( + expect.arrayContaining([expect.stringContaining('bundle offline')]), + ); + } finally { + warn.mockRestore(); + } + }); +}); diff --git a/packages/runtime/src/domains/mcp.ts b/packages/runtime/src/domains/mcp.ts index fe06680ebad..b6d0c3528b7 100644 --- a/packages/runtime/src/domains/mcp.ts +++ b/packages/runtime/src/domains/mcp.ts @@ -1630,7 +1630,7 @@ export function buildMcpBridge( */ export interface McpDatasetToolsService { datasetTools(deps: { - loadDatasets: (context: unknown) => Promise; + loadDatasets: (context: unknown) => Promise; diagnoseDelegation?: (object: string, context: unknown) => Promise<{ narrowed: boolean; statement?: string } | undefined>; maxQueryLimit?: number; }): { @@ -1716,7 +1716,8 @@ function metaTranslationSources( * localized with the `/meta` list translation for this request's locale, as * the REST door localizes a saved dataset. A throwing read is left to throw: * the executor answers it as a degraded read (`partial` / 503), never as an - * empty catalogue. + * empty catalogue. [#34993] A translation fault is no failed read: the rows + * are handed over untranslated, with the fault's sentence as their `warning`. * - The narrowing probe is the bridge's own `diagnoseDelegation` read, asked * of this request's security service, so `query_dataset` states a narrowing * exactly where `query_records` does. @@ -1731,15 +1732,17 @@ function datasetToolMembers( context: HttpProtocolContext, ) { const envId = context.environmentId; - const loadDatasets = async (): Promise => { + const loadDatasets = async () => { const protocol = await getProtocol(); const items = (await actionExec.readMergedItems(protocol, 'dataset')) ?? []; + let warning: string | undefined; const translated = await translateMetaList( - metaTranslationSources(deps, context, async () => protocol), + { ...metaTranslationSources(deps, context, async () => protocol), reportTranslationFault: (w) => { warning = w; } }, 'dataset', items, ); - return Array.isArray(translated) ? translated : items; + const rows = Array.isArray(translated) ? translated : items; + return warning === undefined ? rows : { items: rows, warning }; }; const diagnoseDelegation = async (object: string) => { try { diff --git a/packages/runtime/src/mcp-dataset-tools-bridge.test.ts b/packages/runtime/src/mcp-dataset-tools-bridge.test.ts index 5fef5c4cbcc..28474335f4e 100644 --- a/packages/runtime/src/mcp-dataset-tools-bridge.test.ts +++ b/packages/runtime/src/mcp-dataset-tools-bridge.test.ts @@ -10,9 +10,9 @@ * carries no dataset member); the executor is bound to the saved datasets of * the protocol's merged read, to the request's security probe and to the tool * layer's page cap; and every call runs as the request's own principal. - * Also pinned (its own describe below): an i18n service that resolves but - * whose `getLocales` / `getTranslations` throws, over the REAL executor, is a - * degraded read on both dataset tools (seat ruling A). + * Also pinned (its own describes below): an i18n service that resolves but + * whose `getLocales` / `getTranslations` throws, over the REAL executor, serves + * the datasets untranslated with a warning (#34993). */ import { describe, it, expect, vi } from 'vitest'; @@ -114,22 +114,15 @@ describe('[ADR-0149 D2] the MCP bridge\'s dataset members', () => { }); /** - * [ADR-0149 D2] The HTTP door's dataset members when the request's i18n - * service RESOLVES but its reads throw — not the lookup that throws, which - * `metaTranslationSources` reads as none (text served untranslated). - * `translationBundleOf` calls `getLocales` and `getTranslations` unguarded, so - * the `/meta` list translation rejects with the i18n error, and `loadDatasets` - * leaves that rejection to throw. The executor is the REAL one (the analytics - * service `AnalyticsServicePlugin` registers, admission wired), so the answer - * is its degraded-read contract: `list_datasets` lists nothing, says `partial` - * and names the error; `query_dataset` refuses 503 `SERVICE_UNAVAILABLE`. - * The control case lists the dataset over the same harness, so the empty - * catalogue is the failed read's doing, not the harness's. + * [ADR-0149 D2 · #34993] The HTTP door's dataset members when the request's + * i18n service RESOLVES but its reads throw — a translation fault, which the + * shared translator (`translationBundleOf`) answers as no bundle and says. The + * executor is the REAL one (the analytics service `AnalyticsServicePlugin` + * registers, admission wired): `list_datasets` keeps the dataset, in its + * authored text, `partial` with the fault's warning; `query_dataset` answers. * - * Pinned on purpose under seat ruling A: the catalogue degrades and says so. - * A follow-up (B: serve the untranslated text on a translation fault, inside - * the shared translator) would flip these expectations deliberately, on both - * transports at once. + * Flipped on purpose by #34993 (seat ruling B) from #34876's ruling-A pin + * (`datasets: []` + `partial`, and a 503), on both transports at once. */ describe('[ADR-0149 D2] the HTTP dataset tools when the i18n service resolves but its reads throw', () => { const METRICS = { @@ -214,24 +207,17 @@ describe('[ADR-0149 D2] the HTTP dataset tools when the i18n service resolves bu expect(answer.datasets.map((d: { name: string; label: string }) => [d.name, d.label])).toEqual([['sales_analysis', '销售分析']]); }); - it.each(CASES)('$read throwing: list_datasets lists nothing, says partial and names the i18n error', async ({ read, message }) => { + it.each(CASES)('$read throwing: list_datasets keeps the dataset untranslated, partial, naming the i18n error', async ({ read, message }) => { const bridge = await bridgeOverRealExecutor(i18nWhoseReadThrows(read, message)); const answer = await bridge.listDatasets!({}); - expect(answer).toEqual({ datasets: [], partial: true, warning: expect.stringContaining(message) }); - expect(answer.warning).toMatch(/^The dataset catalogue could not be read: /); + expect(answer.datasets.map((d: { name: string; label: string }) => [d.name, d.label])).toEqual([['sales_analysis', 'Sales analysis']]); + expect(answer).toMatchObject({ partial: true, warning: expect.stringContaining(message) }); }); - it.each(CASES)('$read throwing: query_dataset refuses 503 SERVICE_UNAVAILABLE, naming the failed read', async ({ read, message }) => { + it.each(CASES)('$read throwing: query_dataset answers, in the authored labels', async ({ read, message }) => { const bridge = await bridgeOverRealExecutor(i18nWhoseReadThrows(read, message)); - const refused = await bridge - .queryDataset!({ datasetName: 'sales_analysis', selection: { measures: ['revenue'] } }, { maxRows: 10 }) - .then( - () => undefined, - (e: unknown) => e as { code?: unknown; status?: unknown; message?: unknown }, - ); - expect(refused).toMatchObject({ code: 'SERVICE_UNAVAILABLE', status: 503 }); - // The failed read's own 503 (naming the i18n error), not the executor's - // "not available on this deployment" one. - expect(refused?.message).toContain(`the dataset read failed (${message})`); + const answer = await bridge.queryDataset!({ datasetName: 'sales_analysis', selection: { measures: ['revenue'] } }, { maxRows: 10 }); + expect(answer.rowCount).toBe(1); + expect(answer.provenance.dataset).toEqual({ name: 'sales_analysis', label: 'Sales analysis' }); }); }); diff --git a/packages/services/service-analytics/src/dataset-tools.ts b/packages/services/service-analytics/src/dataset-tools.ts index 4ee58e083bb..537def26a7b 100644 --- a/packages/services/service-analytics/src/dataset-tools.ts +++ b/packages/services/service-analytics/src/dataset-tools.ts @@ -169,6 +169,9 @@ export function getDatasetToolDefinitions(): readonly AIToolDefinition[] { * The array form is a complete read. The object form carries `partial: true` * and a `warning` when the read was degraded (the `list_objects` shape), and * the tools say so instead of presenting a short list as the whole catalogue. + * [#34993] A `warning` without `partial` is a whole read the host says + * something about (a translation fault: every row, its text untranslated): + * `list_datasets` says it, and `query_dataset` still answers. */ export type DatasetToolSource = | readonly unknown[] @@ -393,6 +396,7 @@ export function createDatasetTools(deps: DatasetToolsDeps): DatasetTools { const source = await deps.loadDatasets(context); const items = Array.isArray(source) ? source : (source as { items?: readonly unknown[] }).items ?? []; const degraded = !Array.isArray(source) && (source as { partial?: unknown }).partial === true; + const said = Array.isArray(source) ? undefined : (source as { warning?: unknown }).warning; const datasets: Dataset[] = []; const holdings: Array = []; for (const item of items) { @@ -410,7 +414,7 @@ export function createDatasetTools(deps: DatasetToolsDeps): DatasetTools { datasets, holdings, partial: degraded, - ...(degraded ? { warning: String((source as { warning?: unknown }).warning ?? 'The dataset read was degraded.') } : {}), + ...(degraded ? { warning: String(said ?? 'The dataset read was degraded.') } : typeof said === 'string' ? { warning: said } : {}), }; } @@ -480,7 +484,7 @@ export function createDatasetTools(deps: DatasetToolsDeps): DatasetTools { const candidates = terms !== undefined ? findDatasetTermCandidates(terms, listed) : []; const warnings: string[] = []; - if (loaded.partial && loaded.warning) warnings.push(loaded.warning); + if (loaded.warning) warnings.push(loaded.warning); if (unresolved) { warnings.push('Some datasets or members could not be checked against this caller\'s permissions and are left out.'); } From 2c712f55dfa269e04e9b1e4f3cb110caf5d3e58d Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 19 Nov 2026 22:10:57 +0000 Subject: [PATCH 2/4] fix(mcp): ?locale= reaches the MCP labels; dataset labels and sentences share one locale metaTranslationSources (and the app-docs locale) read the request's query as well as its headers, the way the /meta doors do. The dataset executor takes an optional translationLocale dependency, the locale loadDatasets translated for, and resolves labels, nextStep and sourceLine in it first; both MCP transports pass it. Pinned: ?locale=zh-CN with no Accept-Language answers what an Accept-Language: zh-CN caller is answered, and a header-less stdio call answers labels and sentences in one language. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_016WV4d1k1GRsQbF3vCPKxhz --- .../34993-translation-fault-untranslated.md | 4 +++ .../stdio-data-bridge.dataset-locale.test.ts | 30 ++++++++++++++-- packages/mcp/src/stdio-data-bridge.ts | 11 ++++-- packages/runtime/src/domains/mcp.ts | 36 +++++++++++++++++-- .../src/mcp-dataset-tools-bridge.test.ts | 34 ++++++++++++++++-- .../service-analytics/src/dataset-tools.ts | 28 ++++++++++++--- 6 files changed, 128 insertions(+), 15 deletions(-) diff --git a/.changeset/34993-translation-fault-untranslated.md b/.changeset/34993-translation-fault-untranslated.md index 69e8671c355..58ea99f464c 100644 --- a/.changeset/34993-translation-fault-untranslated.md +++ b/.changeset/34993-translation-fault-untranslated.md @@ -13,3 +13,7 @@ fix(i18n, mcp): a translation fault serves the untranslated text with a warning When the i18n service resolves but its `getLocales` or `getTranslations` throws, the shared `/meta` translator (`translationBundleOf`, `@objectstack/rest`) now answers it as no bundle: the text is served untranslated and the server log says so at `warn` (`The translations could not be read (…), so labels and descriptions are served untranslated.`). Before, the translation rejected, so `GET /meta/:type` and `GET /meta/:type/:name` answered 500, the MCP object tools failed, `list_datasets` answered `datasets: []` with `partial: true`, and `query_dataset` refused 503 on both MCP transports. Now `list_datasets` keeps every dataset, in its authored text, with `partial: true` and that sentence as its `warning`; `query_dataset` answers. A dataset host's `loadDatasets` may return `{ items, warning }` without `partial`: a whole read the tools say something about, which `query_dataset` does not refuse. The translator's sources take an optional `reportTranslationFault(warning)` to carry the sentence on an answer. + +fix(mcp): `?locale=` reaches the MCP labels, and the dataset tools answer in one language + +The HTTP MCP door now reads a `?locale=` query parameter as the `/meta` doors do (after `Accept-Language`, before the i18n default), for the object and dataset labels and the app-docs tools; it read headers only, though its docblock promised both. The dataset executor (`createDatasetTools`) takes an optional `translationLocale` dependency, the locale its `loadDatasets` translated the rows for, and reads labels and composes `nextStep` and `sourceLine` in it first. Both MCP transports pass it, so a call with no `Accept-Language` (common for MCP clients, and every stdio call) no longer mixes labels in the i18n default with sentences in the workspace locale. diff --git a/packages/mcp/src/stdio-data-bridge.dataset-locale.test.ts b/packages/mcp/src/stdio-data-bridge.dataset-locale.test.ts index 7d37180946f..9a504dfdb76 100644 --- a/packages/mcp/src/stdio-data-bridge.dataset-locale.test.ts +++ b/packages/mcp/src/stdio-data-bridge.dataset-locale.test.ts @@ -24,7 +24,8 @@ * the untranslated list, never an error; * - an i18n service that resolves but whose `getLocales` / `getTranslations` * throws, over the REAL executor: the datasets untranslated, with a warning, - * on both dataset tools and the object tools (#34993, its own describe below). + * on both dataset tools and the object tools (#34993, its own describe below); + * - a header-less call answers labels and sentences in one language (#35083). */ import { describe, it, expect } from 'vitest'; @@ -216,12 +217,12 @@ describe('[ADR-0149 D2] stdio dataset tools when the i18n service resolves but i }; } - async function bridgeOverRealExecutor(i18n: () => unknown) { + async function bridgeOverRealExecutor(i18n: () => unknown, principal: object = PRINCIPAL) { return createStdioDataBridge({ engine: {} as any, metadataService: { list: async () => [] } as any, protocol: () => ({ getMetaItems: async () => ({ items: [METRICS] }) }) as any, - resolvePrincipal: async () => PRINCIPAL as any, + resolvePrincipal: async () => principal as any, datasetTools: await wiredAnalytics(), i18n, }); @@ -263,4 +264,27 @@ describe('[ADR-0149 D2] stdio dataset tools when the i18n service resolves but i expect([listed.label, listed.fields.stage.label]).toEqual(['Opportunity', 'Stage']); expect(((await view.getObject('crm_opportunity')) as typeof deal).label).toBe('Opportunity'); }); + + /** + * [#35083] A header-less stdio call, an i18n default of zh-CN and a + * workspace of `en`: the labels AND the executor's sentences answer what a + * zh-CN principal is answered — one language, the labels'. + */ + it('a header-less call answers labels and sentences in one language', async () => { + const ask = async (principal: object, defaultLocale = 'zh-CN') => { + const bridge = await bridgeOverRealExecutor(() => i18nService(defaultLocale), principal); + return { + list: await bridge.listDatasets!({ terms: ['total_amount'] }), + query: await bridge.queryDataset!({ datasetName: 'opp_metrics', selection: { measures: ['total_amount'] } }, { maxRows: 10 }), + }; + }; + const headerless = await ask({ ...PRINCIPAL, workspaceLocale: 'en' }); + const zh = await ask({ ...PRINCIPAL, locale: 'zh-CN' }); + const en = await ask({ ...PRINCIPAL, locale: 'en' }, 'en'); + expect(headerless.list.datasets[0].label).toBe('商机指标'); + expect(headerless.list.nextStep).toEqual(zh.list.nextStep); + expect(headerless.query.sourceLine).toBe(zh.query.sourceLine); + // Control: the two languages' sentences differ, so the equalities above are the locale's doing. + expect(en.query.sourceLine).not.toBe(zh.query.sourceLine); + }); }); diff --git a/packages/mcp/src/stdio-data-bridge.ts b/packages/mcp/src/stdio-data-bridge.ts index 54373cf951e..5cf5d500c80 100644 --- a/packages/mcp/src/stdio-data-bridge.ts +++ b/packages/mcp/src/stdio-data-bridge.ts @@ -287,6 +287,7 @@ export interface StdioDataBridgeDeps { export interface StdioDatasetToolsService { datasetTools(deps: { loadDatasets: (context: unknown) => Promise; + translationLocale?: (context: unknown) => Promise; diagnoseDelegation?: (object: string, context: unknown) => Promise<{ narrowed: boolean; statement?: string } | undefined>; maxQueryLimit?: number; }): { @@ -1704,7 +1705,9 @@ export function createStdioDataBridge(deps: StdioDataBridgeDeps): McpDataBridge // `metaRequestLocale` answers with no header), the workspace default the // stdio principal speaks. An i18n service this host cannot resolve leaves the // list untranslated, as there. [#34993] So does a translation fault, whose - // sentence the rows carry as their `warning`. The stdio bridge has no delegation probe (an API key is not delegated), so + // sentence the rows carry as their `warning`. [#35083] `translationLocale` + // is that one locale, so the executor's sentences speak the labels' language. + // The stdio bridge has no delegation probe (an API key is not delegated), so // none is passed, as `query_records` here carries none. if (deps.datasetTools) { const service = deps.datasetTools; @@ -1727,8 +1730,12 @@ export function createStdioDataBridge(deps: StdioDataBridgeDeps): McpDataBridge const rows = Array.isArray(translated) ? translated : items; return warning === undefined ? rows : { items: rows, warning }; }; + const translationLocale = async () => { + const sources = defaultLocaleSources(deps.i18n, async () => undefined); + return sources.requestLocale(await sources.resolveI18nService()); + }; const executor = (maxQueryLimit?: number) => - service.datasetTools({ loadDatasets, ...(maxQueryLimit !== undefined ? { maxQueryLimit } : {}) }); + service.datasetTools({ loadDatasets, translationLocale, ...(maxQueryLimit !== undefined ? { maxQueryLimit } : {}) }); bridge.listDatasets = async (input) => executor().listDatasets(input, await resolvePrincipal()); bridge.queryDataset = async (input, opts) => executor(opts.maxRows).queryDataset(input, await resolvePrincipal()); bridge.datasetToolDefinitions = () => executor().definitions; diff --git a/packages/runtime/src/domains/mcp.ts b/packages/runtime/src/domains/mcp.ts index b6d0c3528b7..d3c559f7c15 100644 --- a/packages/runtime/src/domains/mcp.ts +++ b/packages/runtime/src/domains/mcp.ts @@ -1614,7 +1614,7 @@ export function buildMcpBridge( ec as Record | undefined, (name) => deps.resolveService(context, name), ), - locale: metaRequestLocale({ headers: context.request?.headers }), + locale: metaRequestLocale(mcpRequestHttp(context)), })) : {}), }; @@ -1631,6 +1631,7 @@ export function buildMcpBridge( export interface McpDatasetToolsService { datasetTools(deps: { loadDatasets: (context: unknown) => Promise; + translationLocale?: (context: unknown) => Promise; diagnoseDelegation?: (object: string, context: unknown) => Promise<{ narrowed: boolean; statement?: string } | undefined>; maxQueryLimit?: number; }): { @@ -1679,6 +1680,29 @@ export async function resolveMcpPackageDocsProtocol( return protocol && typeof protocol.getMetaItems === 'function' ? (protocol as PackageDocsProtocol) : undefined; } +/** + * [#35083] This request's two locale members, as the REST door reads them: its + * headers, and its query — the host's parsed `query` where the request carries + * one, else its URL's (a repeated `?locale=` stays an array, which the locale + * read sends to the i18n default). + */ +function mcpRequestHttp(context: HttpProtocolContext): { headers?: unknown; query?: Record } { + const request: any = context.request; + if (request?.query && typeof request.query === 'object') return { headers: request.headers, query: request.query }; + let params: URLSearchParams | undefined; + try { + params = typeof request?.url === 'string' ? new URL(request.url, 'http://localhost').searchParams : undefined; + } catch { + params = undefined; + } + const query: Record = {}; + for (const key of new Set(params?.keys() ?? [])) { + const values = params!.getAll(key); + query[key] = values.length > 1 ? values : values[0]; + } + return { headers: request?.headers, query }; +} + /** * [ADR-0149 D2 · #34872] What the `/meta` translation reads for THIS request: * the request's i18n service (a lookup that throws is none, and the text is @@ -1703,7 +1727,7 @@ function metaTranslationSources( } }, resolveProtocol: getProtocol, - requestLocale: (i18n?: unknown) => metaRequestLocale({ headers: context.request?.headers }, i18n), + requestLocale: (i18n?: unknown) => metaRequestLocale(mcpRequestHttp(context), i18n), }; } @@ -1718,6 +1742,8 @@ function metaTranslationSources( * the executor answers it as a degraded read (`partial` / 503), never as an * empty catalogue. [#34993] A translation fault is no failed read: the rows * are handed over untranslated, with the fault's sentence as their `warning`. + * - [#35083] `translationLocale` is the locale that translation read, so the + * executor's labels and its sentences speak one language. * - The narrowing probe is the bridge's own `diagnoseDelegation` read, asked * of this request's security service, so `query_dataset` states a narrowing * exactly where `query_records` does. @@ -1744,6 +1770,10 @@ function datasetToolMembers( const rows = Array.isArray(translated) ? translated : items; return warning === undefined ? rows : { items: rows, warning }; }; + const translationLocale = async () => { + const sources = metaTranslationSources(deps, context, getProtocol); + return sources.requestLocale(await sources.resolveI18nService()); + }; const diagnoseDelegation = async (object: string) => { try { const security = await deps.resolveService(context, 'security', envId) as @@ -1755,7 +1785,7 @@ function datasetToolMembers( } }; const executor = (maxQueryLimit?: number) => - service.datasetTools({ loadDatasets, diagnoseDelegation, ...(maxQueryLimit !== undefined ? { maxQueryLimit } : {}) }); + service.datasetTools({ loadDatasets, translationLocale, diagnoseDelegation, ...(maxQueryLimit !== undefined ? { maxQueryLimit } : {}) }); return { listDatasets: (input: unknown) => executor().listDatasets(input, ec), queryDataset: (input: unknown, opts: { maxRows: number }) => executor(opts.maxRows).queryDataset(input, ec), diff --git a/packages/runtime/src/mcp-dataset-tools-bridge.test.ts b/packages/runtime/src/mcp-dataset-tools-bridge.test.ts index 28474335f4e..e16ba478689 100644 --- a/packages/runtime/src/mcp-dataset-tools-bridge.test.ts +++ b/packages/runtime/src/mcp-dataset-tools-bridge.test.ts @@ -12,7 +12,8 @@ * layer's page cap; and every call runs as the request's own principal. * Also pinned (its own describes below): an i18n service that resolves but * whose `getLocales` / `getTranslations` throws, over the REAL executor, serves - * the datasets untranslated with a warning (#34993). + * the datasets untranslated with a warning (#34993); and a `?locale=` with no + * `Accept-Language` answers labels and sentences in that one locale (#35083). */ import { describe, it, expect, vi } from 'vitest'; @@ -182,10 +183,13 @@ describe('[ADR-0149 D2] the HTTP dataset tools when the i18n service resolves bu }; } - async function bridgeOverRealExecutor(i18n: unknown) { + async function bridgeOverRealExecutor(i18n: unknown, request?: { url?: string; headers?: Record; locale?: string }) { const analytics = await wiredAnalytics(); const protocol = { getMetaItems: async ({ type }: { type: string }) => ({ type, items: type === 'dataset' ? [METRICS] : [] }) }; const { ctx, deps } = harness({ analytics, i18n, protocol }); + if (request?.url) ctx.request.url = request.url; + if (request?.headers) Object.assign(ctx.request.headers, request.headers); + if (request?.locale) ctx.executionContext = { ...EC, locale: request.locale }; expect(await resolveMcpDatasetToolsService(deps, ctx)).toBe(analytics); return buildMcpBridge(deps, ctx, { datasetTools: analytics }); } @@ -220,4 +224,30 @@ describe('[ADR-0149 D2] the HTTP dataset tools when the i18n service resolves bu expect(answer.rowCount).toBe(1); expect(answer.provenance.dataset).toEqual({ name: 'sales_analysis', label: 'Sales analysis' }); }); + + /** + * [#35083] `?locale=zh-CN` with no `Accept-Language`, an i18n default of + * `en`: the labels AND the executor's sentences (`nextStep`, `sourceLine`) + * answer what an `Accept-Language: zh-CN` caller is answered — one language. + */ + it('a ?locale= with no Accept-Language answers labels and sentences in that one locale', async () => { + const enDefault = { + getLocales: () => ['zh-CN', 'en'], + getTranslations: (locale: string) => (locale === 'zh-CN' ? ZH_CN : {}), + getDefaultLocale: () => 'en', + }; + const ask = async (bridge: any) => ({ + list: await bridge.listDatasets({ terms: ['revenue'] }), + query: await bridge.queryDataset({ datasetName: 'sales_analysis', selection: { measures: ['revenue'] } }, { maxRows: 10 }), + }); + const viaQuery = await ask(await bridgeOverRealExecutor(enDefault, { url: '/api/v1/mcp?locale=zh-CN' })); + const viaHeader = await ask(await bridgeOverRealExecutor(enDefault, { headers: { 'accept-language': 'zh-CN' }, locale: 'zh-CN' })); + const plain = await ask(await bridgeOverRealExecutor(enDefault)); + expect(viaQuery.list.datasets[0].label).toBe('销售分析'); + expect(viaQuery.list.nextStep).toEqual(viaHeader.list.nextStep); + expect(viaQuery.query.sourceLine).toBe(viaHeader.query.sourceLine); + // Control: without the parameter, the default's language, so the two above are the locale's doing. + expect(plain.list.datasets[0].label).toBe('Sales analysis'); + expect(plain.query.sourceLine).not.toBe(viaHeader.query.sourceLine); + }); }); diff --git a/packages/services/service-analytics/src/dataset-tools.ts b/packages/services/service-analytics/src/dataset-tools.ts index 537def26a7b..8bbc2078559 100644 --- a/packages/services/service-analytics/src/dataset-tools.ts +++ b/packages/services/service-analytics/src/dataset-tools.ts @@ -206,6 +206,13 @@ export interface DatasetToolsDeps { * degraded read: `list_datasets` answers `partial`, `query_dataset` 503. */ readonly loadDatasets: (context: ExecutionContext | undefined) => Promise; + /** + * [#35083] The locale `loadDatasets` translated the rows for. Labels are + * read, and sentences (`nextStep`, `sourceLine`) composed, in it first, so + * one answer speaks one language. Optional: absent, answering `undefined` or + * throwing, the caller's locale ladder alone (`userTextLocalesOf`). + */ + readonly translationLocale?: (context: ExecutionContext | undefined) => Promise; /** `query_dataset`'s row cap — the bridge's `maxQueryLimit`. Default {@link DATASET_TOOL_DEFAULT_MAX_ROWS}. */ readonly maxQueryLimit?: number; /** @@ -387,6 +394,16 @@ export function createDatasetTools(deps: DatasetToolsDeps): DatasetTools { ? Math.floor(deps.maxQueryLimit) : DATASET_TOOL_DEFAULT_MAX_ROWS; + /** [#35083] The answer's locale ({@link DatasetToolsDeps.translationLocale}), and its sentence ladder. */ + async function answerLocales(context: ExecutionContext | undefined): Promise<{ locale?: string; sentence: string[] }> { + const translated = await Promise.resolve() + .then(() => deps.translationLocale?.(context)) + .catch(() => undefined); + const ladder = sentenceLocales(context); + if (typeof translated !== 'string' || translated === '') return { locale: context?.locale, sentence: ladder }; + return { locale: translated, sentence: [translated, ...ladder.filter((l) => l !== translated)] }; + } + /** * The saved datasets, each stripped of read decorations and parsed as the * REST door parses a saved dataset; one that fails the parse is left out (a @@ -423,6 +440,7 @@ export function createDatasetTools(deps: DatasetToolsDeps): DatasetTools { const parsed = ListDatasetsInputSchema.safeParse(input ?? {}); if (!parsed.success) throw inputRefusal(LIST_DATASETS_TOOL_NAME, parsed.error.issues, input); const terms = parsed.data.terms; + const { locale, sentence } = await answerLocales(context); let loaded: LoadedDatasets; try { @@ -430,7 +448,7 @@ export function createDatasetTools(deps: DatasetToolsDeps): DatasetTools { } catch (e) { // The #6504 shape: never a count that is not a fact. const nextStep = terms !== undefined - ? composeDatasetNextStep({ terms, datasets: [], candidates: [], partial: true, locales: sentenceLocales(context) }) + ? composeDatasetNextStep({ terms, datasets: [], candidates: [], partial: true, locales: sentence }) : undefined; return { datasets: [], @@ -440,7 +458,6 @@ export function createDatasetTools(deps: DatasetToolsDeps): DatasetTools { }; } - const locale = context?.locale; const entries: DatasetToolCatalogEntry[] = []; // The admitted members of each listed dataset, in its entry's order: the // only members a candidate may name (ADR-0149 D3 amendment note). @@ -491,7 +508,7 @@ export function createDatasetTools(deps: DatasetToolsDeps): DatasetTools { // [ADR-0149 M1 note] Composed last, from this answer alone: the entries // and candidates above are the admitted members, and nothing else is read. const nextStep = terms !== undefined - ? composeDatasetNextStep({ terms, datasets: entries, candidates, partial: warnings.length > 0, locales: sentenceLocales(context) }) + ? composeDatasetNextStep({ terms, datasets: entries, candidates, partial: warnings.length > 0, locales: sentence }) : undefined; return { datasets: entries, @@ -602,13 +619,14 @@ export function createDatasetTools(deps: DatasetToolsDeps): DatasetTools { } // Composed last, so nothing the answer carries can stand in for them. - const provenance = composeProvenance(dataset, raw.selection, context?.locale); + const { locale, sentence } = await answerLocales(context); + const provenance = composeProvenance(dataset, raw.selection, locale); return { ...rest, rows: served, provenance, // [ADR-0149 M1 note] The same source as one line, from `provenance` alone. - sourceLine: composeDatasetSourceLine(provenance, sentenceLocales(context)), + sourceLine: composeDatasetSourceLine(provenance, sentence), rowCount: served.length, truncated, ...(totalGroups !== undefined ? { totalGroups } : {}), From 1ac62a18ec24aabd9acf290767996b5c1324699c Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 19 Nov 2026 22:54:04 +0000 Subject: [PATCH 3/4] test(rest): pay the objectql load at collection in the translation-fault pin The REST /meta translation-fault pin reaches a lazy objectql import through RestServer; a module-top side-effect import pays it during collection (check:test-source-alias). Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_016WV4d1k1GRsQbF3vCPKxhz --- packages/rest/src/meta-translation-fault-34993.test.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/rest/src/meta-translation-fault-34993.test.ts b/packages/rest/src/meta-translation-fault-34993.test.ts index 924f0acf27b..e2369d710b5 100644 --- a/packages/rest/src/meta-translation-fault-34993.test.ts +++ b/packages/rest/src/meta-translation-fault-34993.test.ts @@ -10,6 +10,8 @@ */ import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest'; +// Paid at collection, not inside a case's clock: the server's reach loads it lazily. +import '@objectstack/objectql'; import { RestServer } from './rest-server.js'; const ACCOUNT = { name: 'showcase_account', label: 'Account', fields: { industry: { name: 'industry', type: 'text', label: 'Industry' } } }; From ee348e46da2f09d614cf403fc0ea60a11c79d0dc Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 20 Nov 2026 01:02:49 +0000 Subject: [PATCH 4/4] docs(changeset): the translation-fault headline names which surface warns the client The untranslated text is served and the fault is logged; only list_datasets carries a client-visible partial flag and warning, while REST /meta, the MCP object tools and query_dataset log only. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_016WV4d1k1GRsQbF3vCPKxhz --- .changeset/34993-translation-fault-untranslated.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/34993-translation-fault-untranslated.md b/.changeset/34993-translation-fault-untranslated.md index 58ea99f464c..b93a1221014 100644 --- a/.changeset/34993-translation-fault-untranslated.md +++ b/.changeset/34993-translation-fault-untranslated.md @@ -8,7 +8,7 @@ Clause-②: yes (widening) Metadata-protocol: none -fix(i18n, mcp): a translation fault serves the untranslated text with a warning instead of failing the read +fix(i18n, mcp): a translation fault serves the untranslated text and the fault is logged, instead of failing the read; `list_datasets` is flagged `partial` with a `warning`, while REST `/meta`, the MCP object tools and `query_dataset` log only When the i18n service resolves but its `getLocales` or `getTranslations` throws, the shared `/meta` translator (`translationBundleOf`, `@objectstack/rest`) now answers it as no bundle: the text is served untranslated and the server log says so at `warn` (`The translations could not be read (…), so labels and descriptions are served untranslated.`). Before, the translation rejected, so `GET /meta/:type` and `GET /meta/:type/:name` answered 500, the MCP object tools failed, `list_datasets` answered `datasets: []` with `partial: true`, and `query_dataset` refused 503 on both MCP transports.