Skip to content

Commit d04e0e2

Browse files
committed
Merge origin/main into claude/project-thread-r2ii08
Claude-Session: https://claude.ai/code/session_017ihL2dvnT51fbSebUyE3zW Co-Authored-By: Claude <noreply@anthropic.com>
2 parents b0db638 + b3bd75d commit d04e0e2

8 files changed

Lines changed: 332 additions & 7 deletions
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
'@objectstack/mcp': patch
3+
---
4+
5+
fix(mcp): a coded refusal from a sandboxed hook or action body answers the body's own sentence, not the sandbox wrapper that names the hook
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
A QuickJS hook or action body that throws with a declared `code` and `status` (for example `throw Object.assign(new Error('Locked.'), { code: 'RECORD_LOCKED', status: 409 })`) reached every MCP tool and the `objectstack://objects/{name}/records/{id}` resource with the sandbox's debug wrapper as its message, `hook '<name>' threw: Error: Locked.`, so an agent saw the hook's internal name. `/api/v1/data` answers the same throw with the body's sentence alone.
11+
12+
The MCP tools and the record resource now read that sentence the way the `/data` door does (`sandboxBusinessMessage`, `@objectstack/types`): `{ "error": { "code": "RECORD_LOCKED", "message": "Locked.", "status": 409 } }`. The code and status are unchanged. A coded refusal that does not come from a sandbox keeps its own message byte for byte, and a sandboxed body that crashed keeps today's message.
13+
14+
This supersedes one sentence of the `@objectstack/mcp` note for the record data tools' code-less throw ("A thrown error that carries a `code` is answered exactly as before"): a coded refusal from a sandboxed body now answers its inner sentence; its code and status are still answered as before.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@objectstack/plugin-auth': patch
3+
---
4+
5+
fix(plugin-auth): a correct-password sign-in refused afterwards, by an organization's allowed IP ranges, a ban or an unverified address, no longer counts toward the account lockout
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
The ADR-0069 D2 lockout counter read every refused `/sign-in/email` as a wrong password. Three refusals come only after the password verified: an organization's own IP list (`403 IP_NOT_ALLOWED`, judged when the new session is scoped to it), a ban (`403 BANNED_USER`, judged when the session is created) and an address the deployment requires verified (`403 EMAIL_NOT_VERIFIED`). Each raised the count, so an account holder with the right password could lock their own account: a member signing in from outside the organization's network was then refused `ACCOUNT_LOCKED` from inside it, a lifted ban left a lock behind, and a person waiting for their verification mail was locked out once it arrived. These three refusals now leave the counter as it stands, neither counting nor clearing it. A wrong password still counts in every case, and a successful sign-in still clears the count. The refusals' status, code and message and their `login_failed` audit rows are unchanged.

‎packages/mcp/src/mcp-coded-refusal.test.ts‎

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,71 @@ describe('the record data tools: a code-less throw answers what the /data door a
424424
});
425425
});
426426

427+
/**
428+
* [#31246] A CODED sandboxed refusal. A QuickJS hook (or action) body that runs
429+
* `throw Object.assign(new Error(SENTENCE), { code: 'RECORD_LOCKED', status: 409 })`
430+
* leaves the runner as this `SandboxError` (measured on the real
431+
* `QuickJSScriptRunner`): `.message` is the `hook '<name>' threw: Error: …`
432+
* debug wrapper, `.innerMessage` the sentence the author addressed to the
433+
* caller, `code` and `status` as declared.
434+
*/
435+
const SANDBOX_SENTENCE = 'A finished invoice cannot be changed.';
436+
const SANDBOX_WRAPPER = `hook 'demo_invoice_guard' threw: Error: ${SANDBOX_SENTENCE}`;
437+
function codedSandboxRefusal(): Error {
438+
return Object.assign(new Error(SANDBOX_WRAPPER), {
439+
name: 'SandboxError',
440+
innerMessage: SANDBOX_SENTENCE,
441+
code: 'RECORD_LOCKED',
442+
status: 409,
443+
});
444+
}
445+
446+
/**
447+
* [#31246] Every tool renders a coded sandboxed refusal as the body's own
448+
* sentence beside its code and status. `thrownRefusalEnvelope` read `.message`,
449+
* so each answered the wrapper, the hook's internal name included, where
450+
* `/api/v1/data` answers the inner sentence. It now reads the sentence through
451+
* `sandboxBusinessMessage` (`@objectstack/types`), the read that door makes.
452+
*/
453+
describe('every tool: a coded sandboxed refusal answers the body\'s sentence, never the wrapper naming the hook (#31246)', () => {
454+
for (const site of SITES) {
455+
it(`${site.tool}: RECORD_LOCKED, the inner sentence and 409; the hook name is absent`, async () => {
456+
const thrown = codedSandboxRefusal();
457+
const result = await callTool(site, thrown);
458+
expect(result.isError).toBe(true);
459+
expect(result.content).toHaveLength(1);
460+
expect(JSON.parse(result.content[0].text)).toEqual({
461+
error: { code: 'RECORD_LOCKED', message: SANDBOX_SENTENCE, status: 409 },
462+
});
463+
// The answer the data door gives the same throw.
464+
const door = mapDataError(thrown, 'task');
465+
expect([door.body.code, door.body.error, door.status]).toEqual(['RECORD_LOCKED', SANDBOX_SENTENCE, 409]);
466+
expect(result.content[0].text).not.toContain('demo_invoice_guard');
467+
expect(result.content[0].text).not.toContain('threw');
468+
});
469+
}
470+
471+
// CONTROL: a READ of the field the sandbox populated, never a strip of the
472+
// wrapper's prose. A coded refusal that is not a sandbox's renders byte for
473+
// byte as before, even when its own sentence reads like the wrapper.
474+
it('CONTROL: a coded non-sandbox refusal renders its own message byte for byte, wrapper-like prose included', async () => {
475+
const query = SITES.find((s) => s.tool === 'query_records')!;
476+
for (const thrown of [
477+
Object.assign(new Error('The period is closed.'), { code: 'RECORD_LOCKED', status: 409 }),
478+
Object.assign(new Error(SANDBOX_WRAPPER), { code: 'RECORD_LOCKED', status: 409 }),
479+
Object.assign(new Error(SANDBOX_WRAPPER), { name: 'SandboxError', innerMessage: '', code: 'RECORD_LOCKED', status: 409 }),
480+
]) {
481+
expect(await callTool(query, thrown), thrown.message).toEqual({
482+
content: [{
483+
type: 'text',
484+
text: JSON.stringify({ error: { code: 'RECORD_LOCKED', message: thrown.message, status: 409 } }, null, 2),
485+
}],
486+
isError: true,
487+
});
488+
}
489+
});
490+
});
491+
427492
describe('the record resource: a coded refusal adds its code beside the unchanged sentence (#23509)', () => {
428493
const URI = 'objectstack://objects/task/records/t1';
429494

@@ -476,6 +541,18 @@ describe('the record resource: a coded refusal adds its code beside the unchange
476541
});
477542
});
478543

544+
it('[#31246] a coded sandboxed refusal: `error` is the inner sentence, beside its code and status', async () => {
545+
const text = await readRefused(codedSandboxRefusal());
546+
expect(JSON.parse(text)).toEqual({ error: SANDBOX_SENTENCE, code: 'RECORD_LOCKED', status: 409 });
547+
expect(text).not.toContain('demo_invoice_guard');
548+
});
549+
550+
it('[#31246] CONTROL: a coded non-sandbox refusal keeps its own sentence, wrapper-like prose included', async () => {
551+
expect(await readRefused(Object.assign(new Error(SANDBOX_WRAPPER), { code: 'RECORD_LOCKED', status: 409 }))).toBe(
552+
JSON.stringify({ error: SANDBOX_WRAPPER, code: 'RECORD_LOCKED', status: 409 }),
553+
);
554+
});
555+
479556
it('a code-less throw answers `{ error }` byte-identically', async () => {
480557
expect(await readRefused(new Error('engine exploded'))).toBe(JSON.stringify({ error: 'engine exploded' }));
481558
expect(await readRefused('a thrown string')).toBe(JSON.stringify({ error: 'a thrown string' }));

‎packages/mcp/src/mcp-delete-records.test.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,33 @@ describe('MCP delete_records: many records of one object in one confirmed call (
653653
});
654654
expect([...rows.keys()]).toEqual(['t2', 't3', 't4', 't5']);
655655
});
656+
657+
it('[#31246] a CODED sandboxed refusal is grouped under its code with the body\'s sentence, never the wrapper naming the hook', async () => {
658+
const sentence = 'This task is approved and cannot be deleted.';
659+
// The `SandboxError` the QuickJS runner raises for a body's
660+
// `throw Object.assign(new Error(sentence), { code, status })`.
661+
rows.get('t3')!.throws = Object.assign(new Error(`hook 'dlr_task_guard' threw: Error: ${sentence}`), {
662+
name: 'SandboxError',
663+
innerMessage: sentence,
664+
code: 'RECORD_LOCKED',
665+
status: 409,
666+
});
667+
668+
const result = await callTool(bridge, 'delete_records', {
669+
objectName: OBJECT,
670+
recordIds: ['t1', 't3', 't6'],
671+
[AI_ACTION_CONFIRMATION_MEMBER]: true,
672+
});
673+
674+
expect(result.isError, result.content[0]?.text).toBeFalsy();
675+
expect(parsed(result)).toMatchObject({
676+
attempted: 3,
677+
deleted: 2,
678+
refused: 1,
679+
refusals: [{ code: 'RECORD_LOCKED', status: 409, reason: sentence, count: 1, recordIds: ['t3'] }],
680+
});
681+
expect(result.content[0]!.text).not.toContain('dlr_task_guard');
682+
});
656683
});
657684

658685
it('the long-lived server the stdio transport serves refuses, previews and deletes the same way', async () => {

‎packages/mcp/src/mcp-http-tools.ts‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import { StandardErrorCode, type ErrorCode } from '@objectstack/spec/api';
5050
// [#23701] The one key every door that translates the engine's unique-violation
5151
// envelope asks (the registered code AND the class name, never message text),
5252
// and the one classification whose arm states the wire code for it.
53-
import { earnedAnswerOf, isEngineDuplicateRecordEnvelope, isServerFault, logServerFault, mapDataError, resolveQueryReadLimits, staleSummaryAnswerLines, structuredCodeAnswer, type SummaryRecomputeRefusal } from '@objectstack/types';
53+
import { earnedAnswerOf, isEngineDuplicateRecordEnvelope, isServerFault, logServerFault, mapDataError, resolveQueryReadLimits, sandboxBusinessMessage, staleSummaryAnswerLines, structuredCodeAnswer, type SummaryRecomputeRefusal } from '@objectstack/types';
5454
import {
5555
MCP_OAUTH_SCOPE_DATA_READ,
5656
MCP_OAUTH_SCOPE_DATA_WRITE,
@@ -1118,14 +1118,27 @@ export interface ThrownRefusalEnvelope {
11181118
* (`developerMessage`, `object`, `field`) in their envelope's context slot;
11191119
* this envelope has none. It is `code`, `message` and `status`, and the data
11201120
* tools withhold `details` by design ({@link errorResultWithCode}).
1121+
*
1122+
* ## The caller-addressed sentence of a sandboxed refusal (#31246)
1123+
*
1124+
* A QuickJS hook or action body that throws with a declared `code` and
1125+
* `status` leaves the runner as a `SandboxError` whose `.message` is the
1126+
* `<kind> '<name>' threw: Error: …` debug wrapper, naming the hook, and whose
1127+
* `.innerMessage` is the sentence the author addressed to the caller. The
1128+
* `message` here is `sandboxBusinessMessage` (`@objectstack/types`), the read
1129+
* the `/api/v1/data` door makes for the same throw, and `.message` only when
1130+
* that read declines: not a sandbox refusal, or a body that crashed. ⛔ One
1131+
* reader, never a copy of its logic here, and never a strip of the wrapper's
1132+
* prose: a non-sandbox refusal keeps its own message byte for byte. The code
1133+
* and status are unchanged.
11211134
*/
11221135
export function thrownRefusalEnvelope(err: unknown): ThrownRefusalEnvelope | undefined {
11231136
const thrownCode = (err as { code?: unknown } | null | undefined)?.code;
11241137
if (typeof thrownCode !== 'string' || thrownCode.length === 0) return undefined;
11251138
const status = (err as { status?: unknown }).status;
11261139
return {
11271140
code: wireCodeOf(err, thrownCode),
1128-
message: messageOf(err),
1141+
message: sandboxBusinessMessage(err) ?? messageOf(err),
11291142
...(typeof status === 'number' ? { status } : {}),
11301143
};
11311144
}

‎packages/mcp/src/mcp-server-runtime.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1567,6 +1567,9 @@ export class MCPServerRuntime {
15671567
// does. A throw with no code answers `{ error }` as before.
15681568
// `details` is withheld, as on the data tools; `errorResultWithCode`
15691569
// in mcp-http-tools.ts says why.
1570+
// [#31246] A coded refusal's `error` is the envelope's sentence,
1571+
// so a sandboxed hook's refusal answers the body's own sentence
1572+
// rather than the runner's wrapper naming the hook, as the tools do.
15701573
const envelope = thrownRefusalEnvelope(err);
15711574
return {
15721575
contents: [{
@@ -1575,7 +1578,7 @@ export class MCPServerRuntime {
15751578
text: JSON.stringify(
15761579
envelope
15771580
? {
1578-
error: message,
1581+
error: envelope.message,
15791582
code: envelope.code,
15801583
...(envelope.status !== undefined ? { status: envelope.status } : {}),
15811584
}

0 commit comments

Comments
 (0)