diff --git a/.changeset/37403-refusal-reasons-listed.md b/.changeset/37403-refusal-reasons-listed.md
new file mode 100644
index 00000000000..fbcccf26734
--- /dev/null
+++ b/.changeset/37403-refusal-reasons-listed.md
@@ -0,0 +1,16 @@
+---
+'@object-ui/types': patch
+'@object-ui/core': patch
+'@object-ui/app-shell': patch
+---
+
+feat(console): a refusal that names several reasons lists every one in its alert box
+
+Clause-②: yes (widening)
+Metadata-protocol: none
+
+The widening: `@object-ui/types` adds the export `ActionRefusalLine` and the optional member `ActionResult.refusals`, and `@object-ui/core` adds the optional member `ActionResponseOutcome.refusals`. Nothing is narrowed; every package ships `patch`.
+
+- **Every reason is shown.** When a refusal names several reasons (the server answers each reason's sentence on `error.details.refusals`), the action dialog's refusal box lists every reason in the order the server sent them, then the refusal's closing sentence, with no "More" toggle hiding any of them. A refusal without such a list renders as before.
+- **The reasons come from the list, not from the text.** The closing sentence is read from the end of the refusal text only when that text still starts with exactly the listed reasons; when the text was cut short, every reason is still shown and the closing sentence is left out.
+- **New: `ActionResult.refusals`** (`@object-ui/types`, with its element type `ActionRefusalLine`) **and `ActionResponseOutcome.refusals`** (`@object-ui/core`): the reasons a failed result's refusal listed, read from the `/actions` response by `interpretActionResponse` and set by the server action handler beside `userMessage`. `RefusalMessage` (`@object-ui/app-shell`) takes them as `lines`.
diff --git a/ui/packages/app-shell/src/components/RefusalMessage.test.tsx b/ui/packages/app-shell/src/components/RefusalMessage.test.tsx
index 9875a10d261..0a68dacb848 100644
--- a/ui/packages/app-shell/src/components/RefusalMessage.test.tsx
+++ b/ui/packages/app-shell/src/components/RefusalMessage.test.tsx
@@ -118,3 +118,53 @@ describe('RefusalMessage — one sentence first, the rest behind More (objectui#
expect(screen.queryByTestId('refusal-detail')).toBeNull();
});
});
+
+/**
+ * A refusal that names several reasons lists every one (objectstack#36877,
+ * ruling term 6). The server answers each reason's sentence on
+ * `error.details.refusals` and joins them, with the refusal's own closing
+ * sentence last, into the text; the `/data` door cuts that text at 500
+ * characters and leaves the list whole. The sentences below are the
+ * `/actions` door's answer pinned on the server side for an expense
+ * submission that refuses two expenses.
+ */
+describe('RefusalMessage — a refusal with several reasons lists every line (objectstack#37403)', () => {
+ const LINES = [
+ { reason: 'on_report', message: 'Expense Taxi 12 is already on an expense report.' },
+ { reason: 'approved', message: 'Expense Hotel 7 is already approved.' },
+ ];
+ const CLOSING = 'Nothing was submitted.';
+ const TEXT = `${LINES[0].message}\n${LINES[1].message}\n${CLOSING}`;
+ const items = () => screen.getAllByTestId('refusal-line').map((li) => li.textContent);
+
+ it('shows every reason in order, then the closing sentence, in one list with no More', () => {
+ render();
+
+ expect(screen.getAllByTestId('refusal-lines')).toHaveLength(1);
+ expect(items()).toEqual([LINES[0].message, LINES[1].message, CLOSING]);
+ expect(screen.queryByTestId('refusal-more')).toBeNull();
+ expect(screen.queryByTestId('refusal-lead')).toBeNull();
+ });
+
+ it('a text cut inside the reasons still shows every reason from the list, and no closing sentence', () => {
+ const cut = `${LINES[0].message}\n${LINES[1].message.slice(0, 12)}…`;
+ render();
+
+ expect(items()).toEqual([LINES[0].message, LINES[1].message]);
+ expect(screen.queryByText(/Nothing was submitted/)).toBeNull();
+ expect(screen.queryByTestId('refusal-more')).toBeNull();
+ });
+
+ it('CONTROL: a single-sentence refusal with no list renders as text alone, as before', () => {
+ const { container } = render();
+ expect(container.innerHTML).toBe(CLOSING);
+ expect(screen.queryByTestId('refusal-lines')).toBeNull();
+ });
+
+ it('CONTROL: an empty list is no list — the text keeps its lead and More', () => {
+ render();
+ expect(screen.queryByTestId('refusal-lines')).toBeNull();
+ expect(screen.getByTestId('refusal-lead')).toHaveTextContent(LINES[0].message);
+ expect(screen.getByTestId('refusal-more')).toBeInTheDocument();
+ });
+});
diff --git a/ui/packages/app-shell/src/components/RefusalMessage.tsx b/ui/packages/app-shell/src/components/RefusalMessage.tsx
index 0df85e27713..10d8749538f 100644
--- a/ui/packages/app-shell/src/components/RefusalMessage.tsx
+++ b/ui/packages/app-shell/src/components/RefusalMessage.tsx
@@ -4,6 +4,7 @@ import { useEffect, useState } from 'react';
import { Check, ChevronDown, Copy } from 'lucide-react';
import { Collapsible, CollapsibleContent, CollapsibleTrigger, cn } from '@object-ui/components';
import { useObjectTranslation } from '@object-ui/i18n';
+import type { ActionRefusalLine } from '@object-ui/types';
import { splitRefusal } from '../utils/refusalLead.js';
/**
@@ -16,8 +17,21 @@ import { splitRefusal } from '../utils/refusalLead.js';
* rest of the server's text one click away, selectable and copyable as sent.
* See {@link splitRefusal} for how the sentence is found. A message that is a
* single sentence renders as it always did, with no disclosure.
+ *
+ * A refusal that names several reasons (objectstack#36877) is the exception:
+ * every reason is shown, as one list, with no "More" — see
+ * {@link refusalListItems} for where each line comes from.
*/
-export function RefusalMessage({ text, className }: { text: string; className?: string }) {
+export function RefusalMessage({
+ text,
+ lines,
+ className,
+}: {
+ text: string;
+ /** The refusal's reasons as the server listed them (`error.details.refusals`). */
+ lines?: readonly ActionRefusalLine[];
+ className?: string;
+}) {
const { t } = useObjectTranslation();
const { lead, full } = splitRefusal(text);
const [open, setOpen] = useState(false);
@@ -29,6 +43,17 @@ export function RefusalMessage({ text, className }: { text: string; className?:
return () => clearTimeout(id);
}, [copied]);
+ const items = refusalListItems(text, lines);
+ if (items !== null) {
+ return (
+
+ {items.map((item, i) => (
+ - {item}
+ ))}
+
+ );
+ }
+
// Nothing to disclose: the text alone, with no wrapper, so the caller's box
// reads exactly as it did before this component existed.
if (full === null) return <>{lead}>;
@@ -78,3 +103,26 @@ export function RefusalMessage({ text, className }: { text: string; className?:
);
}
+
+/**
+ * The lines of a refusal that names several reasons (objectstack#36877,
+ * ruling term 6), in order: each listed reason's sentence, then the refusal's
+ * own closing sentence. `null` when the server sent no list, so the message
+ * renders as a single refusal does.
+ *
+ * The reasons come from the list the server sent, never from splitting the
+ * text: the `/data` door cuts `userMessage` at 500 characters and leaves the
+ * list whole, so a long refusal's text can stop partway through its reasons.
+ * The closing sentence is on no list — the server sends it only as the last
+ * line of the text, after the reasons joined by line breaks — so it is read
+ * from there, and only when the text still starts with exactly those
+ * reasons. A text cut inside the reasons carries no closing sentence, and
+ * the reasons alone are shown.
+ */
+function refusalListItems(text: string, lines?: readonly ActionRefusalLine[]): string[] | null {
+ if (!lines || lines.length === 0) return null;
+ const reasons = lines.map((line) => line.message);
+ const head = `${reasons.join('\n')}\n`;
+ const closing = text.startsWith(head) ? text.slice(head.length).trim() : '';
+ return closing ? [...reasons, closing] : reasons;
+}
diff --git a/ui/packages/app-shell/src/views/ActionParamDialog.refusalKeepsInput-13161.test.tsx b/ui/packages/app-shell/src/views/ActionParamDialog.refusalKeepsInput-13161.test.tsx
index 9d6b1624226..0022d972e24 100644
--- a/ui/packages/app-shell/src/views/ActionParamDialog.refusalKeepsInput-13161.test.tsx
+++ b/ui/packages/app-shell/src/views/ActionParamDialog.refusalKeepsInput-13161.test.tsx
@@ -234,3 +234,31 @@ describe('ActionParamDialog — a refused run keeps the typed input (objectui#13
expect(confirmButton()).not.toBeDisabled();
});
});
+
+/**
+ * A refused run whose refusal names several reasons (objectstack#36877) hands
+ * the reasons the runner relayed (`ActionResult.refusals`) to the refusal box,
+ * which lists every one with the closing sentence last (objectstack#37403).
+ */
+describe('ActionParamDialog — a refusal with several reasons lists them in the box (objectstack#37403)', () => {
+ it('every reason in order, the closing sentence last, in the one alert box', async () => {
+ const refusals = [
+ { reason: 'on_report', message: 'Expense Taxi 12 is already on an expense report.' },
+ { reason: 'approved', message: 'Expense Hotel 7 is already approved.' },
+ ];
+ const text = `${refusals[0].message}\n${refusals[1].message}\nNothing was submitted.`;
+ const run = vi.fn(async (): Promise => ({ success: false, error: text, userMessage: text, refusals }));
+ openWith({ run });
+
+ await type('Email', 'ada@example.com');
+ fireEvent.click(confirmButton());
+
+ const alert = await screen.findByTestId('action-param-refusal');
+ expect(within(alert).getAllByTestId('refusal-line').map((li) => li.textContent)).toEqual([
+ refusals[0].message,
+ refusals[1].message,
+ 'Nothing was submitted.',
+ ]);
+ expect(within(alert).queryByTestId('refusal-more')).toBeNull();
+ });
+});
diff --git a/ui/packages/app-shell/src/views/ActionParamDialog.tsx b/ui/packages/app-shell/src/views/ActionParamDialog.tsx
index fa9cd8a6191..482f6d0f564 100644
--- a/ui/packages/app-shell/src/views/ActionParamDialog.tsx
+++ b/ui/packages/app-shell/src/views/ActionParamDialog.tsx
@@ -670,6 +670,9 @@ export function ActionParamDialog({ state, onOpenChange }: ActionParamDialogProp
const [submitting, setSubmitting] = useState(false);
// The last run's refusal, shown above the buttons until the next Confirm.
const [refusal, setRefusal] = useState(null);
+ // The reasons a refusal that names several listed (objectstack#36877), shown
+ // one per line in the refusal box.
+ const [refusalLines, setRefusalLines] = useState(undefined);
// A param may carry a `visible` predicate (CEL) gating it on the same scope as
// action visibility (features / user / app / data) — e.g. `create_user`'s
@@ -901,6 +904,7 @@ export function ActionParamDialog({ state, onOpenChange }: ActionParamDialogProp
const { marks, complete } = refusalParamMarks(result, dialogParams);
setErrors(marks);
setRefusal(complete ? null : refusalText(result));
+ setRefusalLines(result.refusals);
return;
}
}
@@ -1246,7 +1250,7 @@ export function ActionParamDialog({ state, onOpenChange }: ActionParamDialogProp
data-testid="action-param-refusal"
className="rounded-md border border-destructive/50 bg-destructive/10 p-3 text-sm text-destructive whitespace-pre-line"
>
-
+
)}
diff --git a/ui/packages/core/src/actions/__tests__/actionResponse.test.ts b/ui/packages/core/src/actions/__tests__/actionResponse.test.ts
index c9e022739e0..1cc2b6fab7a 100644
--- a/ui/packages/core/src/actions/__tests__/actionResponse.test.ts
+++ b/ui/packages/core/src/actions/__tests__/actionResponse.test.ts
@@ -107,3 +107,33 @@ describe('readActionPayload — legacy double wrap vs #3962 single wrap', () =>
expect(readActionPayload([1, 2])).toEqual([1, 2]);
});
});
+
+/**
+ * A refusal that names several reasons (objectstack#36877) answers each
+ * reason's sentence on `error.details.refusals`; the outcome carries the list
+ * so the console can show every reason (objectstack#37403). The list is read
+ * whole or not at all, as the server's own reader reads it.
+ */
+describe('interpretActionResponse — a refusal with several reasons (objectstack#37403)', () => {
+ const refusals = [
+ { reason: 'on_report', message: 'Expense Taxi 12 is already on an expense report.' },
+ { reason: 'approved', message: 'Expense Hotel 7 is already approved.' },
+ ];
+ const text = `${refusals[0].message}\n${refusals[1].message}\nNothing was submitted.`;
+ const refused = (details: unknown) => interpretActionResponse({ ok: false, status: 409 }, {
+ success: false,
+ error: { code: 'NOT_SUBMITTED', message: text, userMessage: text, details },
+ }, 'Action "submit_expenses"');
+
+ it('carries error.details.refusals in order, each copied to reason and message', () => {
+ const out = refused({ refusals: refusals.map((r) => ({ ...r, extra: 1 })) });
+ expect(out).toMatchObject({ ok: false, error: text, userMessage: text });
+ expect(out.refusals).toEqual(refusals);
+ });
+
+ it('CONTROL: no list, an empty list or a list with a malformed element carries none', () => {
+ for (const details of [undefined, {}, { refusals: [] }, { refusals: [refusals[0], { reason: 'approved' }] }, { refusals: 'x' }]) {
+ expect('refusals' in refused(details)).toBe(false);
+ }
+ });
+});
diff --git a/ui/packages/core/src/actions/__tests__/serverActionHandler.test.ts b/ui/packages/core/src/actions/__tests__/serverActionHandler.test.ts
index 16d4e96e7e9..fab700eac4f 100644
--- a/ui/packages/core/src/actions/__tests__/serverActionHandler.test.ts
+++ b/ui/packages/core/src/actions/__tests__/serverActionHandler.test.ts
@@ -464,3 +464,28 @@ describe('createServerActionHandler — userMessage relay (objectstack#34173)',
}
});
});
+
+/**
+ * The reasons of a refusal that names several (`error.details.refusals`,
+ * objectstack#36877) ride on `ActionResult.refusals`, beside `userMessage`,
+ * so the param dialog's refusal box can list them (objectstack#37403).
+ */
+describe('createServerActionHandler — refusal reasons relay (objectstack#37403)', () => {
+ it('relays error.details.refusals beside error and userMessage', async () => {
+ const refusals = [
+ { reason: 'on_report', message: 'Expense Taxi 12 is already on an expense report.' },
+ { reason: 'approved', message: 'Expense Hotel 7 is already approved.' },
+ ];
+ const text = `${refusals[0].message}\n${refusals[1].message}\nNothing was submitted.`;
+ const fetch = vi.fn(async () => ({
+ ok: false,
+ status: 409,
+ json: async () => ({ success: false, error: { code: 'NOT_SUBMITTED', message: text, userMessage: text, details: { refusals } } }),
+ })) as unknown as ServerActionFetch;
+ const handler = createServerActionHandler({ fetch });
+
+ const res = await handler({ type: 'script', name: 'submit_expenses' } as ActionDef);
+
+ expect(res).toEqual({ success: false, error: text, userMessage: text, refusals });
+ });
+});
diff --git a/ui/packages/core/src/actions/actionResponse.ts b/ui/packages/core/src/actions/actionResponse.ts
index 6dbb8748f70..09e89ff5ffa 100644
--- a/ui/packages/core/src/actions/actionResponse.ts
+++ b/ui/packages/core/src/actions/actionResponse.ts
@@ -49,7 +49,7 @@
* failure directly.
*/
-import type { ActionFieldError } from '@object-ui/types';
+import type { ActionFieldError, ActionRefusalLine } from '@object-ui/types';
import { actionErrorDetail } from './actionErrorDetail.js';
export interface ActionResponseOutcome {
@@ -66,6 +66,11 @@ export interface ActionResponseOutcome {
* when it carried one. Only on a failure; `error` stays the whole text.
*/
userMessage?: string;
+ /**
+ * The reasons of a refusal that names several (`error.details.refusals`),
+ * when it carried such a list. Only on a failure.
+ */
+ refusals?: ActionRefusalLine[];
/**
* The ACTION ENVELOPE (`body.data`) — `{ success, data }`. Kept as-is
* because `ActionResult.data` has always carried this level and
@@ -132,6 +137,7 @@ export function interpretActionResponse(
// crashes the page, React #31).
const fieldErrors = refusalFieldErrors(innerFailed ? envelope : json);
const userMessage = refusalUserMessage(innerFailed ? envelope : json);
+ const refusals = refusalLines(innerFailed ? envelope : json);
return {
ok: false,
error: innerFailed
@@ -139,6 +145,7 @@ export function interpretActionResponse(
: actionErrorDetail(json, `${label} failed (HTTP ${res.status})`),
...(fieldErrors ? { fieldErrors } : {}),
...(userMessage !== undefined ? { userMessage } : {}),
+ ...(refusals ? { refusals } : {}),
};
}
@@ -161,6 +168,31 @@ export function refusalUserMessage(body: unknown): string | undefined {
return typeof raw === 'string' && raw.trim() ? raw : undefined;
}
+/**
+ * The reasons of a refusal that names several (objectstack#36877), as
+ * `ActionResult.refusals` carries them: `error.details.refusals`, each element
+ * `{ reason, message }` with both members strings, the reason's sentence
+ * already rendered in the request's locale. The list is read whole or not at
+ * all: an empty list, or one with any element of another shape, is no list.
+ * That is the element rule the server's own reader (`declaredRefusalLines`)
+ * applies before it answers one; the server also requires a declared
+ * `userMessage` beside the list, which this reader does not re-check because
+ * it reads only what the server answered. Each element is copied to exactly
+ * those two members.
+ */
+export function refusalLines(body: unknown): ActionRefusalLine[] | undefined {
+ const b = body as { error?: { details?: { refusals?: unknown } } } | null | undefined;
+ const raw = b?.error && typeof b.error === 'object' ? b.error.details?.refusals : undefined;
+ if (!Array.isArray(raw) || raw.length === 0) return undefined;
+ const out: ActionRefusalLine[] = [];
+ for (const entry of raw) {
+ const e = entry as { reason?: unknown; message?: unknown } | null;
+ if (!e || typeof e !== 'object' || typeof e.reason !== 'string' || typeof e.message !== 'string') return undefined;
+ out.push({ reason: e.reason, message: e.message });
+ }
+ return out;
+}
+
/**
* The `fields` list of a refusal body, as `ActionResult.fieldErrors` carries
* it. The ADR-0112 envelope carries the list in one of two members, both on
diff --git a/ui/packages/core/src/actions/serverActionHandler.ts b/ui/packages/core/src/actions/serverActionHandler.ts
index 7c9a6bb41b5..b967c7e8987 100644
--- a/ui/packages/core/src/actions/serverActionHandler.ts
+++ b/ui/packages/core/src/actions/serverActionHandler.ts
@@ -306,6 +306,7 @@ export function createServerActionHandler(config: ServerActionHandlerConfig): Se
error: outcome.error,
...(outcome.fieldErrors ? { fieldErrors: outcome.fieldErrors } : {}),
...(outcome.userMessage !== undefined ? { userMessage: outcome.userMessage } : {}),
+ ...(outcome.refusals ? { refusals: outcome.refusals } : {}),
};
}
// A declared `operation: 'update'` wrote the record it addresses — that
diff --git a/ui/packages/types/src/index.ts b/ui/packages/types/src/index.ts
index bed7bb421a3..0c7bb32251d 100644
--- a/ui/packages/types/src/index.ts
+++ b/ui/packages/types/src/index.ts
@@ -1274,6 +1274,7 @@ export type {
ActionContext,
ActionResult,
ActionFieldError,
+ ActionRefusalLine,
// The `undo` payload of `ActionResult`, moved down from `@object-ui/core`'s
// `UndoManager` with it (objectui#6349, batch 4); core re-exports it.
UndoableOperation,
diff --git a/ui/packages/types/src/ui-action.ts b/ui/packages/types/src/ui-action.ts
index 7d368ae34f4..b41311325fb 100644
--- a/ui/packages/types/src/ui-action.ts
+++ b/ui/packages/types/src/ui-action.ts
@@ -1279,6 +1279,18 @@ export interface ActionFieldError {
label?: string;
}
+/**
+ * One reason of a refusal that names several (objectstack#36877), as the
+ * server answers it in `error.details.refusals`: the declared reason's key
+ * and its sentence, already rendered in the request's locale.
+ */
+export interface ActionRefusalLine {
+ /** The declared reason's key. */
+ reason: string;
+ /** The reason's sentence, shown verbatim. */
+ message: string;
+}
+
/**
* Action execution result — the ONE declaration of this name (objectui#6349,
* batch 4). `@object-ui/core`'s `ActionRunner` module used to declare a second
@@ -1319,6 +1331,15 @@ export interface ActionResult {
*/
userMessage?: string;
+ /**
+ * The reasons of a refusal that names several, in the order the server
+ * answered them (`error.details.refusals`, objectstack#36877). Set only on a
+ * failed result whose refusal carried such a list. The refusal's closing
+ * sentence is not on the list: it is the last line of `userMessage` and of
+ * `error`, which stay the whole text.
+ */
+ refusals?: ActionRefusalLine[];
+
/** Whether the caller should reload its data after the action */
reload?: boolean;