gdp-wired 0.48.0 → 0.49.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.
Files changed (295) hide show
  1. package/README.md +2 -2
  2. package/dist/core/bmc.js +10 -7
  3. package/dist/core/check.js +7 -2
  4. package/dist/core/count-attempt-work.d.ts +29 -0
  5. package/dist/core/count-attempt-work.js +96 -0
  6. package/dist/core/count-boolean-partition.d.ts +5 -0
  7. package/dist/core/count-boolean-partition.js +47 -0
  8. package/dist/core/count-bounded-quotient.d.ts +2 -0
  9. package/dist/core/count-bounded-quotient.js +13 -0
  10. package/dist/core/count-case-compose.d.ts +20 -0
  11. package/dist/core/count-case-compose.js +289 -0
  12. package/dist/core/count-cases.js +3 -2
  13. package/dist/core/count-cert-rename.d.ts +10 -0
  14. package/dist/core/count-cert-rename.js +69 -0
  15. package/dist/core/count-cert-transport.d.ts +10 -2
  16. package/dist/core/count-cert-transport.js +60 -9
  17. package/dist/core/count-certificate-minimize.d.ts +57 -0
  18. package/dist/core/count-certificate-minimize.js +263 -0
  19. package/dist/core/count-closed-family.d.ts +32 -0
  20. package/dist/core/count-closed-family.js +143 -0
  21. package/dist/core/count-closing-budget.d.ts +10 -0
  22. package/dist/core/count-closing-budget.js +49 -0
  23. package/dist/core/count-closing-needs.d.ts +5 -0
  24. package/dist/core/count-closing-needs.js +9 -0
  25. package/dist/core/count-component-budget.d.ts +5 -0
  26. package/dist/core/count-component-budget.js +9 -0
  27. package/dist/core/count-copy-shape.d.ts +11 -0
  28. package/dist/core/count-copy-shape.js +40 -0
  29. package/dist/core/count-disjoint-funding.d.ts +75 -0
  30. package/dist/core/count-disjoint-funding.js +284 -0
  31. package/dist/core/count-emitter-frame-pool.d.ts +23 -0
  32. package/dist/core/count-emitter-frame-pool.js +87 -0
  33. package/dist/core/count-final-step.d.ts +5 -0
  34. package/dist/core/count-final-step.js +20 -0
  35. package/dist/core/count-fixed-frame.d.ts +4 -0
  36. package/dist/core/count-fixed-frame.js +30 -0
  37. package/dist/core/count-frames.d.ts +25 -0
  38. package/dist/core/count-frames.js +118 -0
  39. package/dist/core/count-frozen-guard.d.ts +2 -0
  40. package/dist/core/count-frozen-guard.js +31 -0
  41. package/dist/core/count-generation-phase.d.ts +7 -0
  42. package/dist/core/count-generation-phase.js +33 -0
  43. package/dist/core/count-guard-composition.d.ts +12 -0
  44. package/dist/core/count-guard-composition.js +48 -0
  45. package/dist/core/count-guard-context.d.ts +11 -0
  46. package/dist/core/count-guard-context.js +50 -0
  47. package/dist/core/count-guard-facts.d.ts +50 -0
  48. package/dist/core/count-guard-facts.js +97 -0
  49. package/dist/core/count-guard-proposals.d.ts +7 -0
  50. package/dist/core/count-guard-proposals.js +106 -0
  51. package/dist/core/count-guard-shape.d.ts +18 -0
  52. package/dist/core/count-guard-shape.js +100 -0
  53. package/dist/core/count-guard-tree.d.ts +17 -0
  54. package/dist/core/count-guard-tree.js +125 -0
  55. package/dist/core/count-leader-facts.d.ts +10 -0
  56. package/dist/core/count-leader-facts.js +52 -0
  57. package/dist/core/count-leader.d.ts +10 -0
  58. package/dist/core/count-leader.js +331 -0
  59. package/dist/core/count-lemma-transport.d.ts +8 -0
  60. package/dist/core/count-lemma-transport.js +47 -0
  61. package/dist/core/count-lifted-budget.d.ts +54 -0
  62. package/dist/core/count-lifted-budget.js +97 -0
  63. package/dist/core/count-lifted-copy.d.ts +3 -0
  64. package/dist/core/count-lifted-copy.js +166 -0
  65. package/dist/core/count-lifted-increment.d.ts +3 -0
  66. package/dist/core/count-lifted-increment.js +146 -0
  67. package/dist/core/count-lifted-load.d.ts +5 -0
  68. package/dist/core/count-lifted-load.js +179 -0
  69. package/dist/core/count-lifted-prerequisite.d.ts +14 -0
  70. package/dist/core/count-lifted-prerequisite.js +53 -0
  71. package/dist/core/count-lifted-replacement.d.ts +3 -0
  72. package/dist/core/count-lifted-replacement.js +540 -0
  73. package/dist/core/count-lifted-shape.d.ts +63 -0
  74. package/dist/core/count-lifted-shape.js +115 -0
  75. package/dist/core/count-lifted-strategy.d.ts +7 -0
  76. package/dist/core/count-lifted-strategy.js +226 -0
  77. package/dist/core/count-lifted-transports.d.ts +32 -0
  78. package/dist/core/count-lifted-transports.js +293 -0
  79. package/dist/core/count-load-shape.d.ts +17 -0
  80. package/dist/core/count-load-shape.js +67 -0
  81. package/dist/core/count-minimal-view.d.ts +26 -0
  82. package/dist/core/count-minimal-view.js +46 -0
  83. package/dist/core/count-operation-observation.d.ts +9 -0
  84. package/dist/core/count-operation-observation.js +22 -0
  85. package/dist/core/count-operation-order.d.ts +5 -0
  86. package/dist/core/count-operation-order.js +4 -0
  87. package/dist/core/count-phase.d.ts +9 -0
  88. package/dist/core/count-phase.js +127 -0
  89. package/dist/core/count-premise-search.d.ts +9 -0
  90. package/dist/core/count-premise-search.js +41 -0
  91. package/dist/core/count-premise-view.d.ts +19 -0
  92. package/dist/core/count-premise-view.js +220 -0
  93. package/dist/core/count-prerequisite-components.d.ts +67 -0
  94. package/dist/core/count-prerequisite-components.js +239 -0
  95. package/dist/core/count-prerequisite-memory.d.ts +24 -0
  96. package/dist/core/count-prerequisite-memory.js +37 -0
  97. package/dist/core/count-prerequisite-plan.d.ts +12 -0
  98. package/dist/core/count-prerequisite-plan.js +88 -0
  99. package/dist/core/count-primitive-budget.d.ts +1 -0
  100. package/dist/core/count-primitive-budget.js +8 -0
  101. package/dist/core/count-project-free.d.ts +3 -0
  102. package/dist/core/count-project-free.js +24 -0
  103. package/dist/core/count-project-witness.d.ts +4 -0
  104. package/dist/core/count-project-witness.js +48 -0
  105. package/dist/core/count-proof-rescope.d.ts +14 -0
  106. package/dist/core/count-proof-rescope.js +71 -0
  107. package/dist/core/count-proof-scope.d.ts +68 -0
  108. package/dist/core/count-proof-scope.js +333 -0
  109. package/dist/core/count-prune-owned-root.d.ts +5 -0
  110. package/dist/core/count-prune-owned-root.js +27 -0
  111. package/dist/core/count-query-context.d.ts +3 -0
  112. package/dist/core/count-query-context.js +7 -0
  113. package/dist/core/count-query.d.ts +15 -0
  114. package/dist/core/count-query.js +59 -0
  115. package/dist/core/count-quorum-leaf.d.ts +9 -0
  116. package/dist/core/count-quorum-leaf.js +38 -0
  117. package/dist/core/count-reachability-budget.d.ts +1 -0
  118. package/dist/core/count-reachability-budget.js +7 -0
  119. package/dist/core/count-reachability-reconcile.d.ts +11 -0
  120. package/dist/core/count-reachability-reconcile.js +19 -0
  121. package/dist/core/count-reachability.d.ts +50 -0
  122. package/dist/core/count-reachability.js +351 -0
  123. package/dist/core/count-rebase-path.d.ts +9 -0
  124. package/dist/core/count-rebase-path.js +68 -0
  125. package/dist/core/count-recipe-context.d.ts +45 -0
  126. package/dist/core/count-recipe-context.js +71 -0
  127. package/dist/core/count-recipe-controller.d.ts +115 -0
  128. package/dist/core/count-recipe-controller.js +417 -0
  129. package/dist/core/count-recipe-graph.d.ts +36 -0
  130. package/dist/core/count-recipe-graph.js +211 -0
  131. package/dist/core/count-recovery/conditional-check-cache.js +3 -2
  132. package/dist/core/count-recovery/conditional-cuts.js +5 -4
  133. package/dist/core/count-recovery/conditional-proof.d.ts +37 -3
  134. package/dist/core/count-recovery/conditional-proof.js +72 -30
  135. package/dist/core/count-recovery/derivability-closure.js +2 -1
  136. package/dist/core/count-recovery/guard-cases.js +2 -1
  137. package/dist/core/count-recovery/reframe-tree.d.ts +2 -0
  138. package/dist/core/count-recovery/reframe-tree.js +24 -0
  139. package/dist/core/count-recovery/replay-linear-skeleton.d.ts +2 -0
  140. package/dist/core/count-recovery/replay-linear-skeleton.js +28 -0
  141. package/dist/core/count-recovery/row-cases.js +2 -1
  142. package/dist/core/count-rejection-budget.d.ts +8 -0
  143. package/dist/core/count-rejection-budget.js +15 -0
  144. package/dist/core/count-replacement.d.ts +5 -0
  145. package/dist/core/count-replacement.js +129 -0
  146. package/dist/core/count-replay-diagnostic.d.ts +21 -0
  147. package/dist/core/count-replay-diagnostic.js +49 -0
  148. package/dist/core/count-replay-skeleton.d.ts +4 -0
  149. package/dist/core/count-replay-skeleton.js +28 -0
  150. package/dist/core/count-rescope-funding.d.ts +3 -0
  151. package/dist/core/count-rescope-funding.js +17 -0
  152. package/dist/core/count-restrictions.d.ts +11 -0
  153. package/dist/core/count-restrictions.js +31 -0
  154. package/dist/core/count-retry-budget.d.ts +67 -0
  155. package/dist/core/count-retry-budget.js +114 -0
  156. package/dist/core/count-retry-round.d.ts +24 -0
  157. package/dist/core/count-retry-round.js +44 -0
  158. package/dist/core/count-row-agreement.d.ts +35 -0
  159. package/dist/core/count-row-agreement.js +270 -0
  160. package/dist/core/count-row-aliases.d.ts +3 -0
  161. package/dist/core/count-row-aliases.js +59 -0
  162. package/dist/core/count-row-composition.d.ts +6 -0
  163. package/dist/core/count-row-composition.js +55 -0
  164. package/dist/core/count-row-copy-linear.d.ts +4 -0
  165. package/dist/core/count-row-copy-linear.js +83 -0
  166. package/dist/core/count-row-copy.d.ts +4 -0
  167. package/dist/core/count-row-copy.js +94 -0
  168. package/dist/core/count-row-policy.d.ts +3 -0
  169. package/dist/core/count-row-policy.js +56 -0
  170. package/dist/core/count-row-reindex.d.ts +11 -0
  171. package/dist/core/count-row-reindex.js +126 -0
  172. package/dist/core/count-row-support.d.ts +9 -0
  173. package/dist/core/count-row-support.js +42 -0
  174. package/dist/core/count-row-symmetry.d.ts +7 -0
  175. package/dist/core/count-row-symmetry.js +100 -0
  176. package/dist/core/count-scope-hyps.d.ts +2 -0
  177. package/dist/core/count-scope-hyps.js +163 -0
  178. package/dist/core/count-scope-row-reuse.d.ts +3 -0
  179. package/dist/core/count-scope-row-reuse.js +92 -0
  180. package/dist/core/count-search-allowance.d.ts +1 -0
  181. package/dist/core/count-search-allowance.js +17 -0
  182. package/dist/core/count-stabilize-tree.d.ts +9 -0
  183. package/dist/core/count-stabilize-tree.js +35 -0
  184. package/dist/core/count-stage-trace.d.ts +8 -0
  185. package/dist/core/count-stage-trace.js +45 -0
  186. package/dist/core/count-strategies.d.ts +16 -0
  187. package/dist/core/count-strategies.js +155 -0
  188. package/dist/core/count-strategy-premises.d.ts +5 -0
  189. package/dist/core/count-strategy-premises.js +14 -0
  190. package/dist/core/count-strategy.d.ts +41 -0
  191. package/dist/core/count-strategy.js +76 -0
  192. package/dist/core/count-support.js +3 -2
  193. package/dist/core/count-tier-budget.d.ts +14 -0
  194. package/dist/core/count-tier-budget.js +64 -0
  195. package/dist/core/count-unwritten-prefix.d.ts +24 -0
  196. package/dist/core/count-unwritten-prefix.js +97 -0
  197. package/dist/core/count-write-shape.d.ts +15 -0
  198. package/dist/core/count-write-shape.js +73 -0
  199. package/dist/core/counts.d.ts +37 -13
  200. package/dist/core/counts.js +990 -127
  201. package/dist/core/cycles.js +5 -4
  202. package/dist/core/cyclic.js +11 -10
  203. package/dist/core/data.js +16 -15
  204. package/dist/core/dsl-deadline.d.ts +3 -0
  205. package/dist/core/dsl-deadline.js +27 -0
  206. package/dist/core/dsl.d.ts +9 -0
  207. package/dist/core/dsl.js +156 -51
  208. package/dist/core/evaluation-admission.d.ts +1 -0
  209. package/dist/core/evaluation-admission.js +3 -0
  210. package/dist/core/exists.d.ts +6 -1
  211. package/dist/core/exists.js +51 -9
  212. package/dist/core/field-laws.d.ts +3 -1
  213. package/dist/core/field-laws.js +140 -2
  214. package/dist/core/finite-houdini.d.ts +6 -0
  215. package/dist/core/finite-houdini.js +63 -21
  216. package/dist/core/finite-tiny.js +95 -67
  217. package/dist/core/fixtures/count-completion/paxos-decision.json +1 -0
  218. package/dist/core/fresh.js +5 -1
  219. package/dist/core/infer.js +45 -30
  220. package/dist/core/kind.js +2 -1
  221. package/dist/core/lemma-cuts.js +11 -10
  222. package/dist/core/linear-admission.d.ts +14 -0
  223. package/dist/core/linear-admission.js +151 -0
  224. package/dist/core/machine.d.ts +5 -2
  225. package/dist/core/machine.js +105 -31
  226. package/dist/core/meter.d.ts +22 -0
  227. package/dist/core/meter.js +34 -0
  228. package/dist/core/nonterm.js +4 -3
  229. package/dist/core/prover-row-budget.d.ts +3 -0
  230. package/dist/core/prover-row-budget.js +106 -0
  231. package/dist/core/quorum-laws.d.ts +21 -1
  232. package/dist/core/quorum-laws.js +27 -3
  233. package/dist/core/rationals.js +3 -2
  234. package/dist/core/rejection-discovery.d.ts +34 -0
  235. package/dist/core/rejection-discovery.js +36 -0
  236. package/dist/core/rejection-stage.d.ts +39 -0
  237. package/dist/core/rejection-stage.js +205 -0
  238. package/dist/core/request-quotient.d.ts +8 -0
  239. package/dist/core/request-quotient.js +299 -0
  240. package/dist/core/row-agreement-shape.d.ts +15 -0
  241. package/dist/core/row-agreement-shape.js +68 -0
  242. package/dist/core/runtime-wall.d.ts +2 -0
  243. package/dist/core/search-policy.d.ts +15 -0
  244. package/dist/core/search-policy.js +68 -0
  245. package/dist/core/solver.d.ts +1 -1
  246. package/dist/core/solver.js +40 -6
  247. package/dist/core/step-work.d.ts +12 -0
  248. package/dist/core/step-work.js +14 -0
  249. package/dist/core/strategy-premises.d.ts +8 -0
  250. package/dist/core/strategy-premises.js +64 -0
  251. package/dist/core/system.js +4 -3
  252. package/dist/core/table-admission.d.ts +1 -0
  253. package/dist/core/table-admission.js +3 -0
  254. package/dist/core/trace-clock.d.ts +3 -0
  255. package/dist/core/trace-clock.js +16 -0
  256. package/dist/core/transfer.js +3 -2
  257. package/dist/core/translate.js +16 -3
  258. package/dist/core/wall.d.ts +6 -1
  259. package/dist/core/wall.js +23 -9
  260. package/dist/core/watch.d.ts +1 -1
  261. package/dist/core/watch.js +13 -4
  262. package/dist/core/work-admission.d.ts +164 -0
  263. package/dist/core/work-admission.js +418 -0
  264. package/dist/core/work-amount.d.ts +21 -0
  265. package/dist/core/work-amount.js +80 -0
  266. package/dist/core/work-collections.d.ts +11 -0
  267. package/dist/core/work-collections.js +198 -0
  268. package/dist/core/work-kinds.d.ts +11 -0
  269. package/dist/core/work-kinds.js +9 -0
  270. package/dist/core/work-meter.d.ts +8 -0
  271. package/dist/core/work-meter.js +83 -0
  272. package/dist/core/work-observe.d.ts +12 -0
  273. package/dist/core/work-observe.js +39 -0
  274. package/dist/core/work-profile.d.ts +10 -0
  275. package/dist/core/work-profile.js +21 -0
  276. package/dist/core/work-refusal.d.ts +1 -0
  277. package/dist/core/work-refusal.js +6 -0
  278. package/dist/interchange/format.js +2 -0
  279. package/dist/kernel/cdcl.js +93 -40
  280. package/dist/kernel/epr.js +23 -8
  281. package/dist/kernel/kernel.d.ts +47 -1
  282. package/dist/kernel/kernel.js +417 -68
  283. package/dist/kernel/prove.d.ts +49 -3
  284. package/dist/kernel/prove.js +468 -122
  285. package/dist/kernel/prover-rows.d.ts +1 -0
  286. package/dist/kernel/prover-rows.js +12 -1
  287. package/dist/kernel/reader.d.ts +1 -1
  288. package/dist/kernel/reader.js +57 -12
  289. package/dist/kernel/simplex.js +9 -2
  290. package/dist/lean-kernel/emit.d.ts +9 -1
  291. package/dist/lean-kernel/emit.js +144 -22
  292. package/dist/lean-kernel/legacy-family-library.d.ts +1 -0
  293. package/dist/lean-kernel/legacy-family-library.js +5 -0
  294. package/dist/lean-kernel/library.js +3 -3
  295. package/package.json +1 -1
@@ -0,0 +1,143 @@
1
+ // Untrusted closure bookkeeping. Only the existing native family check can accept.
2
+ import { startWork } from "./work-admission.js";
3
+ import { checkWall } from "./wall.js";
4
+ import { workSetArray, workStrings } from "./work-collections.js";
5
+ const control = () => { checkWall('closed counted family'); startWork('ticks', 1, 'closed counted family'); };
6
+ // Frozen H/S: monotone deletion removes at most |H| members. Every closed subset
7
+ // survives every deletion, hence the fixed point is the unique greatest one.
8
+ export function greatestClosedCountFamily(order, held, options = {}) {
9
+ const tick = options.tick ?? control, rank = new Map(), dependencies = new Map(), basis = new Set();
10
+ for (const name of options.basis ?? []) {
11
+ tick();
12
+ basis.add(name);
13
+ }
14
+ for (const name of order) {
15
+ tick();
16
+ if (rank.has(name))
17
+ throw Error('duplicate family member');
18
+ rank.set(name, rank.size);
19
+ }
20
+ for (const [name, premises] of held) {
21
+ tick();
22
+ if (!rank.has(name))
23
+ throw Error('held member missing from family order');
24
+ const copy = [], seen = new Set();
25
+ for (const premise of premises) {
26
+ tick();
27
+ if (!seen.has(premise)) {
28
+ seen.add(premise);
29
+ copy.push(premise);
30
+ }
31
+ }
32
+ dependencies.set(name, copy);
33
+ }
34
+ const members = new Set();
35
+ for (const name of order) {
36
+ tick();
37
+ if (dependencies.has(name))
38
+ members.add(name);
39
+ }
40
+ let changed = true;
41
+ while (changed) {
42
+ changed = false;
43
+ for (const name of order) {
44
+ tick();
45
+ if (!members.has(name))
46
+ continue;
47
+ for (const premise of dependencies.get(name)) {
48
+ tick();
49
+ if (!members.has(premise) && !basis.has(premise)) {
50
+ members.delete(name);
51
+ changed = true;
52
+ break;
53
+ }
54
+ }
55
+ }
56
+ }
57
+ const closed = [], missing = new Map(), paths = new Map(), allRoots = new Set();
58
+ for (const name of order) {
59
+ tick();
60
+ if (members.has(name)) {
61
+ closed.push(name);
62
+ continue;
63
+ }
64
+ if (!dependencies.has(name))
65
+ continue;
66
+ const outside = [];
67
+ for (const premise of dependencies.get(name)) {
68
+ tick();
69
+ if (!members.has(premise) && !basis.has(premise))
70
+ outside.push(premise);
71
+ }
72
+ missing.set(name, outside);
73
+ const seen = new Set(), queue = [{ name, path: [name] }], found = [];
74
+ for (let at = 0; at < queue.length; at++) {
75
+ tick();
76
+ const item = queue[at];
77
+ if (seen.has(item.name) || basis.has(item.name) || members.has(item.name))
78
+ continue;
79
+ seen.add(item.name);
80
+ const next = dependencies.get(item.name);
81
+ if (!next) {
82
+ allRoots.add(item.name);
83
+ found.push({ blocker: item.name, path: item.path });
84
+ continue;
85
+ }
86
+ for (const premise of next) {
87
+ tick();
88
+ const path = [];
89
+ for (const part of item.path) {
90
+ tick();
91
+ path.push(part);
92
+ }
93
+ path.push(premise);
94
+ queue.push({ name: premise, path });
95
+ }
96
+ }
97
+ paths.set(name, found);
98
+ }
99
+ const blockers = [];
100
+ for (const name of order) {
101
+ tick();
102
+ if (allRoots.delete(name))
103
+ blockers.push(name);
104
+ }
105
+ for (const name of workStrings(workSetArray(allRoots, 'closed-family:unknown-roots'), 'closed-family:unknown-blockers')) {
106
+ tick();
107
+ blockers.push(name);
108
+ }
109
+ return { members: closed, missing, blockers, paths };
110
+ }
111
+ // A owns callbacks, checked-basis policy and native verdict interpretation.
112
+ // The legacy callback receives no reconstructed family. No callback result is
113
+ // promoted to success for an outside target, even when its subset was accepted.
114
+ export function closeGreatestCountFamily(target, held, callbacks, options = {}) {
115
+ const tick = options.tick ?? control, order = [], byName = new Map(), dependencies = new Map();
116
+ for (const row of held) {
117
+ tick();
118
+ if (byName.has(row.id))
119
+ throw Error('duplicate held payload');
120
+ order.push(row.id);
121
+ byName.set(row.id, row);
122
+ dependencies.set(row.id, row.premises);
123
+ }
124
+ const plan = greatestClosedCountFamily(order, dependencies, options);
125
+ let containsTarget = false;
126
+ for (const name of plan.members) {
127
+ tick();
128
+ if (name === target)
129
+ containsTarget = true;
130
+ }
131
+ if (containsTarget)
132
+ return { plan, targetInFamily: true, route: 'legacy', submitted: true, result: callbacks.legacy() };
133
+ if (!plan.members.length)
134
+ return { plan, targetInFamily: false, route: 'empty', submitted: false };
135
+ const selected = [];
136
+ for (const name of plan.members) {
137
+ tick();
138
+ selected.push(byName.get(name));
139
+ }
140
+ if (!callbacks.reserve(selected))
141
+ return { plan, targetInFamily: false, route: 'unfunded', submitted: false };
142
+ return { plan, targetInFamily: false, route: 'subset', submitted: true, result: callbacks.submit(selected) };
143
+ }
@@ -0,0 +1,10 @@
1
+ import { type CountTierBudget } from './count-tier-budget.js';
2
+ export type CountClosingBudget = CountTierBudget & Readonly<{
3
+ closingMode: 'family-check-once';
4
+ closingFloor: number;
5
+ searchUntil: number;
6
+ initialUntil: number;
7
+ }>;
8
+ export declare function reserveCountClosing(budget: CountTierBudget, enabled?: boolean, rootUntil?: number): CountTierBudget | CountClosingBudget;
9
+ export declare function reserveCheckedCountClosing(budget: CountClosingBudget, costs: readonly number[], now: number): CountClosingBudget;
10
+ export declare function countOrdinaryUntil(budget: CountTierBudget): number;
@@ -0,0 +1,49 @@
1
+ // Opt-in family check-once scheduling, not proof acceptance or calibration.
2
+ import { countTierBudget } from "./count-tier-budget.js";
3
+ import { budgetEnd } from "../kernel/prove.js";
4
+ // Explicit replacement allocation: generation <=1/4, strategy floor7/20,
5
+ // ordinary/INIT floor1/40, closing native floor3/8. They sum to one root W.
6
+ // The old ordinary-search floor3/10 is NOT claimed in this opt-in mode.
7
+ export function reserveCountClosing(budget, enabled = false, rootUntil = budgetEnd()) {
8
+ if (!enabled || !budget.active)
9
+ return budget;
10
+ if (Number.isNaN(rootUntil) || rootUntil === -Infinity)
11
+ throw new RangeError('invalid root endpoint');
12
+ const until = Math.min(budget.until, rootUntil);
13
+ if (until < budget.until) {
14
+ const start = budget.until - budget.workAllowance, clamped = countTierBudget(start, until, 1);
15
+ budget = Object.freeze({ ...clamped, generationUntil: Math.min(budget.generationUntil, clamped.generationUntil) });
16
+ }
17
+ if ('closingMode' in budget) {
18
+ if (budget.closingMode !== 'family-check-once')
19
+ throw new RangeError('unknown closing mode');
20
+ return budget;
21
+ }
22
+ const width = budget.workAllowance;
23
+ if (!Number.isFinite(width) || width < 0 || !Number.isFinite(budget.until))
24
+ throw new RangeError('invalid closing allowance');
25
+ const ordinaryFloor = width / 40, closingFloor = width * 3 / 8, searchUntil = budget.until - closingFloor;
26
+ const strategyUntil = Math.min(budget.strategyUntil ?? budget.until, searchUntil - ordinaryFloor);
27
+ return Object.freeze({ ...budget, ordinaryFloor, strategyUntil, closingMode: 'family-check-once', closingFloor, searchUntil, initialUntil: searchUntil });
28
+ }
29
+ // An observed-cost estimate, NOT a worst-case kernel bound. Two times the
30
+ // checked held packets' measured replay/check cost leaves an explicit margin.
31
+ // If there is no measurement retain the old reserve. Insufficient estimates
32
+ // can only produce UNKNOWN at the unchanged root/native acceptance boundary.
33
+ export function reserveCheckedCountClosing(budget, costs, now) {
34
+ if (!Number.isFinite(now))
35
+ throw new RangeError('invalid reserve clock');
36
+ if (costs.some(cost => !Number.isFinite(cost) || cost < 0))
37
+ throw new RangeError('invalid checked packet cost');
38
+ if (!costs.length)
39
+ return budget;
40
+ const total = costs.reduce((sum, cost) => sum + cost, 0);
41
+ const closingFloor = Math.min(budget.workAllowance, Math.max(0, budget.until - now), Math.max(1, total * 2));
42
+ const searchUntil = budget.until - closingFloor;
43
+ const ordinaryFloor = Math.min(budget.ordinaryFloor, Math.max(0, searchUntil - now));
44
+ const strategyUntil = searchUntil - ordinaryFloor;
45
+ return Object.freeze({ ...budget, ordinaryFloor, closingFloor, searchUntil, initialUntil: searchUntil, strategyUntil });
46
+ }
47
+ export function countOrdinaryUntil(budget) {
48
+ return 'closingMode' in budget ? budget.searchUntil : budget.until;
49
+ }
@@ -0,0 +1,5 @@
1
+ export declare function countClosingNeeds(callers: readonly string[], scopes: ReadonlyMap<string, {
2
+ premises: readonly {
3
+ name: string;
4
+ }[];
5
+ }>): Set<string>;
@@ -0,0 +1,9 @@
1
+ // Untrusted scheduling only. Missing or cyclic proof metadata never authorizes
2
+ // acceptance; the final family is still replayed and checked by the kernel.
3
+ export function countClosingNeeds(callers, scopes) {
4
+ const needed = new Set(callers);
5
+ for (const name of needed)
6
+ for (const premise of scopes.get(name)?.premises ?? [])
7
+ needed.add(premise.name);
8
+ return needed;
9
+ }
@@ -0,0 +1,5 @@
1
+ export declare function countComponentAttemptBudget(now: number, componentEnd: number, unattempted: number, minimum?: number, fair?: boolean): {
2
+ end: number;
3
+ allotted: number;
4
+ reserved: number;
5
+ };
@@ -0,0 +1,9 @@
1
+ // Pure remaining-pool allocation. The caller supplies an already-clamped
2
+ // component endpoint; this helper never creates a new root or tier grant.
3
+ export function countComponentAttemptBudget(now, componentEnd, unattempted, minimum = 1, fair = false) {
4
+ if (!Number.isFinite(now) || !Number.isFinite(componentEnd) || !Number.isInteger(unattempted) || unattempted < 1 || !Number.isFinite(minimum) || minimum < 0)
5
+ throw new RangeError('invalid component allowance');
6
+ const width = Math.max(0, componentEnd - now), floor = Math.min(minimum, width / unattempted);
7
+ const reserved = fair ? width - width / unattempted : floor * (unattempted - 1), allotted = fair ? width / unattempted : Math.max(0, width - reserved);
8
+ return { end: Math.min(componentEnd, now + allotted), allotted, reserved };
9
+ }
@@ -0,0 +1,11 @@
1
+ import { type Machine } from './machine.js';
2
+ import { type CountGuardShape } from './count-guard-shape.js';
3
+ export type CountRowCopy = {
4
+ from: string;
5
+ to: string;
6
+ guard: string;
7
+ };
8
+ export declare function discoverCountRowCopy(m: Machine, shape: CountGuardShape, choice: {
9
+ name: string;
10
+ value: number;
11
+ }): CountRowCopy | undefined;
@@ -0,0 +1,40 @@
1
+ // Structural hints only; a matched write still needs an ordinary checked proof.
2
+ import { walkOnce } from "./machine.js";
3
+ const atoms = (c) => c.op === 'and' ? c.xs.flatMap(atoms) : [c];
4
+ export function discoverCountRowCopy(m, shape, choice) {
5
+ const write = m.step.maps?.[shape.thresholdField];
6
+ if (!write || !('each' in write))
7
+ return;
8
+ const found = [];
9
+ walkOnce(write.value, (node) => {
10
+ if (node.op !== 'if' || node.then.op !== 'get' || node.then.map !== shape.thresholdField || node.then.key.op !== 'var' || !m.inputs.includes(node.then.key.name))
11
+ return;
12
+ const gate = atoms(node.c), target = gate.flatMap(c => {
13
+ if (c.op !== '=')
14
+ return [];
15
+ const [a, b] = c.a.op === 'var' && c.a.name === write.each ? [c.a, c.b] : [c.b, c.a];
16
+ return a.op === 'var' && a.name === write.each && b.op === 'var' && m.inputs.includes(b.name) ? [b.name] : [];
17
+ });
18
+ if (target.length !== 1)
19
+ return;
20
+ for (const c of gate) {
21
+ if (c.op !== 'flag')
22
+ continue;
23
+ const guard = m.step.flags?.[c.name];
24
+ if (!guard || guard.op === 'all' || !atoms(guard).some(a => {
25
+ if (a.op !== '=')
26
+ return false;
27
+ const [v, n] = a.a.op === 'var' ? [a.a, a.b] : [a.b, a.a];
28
+ return v.op === 'var' && v.name === choice.name && n.op === 'const' && n.value === choice.value;
29
+ }))
30
+ continue;
31
+ let used = false;
32
+ walkOnce(m.step.maps?.[shape.membershipMap], (node) => { if (node.op === 'flag' && node.name === c.name)
33
+ used = true; });
34
+ if (used)
35
+ found.push({ from: node.then.key.name, to: target[0], guard: c.name });
36
+ }
37
+ });
38
+ const unique = [...new Map(found.map(copy => [JSON.stringify(copy), copy])).values()];
39
+ return unique.length === 1 ? unique[0] : undefined;
40
+ }
@@ -0,0 +1,75 @@
1
+ import { type WorkLedger } from './work-admission.js';
2
+ import { type WorkAmount } from './work-amount.js';
3
+ import { CountAttemptTickets, type CountAttemptStop, type CountSlice } from './count-retry-budget.js';
4
+ import { type CountRoundValue, type CountRoundResult } from './count-retry-round.js';
5
+ export type CountFundingCaps = Readonly<{
6
+ cases: ReadonlyMap<string, WorkAmount>;
7
+ leaf: WorkAmount;
8
+ }>;
9
+ export type CountBodyHistory = Readonly<{
10
+ completed: boolean;
11
+ used: WorkAmount;
12
+ instance: CountAttemptTickets;
13
+ rootEpoch: number;
14
+ }>;
15
+ export type CountDisjointContext = Readonly<{
16
+ instance: CountAttemptTickets;
17
+ bank: WorkLedger;
18
+ parentId: number;
19
+ parentEpoch: number;
20
+ started: number;
21
+ }>;
22
+ export declare function countDisjointContext(instance: CountAttemptTickets, bank?: WorkLedger): CountDisjointContext;
23
+ export type CountDisjointPlan = Readonly<{
24
+ kind: 'admitted';
25
+ caps: CountFundingCaps;
26
+ body: WorkAmount;
27
+ minimumBody: WorkAmount;
28
+ need: WorkAmount;
29
+ rootEpoch: number;
30
+ context: CountDisjointContext;
31
+ }> | Readonly<{
32
+ kind: 'refused';
33
+ reason: 'tickets' | 'root' | 'headroom' | 'parent' | 'stop' | 'inventory';
34
+ }>;
35
+ export declare function planDisjointCountRound(caps: CountFundingCaps, body0: WorkAmount, history: readonly CountBodyHistory[], tickets: CountAttemptTickets, stop?: CountAttemptStop & {
36
+ caseKey?: string;
37
+ }, bank?: WorkLedger): CountDisjointPlan;
38
+ export type CountOwnerReceipt = Readonly<{
39
+ body: WorkAmount;
40
+ cases: ReadonlyMap<string, WorkAmount>;
41
+ sum: WorkAmount;
42
+ round: WorkAmount;
43
+ complete: boolean;
44
+ }>;
45
+ export declare class CountFundingOwners {
46
+ private plan;
47
+ private bank;
48
+ private completion;
49
+ private failedSlice;
50
+ get slices(): readonly CountSlice[];
51
+ private active;
52
+ private ending;
53
+ private settling;
54
+ private bodyUse;
55
+ private caseUse;
56
+ private ownerUse;
57
+ private finished;
58
+ private readonly start;
59
+ constructor(plan: Extract<CountDisjointPlan, {
60
+ kind: 'admitted';
61
+ }>, bank?: WorkLedger, completion?: WorkAmount);
62
+ ownsBank(bank: WorkLedger): boolean;
63
+ body<T>(run: () => T): T;
64
+ settle<T>(run: () => T): T;
65
+ checkCoverage(): void;
66
+ case<T>(key: string, run: () => T): T;
67
+ private segment;
68
+ leaf<T>(physicalKey: string, run: () => T, expectedCase?: string): T;
69
+ private retainFailure;
70
+ receipt(complete: boolean): CountOwnerReceipt;
71
+ }
72
+ export declare function runDisjointCountRound<T>(plan: CountDisjointPlan, tickets: CountAttemptTickets, run: (owners: CountFundingOwners) => CountRoundValue<T>, bank?: WorkLedger, eligible?: () => boolean): Readonly<{
73
+ result: CountRoundResult<T>;
74
+ receipt?: CountOwnerReceipt;
75
+ }>;
@@ -0,0 +1,284 @@
1
+ // Section46.17 NEXT-PIN API ONLY: not selected by the production controller.
2
+ // The interim production policy remains planCountRetry with the narrow cap fix.
3
+ // Callers must split their callback into explicit body/case segments; this API
4
+ // neither suspends ledger endpoints nor attributes work merely by its label.
5
+ import { BudgetExpired, workLedger } from "./work-admission.js";
6
+ import { compareWork, workAdd, workShare, workSub, zeroWork } from "./work-amount.js";
7
+ import { countAttemptStop } from "./count-retry-budget.js";
8
+ // Identity metadata only: this never grants work or creates a ticket.
9
+ export function countDisjointContext(instance, bank = workLedger) {
10
+ const parent = bank.currentScope();
11
+ if (!parent || !bank.inBudget())
12
+ throw Error('disjoint count context needs an existing root');
13
+ return Object.freeze({ instance, bank, parentId: parent.id, parentEpoch: bank.snapshot().scopeEpoch, started: instance.snapshot().started });
14
+ }
15
+ function sameContext(context, instance, bank) {
16
+ return context.instance === instance && context.bank === bank && context.started === instance.snapshot().started
17
+ && context.parentId === bank.currentScope()?.id && context.parentEpoch === bank.snapshot().scopeEpoch;
18
+ }
19
+ const limit = 1n << 4096n;
20
+ const valid = (n) => n.den > 0n && n.num >= 0n && n.den <= limit && n.num <= limit;
21
+ export function planDisjointCountRound(caps, body0, history, tickets, stop, bank = workLedger) {
22
+ bank.start('ticks', 1, 'disjoint count plan header');
23
+ if (!bank.inBudget())
24
+ return { kind: 'refused', reason: 'root' };
25
+ if (tickets.snapshot().terminal || tickets.snapshot().remaining === 0)
26
+ return { kind: 'refused', reason: 'tickets' };
27
+ if (!caps.cases.size || caps.cases.size > 63 || history.length > 7 || !valid(caps.leaf) || caps.leaf.num === 0n || !valid(body0))
28
+ return { kind: 'refused', reason: 'inventory' };
29
+ const cases = new Map();
30
+ let leaf = caps.leaf, total = zeroWork, minimumBody = body0;
31
+ if (stop && stop.kind !== 'soft-slice')
32
+ return { kind: 'refused', reason: 'stop' };
33
+ if (stop && stop.rootEpoch !== bank.snapshot().rootEpoch)
34
+ return { kind: 'refused', reason: 'root' };
35
+ let found = !stop;
36
+ for (const [key, cap] of caps.cases) {
37
+ bank.start('ticks', 1, 'disjoint count case validation');
38
+ if (!key || key.length > 256 || key === 'leaf' || key === 'body' || !valid(cap) || cap.num === 0n)
39
+ return { kind: 'refused', reason: 'inventory' };
40
+ if (stop?.key === key) {
41
+ if (compareWork(stop.allocation, cap) !== 0)
42
+ return { kind: 'refused', reason: 'stop' };
43
+ found = true;
44
+ }
45
+ const next = stop?.key === key ? workShare(cap, 2n, 1n) : cap;
46
+ cases.set(key, next);
47
+ total = workAdd(total, next);
48
+ }
49
+ if (stop?.key === 'leaf') {
50
+ if (compareWork(stop.allocation, leaf) !== 0 || !stop.caseKey || !cases.has(stop.caseKey))
51
+ return { kind: 'refused', reason: 'parent' };
52
+ leaf = workShare(leaf, 2n, 1n);
53
+ if (compareWork(leaf, cases.get(stop.caseKey)) > 0)
54
+ return { kind: 'refused', reason: 'parent' };
55
+ found = true;
56
+ }
57
+ if (!found)
58
+ return { kind: 'refused', reason: 'stop' };
59
+ let completed = false;
60
+ for (const entry of history) {
61
+ bank.start('ticks', 1, 'disjoint count body history');
62
+ if (!valid(entry.used) || entry.instance !== tickets || entry.rootEpoch !== bank.snapshot().rootEpoch)
63
+ return { kind: 'refused', reason: 'inventory' };
64
+ if (entry.completed && (!completed || compareWork(entry.used, minimumBody) > 0)) {
65
+ minimumBody = entry.used;
66
+ completed = true;
67
+ }
68
+ }
69
+ // Read H only after every paid preparation step. It already intersects every
70
+ // live ancestor and outstanding reservation; no caller-supplied H is trusted.
71
+ const headroom = bank.available();
72
+ if (headroom === null)
73
+ return { kind: 'refused', reason: 'root' };
74
+ if (compareWork(workAdd(total, minimumBody), headroom) > 0)
75
+ return { kind: 'refused', reason: 'headroom' };
76
+ return Object.freeze({ kind: 'admitted', caps: { cases, leaf }, body: workSub(headroom, total), minimumBody, need: headroom, rootEpoch: bank.snapshot().rootEpoch, context: countDisjointContext(tickets, bank) });
77
+ }
78
+ export class CountFundingOwners {
79
+ plan;
80
+ bank;
81
+ completion;
82
+ failedSlice;
83
+ get slices() { return this.failedSlice ? [this.failedSlice] : []; }
84
+ active;
85
+ ending = false;
86
+ settling = false;
87
+ bodyUse = zeroWork;
88
+ caseUse = new Map();
89
+ ownerUse = zeroWork;
90
+ finished;
91
+ start;
92
+ constructor(plan, bank = workLedger, completion = zeroWork) {
93
+ this.plan = plan;
94
+ this.bank = bank;
95
+ this.completion = completion;
96
+ this.start = bank.actual();
97
+ }
98
+ ownsBank(bank) { return this.bank === bank; }
99
+ body(run) { return this.segment('body', 'body', workSub(this.plan.body, this.completion), run); }
100
+ // The runner reserves this tail inside the SAME body cap before user work.
101
+ // No case credit or new allowance can pay settlement after an interruption.
102
+ settle(run) {
103
+ if (this.ending || this.active)
104
+ throw new BudgetExpired('duplicate disjoint settlement');
105
+ this.ending = true;
106
+ this.settling = true;
107
+ try {
108
+ return this.segment('body', 'body', this.plan.body, run);
109
+ }
110
+ finally {
111
+ this.settling = false;
112
+ }
113
+ }
114
+ checkCoverage() {
115
+ const now = this.bank.actual(), live = this.active ? workSub(now, this.active.start) : zeroWork;
116
+ if (compareWork(workAdd(this.ownerUse, live), workSub(now, this.start)) !== 0)
117
+ throw new BudgetExpired('unowned or overlapping count round work');
118
+ }
119
+ case(key, run) {
120
+ const cap = this.plan.caps.cases.get(key);
121
+ if (!cap)
122
+ throw new BudgetExpired('unknown disjoint count case');
123
+ return this.segment('case', key, cap, run);
124
+ }
125
+ segment(kind, key, cap, run) {
126
+ if (this.finished || this.ending && !this.settling)
127
+ throw new BudgetExpired('closed disjoint count owners');
128
+ if (this.active)
129
+ throw new BudgetExpired('overlapping disjoint count owners');
130
+ const used = kind === 'body' ? this.bodyUse : this.caseUse.get(key) ?? zeroWork, left = workSub(cap, used), before = this.bank.actual();
131
+ if (compareWork(left, zeroWork) < 0)
132
+ throw new BudgetExpired('spent disjoint count owner');
133
+ try {
134
+ return this.bank.withBudget(left, () => {
135
+ this.active = { kind, key, start: before };
136
+ const scope = this.bank.currentScope(), slice = { key, allocation: cap, scopeId: scope.id, rootEpoch: this.plan.rootEpoch };
137
+ try {
138
+ this.bank.start('ticks', 1, 'disjoint count owner bookkeeping');
139
+ return run();
140
+ }
141
+ catch (error) {
142
+ this.retainFailure(error, slice, kind === 'case');
143
+ throw error;
144
+ }
145
+ finally {
146
+ this.active = undefined;
147
+ }
148
+ });
149
+ }
150
+ finally {
151
+ const amount = workSub(this.bank.actual(), before);
152
+ this.ownerUse = workAdd(this.ownerUse, amount);
153
+ if (kind === 'body')
154
+ this.bodyUse = workAdd(this.bodyUse, amount);
155
+ else
156
+ this.caseUse.set(key, workAdd(used, amount));
157
+ }
158
+ }
159
+ leaf(physicalKey, run, expectedCase) {
160
+ const owner = this.active;
161
+ if (this.finished)
162
+ throw new BudgetExpired('closed disjoint count owners');
163
+ if (!owner)
164
+ throw new BudgetExpired('unowned count leaf');
165
+ if (expectedCase !== undefined && (owner.kind !== 'case' || owner.key !== expectedCase))
166
+ throw new BudgetExpired('mismatched count leaf owner');
167
+ return this.bank.withBudget(this.plan.caps.leaf, () => {
168
+ const scope = this.bank.currentScope(), slice = { key: 'leaf', allocation: this.plan.caps.leaf, scopeId: scope.id, rootEpoch: this.plan.rootEpoch, caseKey: owner.kind === 'case' ? owner.key : undefined, physicalKey };
169
+ try {
170
+ this.bank.start('ticks', 1, 'disjoint count leaf bookkeeping');
171
+ return run();
172
+ }
173
+ catch (error) {
174
+ this.retainFailure(error, slice, owner.kind === 'case');
175
+ throw error;
176
+ }
177
+ });
178
+ }
179
+ retainFailure(error, slice, renewable) {
180
+ const refusal = this.bank.capacityRefusal(error);
181
+ if (renewable && refusal?.limiting.length === 1 && refusal.limiting[0].id === slice.scopeId) {
182
+ this.failedSlice = slice;
183
+ }
184
+ }
185
+ receipt(complete) {
186
+ if (this.finished)
187
+ return this.finished;
188
+ if (this.active)
189
+ throw new BudgetExpired('live disjoint owner at return');
190
+ const round = workSub(this.bank.actual(), this.start);
191
+ if (compareWork(this.ownerUse, round) !== 0)
192
+ throw new BudgetExpired('unowned or overlapping count round work');
193
+ // No traversal/copy is hidden at an exhausted owner boundary. The private
194
+ // map is exposed as a read-only final view; all subsequent segments refuse.
195
+ return this.finished = Object.freeze({ body: this.bodyUse, cases: this.caseUse, sum: this.ownerUse, round, complete });
196
+ }
197
+ }
198
+ export function runDisjointCountRound(plan, tickets, run, bank = workLedger, eligible) {
199
+ if (plan.kind === 'refused')
200
+ return { result: { kind: 'not-started', reason: plan.reason } };
201
+ if (!bank.inBudget() || plan.rootEpoch !== bank.snapshot().rootEpoch)
202
+ return { result: { kind: 'not-started', reason: 'missing-root' } };
203
+ if (!sameContext(plan.context, tickets, bank))
204
+ return { result: { kind: 'not-started', reason: 'context' } };
205
+ if (tickets.snapshot().terminal || tickets.snapshot().active)
206
+ return { result: { kind: 'not-started', reason: 'tickets' } };
207
+ // One terminal owner-entry tick and three fixed control operations: stop/
208
+ // coverage classification, ticket settlement, and final receipt preparation.
209
+ const completion = workShare(bank.weights.ticks, 4n, 1n);
210
+ try {
211
+ bank.checkAmount(plan.need, 'disjoint count atomic admission');
212
+ }
213
+ catch (error) {
214
+ if (error instanceof BudgetExpired)
215
+ return { result: { kind: 'not-started', reason: 'headroom' } };
216
+ throw error;
217
+ }
218
+ return bank.withBudget(plan.need, () => {
219
+ const owners = new CountFundingOwners(plan, bank, completion);
220
+ let started = false, failed = false, failure, refusal, value;
221
+ try {
222
+ refusal = owners.body(() => {
223
+ const active = countDisjointContext(tickets, bank);
224
+ if (eligible && !eligible())
225
+ return 'ineligible';
226
+ if (!sameContext(active, tickets, bank) || active.started !== plan.context.started)
227
+ return 'context';
228
+ if (tickets.snapshot().terminal || tickets.snapshot().active)
229
+ return 'tickets';
230
+ bank.start('ticks', 1, 'disjoint count ticket');
231
+ started = tickets.start();
232
+ return started ? undefined : 'tickets';
233
+ });
234
+ if (!refusal)
235
+ value = run(owners);
236
+ }
237
+ catch (error) {
238
+ failed = true;
239
+ failure = error;
240
+ }
241
+ let result = { kind: 'not-started', reason: 'precommit' };
242
+ try {
243
+ owners.settle(() => {
244
+ bank.start('ticks', 1, 'disjoint terminal classification');
245
+ try {
246
+ owners.checkCoverage();
247
+ }
248
+ catch (error) {
249
+ failed = true;
250
+ failure = error;
251
+ }
252
+ if (failed) {
253
+ const stop = countAttemptStop(failure, owners.slices, bank);
254
+ result = !started ? { kind: 'not-started', reason: 'precommit' } : stop.kind === 'soft-slice' ? { kind: 'unfinished', stop } : { kind: 'hard-cap', stop };
255
+ }
256
+ else
257
+ result = refusal ? { kind: 'not-started', reason: refusal } : value;
258
+ bank.start('ticks', 1, 'disjoint terminal ticket');
259
+ if (started)
260
+ tickets.finish(result.kind === 'proposal' || result.kind === 'decline' ? result.kind : result.kind === 'unfinished' ? 'unfinished' : 'hard-cap');
261
+ bank.start('ticks', 1, 'disjoint terminal receipt');
262
+ });
263
+ }
264
+ catch (error) {
265
+ // If even the reserved tail cannot run (e.g. unowned work spent its credit),
266
+ // do not invent a free cleanup allowance. An active ticket stays unusable.
267
+ if (!(error instanceof BudgetExpired))
268
+ throw error;
269
+ return { result: { kind: 'hard-cap', stop: { kind: 'hard-cap', reason: 'unclassified', error } } };
270
+ }
271
+ let receipt;
272
+ try {
273
+ receipt = owners.receipt(!failed && !refusal);
274
+ }
275
+ catch (error) {
276
+ failed = true;
277
+ failure = error;
278
+ result = { kind: 'hard-cap', stop: { kind: 'hard-cap', reason: 'unclassified', error } };
279
+ }
280
+ if (failed && !(failure instanceof BudgetExpired))
281
+ throw failure;
282
+ return { result, receipt };
283
+ });
284
+ }