@ref0/git 0.7.0 → 0.9.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 (245) hide show
  1. package/dist/access/private-refs.mjs +0 -2
  2. package/dist/auth/authorize.mjs +31 -24
  3. package/dist/auth/bridge.mjs +8 -8
  4. package/dist/auth/fences.d.mts +0 -1
  5. package/dist/auth/fences.mjs +1 -1
  6. package/dist/auth/grants.d.mts +0 -1
  7. package/dist/auth/grants.mjs +2 -2
  8. package/dist/auth/host-function.d.mts +1 -7
  9. package/dist/auth/host-function.mjs +38 -38
  10. package/dist/auth/identify.d.mts +0 -1
  11. package/dist/auth/identify.mjs +1 -1
  12. package/dist/auth/policy.d.mts +7 -4
  13. package/dist/auth/policy.mjs +13 -10
  14. package/dist/auth/token-rows.mjs +2 -5
  15. package/dist/auth/tokens-layer.d.mts +0 -2
  16. package/dist/auth/tokens-public.d.mts +3 -3
  17. package/dist/auth/tokens-public.mjs +4 -2
  18. package/dist/auth/tokens.d.mts +6 -1
  19. package/dist/auth/tokens.mjs +7 -1
  20. package/dist/client/client.d.mts +22 -15
  21. package/dist/client/client.mjs +31 -27
  22. package/dist/client/git-http.mjs +22 -5
  23. package/dist/client/local.mjs +1 -1
  24. package/dist/client/namespace.d.mts +2 -0
  25. package/dist/client/push-upload.d.mts +1 -0
  26. package/dist/client/push-upload.mjs +169 -2
  27. package/dist/client/remote-helper.mjs +2 -4
  28. package/dist/client/remote.mjs +37 -15
  29. package/dist/client/run-remote-helper.mjs +4 -4
  30. package/dist/client/transport.mjs +26 -19
  31. package/dist/contracts/actors.d.mts +57 -28
  32. package/dist/contracts/actors.mjs +38 -2
  33. package/dist/contracts/authorize.d.mts +21 -15
  34. package/dist/contracts/callers.mjs +40 -0
  35. package/dist/contracts/calls-spent.d.mts +2 -12
  36. package/dist/contracts/calls-spent.mjs +4 -5
  37. package/dist/contracts/client.d.mts +16 -9
  38. package/dist/contracts/events.d.mts +82 -14
  39. package/dist/contracts/events.mjs +35 -9
  40. package/dist/contracts/files.d.mts +42 -42
  41. package/dist/contracts/forks.d.mts +0 -24
  42. package/dist/contracts/git-hooks.d.mts +217 -0
  43. package/dist/contracts/git-hooks.mjs +3 -1
  44. package/dist/contracts/git.d.mts +13 -3
  45. package/dist/contracts/grants.d.mts +46 -27
  46. package/dist/contracts/lfs.d.mts +17 -4
  47. package/dist/contracts/merges.d.mts +7 -7
  48. package/dist/contracts/objects.d.mts +38 -4
  49. package/dist/contracts/opaque.mjs +19 -1
  50. package/dist/contracts/operations.d.mts +8 -1
  51. package/dist/contracts/operations.mjs +209 -0
  52. package/dist/contracts/queue.d.mts +6 -5
  53. package/dist/contracts/queue.mjs +9 -20
  54. package/dist/contracts/remote.d.mts +13 -4
  55. package/dist/contracts/remote.mjs +3 -3
  56. package/dist/contracts/repos.d.mts +11 -40
  57. package/dist/contracts/repos.mjs +11 -10
  58. package/dist/contracts/result.d.mts +28 -11
  59. package/dist/contracts/result.mjs +32 -2
  60. package/dist/contracts/rules.d.mts +706 -46
  61. package/dist/contracts/rules.mjs +81 -2
  62. package/dist/contracts/server.d.mts +5 -275
  63. package/dist/contracts/services.d.mts +0 -3
  64. package/dist/contracts/services.mjs +1 -3
  65. package/dist/contracts/signin.d.mts +2 -2
  66. package/dist/contracts/signin.mjs +4 -5
  67. package/dist/contracts/sync.d.mts +1 -4
  68. package/dist/contracts/tokens.d.mts +29 -17
  69. package/dist/contracts/tokens.mjs +14 -3
  70. package/dist/contracts/topics.d.mts +38 -11
  71. package/dist/contracts/topics.mjs +8 -2
  72. package/dist/core/access.d.mts +0 -2
  73. package/dist/core/access.mjs +15 -4
  74. package/dist/core/ancestry.mjs +5 -4
  75. package/dist/core/events/deliver.mjs +19 -1
  76. package/dist/core/forks.mjs +30 -11
  77. package/dist/core/hooks/groups.d.mts +0 -1
  78. package/dist/core/hooks/groups.mjs +8 -9
  79. package/dist/core/index-job.mjs +23 -1
  80. package/dist/core/index-lost.d.mts +11 -0
  81. package/dist/core/index-lost.mjs +55 -0
  82. package/dist/core/loose-tally.mjs +46 -0
  83. package/dist/core/objects/commit-writes.mjs +1 -1
  84. package/dist/core/objects/commits.mjs +10 -9
  85. package/dist/core/objects/merges.mjs +1 -1
  86. package/dist/core/objects/reading.mjs +28 -13
  87. package/dist/core/objects/trees.mjs +1 -1
  88. package/dist/core/objects/writing.mjs +1 -0
  89. package/dist/core/parts.d.mts +7 -0
  90. package/dist/core/promise.mjs +1 -15
  91. package/dist/core/publish.mjs +9 -5
  92. package/dist/core/purge.mjs +30 -12
  93. package/dist/core/push.mjs +39 -16
  94. package/dist/core/ref-view.mjs +14 -6
  95. package/dist/core/repack.mjs +54 -27
  96. package/dist/core/repo-info.mjs +8 -6
  97. package/dist/core/repos.mjs +1 -0
  98. package/dist/core/rules/check.mjs +10 -10
  99. package/dist/core/rules/context.d.mts +3 -1
  100. package/dist/core/rules/context.mjs +16 -13
  101. package/dist/core/rules/fetch.mjs +17 -23
  102. package/dist/core/tokens.mjs +2 -1
  103. package/dist/core/view.d.mts +10 -1
  104. package/dist/core/view.mjs +15 -6
  105. package/dist/effect.d.mts +3 -6
  106. package/dist/effect.mjs +3 -6
  107. package/dist/engine/commits.mjs +23 -50
  108. package/dist/engine/failures.d.mts +1 -2
  109. package/dist/engine/failures.mjs +1 -3
  110. package/dist/engine/merge-base-walk.mjs +57 -142
  111. package/dist/engine/merge-bases.mjs +9 -7
  112. package/dist/engine/merge.mjs +20 -17
  113. package/dist/engine/parts.d.mts +1 -0
  114. package/dist/engine/parts.mjs +1 -1
  115. package/dist/engine/walk.mjs +15 -11
  116. package/dist/extend.d.mts +1 -2
  117. package/dist/extend.mjs +1 -2
  118. package/dist/http/core-parts.mjs +18 -10
  119. package/dist/http/handler.mjs +11 -31
  120. package/dist/http/parts.d.mts +0 -1
  121. package/dist/index.d.mts +29 -22
  122. package/dist/index.mjs +5 -2
  123. package/dist/lfs/base.d.mts +6 -3
  124. package/dist/lfs/base.mjs +2 -1
  125. package/dist/lfs/layer.d.mts +4 -3
  126. package/dist/lfs/layer.mjs +23 -9
  127. package/dist/lfs/objects.mjs +93 -41
  128. package/dist/lfs/pointers.mjs +69 -18
  129. package/dist/lfs/purge.mjs +6 -2
  130. package/dist/lfs/rows.mjs +24 -7
  131. package/dist/lfs/service.d.mts +6 -3
  132. package/dist/lfs/service.mjs +8 -2
  133. package/dist/lfs/upkeep.mjs +47 -28
  134. package/dist/lfs/upload-most.mjs +47 -0
  135. package/dist/lfs/uploaded.mjs +59 -0
  136. package/dist/protocol/bytes/sha256-hasher.mjs +51 -0
  137. package/dist/protocol/bytes/streams.mjs +84 -2
  138. package/dist/protocol/bytes/text.mjs +6 -1
  139. package/dist/protocol/diff/read.d.mts +1 -0
  140. package/dist/protocol/diff/read.mjs +5 -2
  141. package/dist/protocol/objects/commit.d.mts +7 -0
  142. package/dist/protocol/objects/commit.mjs +5 -1
  143. package/dist/protocol/objects/fsck.mjs +6 -3
  144. package/dist/queue/advance.mjs +77 -18
  145. package/dist/queue/calls.mjs +4 -14
  146. package/dist/queue/host.d.mts +4 -0
  147. package/dist/queue/lanes.mjs +1 -1
  148. package/dist/queue/layer.mjs +4 -2
  149. package/dist/queue/limits.mjs +18 -2
  150. package/dist/queue/rows.mjs +10 -1
  151. package/dist/queue/schedule.mjs +1 -1
  152. package/dist/queue/search.mjs +3 -4
  153. package/dist/queue/trim.mjs +2 -2
  154. package/dist/rest/client-namespace.d.mts +2 -0
  155. package/dist/rest/client.d.mts +32 -8
  156. package/dist/rest/client.mjs +308 -382
  157. package/dist/rest/commits.d.mts +150 -150
  158. package/dist/rest/files.d.mts +18 -18
  159. package/dist/rest/forks.d.mts +77 -89
  160. package/dist/rest/handlers.mjs +2 -1
  161. package/dist/rest/listen.d.mts +8 -6
  162. package/dist/rest/listen.mjs +31 -75
  163. package/dist/rest/me.d.mts +2 -2
  164. package/dist/rest/merges.d.mts +7 -7
  165. package/dist/rest/refs.d.mts +27 -27
  166. package/dist/rest/repos.d.mts +40 -52
  167. package/dist/rest/tokens.d.mts +12 -12
  168. package/dist/rest/topics.d.mts +13 -13
  169. package/dist/rest/trees.d.mts +66 -66
  170. package/dist/rest/wire.d.mts +20 -2
  171. package/dist/rest/work.d.mts +39 -39
  172. package/dist/rest.d.mts +1 -7
  173. package/dist/rest.mjs +1 -5
  174. package/dist/server/git-layer.d.mts +10 -2
  175. package/dist/server/git-layer.mjs +29 -10
  176. package/dist/server/joined.d.mts +12 -6
  177. package/dist/server/joined.mjs +3 -2
  178. package/dist/server/registry.mjs +11 -5
  179. package/dist/server/server.d.mts +0 -1
  180. package/dist/server/server.mjs +42 -49
  181. package/dist/signin/context.d.mts +0 -1
  182. package/dist/signin/context.mjs +5 -9
  183. package/dist/storage/clean-up.mjs +3 -1
  184. package/dist/storage/fsck.mjs +12 -2
  185. package/dist/storage/graph-rebuild.mjs +262 -0
  186. package/dist/storage/index-bitmaps.mjs +16 -10
  187. package/dist/storage/index-build.mjs +160 -24
  188. package/dist/storage/index-graph.d.mts +1 -0
  189. package/dist/storage/index-graph.mjs +29 -5
  190. package/dist/storage/index-layers.d.mts +1 -0
  191. package/dist/storage/index-layers.mjs +5 -2
  192. package/dist/storage/index-reach.mjs +7 -5
  193. package/dist/storage/index-remap.mjs +5 -5
  194. package/dist/storage/index-visible.mjs +16 -5
  195. package/dist/storage/lfs-pointers.d.mts +5 -5
  196. package/dist/storage/lfs-pointers.mjs +37 -11
  197. package/dist/storage/links.mjs +3 -3
  198. package/dist/storage/loose.mjs +4 -1
  199. package/dist/storage/memory-budget.mjs +1 -1
  200. package/dist/storage/merge-fence.mjs +81 -19
  201. package/dist/storage/merge-most.mjs +1 -0
  202. package/dist/storage/merge-row.mjs +16 -4
  203. package/dist/storage/merge-stream.mjs +9 -6
  204. package/dist/storage/object-rows.mjs +17 -1
  205. package/dist/storage/pack-order.d.mts +1 -0
  206. package/dist/storage/pack-order.mjs +18 -1
  207. package/dist/storage/pack-receive.mjs +10 -6
  208. package/dist/storage/packs.mjs +58 -27
  209. package/dist/storage/prune-walk.mjs +5 -2
  210. package/dist/storage/prune.mjs +168 -70
  211. package/dist/storage/ready.d.mts +1 -1
  212. package/dist/storage/ready.mjs +12 -3
  213. package/dist/storage/receive-bounds.mjs +3 -2
  214. package/dist/storage/receive-state.mjs +1 -1
  215. package/dist/storage/repack-contained.mjs +22 -14
  216. package/dist/storage/repack.d.mts +1 -1
  217. package/dist/storage/repack.mjs +3 -2
  218. package/dist/storage/unpack.mjs +7 -0
  219. package/dist/storage/visible.mjs +3 -2
  220. package/dist/storage/walk.d.mts +1 -0
  221. package/dist/storage/walk.mjs +9 -5
  222. package/dist/storage/wants.mjs +17 -11
  223. package/dist/store/call-count.d.mts +31 -3
  224. package/dist/store/call-count.mjs +51 -20
  225. package/dist/store/errors.d.mts +7 -1
  226. package/dist/store/errors.mjs +7 -1
  227. package/dist/store/job-try.mjs +3 -1
  228. package/dist/store/records.mjs +26 -5
  229. package/dist/store/repo-record.mjs +36 -12
  230. package/dist/store/scopes.mjs +15 -2
  231. package/dist/sync/bound.d.mts +1 -1
  232. package/dist/sync/import.mjs +15 -3
  233. package/dist/sync/layer.d.mts +5 -1
  234. package/dist/sync/layer.mjs +11 -9
  235. package/dist/sync/mirror.mjs +1 -1
  236. package/dist/sync/step.mjs +15 -15
  237. package/dist/topics/advance.mjs +11 -10
  238. package/dist/topics/layer.mjs +1 -1
  239. package/dist/topics/members.mjs +38 -9
  240. package/package.json +3 -3
  241. package/dist/engine/merge-base-walk.d.mts +0 -3
  242. package/dist/server/routes.d.mts +0 -32
  243. package/dist/server/routes.mjs +0 -69
  244. package/dist/sync/bridge.d.mts +0 -6
  245. package/dist/sync/bridge.mjs +0 -29
@@ -4,7 +4,7 @@ import { fail, gitError } from "../contracts/result.mjs";
4
4
  import { hostCall } from "../auth/host-function.mjs";
5
5
  import { buildFence, checkPush, retriedCodes } from "../core/push.mjs";
6
6
  import { host } from "../contracts/git.mjs";
7
- import { CoreParts, asHost, overStore } from "../core/parts.mjs";
7
+ import { asHost, overStore } from "../core/parts.mjs";
8
8
  import { mergedTree } from "../core/objects/commit-writes.mjs";
9
9
  import { openRead, readerOf } from "../core/objects/reading.mjs";
10
10
  import { MadeObjects, madeCommit, writeDigest } from "../core/objects/writing.mjs";
@@ -16,7 +16,7 @@ import { handingOn } from "../protocol/packs/writer.mjs";
16
16
  import { memoryPack } from "../storage/fetch.mjs";
17
17
  import { gitObjectOf } from "../storage/object-rows.mjs";
18
18
  import { decodeRow } from "../store/errors.mjs";
19
- import { gitJob } from "../store/job-try.mjs";
19
+ import { jobParts } from "../store/job-try.mjs";
20
20
  import { readRecord } from "../store/repo-record.mjs";
21
21
  import { isLive, liveState } from "../store/reservations.mjs";
22
22
  import { collections, jobRepo } from "../store/scopes.mjs";
@@ -161,7 +161,7 @@ const groupsKey = (id, entries, most) => JSON.stringify([
161
161
  /**
162
162
  * `groupsOf`, but once per try for a candidate, its entries and its most: a step planned again
163
163
  * after its write found the version moved, by any write in the repo, takes the groups the host
164
- * gave, as it saw the lane then, so the host's `bisect` and `onError` hear of it once.
164
+ * gave, as it saw the lane then, so the host's `bisect` is asked, and its failure logged, once.
165
165
  */
166
166
  const triedGroups = (tried, state, options, id, candidate, most) => {
167
167
  const key = groupsKey(id, candidate.entries, most);
@@ -429,7 +429,10 @@ const advanceStep = /* @__PURE__ */ Effect.fnUntraced(function* (host, context,
429
429
  const schedules = schedulesOf(state, options);
430
430
  const plan = new QueuePlan(state, now);
431
431
  if (yield* openSearched(plan, schedules)) return queueOwn(context, plan, againStep);
432
- const scanned = yield* scan(plan, schedules, stack, holder === void 0 ? void 0 : reserved);
432
+ const live = holder === void 0 ? void 0 : reserved;
433
+ const { frozen } = row;
434
+ const freeze = live === void 0 && frozen !== void 0 && (yield* isLive(context.store, frozen)) ? frozen : void 0;
435
+ const scanned = yield* scan(plan, schedules, stack, live, freeze);
433
436
  if (scanned === "opened") return queueOwn(context, plan, idleStep);
434
437
  return scanned === void 0 ? idle : {
435
438
  kind: "done",
@@ -492,6 +495,25 @@ const pinnedOf = (state, stack) => stack.filter(({ candidate }) => candidate.ent
492
495
  return row !== void 0 && opensAlone(row);
493
496
  }));
494
497
  /**
498
+ * The entries a live topic's freeze of the target lets open: those ahead of its member in one of
499
+ * its lanes, at no higher priority, none jumped since it froze. Each was there when it froze, so
500
+ * the target drains of all but these, and then of these (Q1159). With no member waiting, none.
501
+ */
502
+ const thawedOf = (state, waiting, frozen) => {
503
+ const at = waiting.findIndex((place) => state.entries.get(place.entry)?.topic?.topic === frozen.topic);
504
+ const member = waiting[at];
505
+ const row = member === void 0 ? void 0 : state.entries.get(member.entry);
506
+ if (member === void 0 || row === void 0) return /* @__PURE__ */ new Set();
507
+ const lanes = new Set(lanesOf(row));
508
+ const thawed = waiting.slice(0, at).filter((place) => {
509
+ const entry = state.entries.get(place.entry);
510
+ const shares = entry !== void 0 && lanesOf(entry).some((lane) => lanes.has(lane));
511
+ const before = place.jumped === void 0 || place.jumped < frozen.next;
512
+ return shares && place.priority <= member.priority && before;
513
+ });
514
+ return new Set(thawed.map(({ entry }) => entry));
515
+ };
516
+ /**
495
517
  * Opens the next candidate in the target's order, lane by lane: the oldest waiting entry whose
496
518
  * lanes have room and a place, with the waiting entries after it in no other lane, up to the
497
519
  * smallest `maxSize` among its lanes. An entry that can't open blocks its lanes, and every entry
@@ -499,12 +521,15 @@ const pinnedOf = (state, stack) => stack.filter(({ candidate }) => candidate.ent
499
521
  * tip, with nothing landing and no other pinned one open, so nothing moves the tip under it till it
500
522
  * ends. A topic's member waits, blocking its lanes, till its topic reserves the target, and while
501
523
  * `live`, a topic's reservation, holds it, only that topic's member opens, wherever it is in the
502
- * order. `opened` once it opened one, else when a short batch's `wait` ends.
524
+ * order. While `frozen`, a live topic's freeze, holds it, only the entries `thawedOf` names open,
525
+ * and a short batch waits for none. `opened` once it opened one, else when a short batch's `wait`
526
+ * ends.
503
527
  */
504
- const scan = /* @__PURE__ */ Effect.fnUntraced(function* (plan, schedules, stack, live) {
528
+ const scan = /* @__PURE__ */ Effect.fnUntraced(function* (plan, schedules, stack, live, frozen) {
505
529
  const { state } = plan;
506
530
  const held = stack.some(({ candidate }) => candidate.landing === true) || pinnedOf(state, stack).length > 0;
507
531
  const waiting = orderOf(state.row.order).filter((place) => state.entries.get(place.entry)?.state === "waiting");
532
+ const thawed = frozen === void 0 ? void 0 : thawedOf(state, waiting, frozen);
508
533
  const blocked = /* @__PURE__ */ new Set();
509
534
  let soonest;
510
535
  for (const [at, place] of waiting.entries()) {
@@ -514,6 +539,10 @@ const scan = /* @__PURE__ */ Effect.fnUntraced(function* (plan, schedules, stack
514
539
  const block = () => lanes.forEach((lane) => blocked.add(lane));
515
540
  const { topic } = row;
516
541
  if (live !== void 0 && topic?.topic !== live.topic) continue;
542
+ if (thawed !== void 0 && !thawed.has(place.entry)) {
543
+ block();
544
+ continue;
545
+ }
517
546
  if (live === void 0 && topic !== void 0) {
518
547
  block();
519
548
  continue;
@@ -552,6 +581,7 @@ const scan = /* @__PURE__ */ Effect.fnUntraced(function* (plan, schedules, stack
552
581
  const own = laterRow === void 0 ? [] : lanesOf(laterRow);
553
582
  if (laterRow === void 0 || !own.some((lane) => lanes.has(lane))) continue;
554
583
  if (opensAlone(laterRow) || !own.every((lane) => lanes.has(lane))) break;
584
+ if (thawed !== void 0 && !thawed.has(later.entry)) break;
555
585
  const key = callerKey(laterRow);
556
586
  const past = !callers.has(key) && callers.size >= queueLimits.candidateCallers;
557
587
  closed = laterRow.alone === true || past;
@@ -560,7 +590,7 @@ const scan = /* @__PURE__ */ Effect.fnUntraced(function* (plan, schedules, stack
560
590
  batch.push(later);
561
591
  }
562
592
  const due = Math.min(...batch.map((open) => open.since)) + wait;
563
- if (!closed && batch.length < maxSize && due > plan.now) {
593
+ if (!closed && thawed === void 0 && batch.length < maxSize && due > plan.now) {
564
594
  block();
565
595
  soonest = Math.min(soonest ?? Number.MAX_SAFE_INTEGER, due);
566
596
  continue;
@@ -701,7 +731,11 @@ const liftCandidateWork = (context, state, now, name, key) => {
701
731
  };
702
732
  /** Why a link couldn't be written: a conflict, too many commits, or the host's `merge` failing. */
703
733
  const LinkFailure = /* @__PURE__ */ Schema.Union([Schema.Struct({
704
- kind: Schema.Literals(["conflict", "tooManyCommits"]),
734
+ kind: Schema.Literals([
735
+ "conflict",
736
+ "tooManyCommits",
737
+ "tooLarge"
738
+ ]),
705
739
  summary: Schema.String
706
740
  }), Schema.Struct({
707
741
  kind: Schema.Literal("host-error"),
@@ -725,7 +759,7 @@ const commitsPast = (linking, entry, head, tip) => {
725
759
  return historyUpTo(linking.opened.read, {
726
760
  wants: [head],
727
761
  haves: [tip]
728
- }, most + 1, linking.call).pipe(Effect.flatMap((walked) => {
762
+ }, most + 1, linking.call, linking.opened.roots).pipe(Effect.flatMap((walked) => {
729
763
  if (walked.length <= most) return Effect.succeed([...walked].reverse());
730
764
  const summary = `${entry} adds more than ${most} commits, as many as queue.entryCommits lets a link read`;
731
765
  return Effect.fail(linkFailed(entry, {
@@ -748,10 +782,10 @@ const treeOf = (linking, entry, sides) => mergedTree(linking.opened, linking.mad
748
782
  /** A host's `merge` answer read as a `MergePlan`: a host in plain JavaScript may answer any value. */
749
783
  const decodePlan = /* @__PURE__ */ Schema.decodeUnknownSync(MergePlan);
750
784
  /** The host's plan for an entry's link: a throw or bad plan fails it `host-error`, with the failure's ID. */
751
- const planOf = (linking, entry, row, commits) => Effect.flatMap(Effect.service(CoreParts), ({ checks }) => hostCall(checks.reports, "queue.merge", { repo: linking.repo }, () => decodePlan(linking.options.merge({
785
+ const planOf = (linking, entry, row, commits) => hostCall("queue.merge", { repo: linking.repo }, () => decodePlan(linking.options.merge({
752
786
  entry: entryOf(linking.repo, entry, row, linking.notes.get(entry) ?? {}),
753
787
  commits
754
- })))).pipe(Effect.catch((error) => {
788
+ }))).pipe(Effect.catch((error) => {
755
789
  const id = error.code === "UNAVAILABLE" || error.code === "DEADLINE_EXCEEDED" ? error.context?.id ?? "" : "";
756
790
  return Effect.fail(linkFailed(entry, {
757
791
  kind: "host-error",
@@ -761,7 +795,7 @@ const planOf = (linking, entry, row, commits) => Effect.flatMap(Effect.service(C
761
795
  /** One entry's link onto `tip`, as its plan's method says: the commit the candidate is at after. */
762
796
  const linkOnto = /* @__PURE__ */ Effect.fnUntraced(function* (linking, entry, row, tip) {
763
797
  const { head } = row;
764
- const { bases } = yield* mergeBases(linking.opened.read, { commits: [tip, head] }, linking.call);
798
+ const { bases } = yield* mergeBases(linking.opened.read, { commits: [tip, head] }, linking.call, linking.opened.roots);
765
799
  if (bases.includes(head)) return tip;
766
800
  const [base] = bases;
767
801
  if (base === void 0) {
@@ -865,7 +899,7 @@ const buildStep = /* @__PURE__ */ Effect.fnUntraced(function* (host$1, context,
865
899
  const options = yield* host$1.options(repo);
866
900
  if (options === void 0) return done;
867
901
  const opened = yield* asHost(openRead(host, repo));
868
- const limits = yield* limitsOf();
902
+ const limits = yield* limitsOf({ milliseconds: host$1.buildMilliseconds });
869
903
  const { call } = yield* readerOf(opened, limits, "walk-limit");
870
904
  const made = new MadeObjects();
871
905
  const read = (input) => {
@@ -916,8 +950,18 @@ const buildStep = /* @__PURE__ */ Effect.fnUntraced(function* (host$1, context,
916
950
  candidate: id,
917
951
  by
918
952
  };
953
+ let first;
954
+ const tooLarge = tried.tooLarge?.candidate === id ? tried.tooLarge : void 0;
919
955
  const linkOf = Effect.fnUntraced(function* (entry, entryRow, onto) {
920
956
  const key = yield* linkKey(linking, onto, entry, entryRow);
957
+ if (reached.at === from) first = {
958
+ entry,
959
+ key
960
+ };
961
+ if (tooLarge?.key === key) return yield* Effect.fail(linkFailed(entry, {
962
+ kind: "tooLarge",
963
+ summary: tooLarge.summary
964
+ }));
921
965
  const kept = last.get(key);
922
966
  const before = made.count;
923
967
  if (kept !== void 0) for (const { type, bytes } of kept.objects) yield* made.add(type, bytes);
@@ -939,7 +983,21 @@ const buildStep = /* @__PURE__ */ Effect.fnUntraced(function* (host$1, context,
939
983
  if (reached.at < links.length && (yield* spent(made, call))) break;
940
984
  }
941
985
  return reached;
942
- }).pipe(Effect.catchTag("LinkFailed", (failed) => Effect.succeed({ failed })), Effect.catchIf((error) => atLimit(error) && reached.at > from, () => Effect.succeed(reached)));
986
+ }).pipe(Effect.catchTag("LinkFailed", (failed) => Effect.succeed({ failed })), Effect.catchIf(atLimit, (error) => {
987
+ if (reached.at > from) return Effect.succeed(reached);
988
+ if (first === void 0) return Effect.fail(error);
989
+ const { entry, key } = first;
990
+ const summary = `${entry} can't be linked within one build try: ${error.message}`;
991
+ tried.tooLarge = {
992
+ candidate: id,
993
+ key,
994
+ summary
995
+ };
996
+ return Effect.succeed({ failed: linkFailed(entry, {
997
+ kind: "tooLarge",
998
+ summary
999
+ }) });
1000
+ }));
943
1001
  const plan = new QueuePlan(state, now);
944
1002
  if ("failed" in built) {
945
1003
  const { entry, failure } = built.failed;
@@ -1196,7 +1254,8 @@ const AdvanceJob = /* @__PURE__ */ Job.make(advanceName, {
1196
1254
  });
1197
1255
  const BuildJob = /* @__PURE__ */ Job.make(buildName, {
1198
1256
  payload: CandidateData,
1199
- retry: queueJobRetry
1257
+ retry: queueJobRetry,
1258
+ timeout: queueLimits.buildTryMilliseconds
1200
1259
  });
1201
1260
  const TimeoutJob = /* @__PURE__ */ Job.make(timeoutName, {
1202
1261
  payload: CandidateData,
@@ -1213,9 +1272,9 @@ const queueJobs = (host, onFailure) => {
1213
1272
  const candidateOf = (job, context) => loadCandidate(context, jobRepo(job), job.data.candidate).pipe(Effect.map((loaded) => loaded?.state));
1214
1273
  return [
1215
1274
  queueTrimJob(host, onFailure),
1216
- gitJob(AdvanceJob, (data) => queueTry(data, (job, context) => overCore(host, context, advance(host, job, context))), { onFailure: holdOnFailure(host, targetOf, onFailure, unbatch) }),
1217
- gitJob(BuildJob, (data) => queueTry(data, (job, context) => Effect.asVoid(overCore(host, context, build(job, context)))), { onFailure: holdOnFailure(host, candidateOf, onFailure) }),
1218
- gitJob(TimeoutJob, (data) => queueTry(data, (job, context) => Effect.asVoid(overCore(host, context, timeout(job, context)))), { onFailure: holdOnFailure(host, candidateOf, onFailure) })
1275
+ jobParts(AdvanceJob, (data) => queueTry(data, (job, context) => overCore(host, context, advance(host, job, context))), { onFailure: holdOnFailure(host, targetOf, onFailure, unbatch) }),
1276
+ jobParts(BuildJob, (data) => queueTry(data, (job, context) => Effect.asVoid(overCore(host, context, build(job, context)))), { onFailure: holdOnFailure(host, candidateOf, onFailure) }),
1277
+ jobParts(TimeoutJob, (data) => queueTry(data, (job, context) => Effect.asVoid(overCore(host, context, timeout(job, context)))), { onFailure: holdOnFailure(host, candidateOf, onFailure) })
1219
1278
  ];
1220
1279
  };
1221
1280
  export { checkPublish, queueJobs };
@@ -237,23 +237,13 @@ const askJoin = (options, repo, caller, input) => {
237
237
  },
238
238
  actor: caller.actor
239
239
  };
240
- const asked = Effect.flatMap(Effect.service(CoreParts), ({ checks }) => hostCall(checks.reports, "join", about, async (signal) => decodeJoin(await join({
240
+ const asked = hostCall("join", about, async (signal) => decodeJoin(await join({
241
241
  repo,
242
242
  entry,
243
243
  actor: caller.actor,
244
244
  signal
245
- })), { timeout: 3e4 }));
246
- return Effect.flatMap(asked, (answer) => {
247
- if (answer.kind !== "reject") return Effect.void;
248
- const refused = {
249
- kind: "reject",
250
- message: answer.message
251
- };
252
- if (answer.code !== void 0) refused.code = answer.code;
253
- if (answer.hint !== void 0) refused.hint = answer.hint;
254
- if (answer.context !== void 0) refused.context = answer.context;
255
- return Effect.fail(rejectedError(refused));
256
- });
245
+ })), { timeout: 3e4 });
246
+ return Effect.flatMap(asked, (answer) => answer.kind === "reject" ? Effect.fail(rejectedError(answer)) : Effect.void);
257
247
  };
258
248
  /** The write a call makes as `caller`, once it's authorized. */
259
249
  const writeAs = (caller, name, plan) => ({
@@ -360,7 +350,7 @@ const lanesFor = /* @__PURE__ */ Effect.fnUntraced(function* (caller, opened) {
360
350
  from: tip ?? void 0,
361
351
  to: input.head
362
352
  });
363
- return yield* hostCall(core.checks.reports, "queue.lanes", about, async (signal) => {
353
+ return yield* hostCall("queue.lanes", about, async (signal) => {
364
354
  let diffed;
365
355
  const changes = async () => {
366
356
  diffed ??= runIn(Effect.result(diff), scope, signal);
@@ -17,6 +17,8 @@ export interface QueueHost {
17
17
  readonly options: (repo: RepoName) => Effect.Effect<MergeQueueOptions | undefined, GitError>;
18
18
  /** The `keys` every repo's queue has, as `queueKeysOf` reads them: `undefined` for one per repo. */
19
19
  readonly keys: QueueKeys | undefined;
20
+ /** How long a build try may link for: `queueLimits.buildMilliseconds`, or the host's `cpuMs` when lower. */
21
+ readonly buildMilliseconds: number;
20
22
  }
21
23
  declare const QueueInternals_base: Context.ServiceClass<QueueInternals, "@ref0/git/queue/QueueInternals", QueueHost>;
22
24
  /** Queue internals available only from MergeQueue.layer, never a host's public service. */
@@ -25,6 +27,8 @@ declare const QueueBase_base: Context.ServiceClass<QueueBase, "@ref0/git/queue/Q
25
27
  readonly records: Records.RecordsService;
26
28
  readonly needs: Context.Context<QueueNeeds>;
27
29
  readonly onFailure: WorkFailed | undefined;
30
+ /** The CPU one try may use, from the adapter's `RequestLimits`: none where it gives none. */
31
+ readonly cpuMs: number | undefined;
28
32
  readonly attach: (host: QueueHost) => Effect.Effect<void>;
29
33
  }>;
30
34
  /**
@@ -6,7 +6,7 @@ import * as Schema from "effect/Schema";
6
6
  const decodeLanes = /* @__PURE__ */ Schema.decodeUnknownSync(LanesAnswer);
7
7
  /**
8
8
  * The lanes a host's `lanes` answered, each once in the order first named: throws, which fails
9
- * the entry `host-error` and goes to `onError`, for an answer that isn't strings, names more than
9
+ * the entry `host-error` and is logged at `Error`, for an answer that isn't strings, names more than
10
10
  * `queueLimits.lanes`, or a lane outside 1 to `queueLimits.laneBytes` bytes of UTF-8 as JSON
11
11
  * writes it, as the queue counts its other names, so a control character counts 6.
12
12
  */
@@ -5,6 +5,7 @@ import { acting } from "../core/parts.mjs";
5
5
  import { queueJobs } from "./advance.mjs";
6
6
  import { queueCalls } from "./calls.mjs";
7
7
  import { QueueBase, QueueInternals, queueKeysOf, queueOptions } from "./host.mjs";
8
+ import { buildMillisecondsOf } from "./limits.mjs";
8
9
  import * as Effect from "effect/Effect";
9
10
  import * as Option from "effect/Option";
10
11
  import * as Context from "effect/Context";
@@ -51,9 +52,10 @@ const layer = (options) => {
51
52
  records: base.records,
52
53
  needs: Context.add(base.needs, MergeParts, parts.value),
53
54
  options: optionsOf,
54
- keys: queueKeysOf(options)
55
+ keys: queueKeysOf(options),
56
+ buildMilliseconds: buildMillisecondsOf(base.cpuMs)
55
57
  };
56
- for (const job of queueJobs(host, base.onFailure)) yield* registration.addJob(job);
58
+ for (const job of queueJobs(host, base.onFailure)) yield* job(registration.addJob);
57
59
  yield* base.attach(host);
58
60
  return Context.make(MergeQueue, queueService(host)).pipe(Context.add(QueueInternals, host));
59
61
  }));
@@ -127,8 +127,24 @@ const queueLimits = {
127
127
  * The most `queue.entryCommits` may be, so the walk never grows past it: an entry of more
128
128
  * commits merges by an admin's direct push.
129
129
  */
130
- entryCommitsMost: 1e4
130
+ entryCommitsMost: 1e4,
131
+ /**
132
+ * How long one build try may link for, past `limitsOf`'s 10 s for a call someone waits on, since
133
+ * a build is a job's try (#1969). At queue-entry-10k's reading, about 3 s of CPU each 10 s of
134
+ * wall, it spends about 18 s of CPU, under Cloudflare's 30,000 ms `cpuMs`. A host whose
135
+ * `RequestLimits` gives a lower `cpuMs` takes that instead. A try's first link past it fails its
136
+ * entry `tooLarge`, since the next try would start it over.
137
+ */
138
+ buildMilliseconds: 6e4,
139
+ /**
140
+ * A `queue.build` try's timeout: its links' `buildMilliseconds`, and as long again to write
141
+ * their pack and commit. Past the 30 s a job's try has by default, which would cut the links
142
+ * first, and well within a Cloudflare alarm's.
143
+ */
144
+ buildTryMilliseconds: 12e4
131
145
  };
146
+ /** How long a build try may link for on a host whose tries may use `cpuMs` of CPU: the less of the two. */
147
+ const buildMillisecondsOf = (cpuMs) => Math.min(queueLimits.buildMilliseconds, cpuMs ?? queueLimits.buildMilliseconds);
132
148
  const encoder = new TextEncoder();
133
149
  /** A value's size as UTF-8 JSON, as infra counts a row's. */
134
150
  const jsonSize = (value) => encoder.encode(JSON.stringify(value)).length;
@@ -149,4 +165,4 @@ const targetsFull = () => fail("RESOURCE_EXHAUSTED", `The repo's queues hold ${q
149
165
  hint: `Queue onto a branch the repo queues onto now, or wait: a target's row goes ${queueLimits.kept / day} days after its queue went idle`,
150
166
  context: { reason: "queue-targets-full" }
151
167
  });
152
- export { checkBytes, jsonSize, queueFull, queueJobRetry, queueLimits, targetsFull };
168
+ export { buildMillisecondsOf, checkBytes, jsonSize, queueFull, queueJobRetry, queueLimits, targetsFull };
@@ -65,6 +65,10 @@ const PlaceRow = /* @__PURE__ */ Schema.Struct({
65
65
  * candidate merged, `b` for one its report failed and `c` for one closed otherwise; `previous`: the `concurrency` last asked.
66
66
  * `reserved`: the topic holding the target, at its attempt, which refuses every other writer while
67
67
  * that attempt is live, the queue's own publish and `restart` among them (Q557), `since` it took it.
68
+ * `frozen`: the topic whose member has waited half its `waitTimeout` for the target, with `next`,
69
+ * the order's next number when it froze, so an entry that jumped after it is no entry ahead: while that topic is live and holds no reservation here, the queue opens no new
70
+ * candidate but of the entries ahead of the member in one of its lanes, at no higher priority, and
71
+ * the target drains (Q1159).
68
72
  * `idle`: when the row was put with nothing open, held, searched or reserved, which every later
69
73
  * put of an idle row keeps, and one that isn't drops: `queue.trim` deletes it `queueLimits.kept`
70
74
  * after.
@@ -84,6 +88,10 @@ const TargetRow = /* @__PURE__ */ Schema.Struct({
84
88
  ...Reservation.fields,
85
89
  since: Schema.Int
86
90
  })),
91
+ frozen: Schema.optionalKey(Schema.Struct({
92
+ ...Reservation.fields,
93
+ next: Schema.Int
94
+ })),
87
95
  idle: Schema.optionalKey(Schema.Finite)
88
96
  });
89
97
  /**
@@ -122,7 +130,8 @@ const EntryRow = /* @__PURE__ */ Schema.Struct({
122
130
  "host-error",
123
131
  "interaction",
124
132
  "refused",
125
- "tooManyCommits"
133
+ "tooManyCommits",
134
+ "tooLarge"
126
135
  ])),
127
136
  /** Its candidates' land conflicts, which a `retry` keeps: at `landRestarts`, it's pinned. */
128
137
  conflicts: Schema.optionalKey(Schema.Int),
@@ -90,7 +90,7 @@ const schedulesOf = (state, options) => {
90
90
  if (option === void 0) return fallback;
91
91
  if (!isAsked(option)) return fit(option);
92
92
  const seen = yield* viewOf(/* @__PURE__ */ new Set([lane]));
93
- return yield* hostCall((yield* CoreParts).checks.reports, "queue.schedule", about, () => fit(option(seen))).pipe(Effect.catch(() => Effect.succeed(fallback)));
93
+ return yield* hostCall("queue.schedule", about, () => fit(option(seen))).pipe(Effect.catch(() => Effect.succeed(fallback)));
94
94
  });
95
95
  return {
96
96
  of: Effect.fnUntraced(function* (lane) {
@@ -5,7 +5,6 @@ import { openCandidate } from "./calls.mjs";
5
5
  import { lanesNamed, placeOf, placed } from "./lanes.mjs";
6
6
  import { concurrencyOf, roomFor, schedulesOf } from "./schedule.mjs";
7
7
  import { candidateOf, closeCandidate, endEntry, endSearch, isOpen, releaseEntry, setChecking } from "./steps.mjs";
8
- import { CoreParts } from "../core/parts.mjs";
9
8
  import * as Effect from "effect/Effect";
10
9
  import * as Schema from "effect/Schema";
11
10
  // src/queue/search.ts
@@ -87,8 +86,8 @@ const checkGroups = (answer, entries, most) => {
87
86
  /**
88
87
  * The groups to check `row`'s entries in, naming at most `most`: the host's `bisect`, given the
89
88
  * candidate and its lane's view without it, the target's when it's in several, or halves. An
90
- * answer `checkGroups` refuses, or a throw, takes halves, which `onError` hears of as
91
- * `queue.bisect`.
89
+ * answer `checkGroups` refuses, or a throw, takes halves, logged at `Error` as
90
+ * `queue.bisect`'s.
92
91
  */
93
92
  const groupsOf = /* @__PURE__ */ Effect.fnUntraced(function* (state, options, id, row, most) {
94
93
  const { bisect } = options;
@@ -99,7 +98,7 @@ const groupsOf = /* @__PURE__ */ Effect.fnUntraced(function* (state, options, id
99
98
  ...seen,
100
99
  open: seen.open.filter((open) => open.id !== id)
101
100
  };
102
- return yield* hostCall((yield* CoreParts).checks.reports, "queue.bisect", { repo }, () => checkGroups(decodeGroups(bisect(candidateOf(repo, id, row), view)), row.entries, most)).pipe(Effect.catch(() => Effect.succeed(halve(row.entries))));
101
+ return yield* hostCall("queue.bisect", { repo }, () => checkGroups(decodeGroups(bisect(candidateOf(repo, id, row), view)), row.entries, most)).pipe(Effect.catch(() => Effect.succeed(halve(row.entries))));
103
102
  });
104
103
  const setSearch = (plan, failed, search) => {
105
104
  const row = plan.candidates.get(failed);
@@ -1,5 +1,5 @@
1
1
  import { decodeRow, storeCall } from "../store/errors.mjs";
2
- import { gitJob } from "../store/job-try.mjs";
2
+ import { jobParts } from "../store/job-try.mjs";
3
3
  import { TrimData, trimName } from "../store/queue-jobs.mjs";
4
4
  import { readRecord } from "../store/repo-record.mjs";
5
5
  import { collections, jobRepo, newChangeId, repoScope } from "../store/scopes.mjs";
@@ -285,5 +285,5 @@ const TrimJob = /* @__PURE__ */ Job.make(trimName, {
285
285
  * failure to `onFailure`, so the host's `repo.work.failed` names it and `work.retry` runs it again:
286
286
  * a failed job's row stays failed whatever a target's first write saves.
287
287
  */
288
- const queueTrimJob = (host, onFailure) => gitJob(TrimJob, (cursor) => Effect.flatMap(Effect.all([CurrentJob.store, CurrentJob.current]), ([store, job]) => Effect.flatMap(Effect.provideContext(Clock$1.currentTimeMillis, host.needs), (now) => trimStep(store, jobRepo(job), cursor, now))), onFailure === void 0 ? {} : { onFailure });
288
+ const queueTrimJob = (host, onFailure) => jobParts(TrimJob, (cursor) => Effect.flatMap(Effect.all([CurrentJob.store, CurrentJob.current]), ([store, job]) => Effect.flatMap(Effect.provideContext(Clock$1.currentTimeMillis, host.needs), (now) => trimStep(store, jobRepo(job), cursor, now))), onFailure === void 0 ? {} : { onFailure });
289
289
  export { queueTrimJob };
@@ -0,0 +1,2 @@
1
+ import { client_d_exports } from "./client.mjs";
2
+ export { client_d_exports as RestClient };
@@ -1,18 +1,42 @@
1
- import { CallInput } from "../contracts/actors.mjs";
2
- import { RemoteCalls, RemoteOptions } from "../contracts/remote.mjs";
3
- import { Result } from "../contracts/result.mjs";
1
+ import { RemoteCalls, RemoteOptions, WithoutSignal } from "../contracts/remote.mjs";
2
+ import { GitError } from "../contracts/result.mjs";
4
3
  import { ServerCalls } from "../contracts/server.mjs";
5
4
  import { CreatedToken, TokenCalls, TokenCreateInput, TokenTarget } from "../contracts/tokens.mjs";
6
5
  import { RestEvents } from "./listen.mjs";
7
6
  import { Me } from "./me.mjs";
7
+ import * as Effect from "effect/Effect";
8
+ import * as HttpClient from "effect/http/HttpClient";
9
+ import * as Context from "effect/Context";
10
+ import * as Layer from "effect/Layer";
11
+ declare namespace client_d_exports {
12
+ export { RestClient, RestClientCalls, RestTokenCalls, layer, make };
13
+ }
8
14
  /** `create` takes no `actor`, as REST's caller is it; `revokeKey` is a host's own, with no route. */
9
15
  export interface RestTokenCalls extends Omit<RemoteCalls<TokenCalls>, 'create' | 'revokeKey'> {
10
- readonly create: (target: TokenTarget, input: Omit<TokenCreateInput, 'actor'>) => Promise<Result<CreatedToken>>;
16
+ readonly create: (target: TokenTarget, input: WithoutSignal<Omit<TokenCreateInput, 'actor'>>) => Effect.Effect<CreatedToken, GitError>;
11
17
  }
12
- /** The server's calls over REST, each without `actor`, and who the remote's credential is. */
13
- export interface RestClient extends RemoteCalls<Omit<ServerCalls, 'tokens' | 'lfs'>> {
18
+ /**
19
+ * The server's calls over REST, each an Effect without `actor`, and who the remote's credential
20
+ * is. Interrupting a call stops it, its request and any answer's body it's still reading.
21
+ */
22
+ export interface RestClientCalls extends RemoteCalls<Omit<ServerCalls, 'tokens' | 'lfs'>> {
14
23
  readonly tokens: RestTokenCalls;
15
24
  readonly events: RestEvents;
16
- readonly me: (input?: CallInput) => Promise<Result<Me>>;
25
+ readonly me: () => Effect.Effect<Me, GitError>;
17
26
  }
18
- export declare const createRestClient: (options: RemoteOptions) => RestClient;
27
+ declare const RestClient_base: Context.ServiceClass<RestClient, "@ref0/git/RestClient", RestClientCalls>;
28
+ /**
29
+ * A REST client of one remote as a service, for a program that's handed one: with `RestClient`
30
+ * from `@ref0/git`, `RestClient.layer(options)` provides it.
31
+ */
32
+ export declare class RestClient extends /* @__PURE__ */ RestClient_base {}
33
+ /**
34
+ * A typed client for a Git server's REST at `options.url`: `HttpApiClient` over `GitRestApi`, each
35
+ * call an Effect that fails with the server's own `GitError`. It sends `credentials` on each
36
+ * request, through `options.transport` when given and the `HttpClient` it's provided otherwise. It
37
+ * carries none of REST's serving code.
38
+ */
39
+ export declare const make: (options: RemoteOptions) => Effect.Effect<RestClientCalls, never, HttpClient.HttpClient>;
40
+ /** `RestClient` over `options`' remote, as `make` builds it. */
41
+ export declare const layer: (options: RemoteOptions) => Layer.Layer<RestClient, never, HttpClient.HttpClient>;
42
+ export { client_d_exports };