@ref0/git 0.20.0 → 0.26.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 (379) hide show
  1. package/dist/access/private-refs.mjs +1 -1
  2. package/dist/auth/access-jwt.mjs +3 -3
  3. package/dist/auth/auth-namespace.d.mts +3 -3
  4. package/dist/auth/auth-namespace.mjs +3 -2
  5. package/dist/auth/auth.d.mts +3 -3
  6. package/dist/auth/auth.mjs +9 -8
  7. package/dist/auth/authorize.mjs +1 -1
  8. package/dist/auth/fences.d.mts +1 -1
  9. package/dist/auth/host-function.mjs +1 -1
  10. package/dist/auth/host-services.mjs +4 -6
  11. package/dist/auth/identify.d.mts +1 -1
  12. package/dist/auth/identify.mjs +6 -0
  13. package/dist/auth/token-cleanup.mjs +2 -2
  14. package/dist/auth/token-rows.mjs +6 -1
  15. package/dist/auth/token-text.mjs +1 -1
  16. package/dist/auth/tokens-base.d.mts +1 -1
  17. package/dist/auth/tokens.d.mts +1 -1
  18. package/dist/auth/tokens.mjs +1 -1
  19. package/dist/client/client.d.mts +15 -7
  20. package/dist/client/client.mjs +21 -12
  21. package/dist/client/git-http.mjs +1 -1
  22. package/dist/client/local.mjs +60 -24
  23. package/dist/client/negotiate.mjs +3 -3
  24. package/dist/client/push-upload.mjs +26 -10
  25. package/dist/client/remote.mjs +4 -3
  26. package/dist/client/run-remote-helper.d.mts +2 -2
  27. package/dist/client/run-remote-helper.mjs +6 -6
  28. package/dist/client/slice-push.d.mts +1 -1
  29. package/dist/client/transport.mjs +3 -3
  30. package/dist/contracts/blobs.d.mts +3 -3
  31. package/dist/contracts/blobs.mjs +1 -1
  32. package/dist/contracts/calls-spent.mjs +5 -33
  33. package/dist/contracts/client.d.mts +15 -14
  34. package/dist/contracts/commits.d.mts +4 -4
  35. package/dist/contracts/commits.mjs +1 -1
  36. package/dist/contracts/engine.d.mts +2 -2
  37. package/dist/contracts/events.d.mts +1 -1
  38. package/dist/contracts/events.mjs +1 -1
  39. package/dist/contracts/files.d.mts +4 -4
  40. package/dist/contracts/files.mjs +1 -1
  41. package/dist/contracts/forks.d.mts +4 -4
  42. package/dist/contracts/forks.mjs +1 -1
  43. package/dist/contracts/git-hooks.d.mts +1 -1
  44. package/dist/contracts/git.d.mts +9 -5
  45. package/dist/contracts/grants.d.mts +1 -1
  46. package/dist/contracts/merges.d.mts +1 -1
  47. package/dist/contracts/object-values.d.mts +1 -0
  48. package/dist/contracts/object-values.mjs +16 -1
  49. package/dist/contracts/objects.d.mts +30 -18
  50. package/dist/contracts/opaque.mjs +1 -1
  51. package/dist/contracts/operations.mjs +1 -1
  52. package/dist/contracts/queue.d.mts +208 -44
  53. package/dist/contracts/queue.mjs +5 -5
  54. package/dist/contracts/refs.d.mts +5 -5
  55. package/dist/contracts/refs.mjs +1 -1
  56. package/dist/contracts/remote.d.mts +3 -6
  57. package/dist/contracts/repos.d.mts +3 -3
  58. package/dist/contracts/repos.mjs +1 -1
  59. package/dist/contracts/result.d.mts +10 -7
  60. package/dist/contracts/result.mjs +8 -3
  61. package/dist/contracts/rules.d.mts +13 -12
  62. package/dist/contracts/server.d.mts +8 -10
  63. package/dist/contracts/services.d.mts +6 -9
  64. package/dist/contracts/services.mjs +1 -2
  65. package/dist/contracts/signin.d.mts +1 -1
  66. package/dist/contracts/store.d.mts +2 -2
  67. package/dist/contracts/sync.d.mts +63 -6
  68. package/dist/contracts/sync.mjs +3 -2
  69. package/dist/contracts/tags.d.mts +3 -3
  70. package/dist/contracts/tags.mjs +1 -1
  71. package/dist/contracts/tokens.d.mts +2 -2
  72. package/dist/contracts/tokens.mjs +1 -1
  73. package/dist/contracts/topics.d.mts +9 -9
  74. package/dist/contracts/trees.d.mts +4 -4
  75. package/dist/contracts/trees.mjs +1 -1
  76. package/dist/contracts/work.d.mts +4 -4
  77. package/dist/contracts/work.mjs +2 -2
  78. package/dist/core/access.d.mts +1 -1
  79. package/dist/core/ancestry.mjs +30 -34
  80. package/dist/core/{promise.mjs → call-groups.mjs} +7 -30
  81. package/dist/core/call-services.mjs +1 -1
  82. package/dist/core/events/deliver.d.mts +2 -2
  83. package/dist/core/events/deliver.mjs +3 -3
  84. package/dist/core/events/retired.mjs +1 -1
  85. package/dist/core/forks.mjs +5 -5
  86. package/dist/core/hooks/groups.mjs +2 -2
  87. package/dist/core/imports.mjs +101 -21
  88. package/dist/core/index-job.mjs +14 -9
  89. package/dist/core/index-lost.d.mts +1 -1
  90. package/dist/core/loose-tally.mjs +38 -15
  91. package/dist/core/merge-parts.d.mts +17 -4
  92. package/dist/core/merge-parts.mjs +7 -2
  93. package/dist/core/mirror-rows.mjs +31 -1
  94. package/dist/core/objects/blobs.mjs +8 -10
  95. package/dist/core/objects/files.mjs +20 -17
  96. package/dist/core/objects/objects-layer.mjs +1 -1
  97. package/dist/core/objects/peel.mjs +1 -7
  98. package/dist/core/objects/reading.mjs +19 -18
  99. package/dist/core/objects/tree-edits.mjs +1 -1
  100. package/dist/core/objects/trees.mjs +257 -58
  101. package/dist/core/objects/writing.mjs +3 -9
  102. package/dist/core/own-writes.mjs +1 -1
  103. package/dist/core/parts.d.mts +8 -1
  104. package/dist/core/parts.mjs +8 -4
  105. package/dist/core/purge.mjs +31 -18
  106. package/dist/core/push.d.mts +2 -2
  107. package/dist/core/push.mjs +145 -98
  108. package/dist/core/receipts.d.mts +2 -2
  109. package/dist/core/receipts.mjs +9 -2
  110. package/dist/core/ref-index-job.mjs +4 -4
  111. package/dist/core/ref-view.mjs +74 -31
  112. package/dist/core/refs.mjs +3 -3
  113. package/dist/core/repack.mjs +25 -30
  114. package/dist/core/repo-info.mjs +1 -1
  115. package/dist/core/repos.mjs +1 -1
  116. package/dist/core/rules/changes.mjs +18 -40
  117. package/dist/core/rules/check.mjs +6 -5
  118. package/dist/core/rules/commit-changes.mjs +114 -58
  119. package/dist/core/rules/context.d.mts +3 -3
  120. package/dist/core/rules/context.mjs +18 -14
  121. package/dist/core/rules/fetch.mjs +1 -1
  122. package/dist/core/rules/protect.mjs +30 -17
  123. package/dist/core/saved-caller-views.d.mts +1 -1
  124. package/dist/core/saved-caller-views.mjs +3 -3
  125. package/dist/core/saved-callers.d.mts +1 -1
  126. package/dist/core/saved-callers.mjs +1 -1
  127. package/dist/core/seam.d.mts +1 -2
  128. package/dist/core/view.d.mts +6 -3
  129. package/dist/core/view.mjs +11 -10
  130. package/dist/core/work.mjs +2 -2
  131. package/dist/engine/allotted-xdiff.mjs +3 -16
  132. package/dist/engine/combined.d.mts +3 -0
  133. package/dist/engine/combined.mjs +200 -185
  134. package/dist/engine/content.d.mts +2 -2
  135. package/dist/engine/content.mjs +1 -1
  136. package/dist/engine/merge.mjs +7 -9
  137. package/dist/engine/reads.d.mts +2 -2
  138. package/dist/engine/reads.mjs +22 -14
  139. package/dist/engine/xdiff.d.mts +1 -1
  140. package/dist/engine/xdiff.mjs +1 -1
  141. package/dist/event-streams/event-streams.d.mts +1 -1
  142. package/dist/event-streams/event-streams.mjs +1 -1
  143. package/dist/event-streams/stream.d.mts +2 -2
  144. package/dist/event-streams/stream.mjs +3 -3
  145. package/dist/extend.d.mts +2 -6
  146. package/dist/extend.mjs +1 -5
  147. package/dist/http/core-parts.mjs +83 -26
  148. package/dist/http/handler.mjs +54 -9
  149. package/dist/http/parts.d.mts +1 -0
  150. package/dist/http/push-upload-job.mjs +138 -24
  151. package/dist/http/push-uploads.mjs +2 -2
  152. package/dist/http/receive-pack.mjs +14 -53
  153. package/dist/http/request-snapshot.mjs +258 -0
  154. package/dist/http/upload-pack.mjs +23 -18
  155. package/dist/index.d.mts +29 -21
  156. package/dist/index.mjs +11 -2
  157. package/dist/lfs/base.d.mts +1 -1
  158. package/dist/lfs/copy.d.mts +49 -1
  159. package/dist/lfs/copy.mjs +135 -22
  160. package/dist/lfs/layer.d.mts +4 -3
  161. package/dist/lfs/layer.mjs +4 -5
  162. package/dist/lfs/locks.mjs +2 -2
  163. package/dist/lfs/objects.d.mts +1 -1
  164. package/dist/lfs/objects.mjs +3 -3
  165. package/dist/lfs/pointers.mjs +1 -1
  166. package/dist/lfs/rows.d.mts +1 -1
  167. package/dist/lfs/rows.mjs +11 -4
  168. package/dist/lfs/upkeep.mjs +40 -9
  169. package/dist/lfs/uploaded.mjs +1 -1
  170. package/dist/lfs/wire.mjs +1 -1
  171. package/dist/merges/merges.mjs +17 -2
  172. package/dist/protocol/bytes/buffers.d.mts +1 -1
  173. package/dist/protocol/bytes/buffers.mjs +1 -1
  174. package/dist/protocol/bytes/deflate.d.mts +1 -1
  175. package/dist/protocol/bytes/deflate.mjs +1 -1
  176. package/dist/protocol/bytes/inflate.d.mts +1 -1
  177. package/dist/protocol/bytes/inflate.mjs +1 -1
  178. package/dist/protocol/bytes/sha1.d.mts +1 -1
  179. package/dist/protocol/bytes/sha1.mjs +1 -1
  180. package/dist/protocol/diff/read.d.mts +2 -1
  181. package/dist/protocol/diff/read.mjs +102 -8
  182. package/dist/protocol/packs/graph.mjs +1 -1
  183. package/dist/protocol/packs/idx.d.mts +1 -1
  184. package/dist/protocol/packs/idx.mjs +1 -1
  185. package/dist/protocol/packs/parts.mjs +1 -1
  186. package/dist/protocol/packs/reader.d.mts +1 -1
  187. package/dist/protocol/packs/reader.mjs +1 -1
  188. package/dist/protocol/packs/write-error.d.mts +1 -1
  189. package/dist/protocol/packs/write-error.mjs +1 -1
  190. package/dist/protocol/packs/writer.mjs +3 -3
  191. package/dist/protocol/wire/advertisement.d.mts +1 -1
  192. package/dist/protocol/wire/advertisement.mjs +3 -2
  193. package/dist/protocol/wire/fetch.d.mts +1 -1
  194. package/dist/protocol/wire/fetch.mjs +1 -1
  195. package/dist/protocol/wire/lines.d.mts +9 -1
  196. package/dist/protocol/wire/lines.mjs +28 -1
  197. package/dist/protocol/wire/push-uploads.mjs +10 -7
  198. package/dist/protocol/wire/receive-pack.d.mts +1 -1
  199. package/dist/protocol/wire/receive-pack.mjs +1 -1
  200. package/dist/protocol/wire/report-status.d.mts +1 -1
  201. package/dist/protocol/wire/report-status.mjs +1 -1
  202. package/dist/protocol/wire/v2.d.mts +1 -1
  203. package/dist/protocol/wire/v2.mjs +1 -1
  204. package/dist/queue/advance.mjs +31 -24
  205. package/dist/queue/base.d.mts +5 -3
  206. package/dist/queue/calls.mjs +5 -5
  207. package/dist/queue/commit.mjs +1 -1
  208. package/dist/queue/host.d.mts +1 -1
  209. package/dist/queue/layer.d.mts +0 -1
  210. package/dist/queue/layer.mjs +9 -5
  211. package/dist/queue/schedule.mjs +1 -1
  212. package/dist/queue/search.mjs +1 -1
  213. package/dist/queue/state.mjs +1 -1
  214. package/dist/queue/trim.mjs +2 -2
  215. package/dist/rest/client.d.mts +1 -1
  216. package/dist/rest/client.mjs +6 -6
  217. package/dist/rest/errors.mjs +1 -1
  218. package/dist/rest/handler.mjs +2 -2
  219. package/dist/rest/handlers.mjs +16 -6
  220. package/dist/rest/layer.mjs +1 -1
  221. package/dist/rest/listen.mjs +2 -2
  222. package/dist/rest/refs.mjs +1 -1
  223. package/dist/server/edge.mjs +27 -3
  224. package/dist/server/git-layer.d.mts +1 -2
  225. package/dist/server/git-layer.mjs +4 -5
  226. package/dist/server/lifecycle.mjs +1 -1
  227. package/dist/server/registry.mjs +2 -8
  228. package/dist/server/server.mjs +62 -43
  229. package/dist/signin/context.d.mts +1 -1
  230. package/dist/signin/context.mjs +1 -1
  231. package/dist/signin/forms.mjs +1 -1
  232. package/dist/signin/grants.d.mts +2 -2
  233. package/dist/signin/grants.mjs +1 -1
  234. package/dist/signin/wire.mjs +1 -1
  235. package/dist/storage/allotted.mjs +4 -9
  236. package/dist/storage/batch-upkeep.mjs +31 -12
  237. package/dist/storage/batches.d.mts +2 -3
  238. package/dist/storage/batches.mjs +52 -49
  239. package/dist/storage/budget.mjs +23 -1
  240. package/dist/storage/calls.d.mts +1 -1
  241. package/dist/storage/calls.mjs +41 -43
  242. package/dist/storage/charged-cache.mjs +180 -0
  243. package/dist/storage/chunks.d.mts +3 -3
  244. package/dist/storage/chunks.mjs +121 -8
  245. package/dist/storage/counted-bucket.mjs +32 -10
  246. package/dist/storage/fetch-row-cache.d.mts +6 -0
  247. package/dist/storage/fetch-row-cache.mjs +211 -0
  248. package/dist/storage/fetch.d.mts +1 -0
  249. package/dist/storage/fetch.mjs +54 -242
  250. package/dist/storage/held-types.d.mts +0 -1
  251. package/dist/storage/held-types.mjs +13 -4
  252. package/dist/storage/host-bucket.mjs +9 -4
  253. package/dist/storage/index-bitmaps.mjs +340 -65
  254. package/dist/storage/index-build.d.mts +2 -3
  255. package/dist/storage/index-build.mjs +274 -56
  256. package/dist/storage/index-fetch.d.mts +3 -1
  257. package/dist/storage/index-fetch.mjs +60 -21
  258. package/dist/storage/index-graph.mjs +1 -1
  259. package/dist/storage/index-layers.mjs +55 -25
  260. package/dist/storage/index-reach.mjs +15 -22
  261. package/dist/storage/index-whole.d.mts +7 -0
  262. package/dist/storage/index-whole.mjs +145 -37
  263. package/dist/storage/largest-files.mjs +1 -7
  264. package/dist/storage/layout.mjs +17 -1
  265. package/dist/storage/lfs-pointers.mjs +1 -6
  266. package/dist/storage/link-join.mjs +55 -16
  267. package/dist/storage/list-source.d.mts +7 -0
  268. package/dist/storage/list-source.mjs +288 -0
  269. package/dist/storage/loose.d.mts +8 -8
  270. package/dist/storage/loose.mjs +157 -91
  271. package/dist/storage/memory-budget.mjs +226 -22
  272. package/dist/storage/merge-cut.mjs +9 -6
  273. package/dist/storage/merge-fence.mjs +1 -1
  274. package/dist/storage/merge-row.mjs +1 -1
  275. package/dist/storage/merge.d.mts +2 -3
  276. package/dist/storage/merge.mjs +2 -2
  277. package/dist/storage/object-rows.d.mts +3 -3
  278. package/dist/storage/object-rows.mjs +179 -38
  279. package/dist/storage/pack-order.mjs +97 -44
  280. package/dist/storage/pack-ranges.mjs +44 -16
  281. package/dist/storage/pack-reads.d.mts +5 -3
  282. package/dist/storage/pack-reads.mjs +236 -72
  283. package/dist/storage/pack-receive.d.mts +1 -2
  284. package/dist/storage/pack-receive.mjs +24 -18
  285. package/dist/storage/packs.d.mts +1 -1
  286. package/dist/storage/packs.mjs +477 -116
  287. package/dist/storage/placed-reads.mjs +33 -16
  288. package/dist/storage/prune-seen.mjs +1 -1
  289. package/dist/storage/prune-walk.mjs +1 -1
  290. package/dist/storage/prune.mjs +4 -31
  291. package/dist/storage/push-allotment.mjs +26 -14
  292. package/dist/storage/push-uploads.mjs +195 -57
  293. package/dist/storage/pushed-commits.mjs +20 -1
  294. package/dist/storage/quarantine.d.mts +2 -3
  295. package/dist/storage/range-cache.mjs +175 -40
  296. package/dist/storage/raw-ids.mjs +39 -10
  297. package/dist/storage/ready.d.mts +2 -3
  298. package/dist/storage/ready.mjs +114 -38
  299. package/dist/storage/receive-bounds.mjs +31 -9
  300. package/dist/storage/receive-cache.d.mts +7 -0
  301. package/dist/storage/receive-cache.mjs +147 -0
  302. package/dist/storage/receive-files.mjs +1 -1
  303. package/dist/storage/receive-links.mjs +1 -1
  304. package/dist/storage/receive-state.d.mts +2 -2
  305. package/dist/storage/receive-state.mjs +6 -8
  306. package/dist/storage/receive-steps.d.mts +20 -0
  307. package/dist/storage/receive-steps.mjs +298 -13
  308. package/dist/storage/repack-backlog.mjs +1 -6
  309. package/dist/storage/repack-contained.mjs +2 -2
  310. package/dist/storage/repack-job.mjs +1 -1
  311. package/dist/storage/repack.d.mts +2 -3
  312. package/dist/storage/repack.mjs +54 -9
  313. package/dist/storage/request-cache.mjs +57 -0
  314. package/dist/storage/roots.mjs +1 -24
  315. package/dist/storage/rows.d.mts +2 -2
  316. package/dist/storage/rows.mjs +1 -1
  317. package/dist/storage/runs.d.mts +2 -2
  318. package/dist/storage/runs.mjs +1 -1
  319. package/dist/storage/send-list.mjs +62 -25
  320. package/dist/storage/stream-whole.mjs +84 -63
  321. package/dist/storage/swap-walk.mjs +1 -1
  322. package/dist/storage/unpack.mjs +878 -450
  323. package/dist/storage/visible.mjs +110 -32
  324. package/dist/storage/walk.mjs +1 -0
  325. package/dist/storage/wants.mjs +22 -58
  326. package/dist/store/call-count.d.mts +2 -2
  327. package/dist/store/call-count.mjs +24 -11
  328. package/dist/store/catalogue.d.mts +1 -1
  329. package/dist/store/catalogue.mjs +19 -7
  330. package/dist/store/crossing.mjs +1 -7
  331. package/dist/store/cursor-seal.d.mts +1 -1
  332. package/dist/store/cursor-seal.mjs +1 -1
  333. package/dist/store/door.mjs +9 -4
  334. package/dist/store/errors.d.mts +2 -2
  335. package/dist/store/errors.mjs +107 -19
  336. package/dist/store/git-store.mjs +7 -2
  337. package/dist/store/job-try.mjs +90 -9
  338. package/dist/store/list-job.mjs +10 -34
  339. package/dist/store/outbox.d.mts +2 -2
  340. package/dist/store/outbox.mjs +2 -2
  341. package/dist/store/queue-jobs.mjs +6 -12
  342. package/dist/store/records.d.mts +2 -2
  343. package/dist/store/records.mjs +2 -2
  344. package/dist/store/ref-rows.d.mts +2 -2
  345. package/dist/store/ref-rows.mjs +2 -2
  346. package/dist/store/repo-record.d.mts +2 -2
  347. package/dist/store/repo-record.mjs +3 -3
  348. package/dist/store/request-snapshot.mjs +5 -0
  349. package/dist/store/reservations.mjs +2 -2
  350. package/dist/store/topic-jobs.mjs +5 -11
  351. package/dist/sync/bound.d.mts +3 -3
  352. package/dist/sync/bound.mjs +10 -7
  353. package/dist/sync/github.mjs +65 -67
  354. package/dist/sync/http.mjs +1 -1
  355. package/dist/sync/import.mjs +201 -66
  356. package/dist/sync/layer.d.mts +1 -1
  357. package/dist/sync/layer.mjs +6 -6
  358. package/dist/sync/lfs-batch.mjs +1 -1
  359. package/dist/sync/lfs-copy.mjs +175 -15
  360. package/dist/sync/mirror.mjs +5 -10
  361. package/dist/sync/said.mjs +1 -1
  362. package/dist/sync/step.mjs +268 -86
  363. package/dist/sync/tries.mjs +25 -6
  364. package/dist/sync.d.mts +2 -2
  365. package/dist/sync.mjs +2 -2
  366. package/dist/topics/advance.mjs +3 -3
  367. package/dist/topics/calls.mjs +1 -1
  368. package/dist/topics/layer.d.mts +15 -14
  369. package/dist/topics/members.mjs +1 -1
  370. package/dist/topics/topic.mjs +1 -1
  371. package/package.json +3 -13
  372. package/dist/auth/helpers.mjs +0 -17
  373. package/dist/auth.d.mts +0 -5
  374. package/dist/auth.mjs +0 -5
  375. package/dist/core/rules/commit-changes.d.mts +0 -12
  376. package/dist/effect.d.mts +0 -9
  377. package/dist/effect.mjs +0 -7
  378. package/dist/server/joined.d.mts +0 -70
  379. package/dist/server/joined.mjs +0 -41
@@ -5,7 +5,7 @@ import { stepEffect } from "../protocol/packs/step.mjs";
5
5
  import { basesBlock, openBases } from "./index-files.mjs";
6
6
  import { indexFiles } from "./layout.mjs";
7
7
  import { indexBytes, loadedLookup, rangedLookup } from "./pack-reads.mjs";
8
- import { openPlacedTables, placedEntries, placedEntriesBytes, placedEntriesGets, rangeRanks, searchReads } from "./pack-ranges.mjs";
8
+ import { placedEntries, placedEntriesBytes, placedEntriesGets, placedTablesOf, rangeRanks, searchReads } from "./pack-ranges.mjs";
9
9
  import { basesReadBytes, basesRuns } from "./send-list.mjs";
10
10
  import * as Effect from "effect/Effect";
11
11
  // src/storage/placed-reads.ts
@@ -151,15 +151,18 @@ const placedReads = (input) => {
151
151
  yield* spend(pack, gets);
152
152
  const bases = open ?? (yield* openBases(bucket, indexFiles(listed.repo, layer.build).bases, end));
153
153
  opened.set(layer, bases);
154
- for (const run of runs) {
155
- const bytes = basesReadBytes(run.to - run.from);
154
+ if (runs.length > 0) {
155
+ const bytes = runs.reduce((sum, run) => sum + basesReadBytes(run.to - run.from), 0);
156
156
  yield* read.hold(bytes);
157
157
  held += bytes;
158
- const got = yield* bases.rowsOf(run.from, run.to);
159
- for (let block = Math.floor(run.from / basesBlock), row = 0; block * basesBlock < run.to; block += 1) {
160
- const from = row;
161
- while (row < got.length && (got[row] ?? 0) < (block + 1) * 4096) row += 2;
162
- rows.set(block, got.subarray(from, row));
158
+ const fetched = yield* Effect.forEach(runs, (run) => bases.rowsOf(run.from, run.to), { concurrency: 16 });
159
+ for (const [at, run] of runs.entries()) {
160
+ const got = fetched[at] ?? /* @__PURE__ */ new Uint32Array(0);
161
+ for (let block = Math.floor(run.from / basesBlock), row = 0; block * basesBlock < run.to; block += 1) {
162
+ const from = row;
163
+ while (row < got.length && (got[row] ?? 0) < (block + 1) * 4096) row += 2;
164
+ rows.set(block, got.subarray(from, row));
165
+ }
163
166
  }
164
167
  }
165
168
  const next = [];
@@ -188,13 +191,13 @@ const placedReads = (input) => {
188
191
  if (all === void 0 || whole(all.size)) return void 0;
189
192
  const places = placesOf(pack, all);
190
193
  const known = opens.get(pack.pack.id);
191
- const gets = placedReadGets(pack, places, known !== void 0);
194
+ const tables = known ?? placedTablesOf(bucket, pack.pack, pack.count);
195
+ const gets = placedReadGets(pack, places, tables.headerChecked);
192
196
  if (!fits(pack, gets)) return void 0;
193
197
  yield* spend(pack, gets);
194
- const tables = known ?? (yield* openPlacedTables(bucket, pack.pack, pack.count));
195
- opens.set(pack.pack.id, tables);
196
198
  yield* read.hold(placedEntriesBytes(places.length) + places.length * 64);
197
199
  const entries = yield* placedEntries(tables, places);
200
+ if (known === void 0) opens.set(pack.pack.id, tables);
198
201
  const found = /* @__PURE__ */ new Map();
199
202
  for (let slot = 0; slot < places.length; slot += 1) found.set(hexOf(entries.ids.subarray(slot * 20, slot * 20 + 20)), entries.offsets[slot] ?? 0);
200
203
  yield* read.release(placedEntriesBytes(places.length));
@@ -235,8 +238,7 @@ const placedReads = (input) => {
235
238
  if (group === void 0) byPack.set(pack, [ask]);
236
239
  else group.push(ask);
237
240
  }
238
- const where = /* @__PURE__ */ new Map();
239
- let kept = 0;
241
+ const packEntries = [];
240
242
  for (const [pack, group] of byPack) {
241
243
  const listedPack = listedOf.get(pack.pack.id);
242
244
  if (listedPack === void 0) return yield* Effect.fail(loss(`Pack ${pack.pack.id} isn't listed`));
@@ -244,11 +246,26 @@ const placedReads = (input) => {
244
246
  packLastLevel.set(pack.pack.id, level);
245
247
  packLevels.set(pack.pack.id, (packLevels.get(pack.pack.id) ?? 0) + 1);
246
248
  }
249
+ packEntries.push({
250
+ pack,
251
+ listedPack,
252
+ group
253
+ });
254
+ }
255
+ const resolved = yield* Effect.forEach(packEntries, Effect.fnUntraced(function* ({ pack, listedPack, group }) {
247
256
  const loaded = read.loadedOf?.(listedPack);
248
257
  const placed = loaded === void 0 ? yield* placedAt(pack, listedPack, group) : void 0;
249
- kept += placed?.kept ?? 0;
250
- const at = placed?.at ?? (yield* loadedAt(pack, loaded ?? (yield* input.indexed(listedPack)), group));
251
- for (const [oid, located] of at) where.set(oid, located);
258
+ const from = input.indexHeld === true ? bucket : void 0;
259
+ return {
260
+ at: placed?.at ?? (yield* loadedAt(pack, loaded ?? (yield* input.indexed(listedPack, from)), group)),
261
+ kept: placed?.kept ?? 0
262
+ };
263
+ }), { concurrency: 5 });
264
+ const where = /* @__PURE__ */ new Map();
265
+ let kept = 0;
266
+ for (const entry of resolved) {
267
+ kept += entry.kept;
268
+ for (const [oid, located] of entry.at) where.set(oid, located);
252
269
  }
253
270
  const each = (oids, taken) => Effect.forEach(oids, Effect.fnUntraced(function* (oid) {
254
271
  const located = where.get(oid);
@@ -1,8 +1,8 @@
1
1
  import { gitError } from "../contracts/result.mjs";
2
2
  import { hexOf } from "../protocol/bytes/hex.mjs";
3
3
  import { oidBytes } from "../protocol/packs/idx.mjs";
4
- import * as Effect from "effect/Effect";
5
4
  import * as Schema from "effect/Schema";
5
+ import * as Effect from "effect/Effect";
6
6
  // src/storage/prune-seen.ts
7
7
  /**
8
8
  * #2019: the history objects a prune walk has seen, in place of a table of their IDs: a bit for
@@ -12,8 +12,8 @@ import { blockBytes, blocksHeld, indexBytes, isIndexReloaded, isIndexShort, pack
12
12
  import { SeenSaved, seenSet } from "./prune-seen.mjs";
13
13
  import { StoredRuns, chained, chainsOf, dedupeTableBytes, dropRuns, joinedChains, joinedRuns, mergeHeld, mergeRuns, narrowed, narrowedCalls, passedReads, runWriter, seekChecks, wayLengths, writerHeld } from "./runs.mjs";
14
14
  import { countedReads, idsIn, noIds } from "./walk.mjs";
15
- import * as Effect from "effect/Effect";
16
15
  import * as Schema from "effect/Schema";
16
+ import * as Effect from "effect/Effect";
17
17
  import * as Data from "effect/Data";
18
18
  // src/storage/prune-walk.ts
19
19
  /** The tree IDs a level reads at once, in pack order, at `fetchEntryBytes` each: about 9.2 MB. */
@@ -8,7 +8,7 @@ import { ReachedMark, markHolds } from "../store/records.mjs";
8
8
  import { collections, reachedKey, repoRootsKey, repoScope } from "../store/scopes.mjs";
9
9
  import { bucketDeleteMany, readWhole, sizedPutCalls } from "./calls.mjs";
10
10
  import { putOnce, rootsKeyOf } from "./index-build.mjs";
11
- import { isPackId, objectCollections, runKey } from "./layout.mjs";
11
+ import { isPackId, objectCollections, pruneClearedKey, prunePassKey, runKey } from "./layout.mjs";
12
12
  import { upkeepRuns, upkeepTooLarge } from "./memory-budget.mjs";
13
13
  import { decodeRefused, refusedRead } from "./merge-fence.mjs";
14
14
  import { decodeMerges, droppedStep, mergeKey, mergeRead, takenOf, writtenOf } from "./merge-row.mjs";
@@ -19,23 +19,19 @@ import { noRows, objectKey, rowsMoved } from "./object-rows.mjs";
19
19
  import { bitsBytes, eachHolders, hasBit, keepBitsOn, keepMergeCalls, setBit } from "./prune-keep.mjs";
20
20
  import { WalkSaved, fits, pruneStartsOut, pruneStartsPutCalls, pruneWalk, pruneWalkStartCalls, walkKeys } from "./prune-walk.mjs";
21
21
  import { compareIds } from "./raw-ids.mjs";
22
- import { defaultRepack, leavingRows, mergeWith, namedOf, replacing, wholeRows } from "./repack.mjs";
22
+ import { defaultRepack, foldStep, leavingRows, mergeWith, namedOf, replacing, wholeRows } from "./repack.mjs";
23
23
  import { decodeHeld, pruneFloor, pruneWait } from "./rows.mjs";
24
24
  import { StoredRuns, dropRuns, mergeHeld, mergeRuns } from "./runs.mjs";
25
25
  import { lost } from "./walk.mjs";
26
+ import * as Schema from "effect/Schema";
26
27
  import * as Effect from "effect/Effect";
27
28
  import * as Option from "effect/Option";
28
- import * as Schema from "effect/Schema";
29
29
  import * as DateTime from "effect/DateTime";
30
30
  // src/storage/prune.ts
31
31
  /** A cruft pack's row, by its pack: when a prune pass found its objects unreached. */
32
32
  const CruftRow = /* @__PURE__ */ Schema.Struct({ since: Schema.Int });
33
33
  /** The last prune pass's row: when its last step ran, so the next waits `prune` after it. */
34
34
  const PrunePass = /* @__PURE__ */ Schema.Struct({ at: Schema.Int });
35
- const prunePassKey = {
36
- collection: objectCollections.prune,
37
- id: "pass"
38
- };
39
35
  /**
40
36
  * A pass's walk across its steps: where a try stopped, or what it reached once done, each with
41
37
  * the refs the walks before it began from, which a saved catch-up keeps for the last step's check.
@@ -159,10 +155,6 @@ const pruneStartedKey = {
159
155
  * as soon as its walk ends. Only the pass's row ends it, and the next clear writes it again.
160
156
  */
161
157
  const PruneCleared = /* @__PURE__ */ Schema.Struct({ at: Schema.Int });
162
- const pruneClearedKey = {
163
- collection: objectCollections.prune,
164
- id: "cleared"
165
- };
166
158
  const cruftKey = (pack) => ({
167
159
  collection: objectCollections.cruft,
168
160
  id: pack
@@ -1358,25 +1350,6 @@ const passSteps = /* @__PURE__ */ Effect.fnUntraced(function* (input, read, pack
1358
1350
  last: true
1359
1351
  };
1360
1352
  }, Effect.scoped);
1361
- /**
1362
- * A due pass's step while one read holds only some object rows: the rows it read, folded into a
1363
- * pack of their own, with no walk. A row it didn't read may name an old cruft object, and the
1364
- * repo's objects can't be counted, so the pass waits for these steps to fold the rows until one
1365
- * read holds them all.
1366
- */
1367
- const foldStep = /* @__PURE__ */ Effect.fnUntraced(function* (input, objectRows, most) {
1368
- const rows = yield* wholeRows(objectRows);
1369
- const merged = yield* mergeWith(input, {
1370
- rows,
1371
- most
1372
- });
1373
- if (merged === void 0 || merged === "too big") return void 0;
1374
- return {
1375
- change: replacing(input, merged, [], rows),
1376
- more: true,
1377
- quarantine: merged.quarantine
1378
- };
1379
- });
1380
1353
  /** A moment as ISO 8601, for a log line. */
1381
1354
  const iso = (at) => DateTime.formatIso(DateTime.makeUnsafe(at));
1382
1355
  /**
@@ -1579,4 +1552,4 @@ const pruneStep = /* @__PURE__ */ Effect.fnUntraced(function* (input, prune, rep
1579
1552
  next
1580
1553
  };
1581
1554
  });
1582
- export { CruftRow, PassClasses, PassKeep, PruneCleared, PrunePass, PruneStarted, cruftOf, heldWantedBytes, mergesAlone, passAlone, passDue, passScratch, pruneClearedKey, prunePassKey, pruneStartedKey, pruneStep, reachOf, reachesOnly, readPrune, walkPackOf };
1555
+ export { CruftRow, PassClasses, PassKeep, PruneCleared, PrunePass, PruneStarted, cruftOf, heldWantedBytes, mergesAlone, passAlone, passDue, passScratch, pruneStartedKey, pruneStep, reachOf, reachesOnly, readPrune, walkPackOf };
@@ -4,8 +4,8 @@ import { openTreeBytes, openTreesFloorBytes, pushReaderFloorsOf, readerMost } fr
4
4
  import { isPackId } from "./layout.mjs";
5
5
  import { readBusy } from "./memory-budget.mjs";
6
6
  import { PackBlocks } from "./pack-reads.mjs";
7
- import { noCall, runIn, runnerIn } from "../store/crossing.mjs";
8
7
  import * as Effect from "effect/Effect";
8
+ import * as Exit from "effect/Exit";
9
9
  // src/storage/push-allotment.ts
10
10
  /**
11
11
  * The refusal a push's tree walk gets when its open trees found no room within `growWaitMs`. Git
@@ -84,18 +84,22 @@ var PacksAllotment = class {
84
84
  #trees = 0;
85
85
  /** What the allotment grew past the open trees' floor for them. */
86
86
  #grown = 0;
87
- /** Runs a grow's wait as a Promise, on the clock of the receive that made it. */
88
- #run;
87
+ /** A grow's wait on the clock of the receive that made it, when it has one. */
88
+ #onClock;
89
89
  /** The pack's bytes its receive caught, its blocks' first, until they're made. */
90
90
  #caught;
91
+ /** Stored base objects kept from `receiveRows`, charged into `#allotment` until release. */
92
+ #bases;
91
93
  /**
92
94
  * `context`: the receive's, whose clock a grow's wait runs on. `caught`: the pack's bytes, as
93
95
  * `catchPack` caught them, kept as its one block so neither reader gets them from the bucket.
96
+ * `bases`: stored base objects kept from `receiveRows`, whose bytes are already in `allotment`.
94
97
  */
95
- constructor(allotment, size, context, caught) {
98
+ constructor(allotment, size, context, caught, bases) {
96
99
  this.#allotment = allotment;
97
100
  this.#caught = caught;
98
- this.#run = context === void 0 ? (effect) => runIn(effect, noCall) : runnerIn(context);
101
+ this.#bases = bases !== void 0 && bases.bodies.size > 0 ? bases : void 0;
102
+ this.#onClock = context === void 0 ? (effect) => effect : (effect) => Effect.provideContext(effect, context);
99
103
  this.#floors = {
100
104
  repo: pushReaderFloorsOf(size, false),
101
105
  own: pushReaderFloorsOf(size, true)
@@ -105,6 +109,10 @@ var PacksAllotment = class {
105
109
  get bytes() {
106
110
  return this.#allotment.bytes;
107
111
  }
112
+ /** Stored base objects kept from `receiveRows` for this push's readers, until release. */
113
+ get bases() {
114
+ return this.#allotment.released ? void 0 : this.#bases?.bodies;
115
+ }
108
116
  /**
109
117
  * The allotment for a reader of the repo, or of the push's pack alone when `listedOnly`: its
110
118
  * cache's floor, moved out of this allotment, the first time each is asked for, and the blocks
@@ -142,8 +150,8 @@ var PacksAllotment = class {
142
150
  }
143
151
  /**
144
152
  * The walk holds `bytes` more open: within the floor at once, with no wait; past it, at once
145
- * when free bytes cover it, else a Promise of the grow's answer within `growWaitMs`. Past
146
- * `openTreeBytes`, refused.
153
+ * when free bytes cover it, else an Effect of the grow's answer within `growWaitMs`, run on the
154
+ * receive's clock, which an interrupt ends holding nothing. Past `openTreeBytes`, refused.
147
155
  */
148
156
  grow = (bytes) => {
149
157
  const trees = this.#trees + bytes;
@@ -156,14 +164,16 @@ var PacksAllotment = class {
156
164
  }
157
165
  this.#trees = trees;
158
166
  this.#grown += needed;
159
- return this.#run(Effect.match(this.#allotment.grow(needed), {
160
- onFailure: (error) => {
161
- this.#trees -= bytes;
162
- this.#grown -= needed;
163
- return error;
164
- },
167
+ let taken = false;
168
+ return Effect.uninterruptibleMask((restore) => restore(this.#onClock(this.#allotment.grow(needed, void 0, () => taken = true))).pipe(Effect.onExit((exit) => Effect.sync(() => {
169
+ if (Exit.isSuccess(exit)) return;
170
+ if (taken) return this.shrink(bytes);
171
+ this.#trees -= bytes;
172
+ this.#grown -= needed;
173
+ })), Effect.match({
174
+ onFailure: (error) => error,
165
175
  onSuccess: () => void 0
166
- }));
176
+ })));
167
177
  };
168
178
  /** The walk let go of `bytes`: what it grew past the floor for them goes back. */
169
179
  shrink = (bytes) => {
@@ -180,6 +190,8 @@ var PacksAllotment = class {
180
190
  */
181
191
  release = () => {
182
192
  this.#caught = void 0;
193
+ this.#bases?.clear();
194
+ this.#bases = void 0;
183
195
  this.#blocks?.blocks.release();
184
196
  this.#blocks?.allotment.release();
185
197
  this.#allotment.release();
@@ -1,11 +1,13 @@
1
1
  import { millis } from "../contracts/time.mjs";
2
2
  import { gitError } from "../contracts/result.mjs";
3
- import { decodeRow, storeCall, storeCommit } from "../store/errors.mjs";
3
+ import { bestEffort, decodeRow, storeCall, storeCommit } from "../store/errors.mjs";
4
4
  import { collections, newChangeId, repoScope } from "../store/scopes.mjs";
5
5
  import { bucketCall, bucketDo } from "./calls.mjs";
6
- import * as Effect from "effect/Effect";
7
- import * as Schema from "effect/Schema";
6
+ import { isPackId } from "./layout.mjs";
8
7
  import { limits } from "@ref0/infra";
8
+ import * as Schema from "effect/Schema";
9
+ import * as Effect from "effect/Effect";
10
+ import * as Option from "effect/Option";
9
11
  // src/storage/push-uploads.ts
10
12
  /**
11
13
  * A large push's pack, uploaded to the bucket in parts before the push: its row in the repo's
@@ -57,8 +59,8 @@ const pushUploadGrace = /* @__PURE__ */ millis("1 day");
57
59
  /** A ref edit as the row keeps it: receive-pack's command, `null` for none. */
58
60
  const RefEditRow = /* @__PURE__ */ Schema.Struct({
59
61
  ref: Schema.String,
60
- from: Schema.NullOr(Schema.String),
61
- to: Schema.NullOr(Schema.String)
62
+ from: /* @__PURE__ */ Schema.NullOr(Schema.String),
63
+ to: /* @__PURE__ */ Schema.NullOr(Schema.String)
62
64
  });
63
65
  const PushUploadRow = /* @__PURE__ */ Schema.Struct({
64
66
  /** The staged pack's key, this upload's own. */
@@ -68,25 +70,27 @@ const PushUploadRow = /* @__PURE__ */ Schema.Struct({
68
70
  /** The actor that began it: only they get its part links, or complete it. */
69
71
  actor: Schema.String,
70
72
  bytes: Schema.Int,
71
- updates: Schema.Array(RefEditRow),
72
- pushOptions: Schema.Array(Schema.String),
73
+ updates: /* @__PURE__ */ Schema.Array(RefEditRow),
74
+ pushOptions: /* @__PURE__ */ Schema.Array(Schema.String),
73
75
  atomic: Schema.Boolean,
74
76
  /** Whether its begin asked for `ref0-push-reasons`, which complete's report tells. */
75
77
  reasons: Schema.Boolean,
76
78
  /** Its begin's `shallow` lines, which complete's push reads: none for a whole clone. */
77
- shallow: Schema.Array(Schema.String),
79
+ shallow: /* @__PURE__ */ Schema.Array(Schema.String),
78
80
  /** When its last part link expires. */
79
81
  expiresAt: Schema.Int,
80
82
  /** When upkeep aborts its parts, and deletes its key and the row. */
81
83
  removeAt: Schema.Int,
82
84
  /** When a complete claimed it, once one has: `completingMost` bounds how long it holds it. */
83
- claimedAt: Schema.optionalKey(Schema.Int),
85
+ claimedAt: /* @__PURE__ */ Schema.optionalKey(Schema.Int),
86
+ /** Earliest moment upkeep retries a refused staging abort so stuck rows cannot starve later ones. */
87
+ retryAt: /* @__PURE__ */ Schema.optionalKey(Schema.Int),
84
88
  /**
85
89
  * `receiving` while `git.push-upload`'s steps receive its pack, then `ended` once a complete
86
90
  * has run: its key is deleted, but the row stays until `removeAt`, as a bucket that can't revoke
87
91
  * a link, such as Blob, takes a PUT to the key until the link expires.
88
92
  */
89
- state: Schema.Literals([
93
+ state: /* @__PURE__ */ Schema.Literals([
90
94
  "open",
91
95
  "completing",
92
96
  "receiving",
@@ -121,60 +125,194 @@ const partSizeOf = (bytes, maxParts) => Math.max(pushUploadPart, Math.ceil(bytes
121
125
  const partsOf = (bytes, size) => Math.ceil(bytes / size);
122
126
  /** What part `part` of an upload of `bytes` holds, in parts of `size`: its link signs that length. */
123
127
  const partBytes = (bytes, part, size) => Math.min(size, bytes - (part - 1) * size);
128
+ /** Delay before upkeep retries a refused staging multipart abort. */
129
+ const abortRetryDelay = /* @__PURE__ */ millis("1 minute");
130
+ const soonest = (a, b) => a === void 0 ? b : Math.min(a, b);
124
131
  /**
125
- * The most rows a step reads at once, and ends: a row holds its begin's updates, up to
126
- * `limits.valueBytes`, so a page of 8 stays within half of one answer's `limits.answerBytes`.
132
+ * Tries to abort `open` via the owning `staging` handle. Returns `true` when aborted (or already
133
+ * gone) and `false` when refused so upkeep retains the steps row and quarantine to retry later.
127
134
  */
128
- const upkeepPage = /* @__PURE__ */ Math.floor(limits.answerBytes / limits.valueBytes / 2);
135
+ const tryAbortStage = (staging, open) => staging === void 0 ? Effect.succeed(true) : bestEffort(Effect.as(staging.abort(open.pack, open.token), true), (error) => Effect.logWarning("Upkeep staging multipart abort was refused: retrying later").pipe(Effect.annotateLogs({
136
+ pack: open.pack,
137
+ code: error.code,
138
+ reason: error.message
139
+ }), Effect.as(false)));
129
140
  /**
130
- * Ends the push uploads due at `at` in `repo`: each one's parts aborted, where the host has
131
- * `uploads`, its key deleted from `bucket`, which charges each call, then its rows, at the version
132
- * the rows were read: a job still receiving it finds none, and stops. A crash between leaves the row, and the next step ends it again: aborting an
133
- * ended upload, and deleting a key that's gone, do nothing.
141
+ * Ends the push uploads due at `at` in `repo`, and retries any leftover open staging aborts on
142
+ * `ended` uploads whose terminal abort was refused: each open staging multipart upload is aborted
143
+ * on its owning bucket (`staging.abort`), and its steps row and quarantine are deleted only once
144
+ * the abort succeeds (or the upload is already gone). A refused abort keeps both rows for the next
145
+ * upkeep pass.
134
146
  */
135
- const pushUploadUpkeep = (bucket, uploads) => Effect.fnUntraced(function* (store, repo, at) {
136
- const scope = repoScope(repo);
137
- const due = [];
138
- let next;
139
- let after;
140
- let version = 0;
141
- for (;;) {
142
- const read = {
143
- collection: collections.pushUploads,
144
- limit: upkeepPage
147
+ const pushUploadUpkeep = (bucket, uploads, staging) => {
148
+ const upkeepPage = Math.floor(limits.answerBytes / limits.valueBytes / 2);
149
+ const decodeOpenStaging = Schema.decodeUnknownOption(Schema.Struct({ staging: Schema.optionalKey(Schema.Struct({
150
+ pack: Schema.String,
151
+ token: Schema.String
152
+ })) }));
153
+ const openStagingOf = (row) => {
154
+ const decoded = decodeOpenStaging(row.value);
155
+ if (Option.isNone(decoded)) return void 0;
156
+ const { staging: held } = decoded.value;
157
+ if (held === void 0 || !isPackId(held.pack)) return void 0;
158
+ return {
159
+ pack: held.pack,
160
+ token: held.token
145
161
  };
146
- const snapshot = yield* storeCall(store.read(scope, [after === void 0 ? read : {
147
- ...read,
148
- after
149
- }]));
150
- const rows = snapshot.results[0] ?? [];
151
- version = snapshot.version;
152
- for (const row of rows) {
153
- const upload = yield* decodeRow(PushUploadRow, row, `push upload ${row.id}`);
154
- if (upload.removeAt > at) next = next === void 0 ? upload.removeAt : Math.min(next, upload.removeAt);
155
- else if (due.length < upkeepPage) due.push({
156
- id: row.id,
157
- row: upload
158
- });
159
- }
160
- after = rows.at(-1)?.id;
161
- if (due.length >= upkeepPage || rows.length < upkeepPage || after === void 0) break;
162
- }
163
- if (due.length === 0) return next === void 0 ? { more: false } : {
164
- more: false,
165
- due: next
166
162
  };
167
- yield* Effect.forEach(due, ({ row }) => endUpload(bucket, uploads, row), {
168
- concurrency: 8,
169
- discard: true
163
+ return Effect.fnUntraced(function* (store, repo, at) {
164
+ const scope = repoScope(repo);
165
+ const due = [];
166
+ const endedPending = [];
167
+ let next;
168
+ let after;
169
+ let version = 0;
170
+ for (;;) {
171
+ const read = {
172
+ collection: collections.pushUploads,
173
+ limit: upkeepPage
174
+ };
175
+ const snapshot = yield* storeCall(store.read(scope, [after === void 0 ? read : {
176
+ ...read,
177
+ after
178
+ }]));
179
+ const rows = snapshot.results[0] ?? [];
180
+ version = snapshot.version;
181
+ for (const row of rows) {
182
+ const upload = yield* decodeRow(PushUploadRow, row, `push upload ${row.id}`);
183
+ const { retryAt } = upload;
184
+ const backedOff = retryAt !== void 0 && retryAt > at;
185
+ if (upload.removeAt > at) {
186
+ next = soonest(next, upload.removeAt);
187
+ if (upload.state === "ended") {
188
+ if (backedOff) next = soonest(next, retryAt);
189
+ else if (endedPending.length < upkeepPage) endedPending.push({
190
+ id: row.id,
191
+ row: upload
192
+ });
193
+ }
194
+ } else if (backedOff) next = soonest(next, retryAt);
195
+ else if (due.length < upkeepPage) due.push({
196
+ id: row.id,
197
+ row: upload
198
+ });
199
+ }
200
+ after = rows.at(-1)?.id;
201
+ if (due.length >= upkeepPage || rows.length < upkeepPage || after === void 0) break;
202
+ }
203
+ if (endedPending.length > 0) {
204
+ const stepsSnap = yield* storeCall(store.read(scope, endedPending.map(({ id }) => ({
205
+ collection: collections.pushUploadSteps,
206
+ id
207
+ }))));
208
+ const pendingStages = [];
209
+ for (let i = 0; i < endedPending.length; i += 1) {
210
+ const entry = endedPending[i];
211
+ const held = stepsSnap.results[i]?.[0];
212
+ if (entry === void 0 || held === void 0) continue;
213
+ const open = openStagingOf(held);
214
+ if (open !== void 0) pendingStages.push({
215
+ id: entry.id,
216
+ row: entry.row,
217
+ open
218
+ });
219
+ }
220
+ if (pendingStages.length > 0) {
221
+ const results = yield* Effect.forEach(pendingStages, ({ id, row, open }) => Effect.map(tryAbortStage(staging, open), (aborted) => ({
222
+ id,
223
+ row,
224
+ open,
225
+ aborted
226
+ })), { concurrency: 8 });
227
+ const cleared = results.filter((entry) => entry.aborted);
228
+ const stuck = results.filter((entry) => !entry.aborted);
229
+ const retryAt = at + abortRetryDelay;
230
+ const committed = yield* storeCommit(store.commit(scope, {
231
+ id: newChangeId(),
232
+ expect: stepsSnap.version,
233
+ put: stuck.map(({ id, row }) => ({
234
+ ...pushUploadRowKey(id),
235
+ value: {
236
+ ...row,
237
+ retryAt
238
+ }
239
+ })),
240
+ delete: cleared.map(({ id }) => ({
241
+ collection: collections.pushUploadSteps,
242
+ id
243
+ }))
244
+ }));
245
+ if (committed.ok && staging !== void 0 && cleared.length > 0) yield* Effect.forEach(cleared, ({ open }) => bestEffort(staging.drop(repo, open.pack)), {
246
+ concurrency: 8,
247
+ discard: true
248
+ });
249
+ return committed.ok ? { more: true } : {
250
+ more: false,
251
+ due: soonest(next, retryAt)
252
+ };
253
+ }
254
+ }
255
+ if (due.length === 0) return next === void 0 ? { more: false } : {
256
+ more: false,
257
+ due: next
258
+ };
259
+ const withSteps = due.filter(({ row }) => row.state === "receiving" || row.state === "ended");
260
+ const openById = /* @__PURE__ */ new Map();
261
+ let stepsVersion = version;
262
+ if (withSteps.length > 0) {
263
+ const stepsSnap = yield* storeCall(store.read(scope, withSteps.map(({ id }) => ({
264
+ collection: collections.pushUploadSteps,
265
+ id
266
+ }))));
267
+ stepsVersion = stepsSnap.version;
268
+ for (let i = 0; i < withSteps.length; i += 1) {
269
+ const entry = withSteps[i];
270
+ const held = stepsSnap.results[i]?.[0];
271
+ if (entry === void 0 || held === void 0) continue;
272
+ const open = openStagingOf(held);
273
+ if (open !== void 0) openById.set(entry.id, open);
274
+ }
275
+ }
276
+ const abortedById = /* @__PURE__ */ new Map();
277
+ const stuckIds = /* @__PURE__ */ new Set();
278
+ if (openById.size > 0) {
279
+ const results = yield* Effect.forEach([...openById.entries()], ([id, open]) => Effect.map(tryAbortStage(staging, open), (aborted) => ({
280
+ id,
281
+ open,
282
+ aborted
283
+ })), { concurrency: 8 });
284
+ for (const { id, open, aborted } of results) if (aborted) abortedById.set(id, open);
285
+ else stuckIds.add(id);
286
+ }
287
+ const ready = due.filter(({ id }) => !stuckIds.has(id));
288
+ const stuck = due.filter(({ id }) => stuckIds.has(id));
289
+ const retryAt = at + abortRetryDelay;
290
+ if (ready.length > 0) yield* Effect.forEach(ready, ({ row }) => endUpload(bucket, uploads, row), {
291
+ concurrency: 8,
292
+ discard: true
293
+ });
294
+ const committed = yield* storeCommit(store.commit(scope, {
295
+ id: newChangeId(),
296
+ expect: stepsVersion,
297
+ put: stuck.map(({ id, row }) => ({
298
+ ...pushUploadRowKey(id),
299
+ value: {
300
+ ...row,
301
+ retryAt
302
+ }
303
+ })),
304
+ delete: ready.flatMap(({ id }) => pushUploadKeys(id))
305
+ }));
306
+ if (committed.ok && staging !== void 0 && abortedById.size > 0) yield* Effect.forEach([...abortedById.values()], (open) => bestEffort(staging.drop(repo, open.pack)), {
307
+ concurrency: 8,
308
+ discard: true
309
+ });
310
+ return committed.ok ? { more: true } : {
311
+ more: false,
312
+ due: soonest(next, retryAt)
313
+ };
170
314
  });
171
- yield* storeCommit(store.commit(scope, {
172
- id: newChangeId(),
173
- expect: version,
174
- delete: due.flatMap(({ id }) => pushUploadKeys(id))
175
- }));
176
- return { more: true };
177
- });
315
+ };
178
316
  /** An upload's parts aborted, where the host has `uploads`, then its key deleted. */
179
317
  const endUpload = /* @__PURE__ */ Effect.fnUntraced(function* (bucket, uploads, row) {
180
318
  if (uploads !== void 0) yield* bucketCall(uploads.abortUpload(row.key, row.uploadId));
@@ -1,11 +1,13 @@
1
1
  import { fail } from "../contracts/result.mjs";
2
2
  import { hexOf } from "../protocol/bytes/hex.mjs";
3
3
  import { decodeCommit } from "../protocol/objects/commit.mjs";
4
+ import { stagedOwnOf } from "./batches.mjs";
4
5
  import { isPackId, packFiles } from "./layout.mjs";
5
6
  import { chunkedOf } from "./chunks.mjs";
6
7
  import { receivedObject, receivedRows } from "./object-rows.mjs";
7
8
  import { bucketDo, readWhole } from "./calls.mjs";
8
9
  import * as Effect from "effect/Effect";
10
+ import * as Predicate from "effect/Predicate";
9
11
  // src/storage/pushed-commits.ts
10
12
  /**
11
13
  * The commits a push brings, a page at a time: each received pack's, from the `.graph` its receive
@@ -94,8 +96,25 @@ const graphPage = /* @__PURE__ */ Effect.fnUntraced(function* (bucket, pack, at)
94
96
  }
95
97
  };
96
98
  });
99
+ const oldestFirst = (commits) => {
100
+ const byOid = new Map(commits.map((c) => [c.oid, c]));
101
+ const seen = /* @__PURE__ */ new Map();
102
+ const out = [];
103
+ const stack = commits.toReversed();
104
+ const next = (id) => seen.has(id) ? void 0 : byOid.get(id);
105
+ for (let c = stack.pop(); c !== void 0; c = stack.pop()) {
106
+ const s = seen.get(c.oid);
107
+ if (s === 2) continue;
108
+ seen.set(c.oid, s === 1 ? 2 : 1);
109
+ if (s === 1) out.push(c);
110
+ else stack.push(c, ...c.parents.toReversed().map(next).filter(Predicate.isNotUndefined));
111
+ }
112
+ return out;
113
+ };
97
114
  /** The commits among a push's rows, as a loose push or a small one keeps them. */
98
115
  const rowCommits = /* @__PURE__ */ Effect.fnUntraced(function* (received) {
116
+ const staged = stagedOwnOf(received.change);
117
+ if (staged !== void 0) return oldestFirst(staged.commits);
99
118
  const items = [];
100
119
  for (const [oid, row] of receivedRows(received.change)) {
101
120
  if ((chunkedOf(row.value)?.type ?? "commit") !== "commit") continue;
@@ -107,7 +126,7 @@ const rowCommits = /* @__PURE__ */ Effect.fnUntraced(function* (received) {
107
126
  parents: commit.parents
108
127
  });
109
128
  }
110
- return items;
129
+ return oldestFirst(items);
111
130
  });
112
131
  /**
113
132
  * A page of the commits `input.received` brings, over `bucket`, which keeps its packs' `.graph`s:
@@ -2,9 +2,8 @@ import "../contracts/result.mjs";
2
2
  import "../contracts/objects.mjs";
3
3
  import "../contracts/time.mjs";
4
4
  import "../contracts/ids.mjs";
5
- import "../contracts/services.mjs";
6
5
  import "../contracts/store.mjs";
7
6
  import "./layout.mjs";
8
7
  import "./pack-reads.mjs";
9
- import "effect/Effect";
10
- import { JobInput, Key, Moment, Row } from "@ref0/infra";
8
+ import { JobInput, Key, Moment, Row } from "@ref0/infra";
9
+ import "effect/Effect";