gdp-wired 0.48.0 → 0.50.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -2
- package/dist/core/bmc.js +10 -7
- package/dist/core/candidate-seeds.d.ts +25 -0
- package/dist/core/candidate-seeds.js +90 -0
- package/dist/core/check.js +7 -2
- package/dist/core/cli.js +3 -0
- package/dist/core/count-attempt-work.d.ts +29 -0
- package/dist/core/count-attempt-work.js +96 -0
- package/dist/core/count-boolean-partition.d.ts +5 -0
- package/dist/core/count-boolean-partition.js +47 -0
- package/dist/core/count-bounded-quotient.d.ts +2 -0
- package/dist/core/count-bounded-quotient.js +13 -0
- package/dist/core/count-case-compose.d.ts +20 -0
- package/dist/core/count-case-compose.js +289 -0
- package/dist/core/count-cases.js +3 -2
- package/dist/core/count-cert-rename.d.ts +10 -0
- package/dist/core/count-cert-rename.js +69 -0
- package/dist/core/count-cert-transport.d.ts +10 -2
- package/dist/core/count-cert-transport.js +60 -9
- package/dist/core/count-certificate-minimize.d.ts +57 -0
- package/dist/core/count-certificate-minimize.js +263 -0
- package/dist/core/count-closed-family.d.ts +32 -0
- package/dist/core/count-closed-family.js +143 -0
- package/dist/core/count-closing-budget.d.ts +10 -0
- package/dist/core/count-closing-budget.js +49 -0
- package/dist/core/count-closing-needs.d.ts +5 -0
- package/dist/core/count-closing-needs.js +9 -0
- package/dist/core/count-component-budget.d.ts +5 -0
- package/dist/core/count-component-budget.js +9 -0
- package/dist/core/count-copy-shape.d.ts +11 -0
- package/dist/core/count-copy-shape.js +40 -0
- package/dist/core/count-disjoint-funding.d.ts +75 -0
- package/dist/core/count-disjoint-funding.js +284 -0
- package/dist/core/count-emitter-frame-pool.d.ts +23 -0
- package/dist/core/count-emitter-frame-pool.js +87 -0
- package/dist/core/count-final-step.d.ts +5 -0
- package/dist/core/count-final-step.js +20 -0
- package/dist/core/count-fixed-frame.d.ts +4 -0
- package/dist/core/count-fixed-frame.js +30 -0
- package/dist/core/count-frames.d.ts +25 -0
- package/dist/core/count-frames.js +118 -0
- package/dist/core/count-frozen-guard.d.ts +2 -0
- package/dist/core/count-frozen-guard.js +31 -0
- package/dist/core/count-generation-phase.d.ts +7 -0
- package/dist/core/count-generation-phase.js +33 -0
- package/dist/core/count-guard-composition.d.ts +12 -0
- package/dist/core/count-guard-composition.js +48 -0
- package/dist/core/count-guard-context.d.ts +11 -0
- package/dist/core/count-guard-context.js +50 -0
- package/dist/core/count-guard-facts.d.ts +50 -0
- package/dist/core/count-guard-facts.js +97 -0
- package/dist/core/count-guard-proposals.d.ts +7 -0
- package/dist/core/count-guard-proposals.js +106 -0
- package/dist/core/count-guard-shape.d.ts +18 -0
- package/dist/core/count-guard-shape.js +100 -0
- package/dist/core/count-guard-tree.d.ts +17 -0
- package/dist/core/count-guard-tree.js +125 -0
- package/dist/core/count-leader-facts.d.ts +10 -0
- package/dist/core/count-leader-facts.js +52 -0
- package/dist/core/count-leader.d.ts +10 -0
- package/dist/core/count-leader.js +331 -0
- package/dist/core/count-lemma-transport.d.ts +8 -0
- package/dist/core/count-lemma-transport.js +47 -0
- package/dist/core/count-lifted-budget.d.ts +54 -0
- package/dist/core/count-lifted-budget.js +97 -0
- package/dist/core/count-lifted-copy.d.ts +3 -0
- package/dist/core/count-lifted-copy.js +166 -0
- package/dist/core/count-lifted-increment.d.ts +3 -0
- package/dist/core/count-lifted-increment.js +146 -0
- package/dist/core/count-lifted-load.d.ts +5 -0
- package/dist/core/count-lifted-load.js +179 -0
- package/dist/core/count-lifted-prerequisite.d.ts +14 -0
- package/dist/core/count-lifted-prerequisite.js +53 -0
- package/dist/core/count-lifted-replacement.d.ts +3 -0
- package/dist/core/count-lifted-replacement.js +540 -0
- package/dist/core/count-lifted-shape.d.ts +63 -0
- package/dist/core/count-lifted-shape.js +115 -0
- package/dist/core/count-lifted-strategy.d.ts +7 -0
- package/dist/core/count-lifted-strategy.js +226 -0
- package/dist/core/count-lifted-transports.d.ts +32 -0
- package/dist/core/count-lifted-transports.js +293 -0
- package/dist/core/count-load-shape.d.ts +17 -0
- package/dist/core/count-load-shape.js +67 -0
- package/dist/core/count-minimal-view.d.ts +26 -0
- package/dist/core/count-minimal-view.js +46 -0
- package/dist/core/count-operation-observation.d.ts +9 -0
- package/dist/core/count-operation-observation.js +22 -0
- package/dist/core/count-operation-order.d.ts +5 -0
- package/dist/core/count-operation-order.js +4 -0
- package/dist/core/count-phase.d.ts +9 -0
- package/dist/core/count-phase.js +127 -0
- package/dist/core/count-premise-search.d.ts +9 -0
- package/dist/core/count-premise-search.js +41 -0
- package/dist/core/count-premise-view.d.ts +19 -0
- package/dist/core/count-premise-view.js +220 -0
- package/dist/core/count-prerequisite-components.d.ts +67 -0
- package/dist/core/count-prerequisite-components.js +239 -0
- package/dist/core/count-prerequisite-memory.d.ts +24 -0
- package/dist/core/count-prerequisite-memory.js +37 -0
- package/dist/core/count-prerequisite-plan.d.ts +12 -0
- package/dist/core/count-prerequisite-plan.js +88 -0
- package/dist/core/count-primitive-budget.d.ts +1 -0
- package/dist/core/count-primitive-budget.js +8 -0
- package/dist/core/count-project-free.d.ts +3 -0
- package/dist/core/count-project-free.js +24 -0
- package/dist/core/count-project-witness.d.ts +4 -0
- package/dist/core/count-project-witness.js +48 -0
- package/dist/core/count-proof-rescope.d.ts +14 -0
- package/dist/core/count-proof-rescope.js +71 -0
- package/dist/core/count-proof-scope.d.ts +68 -0
- package/dist/core/count-proof-scope.js +333 -0
- package/dist/core/count-prune-owned-root.d.ts +5 -0
- package/dist/core/count-prune-owned-root.js +27 -0
- package/dist/core/count-query-context.d.ts +3 -0
- package/dist/core/count-query-context.js +7 -0
- package/dist/core/count-query.d.ts +15 -0
- package/dist/core/count-query.js +59 -0
- package/dist/core/count-quorum-leaf.d.ts +9 -0
- package/dist/core/count-quorum-leaf.js +38 -0
- package/dist/core/count-reachability-budget.d.ts +1 -0
- package/dist/core/count-reachability-budget.js +7 -0
- package/dist/core/count-reachability-reconcile.d.ts +11 -0
- package/dist/core/count-reachability-reconcile.js +19 -0
- package/dist/core/count-reachability.d.ts +50 -0
- package/dist/core/count-reachability.js +351 -0
- package/dist/core/count-rebase-path.d.ts +9 -0
- package/dist/core/count-rebase-path.js +68 -0
- package/dist/core/count-recipe-context.d.ts +45 -0
- package/dist/core/count-recipe-context.js +71 -0
- package/dist/core/count-recipe-controller.d.ts +115 -0
- package/dist/core/count-recipe-controller.js +417 -0
- package/dist/core/count-recipe-graph.d.ts +36 -0
- package/dist/core/count-recipe-graph.js +211 -0
- package/dist/core/count-recovery/conditional-check-cache.js +3 -2
- package/dist/core/count-recovery/conditional-cuts.js +5 -4
- package/dist/core/count-recovery/conditional-proof.d.ts +37 -3
- package/dist/core/count-recovery/conditional-proof.js +72 -30
- package/dist/core/count-recovery/derivability-closure.js +2 -1
- package/dist/core/count-recovery/guard-cases.js +2 -1
- package/dist/core/count-recovery/reframe-tree.d.ts +2 -0
- package/dist/core/count-recovery/reframe-tree.js +24 -0
- package/dist/core/count-recovery/replay-linear-skeleton.d.ts +2 -0
- package/dist/core/count-recovery/replay-linear-skeleton.js +28 -0
- package/dist/core/count-recovery/row-cases.js +2 -1
- package/dist/core/count-rejection-budget.d.ts +8 -0
- package/dist/core/count-rejection-budget.js +15 -0
- package/dist/core/count-replacement.d.ts +5 -0
- package/dist/core/count-replacement.js +129 -0
- package/dist/core/count-replay-diagnostic.d.ts +21 -0
- package/dist/core/count-replay-diagnostic.js +49 -0
- package/dist/core/count-replay-skeleton.d.ts +4 -0
- package/dist/core/count-replay-skeleton.js +28 -0
- package/dist/core/count-rescope-funding.d.ts +3 -0
- package/dist/core/count-rescope-funding.js +17 -0
- package/dist/core/count-restrictions.d.ts +11 -0
- package/dist/core/count-restrictions.js +31 -0
- package/dist/core/count-retry-budget.d.ts +67 -0
- package/dist/core/count-retry-budget.js +114 -0
- package/dist/core/count-retry-round.d.ts +24 -0
- package/dist/core/count-retry-round.js +44 -0
- package/dist/core/count-row-agreement.d.ts +35 -0
- package/dist/core/count-row-agreement.js +270 -0
- package/dist/core/count-row-aliases.d.ts +3 -0
- package/dist/core/count-row-aliases.js +59 -0
- package/dist/core/count-row-composition.d.ts +6 -0
- package/dist/core/count-row-composition.js +55 -0
- package/dist/core/count-row-copy-linear.d.ts +4 -0
- package/dist/core/count-row-copy-linear.js +83 -0
- package/dist/core/count-row-copy.d.ts +4 -0
- package/dist/core/count-row-copy.js +94 -0
- package/dist/core/count-row-policy.d.ts +3 -0
- package/dist/core/count-row-policy.js +56 -0
- package/dist/core/count-row-reindex.d.ts +11 -0
- package/dist/core/count-row-reindex.js +126 -0
- package/dist/core/count-row-support.d.ts +9 -0
- package/dist/core/count-row-support.js +42 -0
- package/dist/core/count-row-symmetry.d.ts +7 -0
- package/dist/core/count-row-symmetry.js +100 -0
- package/dist/core/count-scope-hyps.d.ts +2 -0
- package/dist/core/count-scope-hyps.js +163 -0
- package/dist/core/count-scope-row-reuse.d.ts +3 -0
- package/dist/core/count-scope-row-reuse.js +92 -0
- package/dist/core/count-search-allowance.d.ts +1 -0
- package/dist/core/count-search-allowance.js +17 -0
- package/dist/core/count-stabilize-tree.d.ts +9 -0
- package/dist/core/count-stabilize-tree.js +35 -0
- package/dist/core/count-stage-trace.d.ts +8 -0
- package/dist/core/count-stage-trace.js +45 -0
- package/dist/core/count-strategies.d.ts +16 -0
- package/dist/core/count-strategies.js +155 -0
- package/dist/core/count-strategy-premises.d.ts +5 -0
- package/dist/core/count-strategy-premises.js +14 -0
- package/dist/core/count-strategy.d.ts +41 -0
- package/dist/core/count-strategy.js +76 -0
- package/dist/core/count-support.d.ts +1 -0
- package/dist/core/count-support.js +26 -4
- package/dist/core/count-tier-budget.d.ts +14 -0
- package/dist/core/count-tier-budget.js +64 -0
- package/dist/core/count-unwritten-prefix.d.ts +24 -0
- package/dist/core/count-unwritten-prefix.js +97 -0
- package/dist/core/count-write-shape.d.ts +15 -0
- package/dist/core/count-write-shape.js +73 -0
- package/dist/core/counted-candidate-seeds.d.ts +12 -0
- package/dist/core/counted-candidate-seeds.js +31 -0
- package/dist/core/counts.d.ts +37 -13
- package/dist/core/counts.js +999 -129
- package/dist/core/cycles.js +5 -4
- package/dist/core/cyclic.js +11 -10
- package/dist/core/data.js +16 -15
- package/dist/core/dsl-deadline.d.ts +3 -0
- package/dist/core/dsl-deadline.js +27 -0
- package/dist/core/dsl.d.ts +32 -2
- package/dist/core/dsl.js +202 -64
- package/dist/core/evaluation-admission.d.ts +1 -0
- package/dist/core/evaluation-admission.js +3 -0
- package/dist/core/exists.d.ts +6 -1
- package/dist/core/exists.js +53 -10
- package/dist/core/field-laws.d.ts +3 -1
- package/dist/core/field-laws.js +159 -3
- package/dist/core/finite-houdini.d.ts +6 -0
- package/dist/core/finite-houdini.js +63 -21
- package/dist/core/finite-tiny.js +95 -67
- package/dist/core/fixtures/count-completion/paxos-decision.json +1 -0
- package/dist/core/fresh.js +5 -1
- package/dist/core/infer.js +49 -33
- package/dist/core/kind.js +2 -1
- package/dist/core/lemma-cuts.js +11 -10
- package/dist/core/lift-cli.d.ts +11 -0
- package/dist/core/lift-cli.js +113 -0
- package/dist/core/linear-admission.d.ts +14 -0
- package/dist/core/linear-admission.js +151 -0
- package/dist/core/machine.d.ts +5 -2
- package/dist/core/machine.js +105 -31
- package/dist/core/meter.d.ts +22 -0
- package/dist/core/meter.js +34 -0
- package/dist/core/nonterm.js +4 -3
- package/dist/core/proof-output.d.ts +53 -0
- package/dist/core/proof-output.js +38 -0
- package/dist/core/prover-row-budget.d.ts +3 -0
- package/dist/core/prover-row-budget.js +106 -0
- package/dist/core/quorum-laws.d.ts +21 -1
- package/dist/core/quorum-laws.js +80 -17
- package/dist/core/rationals.js +3 -2
- package/dist/core/rejection-discovery.d.ts +34 -0
- package/dist/core/rejection-discovery.js +36 -0
- package/dist/core/rejection-stage.d.ts +39 -0
- package/dist/core/rejection-stage.js +205 -0
- package/dist/core/request-quotient.d.ts +8 -0
- package/dist/core/request-quotient.js +299 -0
- package/dist/core/row-agreement-shape.d.ts +15 -0
- package/dist/core/row-agreement-shape.js +68 -0
- package/dist/core/runtime-wall.d.ts +2 -0
- package/dist/core/search-policy.d.ts +15 -0
- package/dist/core/search-policy.js +68 -0
- package/dist/core/solver.d.ts +1 -1
- package/dist/core/solver.js +40 -6
- package/dist/core/step-work.d.ts +12 -0
- package/dist/core/step-work.js +14 -0
- package/dist/core/strategy-premises.d.ts +8 -0
- package/dist/core/strategy-premises.js +64 -0
- package/dist/core/system.js +4 -3
- package/dist/core/table-admission.d.ts +1 -0
- package/dist/core/table-admission.js +3 -0
- package/dist/core/trace-clock.d.ts +3 -0
- package/dist/core/trace-clock.js +16 -0
- package/dist/core/transfer.js +3 -2
- package/dist/core/translate.js +16 -3
- package/dist/core/wall.d.ts +6 -1
- package/dist/core/wall.js +23 -9
- package/dist/core/watch.d.ts +1 -1
- package/dist/core/watch.js +13 -4
- package/dist/core/work-admission.d.ts +164 -0
- package/dist/core/work-admission.js +418 -0
- package/dist/core/work-amount.d.ts +21 -0
- package/dist/core/work-amount.js +80 -0
- package/dist/core/work-collections.d.ts +11 -0
- package/dist/core/work-collections.js +198 -0
- package/dist/core/work-kinds.d.ts +11 -0
- package/dist/core/work-kinds.js +9 -0
- package/dist/core/work-meter.d.ts +8 -0
- package/dist/core/work-meter.js +83 -0
- package/dist/core/work-observe.d.ts +12 -0
- package/dist/core/work-observe.js +39 -0
- package/dist/core/work-profile.d.ts +10 -0
- package/dist/core/work-profile.js +21 -0
- package/dist/core/work-refusal.d.ts +1 -0
- package/dist/core/work-refusal.js +6 -0
- package/dist/interchange/format.js +2 -0
- package/dist/kernel/cdcl.js +93 -40
- package/dist/kernel/epr.js +23 -8
- package/dist/kernel/function-instances.d.ts +45 -0
- package/dist/kernel/function-instances.js +460 -0
- package/dist/kernel/kernel.d.ts +47 -1
- package/dist/kernel/kernel.js +417 -68
- package/dist/kernel/prove.d.ts +61 -6
- package/dist/kernel/prove.js +625 -205
- package/dist/kernel/prover-rows.d.ts +1 -0
- package/dist/kernel/prover-rows.js +12 -1
- package/dist/kernel/reader.d.ts +1 -1
- package/dist/kernel/reader.js +57 -12
- package/dist/kernel/simplex.js +9 -2
- package/dist/lean-kernel/axiom-audit.d.ts +11 -0
- package/dist/lean-kernel/axiom-audit.js +50 -0
- package/dist/lean-kernel/emit.d.ts +34 -3
- package/dist/lean-kernel/emit.js +215 -28
- package/dist/lean-kernel/legacy-family-library.d.ts +1 -0
- package/dist/lean-kernel/legacy-family-library.js +5 -0
- package/dist/lean-kernel/legacy-family-order.d.ts +1 -0
- package/dist/lean-kernel/legacy-family-order.js +26 -0
- package/dist/lean-kernel/library.js +25 -3
- package/dist/lean-kernel/lift/counted-source-data.d.ts +7 -0
- package/dist/lean-kernel/lift/counted-source-data.js +78 -0
- package/dist/lean-kernel/lift/index.d.ts +82 -0
- package/dist/lean-kernel/lift/index.js +116 -0
- package/dist/lean-kernel/lift/project.d.ts +4 -0
- package/dist/lean-kernel/lift/project.js +15 -0
- package/dist/lean-kernel/lift/proof-capture.d.ts +104 -0
- package/dist/lean-kernel/lift/proof-capture.js +216 -0
- package/dist/lean-kernel/lift/proof-codec.d.ts +28 -0
- package/dist/lean-kernel/lift/proof-codec.js +299 -0
- package/dist/lean-kernel/lift/proof-counted-source.d.ts +16 -0
- package/dist/lean-kernel/lift/proof-counted-source.js +68 -0
- package/dist/lean-kernel/lift/proof-frontier.d.ts +19 -0
- package/dist/lean-kernel/lift/proof-frontier.js +153 -0
- package/dist/lean-kernel/lift/proof-graph.d.ts +17 -0
- package/dist/lean-kernel/lift/proof-graph.js +130 -0
- package/dist/lean-kernel/lift/proof-parts.d.ts +29 -0
- package/dist/lean-kernel/lift/proof-parts.js +131 -0
- package/dist/lean-kernel/lift/proof-prelude.d.ts +2 -0
- package/dist/lean-kernel/lift/proof-prelude.js +38 -0
- package/dist/lean-kernel/lift/proof-witness.d.ts +30 -0
- package/dist/lean-kernel/lift/proof-witness.js +283 -0
- package/dist/lean-kernel/lift/shape.d.ts +5 -0
- package/dist/lean-kernel/lift/shape.js +57 -0
- package/dist/lean-kernel/lift/source-projection.d.ts +16 -0
- package/dist/lean-kernel/lift/source-projection.js +81 -0
- package/dist/lean-kernel/lift/source.d.ts +23 -0
- package/dist/lean-kernel/lift/source.js +111 -0
- package/dist/lean-kernel/lift/witness-alpha.d.ts +9 -0
- package/dist/lean-kernel/lift/witness-alpha.js +31 -0
- package/dist/lean-kernel/lift-legacy.d.ts +58 -0
- package/dist/lean-kernel/lift-legacy.js +84 -0
- package/dist/lean-kernel/lift-names.d.ts +22 -0
- package/dist/lean-kernel/lift-names.js +36 -0
- package/dist/lean-kernel/lift-simulation/index.d.ts +29 -0
- package/dist/lean-kernel/lift-simulation/index.js +352 -0
- package/dist/lean-kernel/lift-simulation/shape.d.ts +41 -0
- package/dist/lean-kernel/lift-simulation/shape.js +173 -0
- package/dist/lean-kernel/lift-special/index.d.ts +36 -0
- package/dist/lean-kernel/lift-special/index.js +241 -0
- package/dist/lean-kernel/lift-special/structural.d.ts +25 -0
- package/dist/lean-kernel/lift-special/structural.js +126 -0
- package/dist/lean-kernel/lift-typed/index.d.ts +35 -0
- package/dist/lean-kernel/lift-typed/index.js +256 -0
- package/dist/lean-kernel/lift-typed/roles.d.ts +17 -0
- package/dist/lean-kernel/lift-typed/roles.js +170 -0
- package/dist/lean-kernel/lift-typed/shape.d.ts +1 -0
- package/dist/lean-kernel/lift-typed/shape.js +12 -0
- package/dist/lean-kernel/lift.d.ts +30 -0
- package/dist/lean-kernel/lift.js +97 -0
- package/package.json +5 -1
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
// Section 46 production scheduling. This module owns finite recipe instances,
|
|
2
|
+
// not proof acceptance. Every payload still goes through the caller's unchanged
|
|
3
|
+
// replay/native-closing path. All allocations below are exact raw root work.
|
|
4
|
+
import { countRecipeGraph, countRecipeRequirements } from "./count-recipe-graph.js";
|
|
5
|
+
import { CountAttemptTickets, planCountRetry, countAttemptStop } from "./count-retry-budget.js";
|
|
6
|
+
import { runCountRetryRound } from "./count-retry-round.js";
|
|
7
|
+
import { CountAttemptWork, countLeafSlot } from "./count-attempt-work.js";
|
|
8
|
+
import { countReplayDiagnostic, emitReplayDiagnostic, replayPassId, withReplayDiagnosticContext } from "./count-replay-diagnostic.js";
|
|
9
|
+
import { liftedWorkLeaseBudget } from "./count-lifted-budget.js";
|
|
10
|
+
import { closeGreatestCountFamily, greatestClosedCountFamily } from "./count-closed-family.js";
|
|
11
|
+
import { BudgetExpired, workLedger } from "./work-admission.js";
|
|
12
|
+
import { compareWork, exactRaw, minWork, workAdd, workFromExact, workShare, workSub, zeroWork } from "./work-amount.js";
|
|
13
|
+
function countMap(input, visit, tick) {
|
|
14
|
+
const out = [];
|
|
15
|
+
for (const value of input) {
|
|
16
|
+
tick();
|
|
17
|
+
out.push(visit(value));
|
|
18
|
+
}
|
|
19
|
+
return out;
|
|
20
|
+
}
|
|
21
|
+
function countFind(input, test, tick) {
|
|
22
|
+
for (const value of input) {
|
|
23
|
+
tick();
|
|
24
|
+
if (test(value))
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
// Untrusted allocation arithmetic only; returned amounts are caps, not grants.
|
|
30
|
+
export function countRecipeAllocationCohort(members, graph, selected, tick) {
|
|
31
|
+
let size = graph.closure.has(selected) && !graph.usable.has(selected) && !graph.blocked.has(selected) ? 0 : 1;
|
|
32
|
+
for (const name of members) {
|
|
33
|
+
tick();
|
|
34
|
+
if (graph.closure.has(name) && !graph.usable.has(name) && !graph.blocked.has(name))
|
|
35
|
+
size++;
|
|
36
|
+
}
|
|
37
|
+
return size;
|
|
38
|
+
}
|
|
39
|
+
export function countRecipeMemberAllotment(remaining, cohort, kind, tick) {
|
|
40
|
+
if (!Number.isSafeInteger(cohort) || cohort < 1)
|
|
41
|
+
throw Error('invalid count allocation cohort');
|
|
42
|
+
if (kind === 'ordinary')
|
|
43
|
+
return workShare(remaining, 1n, BigInt(cohort));
|
|
44
|
+
const reserved = workShare(tick, BigInt(cohort - 1), 1n);
|
|
45
|
+
return compareWork(remaining, reserved) > 0 ? workSub(remaining, reserved) : zeroWork;
|
|
46
|
+
}
|
|
47
|
+
export class CountRecipePass {
|
|
48
|
+
bank;
|
|
49
|
+
rootEpoch;
|
|
50
|
+
original;
|
|
51
|
+
rootEnd;
|
|
52
|
+
states;
|
|
53
|
+
// One cold repair at most for this fixed inventory, even across invocations.
|
|
54
|
+
supplierRepairUsed = false;
|
|
55
|
+
context;
|
|
56
|
+
constructor(members, context, bank = workLedger) {
|
|
57
|
+
this.bank = bank;
|
|
58
|
+
const tick = () => bank.start('ticks', 1, 'count recipe pass setup');
|
|
59
|
+
const snapshot = bank.snapshot(), root = countFind(snapshot.activeEndpoints, scope => scope.kind === 'root', tick);
|
|
60
|
+
if (!root || !snapshot.rootBaseline)
|
|
61
|
+
throw Error('count recipe pass needs an existing raw root');
|
|
62
|
+
this.rootEpoch = snapshot.rootEpoch;
|
|
63
|
+
this.rootEnd = workFromExact(root.end);
|
|
64
|
+
this.original = workSub(this.rootEnd, workFromExact(snapshot.rootBaseline.actual));
|
|
65
|
+
this.context = context;
|
|
66
|
+
this.states = countMap(members, source => {
|
|
67
|
+
const recipes = countMap(source.recipes, recipe => {
|
|
68
|
+
const fixed = Object.freeze({ ...recipe, ...(recipe.required !== undefined ? { required: Object.freeze(countMap(recipe.required, name => name, tick)) } : {}),
|
|
69
|
+
...(recipe.caseKeys !== undefined ? { caseKeys: Object.freeze(countMap(recipe.caseKeys, key => key, tick)) } : {}) });
|
|
70
|
+
return { recipe: fixed, tickets: new CountAttemptTickets(), terminal: false, keys: [] };
|
|
71
|
+
}, tick);
|
|
72
|
+
const member = Object.freeze({ name: source.name, reference: source.reference, recipes: Object.freeze(countMap(recipes, row => row.recipe, tick)) });
|
|
73
|
+
return { member, used: zeroWork, recipes };
|
|
74
|
+
}, tick);
|
|
75
|
+
}
|
|
76
|
+
reconcile(context) {
|
|
77
|
+
this.bank.start('tableCells', Math.min(context.length, this.context.length), 'count recipe context comparison');
|
|
78
|
+
if (context === this.context)
|
|
79
|
+
return;
|
|
80
|
+
// Context changes withdraw payloads, never recreate recipes or grant fuel.
|
|
81
|
+
for (const state of this.states) {
|
|
82
|
+
this.bank.start('ticks', 1, 'count recipe context withdrawal');
|
|
83
|
+
state.held = undefined;
|
|
84
|
+
}
|
|
85
|
+
this.context = context;
|
|
86
|
+
}
|
|
87
|
+
held() {
|
|
88
|
+
const held = new Map();
|
|
89
|
+
for (const state of this.states) {
|
|
90
|
+
this.bank.start('ticks', 1, 'count recipe held snapshot');
|
|
91
|
+
if (state.held)
|
|
92
|
+
held.set(state.member.name, state.held);
|
|
93
|
+
}
|
|
94
|
+
return held;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
// B's whole-held fallback and K's supplier repair share one persistent bit.
|
|
98
|
+
// An actual transport decline belongs to K; the fallback must not consume a
|
|
99
|
+
// separate retry around it. Claim before the fallback so refusal cannot renew it.
|
|
100
|
+
export function claimCountClosingFallback(pass, actualTransportDecline) {
|
|
101
|
+
if (actualTransportDecline || pass.supplierRepairUsed)
|
|
102
|
+
return false;
|
|
103
|
+
pass.supplierRepairUsed = true;
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
export const countRecipeCaptureObservation = { failures: 0 };
|
|
107
|
+
// Shallow data view: large proofs and their sharing are retained, never copied.
|
|
108
|
+
// Ticket snapshots expose data only; the writer cannot start an attempt.
|
|
109
|
+
export function snapshotCountRecipePass(pass) {
|
|
110
|
+
return { rootEpoch: pass.rootEpoch, original: pass.original, rootEnd: pass.rootEnd, context: pass.context, supplierRepairUsed: pass.supplierRepairUsed,
|
|
111
|
+
states: pass.states.map(state => ({ ...state, recipes: state.recipes.map(row => ({ ...row, tickets: row.tickets.snapshot() })) })) };
|
|
112
|
+
}
|
|
113
|
+
export function runCountRecipeController(pass, targets, hooks) {
|
|
114
|
+
const bank = pass.bank, tick = () => bank.start('ticks', 1, 'count recipe controller');
|
|
115
|
+
const map = (input, visit) => countMap(input, visit, tick);
|
|
116
|
+
const find = (input, test) => countFind(input, test, tick);
|
|
117
|
+
if (!bank.inBudget() || bank.snapshot().rootEpoch !== pass.rootEpoch)
|
|
118
|
+
return { reason: 'stale-root' };
|
|
119
|
+
if (!targets.length)
|
|
120
|
+
throw Error('count recipe controller needs a target');
|
|
121
|
+
const nodeRows = () => map(pass.states, state => {
|
|
122
|
+
tick();
|
|
123
|
+
const held = state.held;
|
|
124
|
+
return { name: state.member.name, reference: state.member.reference, recipes: map(state.recipes, row => {
|
|
125
|
+
tick();
|
|
126
|
+
return { id: row.recipe.id, required: row.recipe.required, terminal: row.terminal || row.tickets.snapshot().terminal || hooks.active !== undefined && !hooks.active.has(state.member.name) };
|
|
127
|
+
}), ...(held ? { held: { premises: held.premises, recipeId: held.recipeId, checkedReduced: held.checkedReduced } } : {}) };
|
|
128
|
+
});
|
|
129
|
+
const graph = () => countRecipeGraph(nodeRows(), targets, tick, { basis: hooks.basis });
|
|
130
|
+
let current, reason = 'nothing-eligible', failure;
|
|
131
|
+
let searchEnd = workSub(pass.rootEnd, workShare(pass.original, 3n, 8n));
|
|
132
|
+
const search = (run) => bank.withEndpoint('scope', searchEnd, run);
|
|
133
|
+
try {
|
|
134
|
+
current = search(graph);
|
|
135
|
+
for (;;) {
|
|
136
|
+
const prepared = search(() => {
|
|
137
|
+
const held = pass.held(), dependencies = new Map(map(held, ([name]) => [name, map(current.requirements.get(name) ?? [], value => value)]));
|
|
138
|
+
const closed = greatestClosedCountFamily(map(pass.states, state => state.member.name), dependencies, { basis: hooks.basis, tick });
|
|
139
|
+
if (find(targets, name => find(closed.members, member => member === name) === undefined) === undefined) {
|
|
140
|
+
reason = 'target-held';
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
if (!current.next) {
|
|
144
|
+
reason = current.stop ?? 'nothing-eligible';
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
const choice = current.next, state = find(pass.states, row => row.member.name === choice.name), row = find(state.recipes, row => row.recipe.id === choice.recipe.id);
|
|
148
|
+
tick();
|
|
149
|
+
const measured = map(held.values(), item => item.checkCost);
|
|
150
|
+
let closing = workShare(pass.original, 3n, 8n);
|
|
151
|
+
if (measured.length) {
|
|
152
|
+
let sum = zeroWork;
|
|
153
|
+
for (const cost of measured) {
|
|
154
|
+
tick();
|
|
155
|
+
sum = workAdd(sum, cost);
|
|
156
|
+
}
|
|
157
|
+
closing = minWork(pass.original, compareWork(sum, zeroWork) > 0 ? workShare(sum, 2n, 1n) : bank.weights.ticks);
|
|
158
|
+
}
|
|
159
|
+
const componentEnd = workSub(pass.rootEnd, closing);
|
|
160
|
+
const phaseEnd = row.recipe.kind === 'strategy' ? workSub(componentEnd, workShare(pass.original, 1n, 40n)) : componentEnd;
|
|
161
|
+
searchEnd = componentEnd;
|
|
162
|
+
return { choice, state, row, phaseEnd };
|
|
163
|
+
});
|
|
164
|
+
if (!prepared)
|
|
165
|
+
break;
|
|
166
|
+
const { choice, state, row, phaseEnd } = prepared;
|
|
167
|
+
if (compareWork(phaseEnd, bank.actual()) <= 0) {
|
|
168
|
+
reason = 'phase-cap';
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
let entered = false;
|
|
172
|
+
try {
|
|
173
|
+
bank.withEndpoint('scope', phaseEnd, () => {
|
|
174
|
+
const remaining = bank.available();
|
|
175
|
+
if (remaining === null || compareWork(remaining, zeroWork) <= 0) {
|
|
176
|
+
row.terminal = true;
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
if (!state.allotted) {
|
|
180
|
+
// D6f60c382 / 46.18: widening changes consideration, never the cohort.
|
|
181
|
+
// Q contains only real, non-usable, non-blocked closure members; an
|
|
182
|
+
// outside selected member adds itself, not the other widened candidates.
|
|
183
|
+
const allocation = graph();
|
|
184
|
+
const pending = countRecipeAllocationCohort(map(pass.states, member => member.member.name), allocation, choice.name, tick);
|
|
185
|
+
const remaining = bank.available();
|
|
186
|
+
state.allocationCohort = pending;
|
|
187
|
+
state.allocationRemaining = remaining;
|
|
188
|
+
state.allotted = countRecipeMemberAllotment(remaining, pending, row.recipe.kind, bank.weights.ticks);
|
|
189
|
+
}
|
|
190
|
+
const left = workSub(state.allotted, state.used);
|
|
191
|
+
if (compareWork(left, zeroWork) <= 0) {
|
|
192
|
+
for (const recipe of state.recipes) {
|
|
193
|
+
tick();
|
|
194
|
+
recipe.terminal = true;
|
|
195
|
+
}
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
const before = bank.actual();
|
|
199
|
+
try {
|
|
200
|
+
bank.withBudget(left, () => {
|
|
201
|
+
entered = true;
|
|
202
|
+
// The leaf slot is the 64th key. Unsupported producer inventories are
|
|
203
|
+
// scheduling declines, never malformed-state exceptions or new attempts.
|
|
204
|
+
if (row.recipe.caseKeys !== undefined && row.recipe.caseKeys.length > 63) {
|
|
205
|
+
row.terminal = true;
|
|
206
|
+
failure = { law: choice.name, recipe: row.recipe.id, outcome: 'decline', reason: 'unsupported-case-inventory' };
|
|
207
|
+
hooks.observe?.({ phase: 'count-recipe-result', ...failure, cases: row.recipe.caseKeys.length, maximumCases: 63, tickets: row.tickets.snapshot() });
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
if (hooks.preflight && !hooks.preflight(choice.name, row.recipe)) {
|
|
211
|
+
row.terminal = true;
|
|
212
|
+
failure = { law: choice.name, recipe: row.recipe.id, outcome: 'decline', reason: 'preflight-refused' };
|
|
213
|
+
hooks.observe?.({ phase: 'count-recipe-result', ...failure });
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
if (!row.keys.length) {
|
|
217
|
+
const names = row.recipe.caseKeys;
|
|
218
|
+
row.keys = names?.length ? [...map(names, key => ({ key, allocation: workShare(pass.original, 1n, 30n), used: zeroWork })), { key: countLeafSlot, allocation: workShare(pass.original, 1n, 120n), used: zeroWork }] : [{ key: 'body', allocation: left, used: zeroWork }];
|
|
219
|
+
}
|
|
220
|
+
const headrooms = () => { const snapshot = bank.snapshot(), used = bank.actual(), reserved = bank.reserved(); return map(snapshot.activeEndpoints, scope => ({ scope: scope.kind + ':' + scope.id, remaining: workSub(workSub(workFromExact(scope.end), used), reserved) })); };
|
|
221
|
+
let plan = row.stop ? planCountRetry(row.keys, row.stop, headrooms(), bank) : { kind: 'admitted', need: minWork(left, bank.available()), keys: row.keys, rootEpoch: pass.rootEpoch };
|
|
222
|
+
const attempt = new CountAttemptWork(plan.kind === 'admitted' ? plan.keys : row.keys, bank);
|
|
223
|
+
const admissionAncestors = headrooms();
|
|
224
|
+
// Preparation is charged before the initial full-headroom round. A retry
|
|
225
|
+
// keeps its fixed need and is revalidated atomically by the round helper.
|
|
226
|
+
if (!row.stop && plan.kind === 'admitted')
|
|
227
|
+
plan = { ...plan, need: minWork(left, bank.available()) };
|
|
228
|
+
hooks.observe?.({ phase: 'count-recipe-admission', law: choice.name, recipe: row.recipe.id, plan, previousKeys: row.keys, original: exactRaw(pass.original), allotted: exactRaw(state.allotted), allocationCohort: state.allocationCohort, allocationRemaining: state.allocationRemaining && exactRaw(state.allocationRemaining), used: exactRaw(state.used), ancestors: admissionAncestors, tickets: row.tickets.snapshot() });
|
|
229
|
+
const result = runCountRetryRound(plan, row.tickets, () => {
|
|
230
|
+
hooks.observe?.({ phase: 'count-component-attempt', law: choice.name, recipe: row.recipe.id, mode: 'recipe', purpose: 'required', required: row.recipe.required, rootEpoch: pass.rootEpoch });
|
|
231
|
+
let lease;
|
|
232
|
+
if (row.recipe.kind === 'strategy' && row.recipe.caseKeys !== undefined) {
|
|
233
|
+
const keys = plan.kind === 'admitted' ? plan.keys : row.keys, cases = {};
|
|
234
|
+
let leaf;
|
|
235
|
+
for (const key of keys) {
|
|
236
|
+
tick();
|
|
237
|
+
if (key.key === countLeafSlot)
|
|
238
|
+
leaf = key.allocation;
|
|
239
|
+
else if (key.key !== 'body')
|
|
240
|
+
cases[key.key] = key.allocation;
|
|
241
|
+
}
|
|
242
|
+
lease = liftedWorkLeaseBudget(pass.original, { cases, leaf, trace: event => { attempt.trace(event); hooks.observe?.({ phase: 'count-recipe-slice', law: choice.name, recipe: row.recipe.id, ...event }); } });
|
|
243
|
+
}
|
|
244
|
+
const captured = hooks.construct(choice.name, row.recipe, lease);
|
|
245
|
+
if (!attempt.valid())
|
|
246
|
+
throw new BudgetExpired('unclassified count slice inventory');
|
|
247
|
+
return captured ? { kind: 'proposal', value: captured } : { kind: 'decline', reason: 'constructor-declined' };
|
|
248
|
+
}, { bank, slices: attempt.slices, eligible: () => {
|
|
249
|
+
const fresh = graph();
|
|
250
|
+
return fresh.candidates.has(choice.name) && !fresh.blocked.has(choice.name) && !fresh.usable.has(choice.name) && !row.terminal
|
|
251
|
+
&& (hooks.active === undefined || hooks.active.has(choice.name))
|
|
252
|
+
&& find(row.recipe.required ?? [], name => fresh.blocked.has(name)) === undefined;
|
|
253
|
+
} });
|
|
254
|
+
row.keys = attempt.keys();
|
|
255
|
+
row.terminal = result.kind !== 'unfinished' || row.tickets.snapshot().terminal;
|
|
256
|
+
row.stop = result.kind === 'unfinished' ? result.stop : undefined;
|
|
257
|
+
if (result.kind !== 'proposal')
|
|
258
|
+
failure = { law: choice.name, recipe: row.recipe.id, outcome: result.kind, reason: 'reason' in result ? result.reason : result.stop.kind === 'hard-cap' ? result.stop.reason : result.stop.kind, ...('stop' in result ? { stop: result.stop } : {}) };
|
|
259
|
+
if (result.kind === 'proposal') {
|
|
260
|
+
// The recipe is already terminal. Post-proposal capture/checks execute
|
|
261
|
+
// outside the round but still inside this persistent member/ancestor cap.
|
|
262
|
+
const captured = hooks.capture ? hooks.capture(choice.name, row.recipe, result.value) : result.value;
|
|
263
|
+
if (captured)
|
|
264
|
+
state.held = { ...captured, recipeId: row.recipe.id };
|
|
265
|
+
else
|
|
266
|
+
failure = { law: choice.name, recipe: row.recipe.id, outcome: 'decline', reason: 'capture-declined' };
|
|
267
|
+
}
|
|
268
|
+
hooks.observe?.({ phase: 'count-recipe-result', law: choice.name, recipe: row.recipe.id, outcome: result.kind, ...('reason' in result ? { reason: result.reason } : {}), ...(result.kind === 'proposal' && !state.held ? { reason: 'capture-declined' } : {}), premises: state.held?.premises, checkedReduced: state.held?.checkedReduced, ...('stop' in result ? { stop: result.stop } : {}), tickets: row.tickets.snapshot(), inventory: attempt.inventory(), ancestors: headrooms() });
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
finally {
|
|
272
|
+
state.used = workAdd(state.used, workSub(bank.actual(), before));
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
catch (error) {
|
|
277
|
+
if (!(error instanceof BudgetExpired))
|
|
278
|
+
throw error;
|
|
279
|
+
row.terminal = true;
|
|
280
|
+
const stop = countAttemptStop(error, [], bank);
|
|
281
|
+
failure = { law: choice.name, recipe: row.recipe.id, outcome: 'hard-cap', reason: stop.kind === 'hard-cap' ? stop.reason : stop.kind, stop };
|
|
282
|
+
hooks.observe?.({ phase: 'count-recipe-result', ...failure, capacity: bank.capacityRefusal(error), errorPhase: error.phase, tickets: row.tickets.snapshot() });
|
|
283
|
+
// A root/ancestor failure is not repaired by another child allocation.
|
|
284
|
+
bank.check('count recipe enclosing continuation');
|
|
285
|
+
}
|
|
286
|
+
current = search(() => { if (!entered) {
|
|
287
|
+
tick();
|
|
288
|
+
row.terminal = true;
|
|
289
|
+
} return graph(); });
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
catch (error) {
|
|
293
|
+
if (!(error instanceof BudgetExpired))
|
|
294
|
+
throw error;
|
|
295
|
+
reason = 'phase-cap';
|
|
296
|
+
bank.check('count recipe search continuation');
|
|
297
|
+
}
|
|
298
|
+
// Output-only observation: no new scope, tick, grant, or proof mutation.
|
|
299
|
+
if (hooks.beforeClosing)
|
|
300
|
+
try {
|
|
301
|
+
hooks.beforeClosing({ pass: snapshotCountRecipePass(pass), targets, reason, failure });
|
|
302
|
+
}
|
|
303
|
+
catch {
|
|
304
|
+
countRecipeCaptureObservation.failures++;
|
|
305
|
+
}
|
|
306
|
+
let closingOrdinal = 0;
|
|
307
|
+
const attemptClosing = () => withReplayDiagnosticContext({ passId: replayPassId(pass), closingAttempt: ++closingOrdinal, repairUsed: pass.supplierRepairUsed }, () => {
|
|
308
|
+
const held = pass.held(), rows = [];
|
|
309
|
+
for (const member of nodeRows()) {
|
|
310
|
+
tick();
|
|
311
|
+
const payload = held.get(member.name);
|
|
312
|
+
if (payload)
|
|
313
|
+
rows.push({ id: member.name, premises: map(countRecipeRequirements(member, tick), value => value), payload: payload.payload });
|
|
314
|
+
}
|
|
315
|
+
// This is closing preparation, not search selection: traverse only the held
|
|
316
|
+
// conservative premise relation and never invent or start another recipe.
|
|
317
|
+
const relation = new Map(map(rows, row => [row.id, row.premises])), needed = new Set(), pending = map(targets, name => name);
|
|
318
|
+
for (let at = 0; at < pending.length; at++) {
|
|
319
|
+
tick();
|
|
320
|
+
const name = pending[at];
|
|
321
|
+
if (needed.has(name))
|
|
322
|
+
continue;
|
|
323
|
+
needed.add(name);
|
|
324
|
+
for (const next of relation.get(name) ?? []) {
|
|
325
|
+
tick();
|
|
326
|
+
if (!needed.has(next))
|
|
327
|
+
pending.push(next);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
const plan = greatestClosedCountFamily(map(pass.states, state => state.member.name), new Map(map(rows, row => [row.id, row.premises])), { basis: hooks.basis, tick });
|
|
331
|
+
const target = find(targets, name => find(plan.members, member => member === name) === undefined) ?? targets[0];
|
|
332
|
+
const closing = closeGreatestCountFamily(target, rows, {
|
|
333
|
+
legacy: () => {
|
|
334
|
+
const selected = [];
|
|
335
|
+
for (const row of rows) {
|
|
336
|
+
tick();
|
|
337
|
+
if (needed.has(row.id))
|
|
338
|
+
selected.push(row);
|
|
339
|
+
}
|
|
340
|
+
// Lazy, fixed inventory only: no producer runs and no new work scope.
|
|
341
|
+
return hooks.close(selected, true, () => {
|
|
342
|
+
const names = new Set(), whole = [];
|
|
343
|
+
for (const name of plan.members) {
|
|
344
|
+
tick();
|
|
345
|
+
names.add(name);
|
|
346
|
+
}
|
|
347
|
+
for (const row of rows) {
|
|
348
|
+
tick();
|
|
349
|
+
if (names.has(row.id))
|
|
350
|
+
whole.push(row);
|
|
351
|
+
}
|
|
352
|
+
return whole;
|
|
353
|
+
});
|
|
354
|
+
},
|
|
355
|
+
reserve: selected => {
|
|
356
|
+
let measured = zeroWork;
|
|
357
|
+
for (const row of selected) {
|
|
358
|
+
tick();
|
|
359
|
+
const captured = held.get(row.id);
|
|
360
|
+
if (!captured)
|
|
361
|
+
return false;
|
|
362
|
+
measured = workAdd(measured, captured.checkCost);
|
|
363
|
+
}
|
|
364
|
+
// Match the already declared 2*sum closing requirement, including its
|
|
365
|
+
// original-W clamp and zero-sum tick. Positive headroom alone is not enough.
|
|
366
|
+
const required = compareWork(measured, zeroWork) > 0 ? minWork(pass.original, workShare(measured, 2n, 1n)) : bank.weights.ticks;
|
|
367
|
+
const available = bank.available(), admitted = available !== null && compareWork(available, required) >= 0;
|
|
368
|
+
if (!admitted)
|
|
369
|
+
failure = { outcome: 'not-started', reason: 'closing-reserve' };
|
|
370
|
+
hooks.observe?.({ phase: 'count-recipe-closing-reserve', required: exactRaw(required), available: available && exactRaw(available), admitted });
|
|
371
|
+
return admitted;
|
|
372
|
+
},
|
|
373
|
+
submit: selected => hooks.close(selected, false)
|
|
374
|
+
}, { basis: hooks.basis, tick });
|
|
375
|
+
emitReplayDiagnostic({ kind: 'closing-result', route: closing.route, submitted: closing.submitted, targetInFamily: closing.targetInFamily, members: closing.plan.members, blockers: closing.plan.blockers, repairUsed: pass.supplierRepairUsed });
|
|
376
|
+
return closing;
|
|
377
|
+
});
|
|
378
|
+
let closing = attemptClosing();
|
|
379
|
+
const declined = closing.submitted && !pass.supplierRepairUsed && hooks.repairSuppliers ? hooks.declinedMember?.() : undefined;
|
|
380
|
+
if (declined !== undefined) {
|
|
381
|
+
const state = find(pass.states, state => state.member.name === declined);
|
|
382
|
+
if (state?.held) {
|
|
383
|
+
// Consume the one repair BEFORE entering it: cancellation/refusal cannot
|
|
384
|
+
// renew this allowance on a later controller invocation. No recipe runs.
|
|
385
|
+
pass.supplierRepairUsed = true;
|
|
386
|
+
const repairContext = { passId: replayPassId(pass), member: declined, closingAttempt: closingOrdinal, repairUsed: true };
|
|
387
|
+
emitReplayDiagnostic({ kind: 'resolver-start', context: repairContext, premises: state.held.premises });
|
|
388
|
+
let repaired;
|
|
389
|
+
try {
|
|
390
|
+
repaired = hooks.repairSuppliers(declined, state.held.payload);
|
|
391
|
+
}
|
|
392
|
+
catch (error) {
|
|
393
|
+
emitReplayDiagnostic({ kind: 'resolver-result', context: repairContext, result: 'threw', error: error instanceof Error ? error.name : 'non-error' });
|
|
394
|
+
throw error;
|
|
395
|
+
}
|
|
396
|
+
if (repaired) {
|
|
397
|
+
const premisesBefore = state.held.premises;
|
|
398
|
+
const names = new Set(state.held.premises);
|
|
399
|
+
for (const name of repaired.premises) {
|
|
400
|
+
tick();
|
|
401
|
+
names.add(name);
|
|
402
|
+
}
|
|
403
|
+
state.held = { ...state.held, payload: repaired.payload, premises: map(names, name => name), checkedReduced: false };
|
|
404
|
+
if (countReplayDiagnostic.on)
|
|
405
|
+
emitReplayDiagnostic({ kind: 'resolver-result', context: repairContext, result: 'repaired', premisesBefore, payloadPremisesAfter: repaired.premises, effectivePremisesAfter: state.held.premises, premisesAfterMeaning: 'effective is the controller union; payload is the resolver return' });
|
|
406
|
+
hooks.observe?.({ phase: 'count-recipe-supplier-repair', law: declined, premises: state.held.premises });
|
|
407
|
+
// Rebuild H/S, the target closure, and G from ALL held payloads. A missing
|
|
408
|
+
// supplier can remove the target, never be silently admitted or invented.
|
|
409
|
+
closing = attemptClosing();
|
|
410
|
+
}
|
|
411
|
+
else if (countReplayDiagnostic.on)
|
|
412
|
+
emitReplayDiagnostic({ kind: 'resolver-result', context: repairContext, result: 'declined', premisesBefore: state.held.premises, payloadPremisesAfter: null, effectivePremisesAfter: state.held.premises });
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
hooks.observe?.({ phase: 'count-recipe-closing', reason, route: closing.route, targetInFamily: closing.targetInFamily, members: closing.plan.members, blockers: closing.plan.blockers, paths: [...closing.plan.paths], supplierRepairUsed: pass.supplierRepairUsed });
|
|
416
|
+
return { reason, ...(failure ? { failure } : {}), closingRoute: closing.route, ...(closing.result !== undefined ? { result: closing.result } : {}) };
|
|
417
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export type CountRecipeNode = Readonly<{
|
|
2
|
+
id: string;
|
|
3
|
+
required?: readonly string[];
|
|
4
|
+
terminal: boolean;
|
|
5
|
+
}>;
|
|
6
|
+
export type CountHeldNode = Readonly<{
|
|
7
|
+
premises: readonly string[];
|
|
8
|
+
recipeId: string;
|
|
9
|
+
checkedReduced: boolean;
|
|
10
|
+
}>;
|
|
11
|
+
export type CountRecipeMember = Readonly<{
|
|
12
|
+
name: string;
|
|
13
|
+
reference: number;
|
|
14
|
+
recipes: readonly CountRecipeNode[];
|
|
15
|
+
held?: CountHeldNode;
|
|
16
|
+
}>;
|
|
17
|
+
export type CountRecipeChoice = Readonly<{
|
|
18
|
+
name: string;
|
|
19
|
+
recipe: CountRecipeNode;
|
|
20
|
+
stranded: boolean;
|
|
21
|
+
weight: number;
|
|
22
|
+
requiredSize: number;
|
|
23
|
+
}>;
|
|
24
|
+
export type CountRecipeGraph = Readonly<{
|
|
25
|
+
blocked: ReadonlySet<string>;
|
|
26
|
+
usable: ReadonlySet<string>;
|
|
27
|
+
closure: ReadonlySet<string>;
|
|
28
|
+
candidates: ReadonlySet<string>;
|
|
29
|
+
requirements: ReadonlyMap<string, ReadonlySet<string>>;
|
|
30
|
+
next?: CountRecipeChoice;
|
|
31
|
+
stop?: 'target-blocked' | 'nothing-eligible';
|
|
32
|
+
}>;
|
|
33
|
+
export declare function countRecipeRequirements(member: CountRecipeMember, tick?: () => void): Set<string>;
|
|
34
|
+
export declare function countRecipeGraph(members: readonly CountRecipeMember[], targets: readonly string[], tick?: () => void, options?: Readonly<{
|
|
35
|
+
basis?: ReadonlySet<string>;
|
|
36
|
+
}>): CountRecipeGraph;
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
// Section 46.2'/46.3': untrusted scheduling only. S is computed conservatively
|
|
2
|
+
// here; a checkedReduced marker must come from the accepted exact-scope replay.
|
|
3
|
+
// This graph never accepts a proof, replenishes fuel, or creates a recipe.
|
|
4
|
+
import { startWork } from "./work-admission.js";
|
|
5
|
+
import { checkWall } from "./wall.js";
|
|
6
|
+
const control = () => { checkWall('count recipe graph'); startWork('ticks', 1, 'count recipe graph'); };
|
|
7
|
+
// Shared conservative S computation for search and for the independently
|
|
8
|
+
// funded closing phase. Closing must not reuse a possibly stale search graph.
|
|
9
|
+
export function countRecipeRequirements(member, tick = control) {
|
|
10
|
+
const required = new Set();
|
|
11
|
+
if (!member.held) {
|
|
12
|
+
for (const recipe of member.recipes) {
|
|
13
|
+
tick();
|
|
14
|
+
if (!recipe.terminal)
|
|
15
|
+
for (const name of recipe.required ?? []) {
|
|
16
|
+
tick();
|
|
17
|
+
required.add(name);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
for (const name of member.held.premises) {
|
|
23
|
+
tick();
|
|
24
|
+
required.add(name);
|
|
25
|
+
}
|
|
26
|
+
const producing = member.recipes.find(recipe => { tick(); return recipe.id === member.held.recipeId; });
|
|
27
|
+
if (!producing)
|
|
28
|
+
throw Error('held member has no producing recipe');
|
|
29
|
+
if (!producing.terminal)
|
|
30
|
+
throw Error('completed recipe must be terminal');
|
|
31
|
+
if (!member.held.checkedReduced)
|
|
32
|
+
for (const name of producing.required ?? []) {
|
|
33
|
+
tick();
|
|
34
|
+
required.add(name);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return required;
|
|
38
|
+
}
|
|
39
|
+
export function countRecipeGraph(members, targets, tick = control, options = {}) {
|
|
40
|
+
const byName = new Map(), references = new Set(), requirements = new Map();
|
|
41
|
+
for (const member of members) {
|
|
42
|
+
tick();
|
|
43
|
+
if (byName.has(member.name) || !Number.isSafeInteger(member.reference) || member.reference < 0 || references.has(member.reference))
|
|
44
|
+
throw Error('invalid or duplicate recipe member');
|
|
45
|
+
byName.set(member.name, member);
|
|
46
|
+
references.add(member.reference);
|
|
47
|
+
const ids = new Set();
|
|
48
|
+
for (const recipe of member.recipes) {
|
|
49
|
+
tick();
|
|
50
|
+
if (!recipe.id || ids.has(recipe.id))
|
|
51
|
+
throw Error('duplicate recipe instance');
|
|
52
|
+
ids.add(recipe.id);
|
|
53
|
+
}
|
|
54
|
+
requirements.set(member.name, countRecipeRequirements(member, tick));
|
|
55
|
+
}
|
|
56
|
+
// Only the caller's explicitly natively checked external basis can discharge
|
|
57
|
+
// a missing pass member. Candidate expansion never supplies this authority.
|
|
58
|
+
const basis = new Set();
|
|
59
|
+
for (const name of options.basis ?? []) {
|
|
60
|
+
tick();
|
|
61
|
+
basis.add(name);
|
|
62
|
+
}
|
|
63
|
+
const blocked = new Set();
|
|
64
|
+
// A missing candidate is unobtainable in this pass. It participates in the
|
|
65
|
+
// same least fixed point rather than being silently dropped from a scope.
|
|
66
|
+
for (const required of requirements.values())
|
|
67
|
+
for (const name of required) {
|
|
68
|
+
tick();
|
|
69
|
+
if (!byName.has(name) && !basis.has(name))
|
|
70
|
+
blocked.add(name);
|
|
71
|
+
}
|
|
72
|
+
for (const member of members)
|
|
73
|
+
for (const recipe of member.recipes)
|
|
74
|
+
for (const name of recipe.required ?? []) {
|
|
75
|
+
tick();
|
|
76
|
+
if (!byName.has(name) && !basis.has(name))
|
|
77
|
+
blocked.add(name);
|
|
78
|
+
}
|
|
79
|
+
const eligible = (recipe) => {
|
|
80
|
+
tick();
|
|
81
|
+
if (recipe.terminal)
|
|
82
|
+
return false;
|
|
83
|
+
for (const name of recipe.required ?? []) {
|
|
84
|
+
tick();
|
|
85
|
+
if (blocked.has(name))
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
return true;
|
|
89
|
+
};
|
|
90
|
+
const isUsable = (member) => {
|
|
91
|
+
tick();
|
|
92
|
+
if (!member.held)
|
|
93
|
+
return false;
|
|
94
|
+
for (const name of requirements.get(member.name)) {
|
|
95
|
+
tick();
|
|
96
|
+
if (blocked.has(name))
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
return true;
|
|
100
|
+
};
|
|
101
|
+
let changed = true;
|
|
102
|
+
while (changed) {
|
|
103
|
+
changed = false;
|
|
104
|
+
for (const member of members) {
|
|
105
|
+
tick();
|
|
106
|
+
if (blocked.has(member.name) || isUsable(member))
|
|
107
|
+
continue;
|
|
108
|
+
let hasRecipe = false;
|
|
109
|
+
for (const recipe of member.recipes) {
|
|
110
|
+
tick();
|
|
111
|
+
if (eligible(recipe)) {
|
|
112
|
+
hasRecipe = true;
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (!hasRecipe) {
|
|
117
|
+
blocked.add(member.name);
|
|
118
|
+
changed = true;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
const usable = new Set();
|
|
123
|
+
for (const member of members) {
|
|
124
|
+
tick();
|
|
125
|
+
if (isUsable(member))
|
|
126
|
+
usable.add(member.name);
|
|
127
|
+
}
|
|
128
|
+
const reachable = (starts) => {
|
|
129
|
+
const seen = new Set(), queue = [];
|
|
130
|
+
for (const name of starts) {
|
|
131
|
+
tick();
|
|
132
|
+
queue.push(name);
|
|
133
|
+
}
|
|
134
|
+
for (let at = 0; at < queue.length; at++) {
|
|
135
|
+
tick();
|
|
136
|
+
const name = queue[at];
|
|
137
|
+
if (seen.has(name))
|
|
138
|
+
continue;
|
|
139
|
+
seen.add(name);
|
|
140
|
+
for (const prerequisite of requirements.get(name) ?? []) {
|
|
141
|
+
tick();
|
|
142
|
+
if (!seen.has(prerequisite))
|
|
143
|
+
queue.push(prerequisite);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return seen;
|
|
147
|
+
};
|
|
148
|
+
const closure = reachable(targets), candidates = new Set();
|
|
149
|
+
for (const name of closure) {
|
|
150
|
+
tick();
|
|
151
|
+
candidates.add(name);
|
|
152
|
+
}
|
|
153
|
+
for (const target of targets) {
|
|
154
|
+
tick();
|
|
155
|
+
if (!byName.has(target) || blocked.has(target))
|
|
156
|
+
return { blocked, usable, closure, candidates, requirements, stop: 'target-blocked' };
|
|
157
|
+
}
|
|
158
|
+
// 46.15 changes consideration only. Score the expanded candidate domain
|
|
159
|
+
// through known edges; never add it to Req, S, or a proposal's proof scope.
|
|
160
|
+
let expand = false;
|
|
161
|
+
for (const name of closure) {
|
|
162
|
+
tick();
|
|
163
|
+
const member = byName.get(name);
|
|
164
|
+
if (!member || usable.has(name))
|
|
165
|
+
continue;
|
|
166
|
+
for (const recipe of member.recipes) {
|
|
167
|
+
tick();
|
|
168
|
+
if (recipe.required === undefined && eligible(recipe)) {
|
|
169
|
+
expand = true;
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
if (expand)
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
if (expand)
|
|
177
|
+
for (const member of members) {
|
|
178
|
+
tick();
|
|
179
|
+
candidates.add(member.name);
|
|
180
|
+
}
|
|
181
|
+
const weights = new Map();
|
|
182
|
+
for (const name of candidates) {
|
|
183
|
+
tick();
|
|
184
|
+
for (const prerequisite of reachable([name])) {
|
|
185
|
+
tick();
|
|
186
|
+
if (prerequisite !== name && candidates.has(prerequisite))
|
|
187
|
+
weights.set(prerequisite, (weights.get(prerequisite) ?? 0) + 1);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
let next, bestReference = Infinity;
|
|
191
|
+
for (const member of members) {
|
|
192
|
+
tick();
|
|
193
|
+
if (!candidates.has(member.name) || usable.has(member.name) || blocked.has(member.name))
|
|
194
|
+
continue;
|
|
195
|
+
let recipe;
|
|
196
|
+
for (const candidate of member.recipes) {
|
|
197
|
+
tick();
|
|
198
|
+
if (eligible(candidate) && (!recipe || (recipe.required === undefined && candidate.required !== undefined)))
|
|
199
|
+
recipe = candidate;
|
|
200
|
+
}
|
|
201
|
+
if (!recipe)
|
|
202
|
+
continue;
|
|
203
|
+
const candidate = { name: member.name, recipe, stranded: !!member.held, weight: weights.get(member.name) ?? 0, requiredSize: requirements.get(member.name).size };
|
|
204
|
+
const known = recipe.required !== undefined, previousKnown = next?.recipe.required !== undefined;
|
|
205
|
+
if (!next || candidate.weight > next.weight || candidate.weight === next.weight && (candidate.requiredSize > next.requiredSize || candidate.requiredSize === next.requiredSize && (known && !previousKnown || known === previousKnown && member.reference < bestReference))) {
|
|
206
|
+
next = candidate;
|
|
207
|
+
bestReference = member.reference;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return next ? { blocked, usable, closure, candidates, requirements, next } : { blocked, usable, closure, candidates, requirements, stop: 'nothing-eligible' };
|
|
211
|
+
}
|