@@ -6492,10 +6492,13 @@ export class ObjectQL implements IObjectQLEngine {
64926492 // [ADR-0144 D8 rule 4] A `record`-mode amount is stored with its
64936493 // currency code, or the row is refused (`ERR_CURRENCY_CODE_REQUIRED`).
64946494 assertRecordCurrencyCodes(object, (schemaForValidation as { fields?: unknown } | undefined)?.fields, rows[i], 'insert');
6495- emitValidationAdvisories(options?.onValidationAdvisory, evaluateValidationRules(schemaForValidation as any, rows[i], 'insert', { logger: this.logger, currentUser: this.buildEvalUser(opCtx.context), skipStateMachine: shouldSkipStateMachine(opCtx.context), messages: msgCtx, parent: insertParentForRow?.(rows[i]), related: batchSummaries ? batchSummaries.overlay(insertRelatedForRow(rows[i])) : insertRelatedForRow(rows[i]), permissions: insertPermissionsFor(rows[i]) }), this.logger, object);
6495+ // [#29029] The reference check runs BEFORE the record's validation
6496+ // rules: a reference the caller cannot read answers
6497+ // `reference_not_found`, whatever a rule would answer.
64966498 await this.assertReferencesResolve(
64976499 schemaForValidation, rows[i], suppliedPerRow[i], opCtx.context, msgCtx,
64986500 );
6501+ emitValidationAdvisories(options?.onValidationAdvisory, evaluateValidationRules(schemaForValidation as any, rows[i], 'insert', { logger: this.logger, currentUser: this.buildEvalUser(opCtx.context), skipStateMachine: shouldSkipStateMachine(opCtx.context), messages: msgCtx, parent: insertParentForRow?.(rows[i]), related: batchSummaries ? batchSummaries.overlay(insertRelatedForRow(rows[i])) : insertRelatedForRow(rows[i]), permissions: insertPermissionsFor(rows[i]) }), this.logger, object);
64996502 // [#25579] Admitted: a later row of this batch reads it in the summary.
65006503 batchSummaries?.accept(rows[i]);
65016504 } catch (e) {
@@ -8322,15 +8325,16 @@ export class ObjectQL implements IObjectQLEngine {
83228325 // resolution failure fails this write closed right here.
83238326 const updatePayload = hookContext.input.data as Record<string, unknown>;
83248327 const permissionsForUpdate = (await this.resolveOptionPermissions(updateSchema, [updatePayload], permissionResolution))(updatePayload);
8325- emitValidationAdvisories(options?.onValidationAdvisory, evaluateValidationRules(updateSchema as any, hookContext.input.data as Record<string, unknown>, 'update', { previous: priorRecord, logger: this.logger, currentUser: this.buildEvalUser(opCtx.context), skipStateMachine: shouldSkipStateMachine(opCtx.context), messages: updateMsgCtx, parent: roWhenParent, previousParent: roWhenPreviousParent, related: relatedForUpdate, permissions: permissionsForUpdate }), this.logger, object);
83268328 // [#4441] A repoint is as capable of dangling as an initial link.
83278329 // [#29062] …but a value the row already stores is not a repoint:
83288330 // the prior row is what the check forgives a refused value against.
8331+ // [#29029] Before the record's validation rules, as on insert.
83298332 await this.assertReferencesResolve(
83308333 updateSchema, hookContext.input.data as Record<string, unknown>,
83318334 opCtx.data as Record<string, unknown>, opCtx.context, updateMsgCtx,
83328335 async () => [priorRecord],
83338336 );
8337+ emitValidationAdvisories(options?.onValidationAdvisory, evaluateValidationRules(updateSchema as any, hookContext.input.data as Record<string, unknown>, 'update', { previous: priorRecord, logger: this.logger, currentUser: this.buildEvalUser(opCtx.context), skipStateMachine: shouldSkipStateMachine(opCtx.context), messages: updateMsgCtx, parent: roWhenParent, previousParent: roWhenPreviousParent, related: relatedForUpdate, permissions: permissionsForUpdate }), this.logger, object);
83348338 // [commit 9d7f7259f] The by-id driver exit — where a driver's refusal
83358339 // leaves this door, and where a recognised unique violation
83368340 // stops being the driver's error. `envelopeUniqueViolation`
@@ -8735,6 +8739,18 @@ export class ObjectQL implements IObjectQLEngine {
87358739 // set — the patch is shared, so either every row picks a
87368740 // `can`-gated option or none does. Never per row.
87378741 const bulkPermissions = (await this.resolveOptionPermissions(updateSchema, [bulkPatch], permissionResolution))(bulkPatch);
8742+ // [#4441] The bulk call site too — a guard wired into single-id
8743+ // writes only is still a hole one call site over (AGENTS.md
8744+ // PD #10's own worked example, #3106).
8745+ // [#29062] A refused value is forgiven only when EVERY matched row
8746+ // already stores it (the `readPriorRows` memo, read only then);
8747+ // a row it is new to makes it this write's reference.
8748+ // [#29029] Before the record's validation rules, as on insert.
8749+ await this.assertReferencesResolve(
8750+ updateSchema, hookContext.input.data as Record<string, unknown>,
8751+ opCtx.data as Record<string, unknown>, opCtx.context, updateMsgCtx,
8752+ readPriorRows,
8753+ );
87388754 if (rulesNeedRows) {
87398755 for (const row of priorRows ?? []) {
87408756 try {
@@ -8756,17 +8772,6 @@ export class ObjectQL implements IObjectQLEngine {
87568772 // rule families that never read a header.
87578773 emitValidationAdvisories(options?.onValidationAdvisory, evaluateValidationRules(updateSchema as any, hookContext.input.data as Record<string, unknown>, 'update', { previous: null, logger: this.logger, currentUser: bulkEvalUser, skipStateMachine: shouldSkipStateMachine(opCtx.context), messages: updateMsgCtx, permissions: bulkPermissions }), this.logger, object);
87588774 }
8759- // [#4441] The bulk call site too — a guard wired into single-id
8760- // writes only is still a hole one call site over (AGENTS.md
8761- // PD #10's own worked example, #3106).
8762- // [#29062] A refused value is forgiven only when EVERY matched row
8763- // already stores it (the `readPriorRows` memo, read only then);
8764- // a row it is new to makes it this write's reference.
8765- await this.assertReferencesResolve(
8766- updateSchema, hookContext.input.data as Record<string, unknown>,
8767- opCtx.data as Record<string, unknown>, opCtx.context, updateMsgCtx,
8768- readPriorRows,
8769- );
87708775 // `updateMany` presence is part of the ladder verdict resolved above.
87718776 // [commit 9d7f7259f] The predicate driver exit, enveloped on the same
87728777 // terms as the by-id exit above. A multi-row write names no
0 commit comments