@ref0/git 0.12.0 → 0.14.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 (247) hide show
  1. package/dist/access/private-refs.mjs +3 -3
  2. package/dist/auth/auth.d.mts +2 -2
  3. package/dist/auth/auth.mjs +3 -6
  4. package/dist/auth/authorize.mjs +1 -17
  5. package/dist/auth/helpers.mjs +3 -11
  6. package/dist/auth/host-services.mjs +11 -0
  7. package/dist/auth/policy.d.mts +27 -7
  8. package/dist/auth/policy.mjs +8 -4
  9. package/dist/auth/tokens-layer.d.mts +1 -2
  10. package/dist/auth/tokens-layer.mjs +2 -3
  11. package/dist/auth/tokens-public.d.mts +3 -3
  12. package/dist/auth/tokens.d.mts +1 -8
  13. package/dist/auth/tokens.mjs +1 -8
  14. package/dist/auth.d.mts +1 -4
  15. package/dist/auth.mjs +1 -3
  16. package/dist/client/git-http.mjs +18 -4
  17. package/dist/client/push-upload.mjs +33 -7
  18. package/dist/client/remote.mjs +94 -28
  19. package/dist/client/slice-push.d.mts +1 -1
  20. package/dist/contracts/access.d.mts +8 -8
  21. package/dist/contracts/actors.d.mts +2 -34
  22. package/dist/contracts/blobs.d.mts +2 -2
  23. package/dist/contracts/client.d.mts +8 -3
  24. package/dist/contracts/commits.d.mts +10 -2
  25. package/dist/contracts/commits.mjs +9 -1
  26. package/dist/contracts/files.d.mts +2 -2
  27. package/dist/contracts/forks.d.mts +11 -1
  28. package/dist/contracts/git.d.mts +18 -7
  29. package/dist/contracts/git.mjs +3 -2
  30. package/dist/contracts/lfs.d.mts +0 -7
  31. package/dist/contracts/objects.d.mts +80 -10
  32. package/dist/contracts/operations.d.mts +3 -0
  33. package/dist/contracts/operations.mjs +12 -2
  34. package/dist/contracts/push-uploads.d.mts +44 -5
  35. package/dist/contracts/push-uploads.mjs +7 -3
  36. package/dist/contracts/refs.d.mts +28 -6
  37. package/dist/contracts/remote.mjs +1 -3
  38. package/dist/contracts/repo-records.d.mts +1 -0
  39. package/dist/contracts/repos.d.mts +90 -2
  40. package/dist/contracts/repos.mjs +29 -2
  41. package/dist/contracts/result.d.mts +23 -18
  42. package/dist/contracts/result.mjs +17 -4
  43. package/dist/contracts/rules.d.mts +22 -22
  44. package/dist/contracts/server.d.mts +28 -77
  45. package/dist/contracts/signin.d.mts +1 -1
  46. package/dist/contracts/sync.d.mts +79 -19
  47. package/dist/contracts/sync.mjs +34 -10
  48. package/dist/contracts/tokens.d.mts +1 -6
  49. package/dist/contracts/tokens.mjs +1 -2
  50. package/dist/contracts/topics.d.mts +0 -5
  51. package/dist/contracts/work.d.mts +66 -2
  52. package/dist/contracts/work.mjs +8 -1
  53. package/dist/core/access.mjs +27 -5
  54. package/dist/core/ancestry.d.mts +9 -0
  55. package/dist/core/ancestry.mjs +6 -6
  56. package/dist/core/asked.mjs +42 -4
  57. package/dist/core/call-names.mjs +1 -0
  58. package/dist/core/call-services.mjs +2 -1
  59. package/dist/core/events/deliver.mjs +10 -2
  60. package/dist/core/forks.mjs +3 -3
  61. package/dist/core/imports.mjs +147 -9
  62. package/dist/core/index-job.mjs +9 -6
  63. package/dist/core/job-view.mjs +8 -9
  64. package/dist/core/mirror-rows.mjs +19 -4
  65. package/dist/core/objects/commits.mjs +16 -6
  66. package/dist/core/parts.d.mts +6 -1
  67. package/dist/core/parts.mjs +1 -4
  68. package/dist/core/purge.mjs +76 -6
  69. package/dist/core/push-decide.mjs +1 -1
  70. package/dist/core/push-files.d.mts +12 -0
  71. package/dist/core/push-files.mjs +225 -0
  72. package/dist/core/push-repo.d.mts +8 -0
  73. package/dist/core/push-repo.mjs +56 -0
  74. package/dist/core/push.d.mts +17 -0
  75. package/dist/core/push.mjs +98 -26
  76. package/dist/core/receipts.mjs +26 -10
  77. package/dist/core/ref-view.mjs +59 -5
  78. package/dist/core/refs.mjs +13 -8
  79. package/dist/core/repack.mjs +11 -8
  80. package/dist/core/repo-info.mjs +16 -9
  81. package/dist/core/repos.mjs +30 -14
  82. package/dist/core/seam.mjs +2 -2
  83. package/dist/core/view.d.mts +6 -0
  84. package/dist/core/view.mjs +45 -12
  85. package/dist/core/work.mjs +47 -22
  86. package/dist/effect.d.mts +3 -1
  87. package/dist/effect.mjs +3 -1
  88. package/dist/engine/reads.mjs +13 -6
  89. package/dist/engine/walk.mjs +4 -4
  90. package/dist/event-streams/event-streams.d.mts +1 -1
  91. package/dist/event-streams/event-streams.mjs +1 -1
  92. package/dist/event-streams/stream.d.mts +1 -1
  93. package/dist/event-streams/stream.mjs +1 -1
  94. package/dist/extend.d.mts +3 -3
  95. package/dist/extend.mjs +2 -2
  96. package/dist/http/answers.mjs +4 -2
  97. package/dist/http/core-parts.mjs +64 -15
  98. package/dist/http/handler.mjs +2 -2
  99. package/dist/http/node.mjs +5 -4
  100. package/dist/http/parts.d.mts +1 -0
  101. package/dist/http/push-upload-job.mjs +503 -0
  102. package/dist/http/push-uploads.d.mts +1 -0
  103. package/dist/http/push-uploads.mjs +114 -56
  104. package/dist/http/upload-pack.mjs +7 -6
  105. package/dist/index.d.mts +23 -24
  106. package/dist/index.mjs +4 -7
  107. package/dist/lfs/base.d.mts +7 -3
  108. package/dist/lfs/base.mjs +2 -1
  109. package/dist/lfs/copy.d.mts +46 -0
  110. package/dist/lfs/copy.mjs +26 -0
  111. package/dist/lfs/layer.mjs +4 -2
  112. package/dist/lfs/objects.d.mts +6 -0
  113. package/dist/lfs/objects.mjs +68 -41
  114. package/dist/lfs/rows.d.mts +13 -0
  115. package/dist/lfs/service.d.mts +1 -7
  116. package/dist/lfs/service.mjs +1 -9
  117. package/dist/lfs/upload-most.mjs +5 -5
  118. package/dist/node.d.mts +2 -2
  119. package/dist/protocol/bytes/sha256-hasher.d.mts +15 -0
  120. package/dist/protocol/bytes/sha256.d.mts +32 -0
  121. package/dist/protocol/bytes/sha256.mjs +105 -49
  122. package/dist/protocol/wire/advertisement.mjs +9 -4
  123. package/dist/protocol/wire/lines.d.mts +4 -2
  124. package/dist/protocol/wire/lines.mjs +11 -5
  125. package/dist/protocol/wire/push-uploads.mjs +13 -1
  126. package/dist/protocol/wire/v2.mjs +2 -2
  127. package/dist/protocol.d.mts +3 -1
  128. package/dist/protocol.mjs +3 -1
  129. package/dist/queue/advance.mjs +1 -1
  130. package/dist/queue/host.d.mts +1 -7
  131. package/dist/queue/host.mjs +1 -7
  132. package/dist/queue/layer.mjs +1 -1
  133. package/dist/queue/trim.mjs +1 -1
  134. package/dist/rest/blobs.d.mts +31 -23
  135. package/dist/rest/blobs.mjs +1 -1
  136. package/dist/rest/caller.d.mts +49 -9
  137. package/dist/rest/caller.mjs +1 -1
  138. package/dist/rest/client.d.mts +10 -3
  139. package/dist/rest/client.mjs +4 -0
  140. package/dist/rest/commits.d.mts +273 -240
  141. package/dist/rest/errors.d.mts +24 -4
  142. package/dist/rest/events.d.mts +9 -6
  143. package/dist/rest/events.mjs +1 -2
  144. package/dist/rest/files.d.mts +127 -115
  145. package/dist/rest/forks.d.mts +121 -97
  146. package/dist/rest/handler.mjs +4 -57
  147. package/dist/rest/handlers.d.mts +1 -1
  148. package/dist/rest/handlers.mjs +18 -4
  149. package/dist/rest/layer.mjs +2 -1
  150. package/dist/rest/me.d.mts +8 -4
  151. package/dist/rest/merges.d.mts +8 -4
  152. package/dist/rest/paths.mjs +1 -0
  153. package/dist/rest/queue.d.mts +282 -226
  154. package/dist/rest/refs.d.mts +205 -176
  155. package/dist/rest/repos.d.mts +108 -80
  156. package/dist/rest/tags.d.mts +24 -12
  157. package/dist/rest/tokens.d.mts +235 -211
  158. package/dist/rest/topics.d.mts +53 -33
  159. package/dist/rest/trees.d.mts +105 -89
  160. package/dist/rest/work.d.mts +467 -20
  161. package/dist/rest/work.mjs +8 -0
  162. package/dist/server/edge-node.d.mts +9 -13
  163. package/dist/server/edge-node.mjs +9 -12
  164. package/dist/server/git-layer.d.mts +1 -6
  165. package/dist/server/git-layer.mjs +2 -2
  166. package/dist/server/git-namespace.d.mts +3 -3
  167. package/dist/server/joined.d.mts +15 -22
  168. package/dist/server/joined.mjs +5 -29
  169. package/dist/server/lifecycle.mjs +107 -23
  170. package/dist/server/registry.mjs +9 -1
  171. package/dist/server/server.mjs +133 -212
  172. package/dist/storage/budget.mjs +2 -2
  173. package/dist/storage/clean-up.mjs +13 -10
  174. package/dist/storage/fetch.mjs +13 -8
  175. package/dist/storage/file-limits.mjs +24 -0
  176. package/dist/storage/index-build.d.mts +1 -0
  177. package/dist/storage/index-build.mjs +106 -62
  178. package/dist/storage/index-fetch.mjs +16 -3
  179. package/dist/storage/index-reach.mjs +33 -5
  180. package/dist/storage/index-remap.mjs +8 -1
  181. package/dist/storage/index-shallow.mjs +5 -3
  182. package/dist/storage/largest-files.mjs +48 -0
  183. package/dist/storage/lfs-pointers.mjs +10 -1
  184. package/dist/storage/loose.mjs +3 -1
  185. package/dist/storage/memory-budget.mjs +28 -4
  186. package/dist/storage/pack-reads.mjs +8 -8
  187. package/dist/storage/pack-receive.mjs +83 -25
  188. package/dist/storage/packs.mjs +37 -21
  189. package/dist/storage/prune-keep.mjs +203 -34
  190. package/dist/storage/prune-walk.mjs +54 -16
  191. package/dist/storage/prune.mjs +629 -196
  192. package/dist/storage/push-uploads.mjs +36 -12
  193. package/dist/storage/quarantine.mjs +9 -9
  194. package/dist/storage/ready.mjs +47 -19
  195. package/dist/storage/receive-bounds.mjs +29 -8
  196. package/dist/storage/receive-state.mjs +8 -0
  197. package/dist/storage/receive-steps.mjs +71 -18
  198. package/dist/storage/repack.d.mts +1 -1
  199. package/dist/storage/repack.mjs +1 -8
  200. package/dist/storage/rows.mjs +12 -1
  201. package/dist/storage/shallow.d.mts +1 -0
  202. package/dist/storage/shallow.mjs +26 -4
  203. package/dist/storage/stream-whole.mjs +5 -2
  204. package/dist/storage/visible.mjs +29 -1
  205. package/dist/storage/walk.mjs +2 -1
  206. package/dist/store/catalogue.mjs +1 -0
  207. package/dist/store/cursor-seal-namespace.d.mts +2 -0
  208. package/dist/store/cursor-seal-public.d.mts +5 -0
  209. package/dist/store/cursor-seal-public.mjs +5 -0
  210. package/dist/store/cursor-seal.d.mts +16 -2
  211. package/dist/store/cursor-seal.mjs +26 -14
  212. package/dist/store/errors.mjs +9 -1
  213. package/dist/store/records.d.mts +2 -0
  214. package/dist/store/records.mjs +9 -6
  215. package/dist/store/repo-record.d.mts +9 -7
  216. package/dist/store/repo-record.mjs +102 -19
  217. package/dist/store/scopes.mjs +10 -2
  218. package/dist/sync/bound.d.mts +2 -0
  219. package/dist/sync/bound.mjs +11 -2
  220. package/dist/sync/github.d.mts +6 -1
  221. package/dist/sync/github.mjs +55 -43
  222. package/dist/sync/http.mjs +36 -1
  223. package/dist/sync/import.mjs +1 -0
  224. package/dist/sync/layer.mjs +6 -2
  225. package/dist/sync/lfs-batch.mjs +119 -0
  226. package/dist/sync/lfs-copy.mjs +251 -0
  227. package/dist/sync/mirror.mjs +210 -137
  228. package/dist/sync/smart-http.mjs +4 -2
  229. package/dist/sync/step.mjs +25 -5
  230. package/dist/sync/tries.mjs +45 -14
  231. package/dist/sync.d.mts +2 -2
  232. package/dist/topics/host.mjs +1 -19
  233. package/dist/topics/layer.mjs +1 -1
  234. package/package.json +3 -8
  235. package/dist/auth/bridge.mjs +0 -30
  236. package/dist/auth/helpers.d.mts +0 -17
  237. package/dist/core/purge.d.mts +0 -8
  238. package/dist/core/registered-rows.d.mts +0 -5
  239. package/dist/core/repack.d.mts +0 -11
  240. package/dist/http/handler.d.mts +0 -2
  241. package/dist/rest/handler.d.mts +0 -21
  242. package/dist/rest.d.mts +0 -2
  243. package/dist/rest.mjs +0 -1
  244. package/dist/server/registry.d.mts +0 -16
  245. package/dist/server/server.d.mts +0 -36
  246. package/dist/storage/repack-job.d.mts +0 -3
  247. package/dist/topics/host.d.mts +0 -7
@@ -704,6 +704,14 @@ const sameJob = (a, b) => a.name === b.name && a.key === b.key;
704
704
  /** Whether `job` is a scope's job of a delivery, `git.deliver.<name>`. */
705
705
  const isDeliverJob = (job) => deliveryOf(job.name) !== void 0 && job.key === "deliver";
706
706
  /**
707
+ * Whether `job` is a delivery's job that none of `deliveries` names: a delivery the server no
708
+ * longer runs, whose queue leaves its jobs waiting and never claims them.
709
+ */
710
+ const isStrayDelivery = (job, deliveries) => {
711
+ const delivery = deliveryOf(job.name);
712
+ return delivery !== void 0 && job.key === "deliver" && !deliveries.includes(delivery);
713
+ };
714
+ /**
707
715
  * Whether `job`'s delivery has sent the event at `seq` in `scope`: its newest cursor row is at
708
716
  * `seq` or past it, or the event is gone, which a trim deletes only once every delivery has passed
709
717
  * it and a purge only once none holds it. Else one with no cursor row yet has sent none, and a
@@ -798,7 +806,7 @@ const skipFailed = /* @__PURE__ */ Effect.fnUntraced(function* (store, jobs, sco
798
806
  const longestDelivery = 78e4;
799
807
  /**
800
808
  * Throws an `INVALID_ARGUMENT` `GitError` for a delivery's `timeout` past a Git job's longest try,
801
- * as `createGitServer` checks its options before its runtime is built.
809
+ * as a server checks its deliveries before it serves.
802
810
  */
803
811
  const checkDeliveryTimeout = ({ timeout }) => {
804
812
  if (timeout === void 0 || millis(timeout) <= longestDelivery) return;
@@ -880,4 +888,4 @@ const deliveryJob = (parts, log, delivery) => {
880
888
  const onFailure = workFailed(log, parts.now, tried);
881
889
  return gitJob(DeliverJob, handler, { onFailure });
882
890
  };
883
- export { DeliverData, checkDeliveries, checkDeliveryTimeout, defaultDeliverRetry, deliverJobKey, deliverJobName, deliverTry, deliveryLog, drainCeiling, isDeliverJob, keptFor, notFailed, sentThrough, skipFailed, workFailed };
891
+ export { DeliverData, checkDeliveries, checkDeliveryTimeout, defaultDeliverRetry, deliverJobKey, deliverJobName, deliverTry, deliveryLog, drainCeiling, isDeliverJob, isStrayDelivery, keptFor, notFailed, sentThrough, skipFailed, workFailed };
@@ -31,7 +31,7 @@ import { refCopies } from "./ref-index.mjs";
31
31
  import { forkKept, heldReceipt, receiptKeys, receiptReads, receiptWrites, repoAnswer, withJobs } from "./receipts.mjs";
32
32
  import { badRepoName, repoKept } from "./repos.mjs";
33
33
  import { pushCounts } from "./events/seen.mjs";
34
- import { refViewIn } from "./ref-view.mjs";
34
+ import { anyOwned, refViewIn } from "./ref-view.mjs";
35
35
  import { SealedObjects } from "./view.mjs";
36
36
  import { CoreParts, ObjectsParts } from "./parts.mjs";
37
37
  import { check } from "../contracts/authorize.mjs";
@@ -536,12 +536,12 @@ const forkCalls = (bound) => {
536
536
  /**
537
537
  * `read` with only the refs `caller` sees in the source, so a fork copies, fetches and syncs no
538
538
  * ref the caller couldn't read there: a private one it doesn't see is missing, as on every
539
- * other surface. A source's packs are still shared whole, and the fork's reads by ID follow its
539
+ * other surface, nor one under an `owned` prefix. A source's packs are still shared whole, and the fork's reads by ID follow its
540
540
  * own tips' reach (`objectsFollowRefs`), so no hidden commit is read through it.
541
541
  */
542
542
  const seenSource = Effect.fnUntraced(function* (caller, read) {
543
543
  const refView = yield* refViewIn(caller, repoAccess(read));
544
- if (refView.whole) return {
544
+ if (refView.whole && !anyOwned((yield* CoreParts).hiddenRefs())) return {
545
545
  ...read,
546
546
  headSeen: true
547
547
  };
@@ -1,4 +1,4 @@
1
- import { SyncSource } from "../contracts/sync.mjs";
1
+ import { ImportLfsReason, SyncSource } from "../contracts/sync.mjs";
2
2
  import { readAsked } from "./asked.mjs";
3
3
  import { KeptError, keptError } from "./receipts.mjs";
4
4
  import { SavedCaller } from "./saved-callers.mjs";
@@ -34,6 +34,8 @@ import * as Base64 from "effect/encoding/Base64";
34
34
  * - `receiving`: a segment staged and received in steps, as `ImportReceiving` says;
35
35
  * - `restaged`: whether clean-up ended the stage of the segment the import fetches or receives
36
36
  * now once already, so ending it again fails the import, until that segment lands or halves;
37
+ * - `lfs`: where its copy of the history's Git LFS objects stands, as `ImportLfs` says, on a
38
+ * server with `Lfs.layer`;
37
39
  * - `error`: a failed import's last try's, which never carries a credential.
38
40
  */
39
41
  /**
@@ -55,6 +57,32 @@ const ImportReceiving = /* @__PURE__ */ Schema.Struct({
55
57
  })
56
58
  });
57
59
  /**
60
+ * An import's copy of the Git LFS objects its history points at: `pages` of pointers, which each
61
+ * segment's landing writes beside the record as its receive found them, as `lfsPageKey` says; the
62
+ * copy's cursor, entry `entry` of page `page`; and what it has done so far, `copied` objects of
63
+ * `bytes`, `missing`, those the source didn't give, and `named`, how many of them the record
64
+ * names, as `missedCounted` counts them.
65
+ */
66
+ const ImportLfs = /* @__PURE__ */ Schema.Struct({
67
+ pages: Schema.Int,
68
+ page: Schema.Int,
69
+ entry: Schema.Int,
70
+ copied: Schema.Int,
71
+ bytes: Schema.Int,
72
+ missing: Schema.Int,
73
+ named: Schema.Int
74
+ });
75
+ /** An import's LFS copy before its first page. */
76
+ const noImportLfs = {
77
+ pages: 0,
78
+ page: 0,
79
+ entry: 0,
80
+ copied: 0,
81
+ bytes: 0,
82
+ missing: 0,
83
+ named: 0
84
+ };
85
+ /**
58
86
  * An import's record. `by`: who started it, as `SavedCaller` keeps them, asked again before each
59
87
  * step, so the import fetches, publishes and offers the remote only what they may still see.
60
88
  */
@@ -77,6 +105,7 @@ const ImportRow = /* @__PURE__ */ Schema.Struct({
77
105
  bytes: Schema.Int,
78
106
  receiving: Schema.optionalKey(ImportReceiving),
79
107
  restaged: Schema.optionalKey(Schema.Literal(true)),
108
+ lfs: Schema.optionalKey(ImportLfs),
80
109
  error: Schema.optionalKey(KeptError)
81
110
  });
82
111
  /**
@@ -133,6 +162,84 @@ const tipPageRow = (page, tips) => ({
133
162
  /** The keys of pages `from` to `to`, `to` left out. */
134
163
  const tipPageKeys = (from, to) => Array.from({ length: Math.max(0, to - from) }, (_, at) => tipPageKey(from + at));
135
164
  /**
165
+ * One page of the LFS pointers a segment's receive found, `imports/lfs/<page>` beside the record:
166
+ * at most `pageEntries` of them, 58,368 B as the table lays them out, kept as base64, about 78 KB.
167
+ * A segment's landing writes its pages in the commit that lands it, so a landed segment's
168
+ * pointers are never lost, and the copy deletes each page as its cursor passes it.
169
+ */
170
+ const LfsPage = /* @__PURE__ */ Schema.Struct({ pointers: Schema.String });
171
+ /** LFS page `page`'s key, zero-padded so the pages list in their order. */
172
+ const lfsPageKey = (page) => ({
173
+ collection: collections.imports,
174
+ id: `lfs/${String(page).padStart(6, "0")}`
175
+ });
176
+ const lfsPageRow = (page, pointers) => ({
177
+ ...lfsPageKey(page),
178
+ value: { pointers: Base64.encode(pointers) }
179
+ });
180
+ /**
181
+ * The most pages of LFS pointers an import keeps, 4,194,304 pointers: each unread one is a key
182
+ * the commit that ends the import deletes, beside the tips' pages, within its 10,000 writes.
183
+ * Pointers a segment finds past it are counted `missing`, unnamed.
184
+ */
185
+ const importLfsPagesMost = 4096;
186
+ const lfsPageKeys = (from, to) => Array.from({ length: Math.max(0, to - from) }, (_, at) => lfsPageKey(from + at));
187
+ /**
188
+ * The most LFS objects an import's record names as missing, `imports/lfs-missing/<oid>`: past it
189
+ * they're counted, not named, so an import of a source missing many keeps a bounded record.
190
+ */
191
+ const importLfsMissedMost = 1e3;
192
+ const lfsMissedPrefix = "lfs-missing/";
193
+ /** An LFS object the source didn't give, kept by its oid once the import ends. */
194
+ const LfsMissedRow = /* @__PURE__ */ Schema.Struct({
195
+ size: Schema.Int,
196
+ reason: ImportLfsReason
197
+ });
198
+ const lfsMissedKey = (oid) => ({
199
+ collection: collections.imports,
200
+ id: `${lfsMissedPrefix}${oid}`
201
+ });
202
+ const lfsMissedRow = (missed) => ({
203
+ ...lfsMissedKey(missed.oid),
204
+ value: {
205
+ size: missed.size,
206
+ reason: missed.reason
207
+ }
208
+ });
209
+ /**
210
+ * What a step's `missed` adds to the record's `lfs`, `held` the oids it names already: each new
211
+ * one counted once and named, while the record names fewer than `importLfsMissedMost`, by its row.
212
+ * One the record names is counted no more, wherever its pointers are. Past the names, an object
213
+ * missed again on a later step counts again, since no row says it was.
214
+ */
215
+ const missedCounted = (lfs, missed, held) => {
216
+ const fresh = missed.filter(({ oid }) => !held.has(oid));
217
+ const named = fresh.slice(0, Math.max(0, importLfsMissedMost - lfs.named));
218
+ return {
219
+ missing: lfs.missing + fresh.length,
220
+ named: lfs.named + named.length,
221
+ put: named.map(lfsMissedRow)
222
+ };
223
+ };
224
+ /**
225
+ * Of `oids`, those the import's record names as missing, as the store holds them now: the copy's
226
+ * commit expects the version its step read, so a record that moved since fails it.
227
+ */
228
+ const lfsMissedHeld = /* @__PURE__ */ Effect.fnUntraced(function* (store, internalId, oids) {
229
+ if (oids.length === 0) return /* @__PURE__ */ new Set();
230
+ const snapshot = yield* storeCall(() => store.read(repoScope(internalId), oids.map(lfsMissedKey)));
231
+ return new Set(snapshot.results.flatMap(([row]) => row === void 0 ? [] : [row.id.slice(12)]));
232
+ });
233
+ const lfsPageGone = (page) => gitError("DATA_LOSS", `The import's page ${page} of LFS pointers is gone`, { hint: failedHint });
234
+ /** Page `page` of the import's LFS pointers, as the table lays them out. */
235
+ const readLfsPage = /* @__PURE__ */ Effect.fnUntraced(function* (store, internalId, page) {
236
+ const [[held] = []] = (yield* storeCall(() => store.read(repoScope(internalId), [lfsPageKey(page)]))).results;
237
+ if (held === void 0) return yield* Effect.fail(lfsPageGone(page));
238
+ const { pointers } = yield* decodeRow(LfsPage, held, `The import's LFS page ${page}`);
239
+ const bytes = Base64.decode(pointers);
240
+ return Result.isSuccess(bytes) ? bytes.success : yield* Effect.fail(lfsPageGone(page));
241
+ });
242
+ /**
136
243
  * What every end of an import deletes in the commit that ends it, publish's, a failure's and a
137
244
  * cancel's: each key it keeps only while it runs, its cut, the record of the segment `row` is
138
245
  * receiving in steps, whose keys the quarantine's clean-up takes, and the pages of tips it hasn't
@@ -141,7 +248,8 @@ const tipPageKeys = (from, to) => Array.from({ length: Math.max(0, to - from) },
141
248
  const importEndDeletes = (row) => [
142
249
  { ...cutKey },
143
250
  ...row?.receiving === void 0 ? [] : [receiveKey(row.receiving.pack)],
144
- ...tipPageKeys(row?.publishedPages ?? 0, row?.tipPages ?? 0)
251
+ ...tipPageKeys(row?.publishedPages ?? 0, row?.tipPages ?? 0),
252
+ ...lfsPageKeys(row?.lfs?.page ?? 0, row?.lfs?.pages ?? 0)
145
253
  ];
146
254
  const pageMissing = (page) => gitError("DATA_LOSS", `The import's page ${page} of tips is gone`, { hint: failedHint });
147
255
  /** Pages `from` to `to` of the import's tips, `to` left out, in one read. */
@@ -252,14 +360,44 @@ const readImport = /* @__PURE__ */ Effect.fnUntraced(function* (store, internalI
252
360
  };
253
361
  });
254
362
  /**
255
- * `JoinedCalls.importState`: the repo's import as its row and cancel row hold it, in one read, or
256
- * `undefined` for a repo no import made. A running row whose job has gone stays `running`: this
257
- * read writes nothing, where `importLive` commits it `failed`.
363
+ * `JoinedCalls.importState`: the repo's import as its row, cancel row and missed LFS objects hold
364
+ * it, in one read, or `undefined` for a repo no import made. A running row whose job has gone
365
+ * stays `running`: this read writes nothing, where `importLive` commits it `failed`.
258
366
  */
259
367
  const importStateOf = /* @__PURE__ */ Effect.fnUntraced(function* (store, internalId) {
260
- const { row, cancelled } = yield* readImport(store, internalId);
261
- if (row === void 0) return void 0;
262
- return row.state === "running" && cancelled ? "cancelled" : row.state;
368
+ const reads = [
369
+ { ...importKey },
370
+ { ...cancelKey },
371
+ {
372
+ collection: collections.imports,
373
+ prefix: lfsMissedPrefix,
374
+ limit: importLfsMissedMost
375
+ }
376
+ ];
377
+ const [[own] = [], [cancel] = [], missedRows = []] = (yield* readAsked(store, internalId, reads, [])).results;
378
+ if (own === void 0) return void 0;
379
+ const row = yield* decodeRow(ImportRow, own, "Import");
380
+ const state = row.state === "running" && cancel !== void 0 ? "cancelled" : row.state;
381
+ if (row.lfs === void 0) return { state };
382
+ const missed = [];
383
+ for (const missedRow of missedRows) {
384
+ const { size, reason } = yield* decodeRow(LfsMissedRow, missedRow, "Missed LFS object");
385
+ missed.push({
386
+ oid: missedRow.id.slice(12),
387
+ size,
388
+ reason
389
+ });
390
+ }
391
+ const { copied, bytes, missing } = row.lfs;
392
+ return {
393
+ state,
394
+ lfs: {
395
+ copied,
396
+ bytes,
397
+ missing,
398
+ missed
399
+ }
400
+ };
263
401
  });
264
402
  /** Whether the repo's `sync.import` job is waiting or running: a try is due or under way. */
265
403
  const jobLive = /* @__PURE__ */ Effect.fnUntraced(function* (store, internalId) {
@@ -298,4 +436,4 @@ const importLive = /* @__PURE__ */ Effect.fnUntraced(function* (store, internalI
298
436
  }
299
437
  return true;
300
438
  });
301
- export { ImportReceiving, ImportRow, cancelKey, cutKey, cutRow, failedHint, failedRow, importEndDeletes, importKey, importLive, importRow, importStateOf, readImport, readTipPages, stoppedTry, tipPageKey, tipPageRow, tipPagesOf, tipRowBytes };
439
+ export { ImportLfs, ImportReceiving, ImportRow, cancelKey, cutKey, cutRow, failedHint, failedRow, importEndDeletes, importKey, importLfsMissedMost, importLfsPagesMost, importLive, importRow, importStateOf, lfsMissedHeld, lfsPageKey, lfsPageRow, missedCounted, noImportLfs, readImport, readLfsPage, readTipPages, stoppedTry, tipPageKey, tipPageRow, tipPagesOf, tipRowBytes };
@@ -6,10 +6,10 @@ import { resultCall, storeCall } from "../store/errors.mjs";
6
6
  import { decodePacks } from "../store/git-store.mjs";
7
7
  import { appendEvents, decodeOutbox, outboxReads, repoEnvelope } from "../store/outbox.mjs";
8
8
  import { WholeRepo, wholeRefs } from "../store/ref-rows.mjs";
9
- import { readRecord } from "../store/repo-record.mjs";
9
+ import { readRecord, rootsOf } from "../store/repo-record.mjs";
10
10
  import { budgetedInput } from "../store/call-count.mjs";
11
11
  import { gitJob } from "../store/job-try.mjs";
12
- import { collections, jobRepo, newChangeId, repoScope } from "../store/scopes.mjs";
12
+ import { collections, jobRepo, newChangeId, repoRootsKey, repoScope } from "../store/scopes.mjs";
13
13
  import { settleName } from "../store/settle.mjs";
14
14
  import { SealedObjects } from "./view.mjs";
15
15
  import { fail } from "../contracts/result.mjs";
@@ -55,7 +55,8 @@ const indexWhole = /* @__PURE__ */ WholeRepo.mint();
55
55
  const tryReads = [
56
56
  { collection: collections.refs },
57
57
  { collection: collections.packs },
58
- indexRowKey
58
+ indexRowKey,
59
+ repoRootsKey
59
60
  ];
60
61
  /** A try's reads with `events`: the outbox a refusal's event goes to, too. */
61
62
  const eventReads = [...tryReads, ...outboxReads];
@@ -201,16 +202,17 @@ const refusedEvent = (repo, refusal) => ({
201
202
  error: refusalError(refusal)
202
203
  });
203
204
  /**
204
- * A try's read: the repo's record, refs, packs and `index` row, and with `events` the outbox, at
205
- * one version, and the step's input over them. `undefined` for a repo with no record.
205
+ * A try's read: the repo's record, refs, packs, `index` row and roots, and with `events` the
206
+ * outbox, at one version, and the step's input over them. `undefined` for a repo with no record.
206
207
  */
207
208
  const readTry = /* @__PURE__ */ Effect.fnUntraced(function* (parts, store, internalId, of) {
208
209
  const reads = keepsEvents(parts.events) ? eventReads : tryReads;
209
210
  const { record, snapshot } = yield* readRecord(store, internalId, reads);
210
211
  if (record === void 0) return void 0;
211
- const [, refRows = [], packRows = [], indexRows = [], headRows = [], cursorRows = []] = snapshot.results;
212
+ const [, refRows = [], packRows = [], indexRows = [], rootRows, headRows = [], cursorRows = []] = snapshot.results;
212
213
  const refs = yield* wholeRefs(indexWhole, refRows);
213
214
  const packs = yield* decodePacks(packRows);
215
+ const roots = yield* rootsOf(rootRows);
214
216
  const listed = {
215
217
  repo: internalId,
216
218
  version: snapshot.version,
@@ -227,6 +229,7 @@ const readTry = /* @__PURE__ */ Effect.fnUntraced(function* (parts, store, inter
227
229
  if (of.failed !== void 0 && record.deleted !== true) input.failed = of.failed;
228
230
  const [row] = indexRows;
229
231
  if (row !== void 0) input.row = row.value;
232
+ if (roots.size > 0) input.roots = [...roots];
230
233
  if (of.lastCheck === true) input.lastCheck = true;
231
234
  return {
232
235
  record,
@@ -1,17 +1,16 @@
1
1
  import { advanceName } from "../store/queue-jobs.mjs";
2
- import { mirrorJobName } from "../store/records.mjs";
3
2
  // src/core/job-view.ts
4
3
  /**
5
4
  * The job kinds in a repo's scope that a caller who doesn't see every ref may see, each keyed by
6
- * the ref it's of: a mirror's ref, and an advance's target. Such a caller sees one only when it
7
- * sees the ref. Deny by default: every other kind, and any kind added later that isn't here, is
8
- * seen only by a caller who sees every ref (#2195). A candidate's build and timeout name its ref
9
- * under `refs/queue/` (Q749), a trim its target or the ID it trimmed up to, and a job over the
10
- * whole repo, its upkeep's, its index builds', its listing's or its import's, may say in its
11
- * failure or progress how big the repo is, which a hidden push moves. A delivery's job,
12
- * `git.deliver.<name>`, a hidden push alone saves.
5
+ * the ref it's of: an advance's target. Such a caller sees one only when it sees the ref. Deny by
6
+ * default: every other kind, and any kind added later that isn't here, is seen only by a caller
7
+ * who sees every ref (#2195). A candidate's build and timeout name its ref under `refs/queue/`
8
+ * (Q749), a trim its target or the ID it trimmed up to, a mirror's job pushes each ref its
9
+ * destination's mirrors name, and a job over the whole repo, its upkeep's, its index builds', its
10
+ * listing's or its import's, may say in its failure or progress how big the repo is, which a
11
+ * hidden push moves. A delivery's job, `git.deliver.<name>`, a hidden push alone saves.
13
12
  */
14
- const refKeyed = /* @__PURE__ */ new Set([mirrorJobName, advanceName]);
13
+ const refKeyed = /* @__PURE__ */ new Set([advanceName]);
15
14
  /**
16
15
  * Whether a caller with `refView` sees `job`: `list`, `retry` and `discard` answer one it doesn't
17
16
  * as a missing one, and the event stream leaves out its `repo.work.failed`.
@@ -1,18 +1,33 @@
1
1
  import { MirrorPause, MirrorPush, SyncSource } from "../contracts/sync.mjs";
2
+ import { Sha256 } from "../protocol/bytes/sha256.mjs";
3
+ import { utf8 } from "../protocol/bytes/text.mjs";
2
4
  import { SavedCaller } from "./saved-callers.mjs";
3
5
  import * as Schema from "effect/Schema";
4
6
  // src/core/mirror-rows.ts
5
7
  /**
6
8
  * A mirror's row in `mirrors`, by its ref's full name: where it pushes, by provider name, whether
7
- * it's paused and why, `lastPushed`, the last push the destination took, and `by`, who saved it,
8
- * whom each try asks again before it reads the ref. A push that moves the ref saves the mirror's
9
- * job while it's `active`.
9
+ * it's paused and why, `deletes` when the upstream's ref goes once the ref here does, `lastPushed`,
10
+ * the last push the destination took, and `by`, who saved it, whom each try asks again before it
11
+ * reads the ref. A push that moves the ref, or deletes it, saves its destination's job while it's
12
+ * `active`.
10
13
  */
11
14
  const MirrorRow = /* @__PURE__ */ Schema.Struct({
12
15
  destination: SyncSource,
13
16
  state: Schema.Literals(["active", "paused"]),
14
17
  paused: Schema.optionalKey(MirrorPause),
18
+ deletes: Schema.optionalKey(Schema.Literal(true)),
15
19
  lastPushed: Schema.optionalKey(MirrorPush),
16
20
  by: SavedCaller
17
21
  });
18
- export { MirrorRow };
22
+ /** `destination` as one text, its provider's length first, so no two destinations share one. */
23
+ const destinationText = ({ provider, repo }) => `${provider.length}:${provider}${repo}`;
24
+ /**
25
+ * `sync.mirror`'s key for `destination`: its digest, 64 hex digits however long its `repo`, so one
26
+ * job a destination pushes each of its refs, and a key stays within a job key's bytes.
27
+ */
28
+ const mirrorJobKey = (destination) => {
29
+ const digest = new Sha256();
30
+ digest.update(utf8(destinationText(destination)));
31
+ return digest.hex();
32
+ };
33
+ export { MirrorRow, destinationText, mirrorJobKey };
@@ -1,8 +1,9 @@
1
+ import { fail } from "../../contracts/result.mjs";
1
2
  import { namedCommit } from "../../engine/commits.mjs";
2
3
  import { diffTrees } from "../../engine/diff.mjs";
3
4
  import { fromDiff } from "../../engine/failures.mjs";
4
5
  import { mergeBases } from "../../engine/merge-bases.mjs";
5
- import { badCursor, deadlineOf, limitsOf, timed } from "../../engine/reads.mjs";
6
+ import { badCursor, deadlineOf, limitsOf, logLimitMost, timed } from "../../engine/reads.mjs";
6
7
  import { countHistory, walkHistory, walkPath } from "../../engine/walk.mjs";
7
8
  import { isOid } from "../../protocol/bytes/text.mjs";
8
9
  import { ReadTally } from "../../protocol/diff/read.mjs";
@@ -13,6 +14,8 @@ import { linesOf } from "./lines.mjs";
13
14
  import { notAnOid, treeish } from "./trees.mjs";
14
15
  import * as Effect from "effect/Effect";
15
16
  // src/core/objects/commits.ts
17
+ /** A log that names both `exclude` and `path`, which no walk here lists together. */
18
+ const excludeWithPath = () => fail("INVALID_ARGUMENT", "A log takes `exclude` or `path`, not both", { hint: "List the range without `path`, or the path without `exclude`" });
16
19
  /**
17
20
  * `commits.*`: a commit, a history, merge bases, a diff and a comparison, each over the commits
18
21
  * its revisions named when its first page opened. A later page's cursor holds those commits, so
@@ -31,18 +34,25 @@ const commitCalls = (bound) => {
31
34
  return yield* timed(commit, deadline);
32
35
  }, Effect.scoped),
33
36
  list: Effect.fnUntraced(function* (repo, input) {
34
- const digest = yield* heldDigest("commits.list", [input.ref, input.path ?? ""]);
35
- const held = yield* heldOf(input.page?.after, digest, 1);
36
- const opened = yield* openRead(callerOf(input), repo, held?.oids ?? [input.ref], input.internalId);
37
+ const exclude = input.exclude ?? [];
38
+ if (exclude.length > 0 && input.path !== void 0) return yield* excludeWithPath();
39
+ const digest = yield* heldDigest("commits.list", [
40
+ input.ref,
41
+ input.path ?? "",
42
+ ...exclude.map((revision) => `^${revision}`)
43
+ ]);
44
+ const held = yield* heldOf(input.page?.after, digest, 1 + exclude.length);
45
+ const opened = yield* openRead(callerOf(input), repo, held?.oids ?? [input.ref, ...exclude], input.internalId);
37
46
  const tips = opened.oids;
38
- const [tip = ""] = tips;
47
+ const [tip = "", ...haves] = tips;
39
48
  const page = innerPage(input.page, held);
40
49
  const { read, roots } = opened;
41
50
  const listing = input.path === void 0 ? yield* walkHistory(read, {
42
51
  ...input,
43
52
  wants: [tip],
53
+ haves,
44
54
  page
45
- }, void 0, roots) : yield* walkPath(read, {
55
+ }, void 0, roots, logLimitMost) : yield* walkPath(read, {
46
56
  ...input,
47
57
  want: tip,
48
58
  path: input.path,
@@ -1,5 +1,4 @@
1
1
  import { Authorize } from "../contracts/authorize.mjs";
2
- import "../contracts/actors.mjs";
3
2
  import { AccessOption } from "../contracts/access.mjs";
4
3
  import { EffectiveLimits } from "../contracts/objects.mjs";
5
4
  import { JobQueue as JobQueue$1, RecordStore } from "../contracts/promises.mjs";
@@ -10,6 +9,8 @@ import { EventLog } from "../contracts/events.mjs";
10
9
  import { HiddenRefs } from "../protocol/wire/lines.mjs";
11
10
  import { IndexLost } from "./index-lost.mjs";
12
11
  import { PushChecks } from "./access.mjs";
12
+ import { PushFiles } from "./push-files.mjs";
13
+ import { PushRepo } from "./push-repo.mjs";
13
14
  import { RefIndex } from "./ref-index.mjs";
14
15
  import { SealedObjects } from "./view.mjs";
15
16
  import { Changes } from "./changes.mjs";
@@ -128,6 +129,10 @@ export interface ObjectsFields {
128
129
  * fetch by them. Upkeep's `RepackParts` carry them too, for a deleted repo's `leaving` rows.
129
130
  */
130
131
  readonly fetchLimits: EffectiveLimits;
132
+ /** The server's `pushes.files`, resolved: GitHub's sizes, `defaultPushFiles`, when left out. */
133
+ readonly files?: PushFiles;
134
+ /** The server's `pushes.repo`, resolved: GitHub's, `defaultPushRepo`, when left out. */
135
+ readonly repo?: PushRepo;
131
136
  }
132
137
  declare const ObjectsParts_base: Context.ServiceClass<ObjectsParts, "@ref0/git/core/ObjectsParts", ObjectsFields>;
133
138
  /** The server's sealed objects, which each boundary provides beside `CoreParts`. */
@@ -1,6 +1,5 @@
1
1
  import { Authorize } from "../contracts/authorize.mjs";
2
2
  import { hostAuthorize } from "../auth/authorize.mjs";
3
- import { isHost } from "../contracts/git.mjs";
4
3
  import { Changes } from "./changes.mjs";
5
4
  import { Objects } from "./objects/objects.mjs";
6
5
  import { Rules } from "../contracts/rules.mjs";
@@ -54,8 +53,6 @@ const asHost = (effect) => effect.pipe(decidingWith(hostAuthorize), Effect.updat
54
53
  ...Struct.omit(parts, ["access"]),
55
54
  host: true
56
55
  })));
57
- /** `effect` as `by` makes it: host code's, as `asHost` says, when `by` is `Git.host`. */
58
- const acting = (by, effect) => isHost(by) ? asHost(effect) : effect;
59
56
  /** Core's binding and one push's ref bound, given to Sync.layer as it builds. */
60
57
  var SyncBase = class extends (/* @__PURE__ */ Context.Service()("@ref0/git/SyncBase")) {};
61
- export { CoreParts, ObjectsParts, QueueParts, SyncBase, acting, asHost, coreContext, decidingWith, overStore };
58
+ export { CoreParts, ObjectsParts, QueueParts, SyncBase, asHost, coreContext, decidingWith, overStore };
@@ -8,11 +8,11 @@ import { outboxCollections } from "../store/outbox.mjs";
8
8
  import { keyKept } from "../store/records.mjs";
9
9
  import { readRecord } from "../store/repo-record.mjs";
10
10
  import { collections, newChangeId, repoScope } from "../store/scopes.mjs";
11
- import { isDeliverJob, sentThrough } from "./events/deliver.mjs";
11
+ import { isDeliverJob, isStrayDelivery, sentThrough } from "./events/deliver.mjs";
12
12
  import { indexJobName } from "./index-job.mjs";
13
13
  import * as Effect from "effect/Effect";
14
14
  import * as Schema from "effect/Schema";
15
- import { Job, limits } from "@ref0/infra";
15
+ import { Job, defineJob, limits } from "@ref0/infra";
16
16
  // src/core/purge.ts
17
17
  /**
18
18
  * `git.purge`, a deleted repo's last job (L61, L130). Not before its delete's `fetchLimits` has
@@ -39,6 +39,11 @@ const purgeBackstop = 6e5;
39
39
  */
40
40
  const purgeRunningRelook = 6e4;
41
41
  /**
42
+ * The lease a purge claims a stray delivery's waiting job under, only to settle it done in the
43
+ * same try: no handler runs under it.
44
+ */
45
+ const strayLease = "1 minute";
46
+ /**
42
47
  * A step's page where its rows passed one read's `limits.answerBytes`, as object rows can: rows
43
48
  * of `limits.valueBytes` each fill half an answer.
44
49
  */
@@ -49,7 +54,9 @@ const purgeLargePage = /* @__PURE__ */ Math.floor(limits.answerBytes / limits.va
49
54
  * deletes its index's files, and each delivery's, `git.deliver.<name>`, sends `repo.deleted`. A
50
55
  * failed one holds the purge until a host retries or discards it. A delivery's waiting job that
51
56
  * has sent `repo.deleted` holds it no longer, since it waits only to trim events the purge
52
- * deletes itself. A new job that deletes a repo's bytes joins this list, or its check below.
57
+ * deletes itself. A stray's, a delivery the server no longer runs, holds it only `purgeBackstop`
58
+ * past its own time, while an instance that still runs it, in a deploy, may claim it; then the
59
+ * purge ends it. A new job that deletes a repo's bytes joins this list, or its check below.
53
60
  * Every other job ends on the record the purge deletes last: git.list's projection the purge runs
54
61
  * itself before it.
55
62
  */
@@ -122,11 +129,24 @@ const relookFor = (item, at) => {
122
129
  return item.state === "waiting" ? Math.max(item.due, at + purgeRunningRelook) : at + purgeRunningRelook;
123
130
  };
124
131
  /**
132
+ * When a stray delivery's job, one the server no longer runs, stops holding the purge:
133
+ * `purgeBackstop` past its due, or past its failure, by which an instance that still runs it would
134
+ * have claimed it.
135
+ *
136
+ * Which delivery is stray is this instance's own list, and the time is the row's, not the
137
+ * deploy's. In a rolling deploy that drops a delivery, a new instance purges at once a repo already
138
+ * deleted whose job of it is overdue or failed past `purgeBackstop`, within seconds of starting, and
139
+ * an old instance that still runs the delivery loses that repo's `repo.deleted`. So can one whose
140
+ * claim, or a host's retry, lands between a step's read and its deletes, which no store call fences.
141
+ */
142
+ const strayEnd = (item) => (item.state === "failed" ? item.failedAt ?? item.due : item.due) + purgeBackstop;
143
+ /**
125
144
  * When a purge at `at` looks again for the drain jobs and deliveries waiting, running or failed in
126
145
  * `scope`, the soonest of theirs: none when none is left. A page of its jobs at a time. `deleted`
127
146
  * is `repo.deleted`'s `seq`, past which a waiting delivery holds nothing; with none, each holds.
147
+ * A stray delivery's job holds only till its `strayEnd`, unless it runs.
128
148
  */
129
- const draining = /* @__PURE__ */ Effect.fnUntraced(function* (store, scope, at, deleted) {
149
+ const draining = /* @__PURE__ */ Effect.fnUntraced(function* (store, scope, at, deleted, deliveries) {
130
150
  let after;
131
151
  let soonest;
132
152
  for (;;) {
@@ -136,7 +156,9 @@ const draining = /* @__PURE__ */ Effect.fnUntraced(function* (store, scope, at,
136
156
  const delivery = isDeliverJob(item);
137
157
  if (!drainJobs.has(item.name) && !delivery) continue;
138
158
  if (delivery && item.state === "waiting" && deleted !== void 0 && (yield* sentThrough(store, scope, item, deleted))) continue;
139
- const relook = relookFor(item, at);
159
+ const ends = item.state !== "running" && isStrayDelivery(item, deliveries) ? strayEnd(item) : void 0;
160
+ if (ends !== void 0 && ends <= at) continue;
161
+ const relook = ends ?? relookFor(item, at);
140
162
  soonest = soonest === void 0 ? relook : Math.min(soonest, relook);
141
163
  }
142
164
  if (listing.next === void 0) return soonest;
@@ -216,6 +238,53 @@ const dropScopes = /* @__PURE__ */ Effect.fnUntraced(function* (parts, store, in
216
238
  for (const scope of [...named, repoScope(internalId)]) yield* storeCall(() => store.drop(scope));
217
239
  });
218
240
  /**
241
+ * A stray delivery's waiting job made due at `at`: a save moves a waiting job's due only earlier,
242
+ * so a claim takes it. Its handler never runs, since no queue of this server runs its delivery.
243
+ */
244
+ const strayDueAt = (item, at) => defineJob({
245
+ name: item.name,
246
+ schema: Schema.toStandardSchemaV1(Schema.Unknown),
247
+ handler: () => {
248
+ throw new TypeError(`${item.name} is a delivery this server doesn't run`);
249
+ }
250
+ }).job({
251
+ key: item.key,
252
+ data: item.data,
253
+ at
254
+ });
255
+ /**
256
+ * The waiting jobs left in `scope` of deliveries the server doesn't run, each claimed and settled
257
+ * done, a page of them at a time: no queue of this server claims one, and their repo is gone.
258
+ * `draining` let each go past its `strayEnd`, or once it had sent `repo.deleted`, when it may
259
+ * wait for a trim due long after `at`: such a job is made due at `at` first, so the claim takes
260
+ * it, as `sqlite()`'s and `postgres()`'s drop would leave it.
261
+ */
262
+ const endStrays = /* @__PURE__ */ Effect.fnUntraced(function* (store, scope, at, deliveries) {
263
+ let after;
264
+ for (;;) {
265
+ const page = after === void 0 ? {} : { page: { after } };
266
+ const listing = yield* storeCall(() => store.list(scope, {
267
+ state: "waiting",
268
+ ...page
269
+ }));
270
+ const strays = listing.items.filter((item) => isStrayDelivery(item, deliveries));
271
+ const names = strays.map((item) => item.name);
272
+ const later = strays.flatMap((item) => item.due > at ? [strayDueAt(item, at)] : []);
273
+ if (later.length > 0) yield* storeCall(() => store.add(scope, { jobs: later }));
274
+ if (names.length > 0) {
275
+ const request = {
276
+ lease: strayLease,
277
+ names,
278
+ limit: names.length
279
+ };
280
+ const { claims } = yield* storeCall(() => store.claim(scope, request));
281
+ yield* Effect.forEach(claims, (claim) => storeCall(() => store.settle(claim, { kind: "done" })), { discard: true });
282
+ }
283
+ if (listing.next === void 0) return;
284
+ after = listing.next;
285
+ }
286
+ });
287
+ /**
219
288
  * One step in the repo's scope: none for a repo that isn't deleted. It waits until its delete's
220
289
  * `fetchLimits` has passed, nor while a receipt it holds still answers, `keyKept` past the delete;
221
290
  * then while a drain job or a drained row stands, or a fork holds the
@@ -255,7 +324,7 @@ const purgeStep = /* @__PURE__ */ Effect.fnUntraced(function* (parts, store, int
255
324
  at: at + purgeBackstop
256
325
  };
257
326
  const deleted = record.nextSeq === void 0 ? void 0 : record.nextSeq - 1;
258
- const drain = yield* draining(store, scope, at, deleted);
327
+ const drain = yield* draining(store, scope, at, deleted, parts.deliveries);
259
328
  if (drain !== void 0) return {
260
329
  ...again,
261
330
  at: drain
@@ -280,6 +349,7 @@ const purgeStep = /* @__PURE__ */ Effect.fnUntraced(function* (parts, store, int
280
349
  yield* reconcile(store, internalId);
281
350
  if (!(yield* releaseHold(store, internalId, record))) return again;
282
351
  yield* discardFailed(store, scope);
352
+ yield* endStrays(store, scope, at, parts.deliveries);
283
353
  const own = yield* pageOf(store, scope, collections.repo);
284
354
  if (own.version !== version) return again;
285
355
  if (!(yield* storeCall(() => store.commit(scope, {
@@ -11,7 +11,7 @@ import { jsonBytes, limits } from "@ref0/infra";
11
11
  const pushRefLimit = 4e3;
12
12
  /**
13
13
  * What a push at `pushRefLimit` leaves of a commit's writes for its other rows: 2,000. Its mirror
14
- * jobs, `mirrorLimits.mirrors` at most, its `git.queue.advance` jobs, one a moved target and
14
+ * jobs, one a destination and `mirrorLimits.mirrors` at most, its `git.queue.advance` jobs, one a moved target and
15
15
  * `queueLimits.targets` at most, its delivery jobs, one a delivery and `deliveryLimit` at most,
16
16
  * and its fixed rows stay within it by construction.
17
17
  */
@@ -0,0 +1,12 @@
1
+ import "../contracts/ids.mjs";
2
+ import "../contracts/objects.mjs";
3
+ import "../contracts/push-uploads.mjs";
4
+ import "../contracts/result.mjs";
5
+ import "../store/call-count.mjs";
6
+ import "./ancestry.mjs";
7
+ import "effect/Effect";
8
+ /** A server's sizes for a pushed file, `pushes.files` resolved: a warning only when there's one. */
9
+ export interface PushFiles {
10
+ readonly warnAbove: number | undefined;
11
+ readonly refuseAbove: number;
12
+ }