parent_job_id ?? 0);', 'private static function throwInvalidSettingsResult(' ); $assert($ordered($finish, [ "CloudJob::where('id', \$aggregateParentId)", 'CloudTemplateCatalogService::lockAggregateCatalogLocked(', 'CloudUserIsoService::lockAggregateCatalogLocked(', "CloudJob::where('id', \$claimed->id)", 'CloudTemplateCatalogService::finishJobLocked(', ]), 'Worker completion does not lock parent, catalog, child, replica in order.'); foreach ([ 'prepareApplied' => [ 'end' => 'public static function commitApplied(', 'resolution' => 'applied', ], 'prepareNotApplied' => [ 'end' => 'public static function commitNotApplied(', 'resolution' => 'not_applied', ], ] as $name => $contract) { $wrapper = $method( $recovery, 'public static function ' . $name . '(', $contract['end'] ); $assert($ordered($wrapper, [ 'return self::prepareResolution(', "'" . $contract['resolution'] . "'", ]), $name . ' does not preserve its public resolution adapter.'); } foreach ([ 'commitApplied' => 'applied', 'commitNotApplied' => 'not_applied', ] as $name => $resolution) { $wrapper = $method( $recovery, 'public static function ' . $name . '(', $name === 'commitApplied' ? 'public static function prepareNotApplied(' : 'private static function prepareResolution(' ); $assert($ordered($wrapper, [ 'return self::commitResolution(', "'" . $resolution . "'", '$resolvedBy', '$completionEvent', ]), $name . ' does not preserve its public resolution adapter.'); } $commit = $method( $recovery, 'private static function commitResolution(', 'public static function settleLateReceipt(' ); $assert($ordered($commit, [ '$aggregateParent = CloudJob::where(', '$aggregateParentId', 'CloudTemplateCatalogService::lockAggregateCatalogLocked(', 'CloudUserIsoService::lockAggregateCatalogLocked(', "CloudJob::where('id', \$jobId)", ]), 'Shared recovery commit does not lock parent, catalog, then child.'); $assert($ordered($commit, [ 'self::assertLockedAgentRecoveryEnvelope(', 'self::assertEvidenceSource(', 'self::assertOperationIdentity(', 'self::lockLateReceiptEvent(', 'self::assertRecoveryCommitMayPublish(', 'self::assertRecoverableEvidence(', 'self::preparedMarker(', 'self::preparedMarkerMatches(', '$job->effect_resolution = $resolution;', '$job->sealed_payload = self::finalizedRecoveryPayload($job);', '$job->save();', 'CloudJobService::reconcileAggregateParentEffectLocked(', ]), 'Shared recovery commit changed validation or ledger publish order.'); $commitSave = strpos($commit, '$job->save();'); $commitReconcile = strpos( $commit, 'CloudJobService::reconcileAggregateParentEffectLocked(' ); $commitAck = strrpos($commit, 'self::markLateReceiptApplied('); $assert($commitSave !== false && $commitReconcile !== false && $commitAck !== false && $commitSave < $commitReconcile && $commitReconcile < $commitAck, 'Shared recovery commit ACKs a receipt before ledger convergence.'); $automaticCommit = $method( $automatic, 'private static function resolveFenceAndCommit(', 'private static function assertFreshInspection(' ); $assert($ordered($automaticCommit, [ '$aggregateParent = CloudJob::where(', '$aggregateParentId', 'CloudTemplateCatalogService::lockAggregateCatalogLocked(', 'CloudUserIsoService::lockAggregateCatalogLocked(', "\$aggregateChildren = CloudJob::where(", "'parent_job_id',", '$aggregateParentId', ]), 'Automatic fence commit locks the child before its catalog.'); $aggregateCommit = $method( $jobs, 'public static function reconcileAggregateParentEffectLocked(', 'private static function wherePublishedAggregateNeedsRecheck(' ); $assert($ordered($aggregateCommit, [ "CloudJob::where('id', \$parentId)", 'CloudTemplateCatalogService::lockAggregateCatalogLocked(', 'CloudUserIsoService::lockAggregateCatalogLocked(', "\$children = CloudJob::where('parent_job_id', \$parentId)", ]), 'Aggregate recovery commit locks children before the catalog.'); $legacy = $method( $jobs, 'public static function reconcileOneLegacyAggregateEffect(): bool', 'private static function aggregateRelationshipConflict(' ); $assert($ordered($legacy, [ '->lockForUpdate()', 'CloudTemplateCatalogService::lockAggregateCatalogLocked(', 'CloudUserIsoService::lockAggregateCatalogLocked(', '$children = CloudJob::where(', "'parent_job_id',", ]), 'Legacy aggregate sweep locks children before the catalog.'); $templateMutation = $method( $templates, 'private static function lockTemplateForMutation(', 'private static function assertMutationBoundaryLocked(' ); $isoMutation = $method( $isos, 'private static function lockIsoForMutation(', 'private static function assertMutationBoundaryLocked(' ); $assert($ordered($templateMutation, [ '$parentSnapshot = $jobId > 0', 'self::isTemplateAggregateParent($parentSnapshot)', "? CloudJob::where('id', \$jobId)", "->where('execution_mode', 'aggregate')", "->whereNull('parent_job_id')", '->lockForUpdate()->first()', '$template = CloudTemplate::query()', '->lockForUpdate()->first();', 'self::assertMutationBoundaryLocked(', ]), 'Template mutation still locks the catalog before its prior parent.'); $assert($ordered($isoMutation, [ '$parentSnapshot = $jobId > 0', 'self::isIsoAggregateParent($parentSnapshot)', "? CloudJob::where('id', \$jobId)", "->where('execution_mode', 'aggregate')", "->whereNull('parent_job_id')", '->lockForUpdate()->first()', '$iso = CloudUserIso::query()', '->lockForUpdate()->first();', 'self::assertMutationBoundaryLocked(', ]), 'ISO mutation still locks the catalog before its prior parent.'); $isoImportMutation = $method( $isos, 'private static function lockIsoRowsForImport(', 'private static function assertMutationBoundaryLocked(' ); $assert($ordered($isoImportMutation, [ '$parentSnapshots =', '$parentIds =', 'self::isIsoAggregateParent($job)', '$parents =', "->where('execution_mode', 'aggregate')", "->whereNull('parent_job_id')", "->orderBy('id')->lockForUpdate()->get()->keyBy('id')", '$rows = CloudUserIso::query()', '->lockForUpdate()->get();', ]), 'ISO import locks an invalid pointer or locks catalogs before parents.'); $templateDelete = $method( $templates, 'public static function delete(', 'public static function finishJobLocked(' ); $assert($ordered($templateDelete, [ 'self::assertNoOrderReferencesLocked($id);', 'self::lockTemplateForMutation($id);', 'self::assertNoJobReferencesLocked($id);', ]), 'Template deletion locks its catalog before pending orders.'); echo "Cloud catalog lock-order contract checks passed.\n";