Skip to content

Commit 86f4903

Browse files
committed
fix(runtime): an elicited accept dispatches on a read taken after the answer
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jTEivi2wogPpeo3xd5
1 parent 3557594 commit 86f4903

3 files changed

Lines changed: 53 additions & 20 deletions

File tree

‎packages/runtime/src/action-dispatch.ts‎

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -286,12 +286,22 @@ export async function runResolvedAction(
286286
requestContext: HttpProtocolContext,
287287
call: ResolvedActionCall,
288288
): Promise<ResolvedActionRun> {
289-
const admission = await admitResolvedAction(deps, requestContext, call);
289+
let admission = await admitResolvedAction(deps, requestContext, call);
290290
if ('refused' in admission) return admission;
291291
if (admission.handOff) {
292292
const confirmation = await confirmAdmittedAction(deps, requestContext, call, admission);
293293
// [#33712] Only an elicited `accept` falls through to the dispatch.
294294
if (confirmation !== 'accepted') return confirmation;
295+
// [#33712] The person answered some time after the admission was read.
296+
// The call dispatches on a read taken AFTER the answer: every gate and
297+
// the subject load again, then the caller-scope verdict on that fresh
298+
// subject, exactly as the question was preceded. A refusal there runs
299+
// nothing; the dispatch never sees the read taken before the question.
300+
const fresh = await admitResolvedAction(deps, requestContext, call);
301+
if ('refused' in fresh) return fresh;
302+
const verdict = await subjectVerdictRefusal(deps, requestContext, call, fresh);
303+
if (verdict) return verdict;
304+
admission = fresh;
295305
}
296306
const outcome = await dispatchAdmittedAction(deps, requestContext, call, admission);
297307
return {
@@ -320,24 +330,47 @@ interface Admission {
320330
* the person is asked there instead, after the same verdict: `'accepted'`
321331
* sends the caller on to the dispatch, any other answer is the refusal.
322332
*/
323-
async function confirmAdmittedAction(
333+
/** The admitted record id as the hand-off and the question carry it: absent for a record-less call. */
334+
function subjectRecordIdOf(recordId: unknown): string | undefined {
335+
return recordId === undefined || recordId === null || recordId === '' ? undefined : String(recordId);
336+
}
337+
338+
/**
339+
* [#33690] The caller-scope subject verdict on an admission, as the dispatch
340+
* arm would read it, rendered as a refusal; `undefined` when the call may go
341+
* on. [#33712] Asked before the person is asked, and again on the read taken
342+
* after an elicited `accept`.
343+
*/
344+
async function subjectVerdictRefusal(
324345
deps: ActionExecutionDeps,
325346
requestContext: HttpProtocolContext,
326347
call: ResolvedActionCall,
327348
admission: Admission,
328-
): Promise<ResolvedActionRun | 'accepted'> {
349+
): Promise<{ refused: ActionRefusal } | undefined> {
329350
const { objectName, wiring } = call;
330-
const { actionDef, recordId, params, subject } = admission;
331-
const subjectRecordId = recordId === undefined || recordId === null || recordId === '' ? undefined : String(recordId);
332351
try {
333-
await actionExec.refuseDeniedSubjectBeforeHandOff(deps, requestContext, actionDef, {
334-
objectName, recordId: subjectRecordId, subject, ec: wiring.ec, envId: wiring.envId,
352+
await actionExec.refuseDeniedSubjectBeforeHandOff(deps, requestContext, admission.actionDef, {
353+
objectName, recordId: subjectRecordIdOf(admission.recordId), subject: admission.subject, ec: wiring.ec, envId: wiring.envId,
335354
});
336355
} catch (error) {
337356
const thrown = error as Error & { code?: unknown; status?: unknown };
338357
if (typeof thrown?.status !== 'number' || typeof thrown?.code !== 'string') throw error;
339358
return { refused: { message: thrown.message, status: thrown.status, details: { code: thrown.code } } };
340359
}
360+
return undefined;
361+
}
362+
363+
async function confirmAdmittedAction(
364+
deps: ActionExecutionDeps,
365+
requestContext: HttpProtocolContext,
366+
call: ResolvedActionCall,
367+
admission: Admission,
368+
): Promise<ResolvedActionRun | 'accepted'> {
369+
const { objectName, wiring } = call;
370+
const { actionDef, recordId, params, subject } = admission;
371+
const subjectRecordId = subjectRecordIdOf(recordId);
372+
const verdict = await subjectVerdictRefusal(deps, requestContext, call, admission);
373+
if (verdict) return verdict;
341374
const handOff = call.confirmationHandOff!;
342375
const actionName = typeof actionDef?.name === 'string' && actionDef.name ? actionDef.name : call.actionName;
343376
// [#33712] Step 1: a client that can be elicited is asked in place, after

‎packages/runtime/src/action-execution.ts‎

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ import {
109109
reconcileActionRegistrations as reconcileActionRegistrationsPure,
110110
resolveActionByPackage,
111111
resolveActionHandlerKeys,
112-
resolveRecordTitle,
112+
servedRecordTitle,
113113
standaloneActionOwnerKey,
114114
SummaryRecomputeError,
115115
type PackageScopedRefusal,
@@ -3287,9 +3287,10 @@ export type ActionConfirmationElicitor = (subject: ActionConfirmationElicitSubje
32873287
/**
32883288
* [#33712] The subject an elicitation names, built from what the admitted
32893289
* sequence already holds: the declaration, the object and the record the
3290-
* caller-scope subject load read. The title is the object's own
3291-
* (`resolveRecordTitle`: its `nameField`, formula or column), and is left out
3292-
* rather than replaced by the id when it does not resolve.
3290+
* caller-scope subject load read. The title is the value that read SERVED
3291+
* under the object's title pointer (`servedRecordTitle`), never re-derived
3292+
* from the row, and is left out rather than replaced by the id when the read
3293+
* served none. The door that phrases the question bounds and neutralises it.
32933294
*/
32943295
export function actionConfirmationElicitSubject(
32953296
action: any,
@@ -3300,15 +3301,9 @@ export function actionConfirmationElicitSubject(
33003301
record: Record<string, unknown> | undefined,
33013302
): ActionConfirmationElicitSubject {
33023303
const label = typeof action?.label === 'string' && action.label !== '' ? action.label : undefined;
3303-
let recordTitle: string | undefined;
3304-
if (recordId !== undefined && record && Object.keys(record).length > 0) {
3305-
try {
3306-
recordTitle = resolveRecordTitle(obj, record);
3307-
} catch {
3308-
// A title that cannot be composed is left out: the id still names the record.
3309-
recordTitle = undefined;
3310-
}
3311-
}
3304+
const recordTitle = recordId !== undefined && record && Object.keys(record).length > 0
3305+
? servedRecordTitle(obj, record)
3306+
: undefined;
33123307
return {
33133308
actionName,
33143309
...(label !== undefined ? { actionLabel: label } : {}),

‎packages/runtime/src/domains/mcp.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2053,6 +2053,11 @@ export async function resumeActionRun(
20532053
...elicited.refused.details,
20542054
});
20552055
}
2056+
// The person answered some time after the gates were read: ask the
2057+
// admitting action's gates again before the resume below, which reads
2058+
// the subject and the screen again itself (`continueAdmittedRun`).
2059+
const regated = resumeAdmissionRefusal(deps, admitted, ec, activationEngine);
2060+
if (regated instanceof Error) throw regated;
20562061
} else if (handOff) {
20572062
await refuseUnresumableAdmittedRun(deps, automation, runId, { objectName, recordId, driver, envId, ec, callData });
20582063
const answer = await actionExec.handOffActionConfirmation(deps, context, envId, {

0 commit comments

Comments
 (0)