@ref0/git 0.8.0 → 0.10.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 (102) hide show
  1. package/dist/contracts/calls-spent.d.mts +2 -12
  2. package/dist/contracts/calls-spent.mjs +4 -5
  3. package/dist/contracts/commits.d.mts +14 -2
  4. package/dist/contracts/commits.mjs +22 -3
  5. package/dist/contracts/events.d.mts +70 -4
  6. package/dist/contracts/events.mjs +27 -3
  7. package/dist/contracts/git.d.mts +13 -3
  8. package/dist/contracts/objects.d.mts +18 -0
  9. package/dist/contracts/queue.d.mts +3 -2
  10. package/dist/contracts/queue.mjs +4 -2
  11. package/dist/contracts/refs.mjs +3 -1
  12. package/dist/core/ancestry.mjs +5 -4
  13. package/dist/core/events/seen.mjs +5 -4
  14. package/dist/core/index-job.mjs +23 -1
  15. package/dist/core/index-lost.d.mts +11 -0
  16. package/dist/core/index-lost.mjs +55 -0
  17. package/dist/core/job-view.mjs +20 -0
  18. package/dist/core/objects/commit-writes.mjs +1 -1
  19. package/dist/core/objects/commits.mjs +10 -9
  20. package/dist/core/objects/merges.mjs +1 -1
  21. package/dist/core/objects/reading.mjs +28 -13
  22. package/dist/core/objects/trees.mjs +1 -1
  23. package/dist/core/parts.d.mts +7 -0
  24. package/dist/core/publish.mjs +9 -5
  25. package/dist/core/purge.mjs +16 -3
  26. package/dist/core/push.mjs +27 -11
  27. package/dist/core/ref-view.mjs +1 -25
  28. package/dist/core/repack.mjs +36 -14
  29. package/dist/core/view.d.mts +10 -1
  30. package/dist/core/view.mjs +15 -6
  31. package/dist/core/work.mjs +47 -4
  32. package/dist/effect.d.mts +2 -3
  33. package/dist/effect.mjs +2 -3
  34. package/dist/engine/commits.mjs +4 -3
  35. package/dist/engine/merge-bases.mjs +5 -3
  36. package/dist/engine/merge.mjs +4 -3
  37. package/dist/engine/parts.d.mts +1 -0
  38. package/dist/engine/parts.mjs +1 -1
  39. package/dist/engine/walk.mjs +62 -20
  40. package/dist/http/core-parts.mjs +17 -8
  41. package/dist/index.d.mts +4 -4
  42. package/dist/index.mjs +3 -3
  43. package/dist/lfs/objects.mjs +7 -4
  44. package/dist/lfs/upkeep.mjs +6 -5
  45. package/dist/lfs/upload-most.mjs +8 -2
  46. package/dist/protocol/bytes/streams.mjs +84 -2
  47. package/dist/protocol/diff/read.d.mts +1 -0
  48. package/dist/protocol/diff/read.mjs +5 -2
  49. package/dist/protocol/objects/commit.d.mts +7 -0
  50. package/dist/protocol/objects/commit.mjs +5 -1
  51. package/dist/queue/advance.mjs +39 -10
  52. package/dist/queue/host.d.mts +4 -0
  53. package/dist/queue/layer.mjs +4 -2
  54. package/dist/queue/limits.mjs +18 -2
  55. package/dist/queue/rows.mjs +2 -1
  56. package/dist/queue/trim.mjs +2 -2
  57. package/dist/rest/commits.d.mts +202 -198
  58. package/dist/rest/forks.d.mts +99 -99
  59. package/dist/rest/refs.d.mts +144 -144
  60. package/dist/rest/repos.d.mts +48 -48
  61. package/dist/rest/topics.d.mts +112 -112
  62. package/dist/rest/trees.d.mts +58 -58
  63. package/dist/rest/wire.d.mts +19 -1
  64. package/dist/rest/work.d.mts +39 -39
  65. package/dist/server/joined.d.mts +11 -5
  66. package/dist/server/joined.mjs +3 -2
  67. package/dist/server/registry.mjs +11 -5
  68. package/dist/server/server.mjs +16 -4
  69. package/dist/storage/index-bitmaps.mjs +16 -10
  70. package/dist/storage/index-build.mjs +61 -13
  71. package/dist/storage/index-graph.d.mts +1 -0
  72. package/dist/storage/index-graph.mjs +29 -5
  73. package/dist/storage/index-layers.d.mts +1 -0
  74. package/dist/storage/index-layers.mjs +5 -2
  75. package/dist/storage/index-reach.mjs +7 -5
  76. package/dist/storage/index-remap.mjs +5 -5
  77. package/dist/storage/index-visible.mjs +16 -5
  78. package/dist/storage/links.mjs +3 -3
  79. package/dist/storage/pack-order.d.mts +1 -0
  80. package/dist/storage/pack-order.mjs +18 -1
  81. package/dist/storage/prune-walk.mjs +5 -2
  82. package/dist/storage/prune.mjs +107 -37
  83. package/dist/storage/receive-bounds.mjs +3 -2
  84. package/dist/storage/visible.mjs +3 -2
  85. package/dist/storage/walk.d.mts +1 -0
  86. package/dist/storage/walk.mjs +9 -5
  87. package/dist/storage/wants.mjs +17 -11
  88. package/dist/store/call-count.d.mts +8 -0
  89. package/dist/store/call-count.mjs +15 -7
  90. package/dist/store/errors.d.mts +7 -1
  91. package/dist/store/errors.mjs +7 -1
  92. package/dist/store/job-try.mjs +3 -1
  93. package/dist/store/records.mjs +17 -2
  94. package/dist/store/repo-record.mjs +9 -2
  95. package/dist/store/scopes.mjs +10 -2
  96. package/dist/sync/bound.d.mts +1 -1
  97. package/dist/sync/import.mjs +1 -1
  98. package/dist/sync/layer.mjs +4 -7
  99. package/dist/sync/mirror.mjs +1 -1
  100. package/dist/topics/advance.mjs +4 -4
  101. package/dist/topics/layer.mjs +1 -1
  102. package/package.json +3 -3
package/dist/index.mjs CHANGED
@@ -3,12 +3,12 @@ import { client_exports as client_exports$1 } from "./rest/client.mjs";
3
3
  import { grantScopes, tokenScopes, tokenStates } from "./contracts/tokens.mjs";
4
4
  import { authorize_exports } from "./contracts/authorize.mjs";
5
5
  import { blobs_exports } from "./contracts/blobs.mjs";
6
- import { commits_exports } from "./contracts/commits.mjs";
6
+ import { commits_exports, logEmailsMost } from "./contracts/commits.mjs";
7
7
  import { events_exports } from "./contracts/events.mjs";
8
8
  import { files_exports } from "./contracts/files.mjs";
9
9
  import { forks_exports } from "./contracts/forks.mjs";
10
10
  import { git_events_exports } from "./contracts/git-events.mjs";
11
- import { refs_exports } from "./contracts/refs.mjs";
11
+ import { maxSeenRefs, refs_exports } from "./contracts/refs.mjs";
12
12
  import { repo_records_exports } from "./contracts/repo-records.mjs";
13
13
  import { repos_exports } from "./contracts/repos.mjs";
14
14
  import { peelMost, peelTagsMost, tags_exports } from "./contracts/tags.mjs";
@@ -46,4 +46,4 @@ import { tokens_public_exports } from "./auth/tokens-public.mjs";
46
46
  import { public_exports } from "./core/hooks/public.mjs";
47
47
  import { public_exports as public_exports$5 } from "./signin/public.mjs";
48
48
  import { jobStates } from "@ref0/infra";
49
- export { auth_namespace_exports as Auth, authorize_exports as Authorize, BeginPushUpload, BlobLimit, BlobNone, blobs_exports as Blobs, commits_exports as Commits, ContextValue, DataLossContext, DataLossReason, ErrorContext, event_streams_exports as EventStreams, events_exports as Events, ExistingContext, ExistingReason, FetchRequest, files_exports as Files, Filter, FinishPushUpload, forks_exports as Forks, git_namespace_exports as Git, client_exports as GitClient, GitErrorBody, git_events_exports as GitEvents, public_exports as GitHooks, HostErrorContext, InternalRepoId, InvalidInputContext, InvalidInputReason, public_exports$1 as Lfs, public_exports$2 as MergeQueue, public_exports$3 as Merges, MissingContext, MissingReason, NotAllowedContext, NotAllowedReason, objects_namespace_exports as Objects, policy_exports as Policy, PreconditionContext, PreconditionReason, public_exports$4 as PrivateRefs, PushUploadPart, PushUploadStarted, refs_exports as Refs, repo_records_exports as RepoRecords, repos_exports as Repos, ResourceContext, ResourceReason, layer_exports as Rest, client_exports$1 as RestClient, rules_exports as Rules, saved_callers_public_exports as SavedCallers, public_exports$5 as SignIn, tags_exports as Tags, tokens_public_exports as Tokens, public_exports$6 as Topics, TreeFilter, trees_exports as Trees, UnavailableContext, UnavailableReason, Verdict, work_exports as Work, accept, allotmentWithin, branchRef, createGitServer, gitError, gitPathOf, grantScopes, httpStatus, isGitError, isInternalId, isRefusalReason, jobStates, lfs, lfsPointerOid, lfsPointers, loose, looseLimits, maxActorIdLength, maxLfsPointerBytes, maxRefNameLength, mergeQueue, objectsReadMost, packs, packsMemory, peelMost, peelTagsMost, reject, shortTarget, tokenScopes, tokenStates, topics };
49
+ export { auth_namespace_exports as Auth, authorize_exports as Authorize, BeginPushUpload, BlobLimit, BlobNone, blobs_exports as Blobs, commits_exports as Commits, ContextValue, DataLossContext, DataLossReason, ErrorContext, event_streams_exports as EventStreams, events_exports as Events, ExistingContext, ExistingReason, FetchRequest, files_exports as Files, Filter, FinishPushUpload, forks_exports as Forks, git_namespace_exports as Git, client_exports as GitClient, GitErrorBody, git_events_exports as GitEvents, public_exports as GitHooks, HostErrorContext, InternalRepoId, InvalidInputContext, InvalidInputReason, public_exports$1 as Lfs, public_exports$2 as MergeQueue, public_exports$3 as Merges, MissingContext, MissingReason, NotAllowedContext, NotAllowedReason, objects_namespace_exports as Objects, policy_exports as Policy, PreconditionContext, PreconditionReason, public_exports$4 as PrivateRefs, PushUploadPart, PushUploadStarted, refs_exports as Refs, repo_records_exports as RepoRecords, repos_exports as Repos, ResourceContext, ResourceReason, layer_exports as Rest, client_exports$1 as RestClient, rules_exports as Rules, saved_callers_public_exports as SavedCallers, public_exports$5 as SignIn, tags_exports as Tags, tokens_public_exports as Tokens, public_exports$6 as Topics, TreeFilter, trees_exports as Trees, UnavailableContext, UnavailableReason, Verdict, work_exports as Work, accept, allotmentWithin, branchRef, createGitServer, gitError, gitPathOf, grantScopes, httpStatus, isGitError, isInternalId, isRefusalReason, jobStates, lfs, lfsPointerOid, lfsPointers, logEmailsMost, loose, looseLimits, maxActorIdLength, maxLfsPointerBytes, maxRefNameLength, maxSeenRefs, mergeQueue, objectsReadMost, packs, packsMemory, peelMost, peelTagsMost, reject, shortTarget, tokenScopes, tokenStates, topics };
@@ -1,4 +1,5 @@
1
1
  import { nativeSha256Hasher } from "../protocol/bytes/sha256-hasher.mjs";
2
+ import { gathered } from "../protocol/bytes/streams.mjs";
2
3
  import { contended, openFor } from "../core/access.mjs";
3
4
  import { ownWriter } from "../core/own-writes.mjs";
4
5
  import { sweepDue } from "../core/receipts.mjs";
@@ -13,7 +14,7 @@ import { isLfsOid, lfsPointerText } from "../protocol/objects/lfs-pointer.mjs";
13
14
  import { ListedRow, UploadRow, largestObject, lfsCollections, linkLife, listedKey, listedRead, objectKey, stagingId, stagingKey, stagingRead, streamMost, uploadGrace, uploadKey, uploadRead } from "./rows.mjs";
14
15
  import { BatchRequest, VerifyRequest, batchMost, bodyOf, lfsAnswer } from "./wire.mjs";
15
16
  import { uploadedRow } from "./uploaded.mjs";
16
- import { pastMost } from "./upload-most.mjs";
17
+ import { pastMost, uploadPieceBytes } from "./upload-most.mjs";
17
18
  import { fail, gitError, httpStatus } from "../contracts/result.mjs";
18
19
  import * as Clock$1 from "effect/Clock";
19
20
  import * as Effect from "effect/Effect";
@@ -411,14 +412,16 @@ const answered = (request) => Effect.promise(async () => {
411
412
  return lfsAnswer(200, { message: "Already uploaded" });
412
413
  });
413
414
  /**
414
- * `body` as it streams to the bucket, counted, and hashed through the runtime's own SHA-256, each
415
- * chunk's write awaited before it goes on, failing past `most` bytes.
415
+ * `body` as it streams to the bucket, gathered into pieces of `uploadPieceBytes`, counted, and
416
+ * hashed through the runtime's own SHA-256, each piece's write awaited before it goes on, failing
417
+ * past `most` bytes. No piece reaches more than one byte past what `most` leaves, so a body that
418
+ * runs past it is read no further than that byte's chunk.
416
419
  */
417
420
  const hashing = (body, most) => {
418
421
  const hasher = nativeSha256Hasher();
419
422
  let size = 0;
420
423
  const read = Stream.fromReadableStream({
421
- evaluate: () => body ?? new ReadableStream({ start: (controller) => controller.close() }),
424
+ evaluate: () => body === null ? new ReadableStream({ start: (controller) => controller.close() }) : gathered(body, (given) => Math.min(uploadPieceBytes, Math.max(1, most - given + 1))),
422
425
  onError: (cause) => new Unavailable({
423
426
  message: bucketFailed,
424
427
  cause
@@ -22,12 +22,13 @@ const upkeepPage = 500;
22
22
  * LFS's registration's upkeep over its `rows` and `bucket`'s objects: `bucket` charges each call, and
23
23
  * `signed` says the host signs LFS's links, so its uploads have upload rows to end.
24
24
  */
25
- const lfsUpkeep = (rows, bucket, signed) => ({ repo, at }) => upkeepStep({
25
+ const lfsUpkeep = (rows, bucket, signed) => ({ repo, at, deleted }) => upkeepStep({
26
26
  rows,
27
27
  bucket,
28
28
  signed,
29
29
  repo,
30
- at
30
+ at,
31
+ deleted
31
32
  });
32
33
  const did = { more: true };
33
34
  const earliest = (a, b) => a === void 0 ? b : b === void 0 ? a : Math.min(a, b);
@@ -62,12 +63,12 @@ const upkeepStep = /* @__PURE__ */ Effect.fnUntraced(function* (upkeep) {
62
63
  if (dueStages.length > 0) return yield* endStages(upkeep, snapshot.version, dueStages);
63
64
  const uploads = yield* dueUploads(upkeep);
64
65
  if (uploads.ids.length > 0) return yield* endUploads(upkeep, uploads.ids);
65
- const sweep = uploadedSweepOf(uploaded, upkeep.at);
66
- if (sweep.delete.length > 0) {
66
+ const sweep = upkeep.deleted ? void 0 : uploadedSweepOf(uploaded, upkeep.at);
67
+ if (sweep !== void 0 && sweep.delete.length > 0) {
67
68
  yield* upkeep.rows.commit(upkeep.repo, snapshot.version, { delete: sweep.delete });
68
69
  return did;
69
70
  }
70
- const due = stages.map((stage) => stage.removeAt).reduce(earliest, earliest(uploads.next, sweep.due));
71
+ const due = stages.map((stage) => stage.removeAt).reduce(earliest, earliest(uploads.next, sweep?.due));
71
72
  return due === void 0 ? { more: false } : {
72
73
  more: false,
73
74
  due
@@ -8,8 +8,14 @@ import { largestObject } from "./rows.mjs";
8
8
  */
9
9
  /** The share of a request's CPU an upload may spend: the rest is its rows', its put's and the runtime's. */
10
10
  const cpuShare = .8;
11
+ /**
12
+ * The bytes an upload through a Worker gathers from its body's chunks before each goes on to its
13
+ * hash and its put, since a client's body reaches a Worker in chunks of at most 4,096 B, each
14
+ * paid for once over (run 46342279485, #2296): one piece an upload, held as it streams.
15
+ */
16
+ const uploadPieceBytes = 1024 ** 2;
11
17
  /** The bytes `cpuMs` of CPU hashes and stores, at `uploadMsPerMiB` within `cpuShare` of it. */
12
- const cpuBytes = (cpuMs) => Math.floor(cpuShare * cpuMs / 64 * 1024 ** 2);
18
+ const cpuBytes = (cpuMs) => Math.floor(cpuShare * cpuMs / 22 * 1024 ** 2);
13
19
  /** The largest upload `caps` let finish: `largestObject` where neither binds below it. */
14
20
  const uploadMostOf = (caps) => {
15
21
  const bounds = [{
@@ -38,4 +44,4 @@ const setBy = {
38
44
  };
39
45
  /** Why an upload of more than `most` is refused, and what takes it. */
40
46
  const pastMost = (most) => `An upload through this server is at most ${most.bytes} bytes, ${setBy[most.by]}: a bucket that signs its links takes a larger one straight`;
41
- export { capsRefusal, cpuShare, pastMost, uploadMostOf };
47
+ export { capsRefusal, cpuShare, pastMost, uploadMostOf, uploadPieceBytes };
@@ -1,4 +1,8 @@
1
1
  // src/protocol/bytes/streams.ts
2
+ /** Refuses a `piece` under 1 byte, or not a whole number, since its stream would never reach the end. */
3
+ const wholePiece = (piece) => {
4
+ if (!Number.isSafeInteger(piece) || piece < 1) throw new RangeError(`a stream's pieces hold a whole number of bytes, at least 1, not ${piece}`);
5
+ };
2
6
  /**
3
7
  * `bytes` as a stream read once, in pieces of at most `piece` bytes: one piece by default. Each
4
8
  * smaller piece is a copy, made when its reader asks for it, so a reader that holds a piece's
@@ -6,7 +10,7 @@
6
10
  * byte, or not a whole number, is refused, since it would never reach the end.
7
11
  */
8
12
  const streamOf = (bytes, piece = Math.max(1, bytes.length)) => {
9
- if (!Number.isSafeInteger(piece) || piece < 1) throw new RangeError(`a stream's pieces hold a whole number of bytes, at least 1, not ${piece}`);
13
+ wholePiece(piece);
10
14
  if (piece >= bytes.length) return new ReadableStream({ start: (controller) => {
11
15
  controller.enqueue(bytes);
12
16
  controller.close();
@@ -18,4 +22,82 @@ const streamOf = (bytes, piece = Math.max(1, bytes.length)) => {
18
22
  if (at >= bytes.length) controller.close();
19
23
  } });
20
24
  };
21
- export { streamOf };
25
+ /**
26
+ * `body` gathered into pieces, each `pieceAt(given)` bytes, `given` the bytes it has handed on,
27
+ * its last smaller, each copied from its chunks as they come, so code that pays for each chunk pays
28
+ * once a piece: a client's body reaches a deployed Worker in chunks of at most 4,096 B (run
29
+ * 46342279485, #2296). A chunk of a piece's bytes or more, or what's left of one, that comes with
30
+ * nothing gathered goes on as it is, uncopied. It's read only as its reader asks, so it holds at
31
+ * most the piece it gathers and the rest of the chunk that filled the last, and it lets go of
32
+ * `body` once it ends, fails or is cancelled, a cancel reaching it. A piece under 1 byte, or not a
33
+ * whole number, fails the stream.
34
+ */
35
+ const gathered = (body, pieceAt) => {
36
+ const reader = body.getReader();
37
+ let rest;
38
+ let given = 0;
39
+ /** Lets go of `body`, which a reader still waiting on it may already have. */
40
+ const release = () => {
41
+ try {
42
+ reader.releaseLock();
43
+ } catch {}
44
+ };
45
+ /** The next piece's bytes, gathered from as many chunks as it takes, or `body`'s end. */
46
+ const next = async (controller) => {
47
+ const piece = pieceAt(given);
48
+ wholePiece(piece);
49
+ let gathering;
50
+ let filled = 0;
51
+ /** `bytes` handed on as the next piece, counted. */
52
+ const hand = (bytes) => {
53
+ given += bytes.length;
54
+ controller.enqueue(bytes);
55
+ };
56
+ for (;;) {
57
+ const read = rest === void 0 ? await reader.read() : {
58
+ done: false,
59
+ value: rest
60
+ };
61
+ rest = void 0;
62
+ if (read.done) {
63
+ if (gathering !== void 0) hand(gathering.subarray(0, filled));
64
+ controller.close();
65
+ release();
66
+ return;
67
+ }
68
+ const chunk = read.value;
69
+ if (chunk.length === 0) continue;
70
+ if (gathering === void 0 && chunk.length >= piece) {
71
+ hand(chunk);
72
+ return;
73
+ }
74
+ gathering ??= new Uint8Array(piece);
75
+ const moved = Math.min(chunk.length, piece - filled);
76
+ gathering.set(chunk.subarray(0, moved), filled);
77
+ filled += moved;
78
+ if (moved < chunk.length) rest = chunk.subarray(moved);
79
+ if (filled === piece) {
80
+ hand(gathering);
81
+ return;
82
+ }
83
+ }
84
+ };
85
+ return new ReadableStream({
86
+ pull: async (controller) => {
87
+ try {
88
+ await next(controller);
89
+ } catch (cause) {
90
+ release();
91
+ throw cause;
92
+ }
93
+ },
94
+ cancel: async (reason) => {
95
+ try {
96
+ await reader.cancel(reason);
97
+ } finally {
98
+ release();
99
+ }
100
+ }
101
+ }, { highWaterMark: 0 });
102
+ };
103
+ export { gathered, streamOf };
@@ -1,5 +1,6 @@
1
1
  import { Allotment, GitObject, ObjectsRead } from "../../contracts/objects.mjs";
2
2
  import { Oid } from "../../contracts/ids.mjs";
3
+ import "../objects/commit.mjs";
3
4
  import "../objects/tree.mjs";
4
5
  import * as Effect from "effect/Effect";
5
6
  import * as Schema from "effect/Schema";
@@ -1,6 +1,6 @@
1
1
  import { allotmentWithin, objectsReadMost } from "../../contracts/object-values.mjs";
2
2
  import { gitError } from "../../contracts/result.mjs";
3
- import { decodeCommit } from "../objects/commit.mjs";
3
+ import { decodeCommit, noRepoRoots } from "../objects/commit.mjs";
4
4
  import { emptyTree } from "../objects/object.mjs";
5
5
  import { decodeTag } from "../objects/tag.mjs";
6
6
  import { parseTreeBytes, treeEntriesIn } from "../objects/tree.mjs";
@@ -143,11 +143,14 @@ var DiffReader = class {
143
143
  limits;
144
144
  tally;
145
145
  batch;
146
- constructor(read, limits = defaultDiffLimits, tally, batch) {
146
+ /** The repo's roots, each of which a walk through this reader sees as having no parents. */
147
+ roots;
148
+ constructor(read, limits = defaultDiffLimits, tally, batch, roots = noRepoRoots) {
147
149
  this.read = read;
148
150
  this.limits = limits;
149
151
  this.tally = tally;
150
152
  this.batch = batch;
153
+ this.roots = roots;
151
154
  }
152
155
  /** The objects read so far. */
153
156
  get objects() {
@@ -1,4 +1,5 @@
1
1
  import { Commit } from "../../contracts/engine.mjs";
2
+ import { Oid } from "../../contracts/ids.mjs";
2
3
  import { WireDecodeError, WireEncodeError } from "../bytes/errors.mjs";
3
4
  import * as Effect from "effect/Effect";
4
5
  import "effect/Result";
@@ -7,6 +8,12 @@ import "effect/Result";
7
8
  * paragraph, each line's trailing space off, joined by spaces.
8
9
  */
9
10
  export declare function subjectOf(message: string): string;
11
+ /**
12
+ * A repo's roots: the commits it holds without their parents, as Git's `shallow` file names them.
13
+ * Every walk of the repo sees a root as having no parents, as Git's shallow grafts make it, and
14
+ * still follows its tree.
15
+ */
16
+ export type RepoRoots = ReadonlySet<Oid>;
10
17
  /**
11
18
  * A commit read from its bytes, as Git reads it: a `tree` line first, then its `parent` lines,
12
19
  * and an `author` and a `committer` among the headers after them, read leniently, as
@@ -37,6 +37,10 @@ function subjectOf(message) {
37
37
  }
38
38
  return paragraph.join(" ");
39
39
  }
40
+ /** A repo with no roots, as every repo without a `repo/roots` row is. */
41
+ const noRepoRoots = /* @__PURE__ */ new Set();
42
+ /** The parents a walk of a repo with `roots` follows from the commit `oid`: none from a root. */
43
+ const parentsWithin = (roots, oid, parents) => roots.has(oid) ? [] : parents;
40
44
  /**
41
45
  * A commit read from its bytes, as Git reads it: a `tree` line first, then its `parent` lines,
42
46
  * and an `author` and a `committer` among the headers after them, read leniently, as
@@ -135,4 +139,4 @@ const encodeCommit = (commit) => Effect.suspend(() => {
135
139
  ];
136
140
  return Effect.succeed(asCommitTreeStores(utf8(`${lines.join("\n")}\n\n${commit.message}`)));
137
141
  });
138
- export { decodeCommit, encodeCommit, readCommit, subjectOf };
142
+ export { decodeCommit, encodeCommit, noRepoRoots, parentsWithin, readCommit, subjectOf };
@@ -16,7 +16,7 @@ import { handingOn } from "../protocol/packs/writer.mjs";
16
16
  import { memoryPack } from "../storage/fetch.mjs";
17
17
  import { gitObjectOf } from "../storage/object-rows.mjs";
18
18
  import { decodeRow } from "../store/errors.mjs";
19
- import { gitJob } from "../store/job-try.mjs";
19
+ import { jobParts } from "../store/job-try.mjs";
20
20
  import { readRecord } from "../store/repo-record.mjs";
21
21
  import { isLive, liveState } from "../store/reservations.mjs";
22
22
  import { collections, jobRepo } from "../store/scopes.mjs";
@@ -731,7 +731,11 @@ const liftCandidateWork = (context, state, now, name, key) => {
731
731
  };
732
732
  /** Why a link couldn't be written: a conflict, too many commits, or the host's `merge` failing. */
733
733
  const LinkFailure = /* @__PURE__ */ Schema.Union([Schema.Struct({
734
- kind: Schema.Literals(["conflict", "tooManyCommits"]),
734
+ kind: Schema.Literals([
735
+ "conflict",
736
+ "tooManyCommits",
737
+ "tooLarge"
738
+ ]),
735
739
  summary: Schema.String
736
740
  }), Schema.Struct({
737
741
  kind: Schema.Literal("host-error"),
@@ -755,7 +759,7 @@ const commitsPast = (linking, entry, head, tip) => {
755
759
  return historyUpTo(linking.opened.read, {
756
760
  wants: [head],
757
761
  haves: [tip]
758
- }, most + 1, linking.call).pipe(Effect.flatMap((walked) => {
762
+ }, most + 1, linking.call, linking.opened.roots).pipe(Effect.flatMap((walked) => {
759
763
  if (walked.length <= most) return Effect.succeed([...walked].reverse());
760
764
  const summary = `${entry} adds more than ${most} commits, as many as queue.entryCommits lets a link read`;
761
765
  return Effect.fail(linkFailed(entry, {
@@ -791,7 +795,7 @@ const planOf = (linking, entry, row, commits) => hostCall("queue.merge", { repo:
791
795
  /** One entry's link onto `tip`, as its plan's method says: the commit the candidate is at after. */
792
796
  const linkOnto = /* @__PURE__ */ Effect.fnUntraced(function* (linking, entry, row, tip) {
793
797
  const { head } = row;
794
- const { bases } = yield* mergeBases(linking.opened.read, { commits: [tip, head] }, linking.call);
798
+ const { bases } = yield* mergeBases(linking.opened.read, { commits: [tip, head] }, linking.call, linking.opened.roots);
795
799
  if (bases.includes(head)) return tip;
796
800
  const [base] = bases;
797
801
  if (base === void 0) {
@@ -895,7 +899,7 @@ const buildStep = /* @__PURE__ */ Effect.fnUntraced(function* (host$1, context,
895
899
  const options = yield* host$1.options(repo);
896
900
  if (options === void 0) return done;
897
901
  const opened = yield* asHost(openRead(host, repo));
898
- const limits = yield* limitsOf();
902
+ const limits = yield* limitsOf({ milliseconds: host$1.buildMilliseconds });
899
903
  const { call } = yield* readerOf(opened, limits, "walk-limit");
900
904
  const made = new MadeObjects();
901
905
  const read = (input) => {
@@ -946,8 +950,18 @@ const buildStep = /* @__PURE__ */ Effect.fnUntraced(function* (host$1, context,
946
950
  candidate: id,
947
951
  by
948
952
  };
953
+ let first;
954
+ const tooLarge = tried.tooLarge?.candidate === id ? tried.tooLarge : void 0;
949
955
  const linkOf = Effect.fnUntraced(function* (entry, entryRow, onto) {
950
956
  const key = yield* linkKey(linking, onto, entry, entryRow);
957
+ if (reached.at === from) first = {
958
+ entry,
959
+ key
960
+ };
961
+ if (tooLarge?.key === key) return yield* Effect.fail(linkFailed(entry, {
962
+ kind: "tooLarge",
963
+ summary: tooLarge.summary
964
+ }));
951
965
  const kept = last.get(key);
952
966
  const before = made.count;
953
967
  if (kept !== void 0) for (const { type, bytes } of kept.objects) yield* made.add(type, bytes);
@@ -969,7 +983,21 @@ const buildStep = /* @__PURE__ */ Effect.fnUntraced(function* (host$1, context,
969
983
  if (reached.at < links.length && (yield* spent(made, call))) break;
970
984
  }
971
985
  return reached;
972
- }).pipe(Effect.catchTag("LinkFailed", (failed) => Effect.succeed({ failed })), Effect.catchIf((error) => atLimit(error) && reached.at > from, () => Effect.succeed(reached)));
986
+ }).pipe(Effect.catchTag("LinkFailed", (failed) => Effect.succeed({ failed })), Effect.catchIf(atLimit, (error) => {
987
+ if (reached.at > from) return Effect.succeed(reached);
988
+ if (first === void 0) return Effect.fail(error);
989
+ const { entry, key } = first;
990
+ const summary = `${entry} can't be linked within one build try: ${error.message}`;
991
+ tried.tooLarge = {
992
+ candidate: id,
993
+ key,
994
+ summary
995
+ };
996
+ return Effect.succeed({ failed: linkFailed(entry, {
997
+ kind: "tooLarge",
998
+ summary
999
+ }) });
1000
+ }));
973
1001
  const plan = new QueuePlan(state, now);
974
1002
  if ("failed" in built) {
975
1003
  const { entry, failure } = built.failed;
@@ -1226,7 +1254,8 @@ const AdvanceJob = /* @__PURE__ */ Job.make(advanceName, {
1226
1254
  });
1227
1255
  const BuildJob = /* @__PURE__ */ Job.make(buildName, {
1228
1256
  payload: CandidateData,
1229
- retry: queueJobRetry
1257
+ retry: queueJobRetry,
1258
+ timeout: queueLimits.buildTryMilliseconds
1230
1259
  });
1231
1260
  const TimeoutJob = /* @__PURE__ */ Job.make(timeoutName, {
1232
1261
  payload: CandidateData,
@@ -1243,9 +1272,9 @@ const queueJobs = (host, onFailure) => {
1243
1272
  const candidateOf = (job, context) => loadCandidate(context, jobRepo(job), job.data.candidate).pipe(Effect.map((loaded) => loaded?.state));
1244
1273
  return [
1245
1274
  queueTrimJob(host, onFailure),
1246
- gitJob(AdvanceJob, (data) => queueTry(data, (job, context) => overCore(host, context, advance(host, job, context))), { onFailure: holdOnFailure(host, targetOf, onFailure, unbatch) }),
1247
- gitJob(BuildJob, (data) => queueTry(data, (job, context) => Effect.asVoid(overCore(host, context, build(job, context)))), { onFailure: holdOnFailure(host, candidateOf, onFailure) }),
1248
- gitJob(TimeoutJob, (data) => queueTry(data, (job, context) => Effect.asVoid(overCore(host, context, timeout(job, context)))), { onFailure: holdOnFailure(host, candidateOf, onFailure) })
1275
+ jobParts(AdvanceJob, (data) => queueTry(data, (job, context) => overCore(host, context, advance(host, job, context))), { onFailure: holdOnFailure(host, targetOf, onFailure, unbatch) }),
1276
+ jobParts(BuildJob, (data) => queueTry(data, (job, context) => Effect.asVoid(overCore(host, context, build(job, context)))), { onFailure: holdOnFailure(host, candidateOf, onFailure) }),
1277
+ jobParts(TimeoutJob, (data) => queueTry(data, (job, context) => Effect.asVoid(overCore(host, context, timeout(job, context)))), { onFailure: holdOnFailure(host, candidateOf, onFailure) })
1249
1278
  ];
1250
1279
  };
1251
1280
  export { checkPublish, queueJobs };
@@ -17,6 +17,8 @@ export interface QueueHost {
17
17
  readonly options: (repo: RepoName) => Effect.Effect<MergeQueueOptions | undefined, GitError>;
18
18
  /** The `keys` every repo's queue has, as `queueKeysOf` reads them: `undefined` for one per repo. */
19
19
  readonly keys: QueueKeys | undefined;
20
+ /** How long a build try may link for: `queueLimits.buildMilliseconds`, or the host's `cpuMs` when lower. */
21
+ readonly buildMilliseconds: number;
20
22
  }
21
23
  declare const QueueInternals_base: Context.ServiceClass<QueueInternals, "@ref0/git/queue/QueueInternals", QueueHost>;
22
24
  /** Queue internals available only from MergeQueue.layer, never a host's public service. */
@@ -25,6 +27,8 @@ declare const QueueBase_base: Context.ServiceClass<QueueBase, "@ref0/git/queue/Q
25
27
  readonly records: Records.RecordsService;
26
28
  readonly needs: Context.Context<QueueNeeds>;
27
29
  readonly onFailure: WorkFailed | undefined;
30
+ /** The CPU one try may use, from the adapter's `RequestLimits`: none where it gives none. */
31
+ readonly cpuMs: number | undefined;
28
32
  readonly attach: (host: QueueHost) => Effect.Effect<void>;
29
33
  }>;
30
34
  /**
@@ -5,6 +5,7 @@ import { acting } from "../core/parts.mjs";
5
5
  import { queueJobs } from "./advance.mjs";
6
6
  import { queueCalls } from "./calls.mjs";
7
7
  import { QueueBase, QueueInternals, queueKeysOf, queueOptions } from "./host.mjs";
8
+ import { buildMillisecondsOf } from "./limits.mjs";
8
9
  import * as Effect from "effect/Effect";
9
10
  import * as Option from "effect/Option";
10
11
  import * as Context from "effect/Context";
@@ -51,9 +52,10 @@ const layer = (options) => {
51
52
  records: base.records,
52
53
  needs: Context.add(base.needs, MergeParts, parts.value),
53
54
  options: optionsOf,
54
- keys: queueKeysOf(options)
55
+ keys: queueKeysOf(options),
56
+ buildMilliseconds: buildMillisecondsOf(base.cpuMs)
55
57
  };
56
- for (const job of queueJobs(host, base.onFailure)) yield* registration.addJob(job);
58
+ for (const job of queueJobs(host, base.onFailure)) yield* job(registration.addJob);
57
59
  yield* base.attach(host);
58
60
  return Context.make(MergeQueue, queueService(host)).pipe(Context.add(QueueInternals, host));
59
61
  }));
@@ -127,8 +127,24 @@ const queueLimits = {
127
127
  * The most `queue.entryCommits` may be, so the walk never grows past it: an entry of more
128
128
  * commits merges by an admin's direct push.
129
129
  */
130
- entryCommitsMost: 1e4
130
+ entryCommitsMost: 1e4,
131
+ /**
132
+ * How long one build try may link for, past `limitsOf`'s 10 s for a call someone waits on, since
133
+ * a build is a job's try (#1969). At queue-entry-10k's reading, about 3 s of CPU each 10 s of
134
+ * wall, it spends about 18 s of CPU, under Cloudflare's 30,000 ms `cpuMs`. A host whose
135
+ * `RequestLimits` gives a lower `cpuMs` takes that instead. A try's first link past it fails its
136
+ * entry `tooLarge`, since the next try would start it over.
137
+ */
138
+ buildMilliseconds: 6e4,
139
+ /**
140
+ * A `queue.build` try's timeout: its links' `buildMilliseconds`, and as long again to write
141
+ * their pack and commit. Past the 30 s a job's try has by default, which would cut the links
142
+ * first, and well within a Cloudflare alarm's.
143
+ */
144
+ buildTryMilliseconds: 12e4
131
145
  };
146
+ /** How long a build try may link for on a host whose tries may use `cpuMs` of CPU: the less of the two. */
147
+ const buildMillisecondsOf = (cpuMs) => Math.min(queueLimits.buildMilliseconds, cpuMs ?? queueLimits.buildMilliseconds);
132
148
  const encoder = new TextEncoder();
133
149
  /** A value's size as UTF-8 JSON, as infra counts a row's. */
134
150
  const jsonSize = (value) => encoder.encode(JSON.stringify(value)).length;
@@ -149,4 +165,4 @@ const targetsFull = () => fail("RESOURCE_EXHAUSTED", `The repo's queues hold ${q
149
165
  hint: `Queue onto a branch the repo queues onto now, or wait: a target's row goes ${queueLimits.kept / day} days after its queue went idle`,
150
166
  context: { reason: "queue-targets-full" }
151
167
  });
152
- export { checkBytes, jsonSize, queueFull, queueJobRetry, queueLimits, targetsFull };
168
+ export { buildMillisecondsOf, checkBytes, jsonSize, queueFull, queueJobRetry, queueLimits, targetsFull };
@@ -130,7 +130,8 @@ const EntryRow = /* @__PURE__ */ Schema.Struct({
130
130
  "host-error",
131
131
  "interaction",
132
132
  "refused",
133
- "tooManyCommits"
133
+ "tooManyCommits",
134
+ "tooLarge"
134
135
  ])),
135
136
  /** Its candidates' land conflicts, which a `retry` keeps: at `landRestarts`, it's pinned. */
136
137
  conflicts: Schema.optionalKey(Schema.Int),
@@ -1,5 +1,5 @@
1
1
  import { decodeRow, storeCall } from "../store/errors.mjs";
2
- import { gitJob } from "../store/job-try.mjs";
2
+ import { jobParts } from "../store/job-try.mjs";
3
3
  import { TrimData, trimName } from "../store/queue-jobs.mjs";
4
4
  import { readRecord } from "../store/repo-record.mjs";
5
5
  import { collections, jobRepo, newChangeId, repoScope } from "../store/scopes.mjs";
@@ -285,5 +285,5 @@ const TrimJob = /* @__PURE__ */ Job.make(trimName, {
285
285
  * failure to `onFailure`, so the host's `repo.work.failed` names it and `work.retry` runs it again:
286
286
  * a failed job's row stays failed whatever a target's first write saves.
287
287
  */
288
- const queueTrimJob = (host, onFailure) => gitJob(TrimJob, (cursor) => Effect.flatMap(Effect.all([CurrentJob.store, CurrentJob.current]), ([store, job]) => Effect.flatMap(Effect.provideContext(Clock$1.currentTimeMillis, host.needs), (now) => trimStep(store, jobRepo(job), cursor, now))), onFailure === void 0 ? {} : { onFailure });
288
+ const queueTrimJob = (host, onFailure) => jobParts(TrimJob, (cursor) => Effect.flatMap(Effect.all([CurrentJob.store, CurrentJob.current]), ([store, job]) => Effect.flatMap(Effect.provideContext(Clock$1.currentTimeMillis, host.needs), (now) => trimStep(store, jobRepo(job), cursor, now))), onFailure === void 0 ? {} : { onFailure });
289
289
  export { queueTrimJob };