@@ -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
0 commit comments