@githolon/runtime 0.110.0 → 0.110.1

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.
@@ -85,6 +85,7 @@
85
85
  45e0c35b4e8b0c1f606ca98a827d5ba041716ef346c5ba77a5c3303a5399b7ff adapter/proto/nomos/runtime/v2/observability_desk_pb.js
86
86
  463a7041ce45ddd801fc0e0981bb11658b76bb44caad19d2971d73d7700d739b node_modules/@bufbuild/protobuf/dist/esm/wire/text-encoding.js
87
87
  46ce19f00a64198852937f4a982c59a5d237aeab590255873e131f2f0468e98e peer-office/src/runtime/workspace_opening.ts
88
+ 46df6f8f4bd0288fed37e8393805df8542556ae7ad663dcef492406000963a63 peer-office/package/package.json
88
89
  475e62094c73367833cec6253c5834a887cae9bcfa43a691a9fe3b7495c19106 node_modules/@bufbuild/protobuf/dist/esm/unknown-enum.js
89
90
  48b8a92448c21da157755c24058a1522d62389815254bd43858e27fc200cc793 peer-office/src/runtime/retention_observer.ts
90
91
  497ee51559f8769c47defb7679dd516b5736c22c433bc857a19e8ccd9593c842 node_modules/is-unsafe/src/contexts/xml.js
@@ -93,7 +94,6 @@
93
94
  4de8a60302e6ab22ef5607ee88ab6dd6559221fb8620780fb874a1dcf3000d06 node_modules/is-unsafe/src/contexts/sql.js
94
95
  4f177e43f1ac36dc25b2b6a44970c97918091416bd15722b65ac938256bda687 node_modules/fast-xml-parser/src/xmlparser/OptionsBuilder.js
95
96
  4f7192626ff16f10e8845dccfce280cfde437dd6faa78d62700e3b21d589ca97 peer-office/src/reception/extremum_read.ts
96
- 4f72a4a85c36309d7d40c387ac6e177ac3f72a7f1227a1a6b92a587dbba1169c peer-office/src/runtime/replica_follow_controller.ts
97
97
  4ff429ac40686adccd2a9ad77e9d12402da95e5396971a9df6e0f3cfa23ff3e7 platform-shells/node/certification_seal.ts
98
98
  501bf6549e9c44a4dbdea0f7a89d567c9b7e7db145b25ec7c8a38e2b4b7a87f2 adapter/custody_retention_refs.ts
99
99
  50e504430270aecdea3794d30f17911099946f38eee258b5837967cb989abd93 node_modules/@bufbuild/protobuf/dist/esm/codegenv2/enum.js
@@ -124,7 +124,6 @@
124
124
  6eb1b52bfa2c7eb3e36b6817973defd7be18dbc7ce4b56ca576b1222dd5df4d7 node_modules/fast-xml-parser/src/xmlparser/DocTypeReader.js
125
125
  6ec9654705968f0c75cb0b184d4bb6629a932c05e3d27d603eb42a3cb9447f6f node_modules/@bufbuild/protobuf/dist/esm/reflect/error.js
126
126
  6fc7191c83f8c3318f656463bab0700d9585aa42a7285c364ee73c9829b488d5 peer-office/src/runtime/live_correspondence_desk.ts
127
- 709b5a7e68558438cdf1e4d11ea458b360e6190572c42219c5b9165533d4fb78 peer-office/src/runtime/workspace_sync.ts
128
127
  70f2527a9fde5075b760e0f2b36c5aced16a44d7ba3767f6f00b249fd81e91ec peer-office/src/runtime/kernel_port.ts
129
128
  711039a2d590af0e112a32c7bc50eb77e5fac6336e56e8eb01cc74df23a2cd44 adapter/git_custody_desk.ts
130
129
  71de64c0b205eed7bcbbe11bd937a363c83cb5ab8e9977c4bb4b73b3c5353cf3 peer-office/src/runtime/placement_discovery_desk.ts
@@ -134,7 +133,6 @@
134
133
  72f4dbde9d104ea96276198f8fab8b32e1a296d7ae57b74f8f175472627c2546 peer-office/src/runtime/custody_return_delta.ts
135
134
  73e489001027c703bc0224ae73f78ecefe028e88284bd06952e8603c3d81472c node_modules/@bufbuild/protobuf/dist/esm/wkt/gen/google/protobuf/api_pb.js
136
135
  74b1e9405ec5b38e957cf85fb9f73885ab485db853a8b0f95200afa42c5921f8 peer-office/src/runtime/model_adoption_desk.ts
137
- 74f630102656bb2cb326296d4a19343ad5fdfa7949696be26110f318abf7b2ff peer-office/package/package.json
138
136
  75ba818bf766331dc4abe3c488f65562968684934b57eb21e6e777c358c561ae peer-office/package/src/remote_reception.ts
139
137
  77a917d8c6427a9b7d819d4941ec6aeecc079ccb9b1a05c0dc1190680b589f78 platform-shells/node/stdio/entry.ts
140
138
  799c15bd106543d60c5422eeda102396a055397f20866c27504598b68d1d288d node_modules/@bufbuild/protobuf/dist/esm/wire/binary-encoding.js
@@ -176,13 +174,13 @@
176
174
  96ec5d127a4e8cd77bdc678422f0d57c8ff9e37bcec999983da71a7b72ce9a0e node_modules/@nodable/entities/src/entities.js
177
175
  98f5abf9a7fb522aab513ef3831dd9c5837cebcb38a960cb546ffd084926d746 node_modules/@bufbuild/protobuf/dist/esm/wkt/gen/google/protobuf/empty_pb.js
178
176
  98f70a85fe9d2578c977bbf26927910479cef472100b5ed7bebd4c390e79213c peer-office/src/runtime/workspace_access_desk.ts
179
- 99be7abab3e81c69c2c2919768779742f2ba5ec07befa4abf18a2907fa1c3d0a peer-office/src/runtime/custody_offer.ts
180
177
  99ce0b71dc7acc73e48634ff609eeb3620cf24b524e89835e804d37fb6b51b2c adapter/offer_transport_contract.ts
181
178
  9a3d4c2296b0139778c8f61319349eac6dc0cdb723688f41ebf3c135dca85702 peer-office/src/runtime/history_acquisition_state.ts
182
179
  9b1e46d587a9ad5d1531a5755ba4feccd2878de77749edce8a0086db3eb2217d peer-office/src/runtime/admission_durability_desk.ts
183
180
  9c4c967ea6c149011acb8aabfbadb73651f84d572335c48391d627e5283c0cd0 node_modules/@bufbuild/protobuf/dist/esm/fields.js
184
181
  9e1bf39540fd14df32aa2307c44dd4d93a40a6024199f334ccf3db001f44a7f6 peer-office/src/runtime/local_copy_readability.ts
185
182
  9e82e1fc1bfd3e3573f64349dc42b4b624ed61d24e5c553f2bb4d041444f166c node_modules/@bjorn3/browser_wasi_shim/dist/fd.js
183
+ 9efa0e5824cc0370ea3596b30cd57ea860df0bae95a0caccbbfe97d845a7a09b peer-office/src/runtime/custody_offer.ts
186
184
  9f7a3b2bb0e2a2da849fd9101228bd9c9682b39d667e20900dd172d954b1a548 peer-office/src/runtime/observability_desk.ts
187
185
  a0eca2694871be026546039e99a71291822d01ba81943d44e69a14b2d766fd1a peer-office/src/runtime/custody_desk.ts
188
186
  a0fcc6110f1154fd197a8ce056e2008dbc7d1750f8dd3ba77c3910af928ed3a1 node_modules/uri-js/dist/es5/uri.all.js
@@ -199,6 +197,7 @@ aa6349944f16d71986273ecfc8e552bfece3d61d5641e526c0ceabf3f154fdaf peer-office/sr
199
197
  ab43714f566a6ccd988cc3a30810d857552dbd14d0f060934907fb4bba1000f0 peer-office/package/src/admission_decision.ts
200
198
  ab80eeeafd4d89a5daaf5d2e00fb471cc6b53fa90776750ca3ad82df482d7c3f peer-office/src/runtime/peer_lifecycle.ts
201
199
  ad3de46df125304b2a61c2fa5537b0e519635997d99686a76119b38cf260963f adapter/proto/nomos/runtime/v2/identity_desk_pb.js
200
+ aeb94bc5762080dca498fcbdfa5c347525dceb1f3748db82106b479c5d23d931 peer-office/src/runtime/workspace_sync.ts
202
201
  afde3ddb29cc6ee2c48b30043feca4ea14b5690035aa134b08b4df83558faa7c platform-shells/shared/system_observation_clock.ts
203
202
  b09ee99807e1edeb746b4a4a1e41519edaff1fed9f71a170bc15e8835af93e25 node_modules/@bufbuild/protobuf/dist/esm/wkt/gen/google/protobuf/timestamp_pb.js
204
203
  b178d69931fdb285d0cd3bae0343a0fd0c80eed27e90d07992153927f9bcc8c3 peer-office/src/runtime/frame_runner.ts
@@ -258,6 +257,7 @@ dd9f3f24fb154cfbfbde94e8f2647647c80c8ca050b98e981a407e760a4b9c1e node_modules/@
258
257
  deaa25227d669aa3fbe99174275588dcc175de648ae6623fddf11d6ae69d7f67 platform-shells/node/local-development/peer_process.ts
259
258
  e20a132033f105a29db1cfdb3d85bbadbb7206b9a7e3336bcb030a63d66b4ab2 node_modules/is-unsafe/src/contexts/nosql.js
260
259
  e2133d7e0f0ce5491a3e9bd560e9e47db2243a6a9f762be89c82e027d99d278e peer-office/src/runtime/credential_sessions.ts
260
+ e24433e22af52db25858865dfff3c6ed1e6932f3257ae242a795acbedda70303 peer-office/src/runtime/replica_follow_controller.ts
261
261
  e2d341fc536c47a45d2e45fc1df232094b4afe67281b92eae91ed9b7698c32ff platform-shells/browser/entry.ts
262
262
  e34016b82b6f6e4c4a1cc2dd44ccd14a348e8156a1f6c5aeeb2c7fc36a15b8f9 adapter/proto/nomos/kernel/v1/kernel_pb.js
263
263
  e34016b82b6f6e4c4a1cc2dd44ccd14a348e8156a1f6c5aeeb2c7fc36a15b8f9 peer-office/package/src/protocol/nomos/kernel/v1/kernel_pb.js
@@ -14173,6 +14173,15 @@ var NomosRuntimeComponent = (() => {
14173
14173
  }
14174
14174
  if (result.stillAhead || result.pushFailed || result.directOfferDeferred || result.reconnectRequired) {
14175
14175
  if (result.directOfferDeferred) {
14176
+ if (!result.reconnectRequired) {
14177
+ this.#desk.transition(result.workspace, {
14178
+ case: ReplicaFollowEventKind.Failed,
14179
+ nowUnixMillis,
14180
+ failure: "remote workspace opening; retrying",
14181
+ retryWithinMillis: 5e3
14182
+ });
14183
+ return delayUntilDue(this.#desk.get(result.workspace), nowUnixMillis);
14184
+ }
14176
14185
  this.#desk.transition(result.workspace, {
14177
14186
  case: ReplicaFollowEventKind.DependencyDeferred,
14178
14187
  nowUnixMillis,
@@ -16051,6 +16060,34 @@ var NomosRuntimeComponent = (() => {
16051
16060
  // ../src/runtime/custody_offer.ts
16052
16061
  var CUSTODY_OFFER_MEDIA_TYPE = "application/vnd.nomos.custody-offer-batch+protobuf";
16053
16062
  var CUSTODY_OFFER_RESULT_MEDIA_TYPE = "application/vnd.nomos.custody-offer-result+protobuf";
16063
+ function settleCustodyOfferExchange(awaiting, response) {
16064
+ if (response.status === 202 && response.contentType?.includes("application/json")) {
16065
+ try {
16066
+ const pending = JSON.parse(new TextDecoder().decode(response.body));
16067
+ if (pending?.retryable === true && typeof pending.preparing === "string") {
16068
+ return { case: "maintenance", kind: pending.preparing };
16069
+ }
16070
+ } catch {
16071
+ }
16072
+ }
16073
+ if (!response.contentType?.includes(CUSTODY_OFFER_RESULT_MEDIA_TYPE)) {
16074
+ return {
16075
+ case: "unexpected",
16076
+ status: response.status,
16077
+ ...response.contentType === void 0 ? {} : { contentType: response.contentType }
16078
+ };
16079
+ }
16080
+ const verdict = decodeCustodyOffer(response.body, awaiting.requestId);
16081
+ const receipt = custodyOfferReceipt(awaiting.requestId, verdict);
16082
+ switch (verdict.case) {
16083
+ case "admission":
16084
+ return { case: "admission", value: verdict.value, receipt, status: response.status };
16085
+ case "failure":
16086
+ return { case: "failure", value: verdict.value, receipt, status: response.status };
16087
+ case "blocked":
16088
+ return { case: "blocked", value: verdict.value, receipt, status: response.status };
16089
+ }
16090
+ }
16054
16091
  function encodeInlineCustodyOffer(args) {
16055
16092
  return toBinary(CustodyOfferBatchRequestSchema, create(CustodyOfferBatchRequestSchema, {
16056
16093
  protocolVersion: 2,
@@ -16177,6 +16214,7 @@ var NomosRuntimeComponent = (() => {
16177
16214
  var PLACEMENT_REF3 = "refs/nomos/placement";
16178
16215
  var LAW_PRODUCTS_MEDIA_TYPE = "application/vnd.nomos.export-law-products-response+protobuf";
16179
16216
  var WorkspaceSyncPhase = Object.freeze({
16217
+ Idle: "idle",
16180
16218
  Probe: "probe",
16181
16219
  Offer: "offer",
16182
16220
  Lease: "lease",
@@ -16210,7 +16248,6 @@ var NomosRuntimeComponent = (() => {
16210
16248
  #rediscover;
16211
16249
  /** The route the directory's answer yields, recomputed once that answer is observed. */
16212
16250
  #reroute;
16213
- #placementFetch;
16214
16251
  #discoveredFrontier;
16215
16252
  #observePlacement;
16216
16253
  /** Ask the directory for the provider's current placement frontier this round although a
@@ -16219,19 +16256,14 @@ var NomosRuntimeComponent = (() => {
16219
16256
  #directoryAnswered;
16220
16257
  #placementFetched;
16221
16258
  /** A round which converged without leasing, finishing once placement alone is fetched. */
16222
- #afterPlacement;
16223
16259
  #leased = false;
16224
- #lease;
16225
16260
  #command;
16226
16261
  #requestId;
16227
16262
  #started;
16228
- #phase = WorkspaceSyncPhase.Lease;
16263
+ #state = { phase: WorkspaceSyncPhase.Idle };
16229
16264
  #localHead;
16230
16265
  #offerHead;
16231
16266
  #previousHead;
16232
- #fetchStarted;
16233
- #offerStarted;
16234
- #offerRequestId;
16235
16267
  #pushMillis = 0;
16236
16268
  #pushBytes = 0n;
16237
16269
  #desiredHead;
@@ -16326,7 +16358,7 @@ var NomosRuntimeComponent = (() => {
16326
16358
  throw new Error(`replica '${this.#binding.replicaId}' has no custody remote`);
16327
16359
  }
16328
16360
  if (this.#rediscover || this.#recheckPlacement || !this.#route?.placementObserved && !this.#route?.placementFrontier && !this.#kernel.resolveRef(this.#mount, this.#requestId, PLACEMENT_REF3)) {
16329
- this.#phase = WorkspaceSyncPhase.Discover;
16361
+ this.#state = { phase: WorkspaceSyncPhase.Discover };
16330
16362
  return this.#remember({
16331
16363
  case: "pending",
16332
16364
  value: create(CorrespondencePendingSchema, {
@@ -16346,13 +16378,13 @@ var NomosRuntimeComponent = (() => {
16346
16378
  #openRound() {
16347
16379
  if (this.#receiveState || this.#replaceLocalHead !== void 0) return this.#leaseEffect();
16348
16380
  if (!this.#localHead) return this.#leaseEffect();
16349
- this.#offerRequestId = `${this.#binding.replicaId}:${this.#requestId}:${this.workId}:frontier`;
16381
+ const requestId = `${this.#binding.replicaId}:${this.#requestId}:${this.workId}:frontier`;
16350
16382
  return this.#beginOffer(encodeInlineCustodyOffer({
16351
16383
  session: this.#binding.replicaId,
16352
- requestId: this.#offerRequestId,
16384
+ requestId,
16353
16385
  observedHead: this.#localHead,
16354
16386
  intents: []
16355
- }), true);
16387
+ }), { case: "awaiting", requestId }, true);
16356
16388
  }
16357
16389
  #offerOrReconcile() {
16358
16390
  if (this.#command.admit && this.#localHead && this.#localHead !== this.#previousHead) {
@@ -16373,13 +16405,13 @@ var NomosRuntimeComponent = (() => {
16373
16405
  throw new Error(`kernel did not classify transport for intent '${unspecified.intentId}'`);
16374
16406
  }
16375
16407
  if (suffix.length > 0) {
16376
- this.#offerStarted = this.#clock.monotonicNanoseconds();
16377
- this.#offerRequestId = `${this.#binding.replicaId}:${this.#requestId}:${this.workId}`;
16408
+ const requestId2 = `${this.#binding.replicaId}:${this.#requestId}:${this.workId}`;
16409
+ const startedAt = this.#clock.monotonicNanoseconds();
16378
16410
  this.#offerAfterConverge = true;
16379
16411
  this.#rebaseFrom = this.#previousHead;
16380
16412
  return this.#beginOffer(encodeInlineCustodyOffer({
16381
16413
  session: this.#binding.replicaId,
16382
- requestId: this.#offerRequestId,
16414
+ requestId: requestId2,
16383
16415
  ...this.#previousHead === void 0 ? {} : { baseHead: this.#previousHead },
16384
16416
  observedHead: this.#localHead,
16385
16417
  intents: suffix,
@@ -16390,17 +16422,17 @@ var NomosRuntimeComponent = (() => {
16390
16422
  this.#previousHead
16391
16423
  ) : void 0,
16392
16424
  fastForwardOnly: true
16393
- }));
16425
+ }), { case: "awaiting", requestId: requestId2, startedAt });
16394
16426
  }
16395
16427
  }
16396
- this.#offerRequestId = `${this.#binding.replicaId}:${this.#requestId}:${this.workId}:reconcile`;
16428
+ const requestId = `${this.#binding.replicaId}:${this.#requestId}:${this.workId}:reconcile`;
16397
16429
  return this.#beginOffer(encodeInlineCustodyOffer({
16398
16430
  session: this.#binding.replicaId,
16399
- requestId: this.#offerRequestId,
16431
+ requestId,
16400
16432
  baseHead: this.#previousHead,
16401
16433
  observedHead: this.#localHead,
16402
16434
  intents: []
16403
- }));
16435
+ }), { case: "awaiting", requestId });
16404
16436
  }
16405
16437
  /**
16406
16438
  * NO COMMON BASE — a round that cannot converge, and must not pay for history to find out.
@@ -16476,18 +16508,18 @@ var NomosRuntimeComponent = (() => {
16476
16508
  #pullBeforeOffer() {
16477
16509
  this.#offerAfterConverge = true;
16478
16510
  this.#rebaseFrom = this.#previousHead;
16479
- this.#offerRequestId = `${this.#binding.replicaId}:${this.#requestId}:${this.workId}:pull-${this.#rebases}`;
16511
+ const requestId = `${this.#binding.replicaId}:${this.#requestId}:${this.workId}:pull-${this.#rebases}`;
16480
16512
  return this.#beginOffer(encodeInlineCustodyOffer({
16481
16513
  session: this.#binding.replicaId,
16482
- requestId: this.#offerRequestId,
16514
+ requestId,
16483
16515
  ...this.#previousHead === void 0 ? {} : { baseHead: this.#previousHead },
16484
16516
  observedHead: this.#localHead,
16485
16517
  intents: []
16486
- }));
16518
+ }), { case: "awaiting", requestId });
16487
16519
  }
16488
- #leaseEffect() {
16520
+ #leaseEffect(afterPlacement) {
16489
16521
  const token = this.#authToken();
16490
- this.#phase = WorkspaceSyncPhase.Lease;
16522
+ this.#state = { phase: WorkspaceSyncPhase.Lease, ...afterPlacement ? { afterPlacement } : {} };
16491
16523
  return this.#remember({
16492
16524
  case: "pending",
16493
16525
  value: create(CorrespondencePendingSchema, {
@@ -16516,35 +16548,38 @@ var NomosRuntimeComponent = (() => {
16516
16548
  `workspace sync '${this.workId}' expected effect '${expected}', received '${receipt.effectId}'`
16517
16549
  );
16518
16550
  }
16551
+ const state = this.#state;
16519
16552
  const previousReceipt = this.#lastReceiptEffectId;
16520
16553
  this.#lastReceiptEffectId = receipt.effectId;
16521
16554
  try {
16522
16555
  if (receipt.outcome.case === "failure") {
16523
- if (this.#phase === WorkspaceSyncPhase.Discover) return this.#openRound();
16556
+ if (state.phase === WorkspaceSyncPhase.Discover) return this.#openRound();
16524
16557
  return this.#transportFailure(
16525
16558
  receipt.outcome.value.message,
16526
16559
  receipt.outcome.value.reason === PeerEffectFailureReason.OFFLINE
16527
16560
  );
16528
16561
  }
16529
- if (this.#phase === WorkspaceSyncPhase.Offer || this.#phase === WorkspaceSyncPhase.Probe) return this.#acceptOffer(receipt);
16530
- if (this.#phase === WorkspaceSyncPhase.Lease) return this.#acceptLease(receipt);
16531
- if (this.#phase === WorkspaceSyncPhase.Discover) return this.#acceptDiscovery(receipt);
16532
- if (this.#phase === WorkspaceSyncPhase.Placement) {
16533
- if (!this.#placementFetch || !this.#lease) throw new Error("placement transfer lost its lease");
16534
- this.#placementFetch.accept(receipt);
16562
+ if (state.phase === WorkspaceSyncPhase.Offer || state.phase === WorkspaceSyncPhase.Probe) {
16563
+ return this.#acceptOffer(receipt, state);
16564
+ }
16565
+ if (state.phase === WorkspaceSyncPhase.Lease) return this.#acceptLease(receipt, state);
16566
+ if (state.phase === WorkspaceSyncPhase.Discover) return this.#acceptDiscovery(receipt);
16567
+ if (state.phase === WorkspaceSyncPhase.Placement) {
16568
+ state.transfer.accept(receipt);
16535
16569
  this.#placementFetched?.();
16536
- if (this.#afterPlacement) return this.#finish(this.#afterPlacement);
16537
- return this.#beginMainFetch(this.#lease);
16570
+ if (state.afterPlacement) return this.#finish(state.afterPlacement);
16571
+ return this.#beginMainFetch(state.lease);
16538
16572
  }
16539
- if (this.#phase === WorkspaceSyncPhase.Fetch) return this.#acceptFetch(receipt);
16573
+ if (state.phase === WorkspaceSyncPhase.Fetch) return this.#acceptFetch(receipt, state);
16540
16574
  throw new Error(`workspace sync '${this.workId}' is already complete`);
16541
16575
  } catch (error) {
16542
16576
  this.#lastReceiptEffectId = previousReceipt;
16543
16577
  throw error;
16544
16578
  }
16545
16579
  }
16546
- #beginOffer(body, probe = false) {
16547
- this.#phase = probe ? WorkspaceSyncPhase.Probe : WorkspaceSyncPhase.Offer;
16580
+ #beginOffer(body, exchange, probe = false) {
16581
+ const phase = probe ? WorkspaceSyncPhase.Probe : WorkspaceSyncPhase.Offer;
16582
+ this.#state = { phase, exchange };
16548
16583
  const token = this.#authToken();
16549
16584
  this.#pushBytes += BigInt(body.byteLength);
16550
16585
  return this.#remember({
@@ -16554,7 +16589,7 @@ var NomosRuntimeComponent = (() => {
16554
16589
  effect: {
16555
16590
  case: "http",
16556
16591
  value: create(PeerHttpEffectSchema, {
16557
- effectId: `${this.workId}:${this.#phase}`,
16592
+ effectId: `${this.workId}:${phase}`,
16558
16593
  method: PeerHttpMethod.POST,
16559
16594
  url: this.#offerEndpoint(),
16560
16595
  contentType: CUSTODY_OFFER_MEDIA_TYPE,
@@ -16571,28 +16606,30 @@ var NomosRuntimeComponent = (() => {
16571
16606
  })
16572
16607
  });
16573
16608
  }
16574
- #acceptOffer(receipt) {
16575
- this.#pushMillis = this.#offerStarted === void 0 ? 0 : elapsedMillis(this.#clock, this.#offerStarted);
16609
+ #acceptOffer(receipt, state) {
16610
+ const exchange = state.exchange;
16611
+ this.#pushMillis = exchange.startedAt === void 0 ? 0 : elapsedMillis(this.#clock, exchange.startedAt);
16576
16612
  if (receipt.outcome.case !== "response") {
16577
16613
  throw new Error("platform returned the wrong receipt for a custody offer");
16578
16614
  }
16579
- const response = receipt.outcome.value;
16580
- if (!response.contentType?.includes(CUSTODY_OFFER_RESULT_MEDIA_TYPE)) {
16615
+ const outcome = settleCustodyOfferExchange(exchange, receipt.outcome.value);
16616
+ if (outcome.case === "maintenance") {
16617
+ return this.#finishOfferOutcome(true, false);
16618
+ }
16619
+ if (outcome.case === "unexpected") {
16581
16620
  this.#pushError = create(RuntimeTransportFailureSchema, {
16582
16621
  endpoint: this.#offerEndpoint(),
16583
- status: response.status,
16622
+ status: outcome.status,
16584
16623
  refused: false,
16585
- message: `Sync received an unexpected server response (HTTP ${response.status}; ${response.contentType || "no content type"}). No custody receipt was returned.`
16624
+ message: `Sync received an unexpected server response (HTTP ${outcome.status}; ${outcome.contentType || "no content type"}). No custody receipt was returned.`
16586
16625
  });
16587
16626
  return this.#finishOfferOutcome(false);
16588
16627
  }
16589
- if (!this.#offerRequestId) throw new Error("custody offer has no request identity");
16590
- const outcome = decodeCustodyOffer(response.body, this.#offerRequestId);
16591
- this.#offerReceipt = custodyOfferReceipt(this.#offerRequestId, outcome);
16628
+ this.#offerReceipt = outcome.receipt;
16592
16629
  if (outcome.case === "failure") {
16593
16630
  this.#pushError = create(RuntimeTransportFailureSchema, {
16594
16631
  endpoint: this.#offerEndpoint(),
16595
- status: response.status,
16632
+ status: outcome.status,
16596
16633
  refused: false,
16597
16634
  message: `${outcome.value.code}: ${outcome.value.message}`
16598
16635
  });
@@ -16601,12 +16638,12 @@ var NomosRuntimeComponent = (() => {
16601
16638
  if (outcome.case === "blocked") {
16602
16639
  return this.#finishOfferOutcome(true);
16603
16640
  }
16604
- if (response.status < 200 || response.status >= 300) {
16641
+ if (outcome.status < 200 || outcome.status >= 300) {
16605
16642
  this.#pushError = create(RuntimeTransportFailureSchema, {
16606
16643
  endpoint: this.#offerEndpoint(),
16607
- status: response.status,
16608
- refused: response.status === 422,
16609
- message: `custody offer returned an admission verdict with HTTP ${response.status}`
16644
+ status: outcome.status,
16645
+ refused: outcome.status === 422,
16646
+ message: `custody offer returned an admission verdict with HTTP ${outcome.status}`
16610
16647
  });
16611
16648
  return this.#finishOfferOutcome(false);
16612
16649
  }
@@ -16614,7 +16651,7 @@ var NomosRuntimeComponent = (() => {
16614
16651
  this.#desiredHead = admission.main || void 0;
16615
16652
  if (!this.#desiredHead) return this.#transportFailure("resident peer returned no admitted frontier", false);
16616
16653
  this.#candidateDurable = admission.sealedMain === this.#desiredHead;
16617
- if (this.#phase === WorkspaceSyncPhase.Probe && this.#desiredHead !== this.#localHead) {
16654
+ if (state.phase === WorkspaceSyncPhase.Probe && this.#desiredHead !== this.#localHead) {
16618
16655
  if (!this.#establishBase(this.#desiredHead)) return this.#noCommonBaseResult();
16619
16656
  if (this.#alreadyJudged(this.#desiredHead)) {
16620
16657
  return this.#finish(create(SyncWorkspaceResponseSchema, {
@@ -16676,7 +16713,7 @@ var NomosRuntimeComponent = (() => {
16676
16713
  if (admission.recoveryRequired !== false) return this.#leaseEffect();
16677
16714
  return this.#transportFailure("resident peer supplied neither the missing delta nor a history gap", false);
16678
16715
  }
16679
- #acceptLease(receipt) {
16716
+ #acceptLease(receipt, state) {
16680
16717
  if (receipt.outcome.case !== "response") {
16681
16718
  throw new Error("platform returned the wrong receipt for a Git read lease");
16682
16719
  }
@@ -16692,21 +16729,25 @@ var NomosRuntimeComponent = (() => {
16692
16729
  this.#leased = true;
16693
16730
  const frontier = this.#placementFrontier();
16694
16731
  if (frontier) {
16695
- this.#placementFetch = new PlacementFetch(
16732
+ const transfer = new PlacementFetch(
16696
16733
  this.#kernel,
16697
16734
  this.#mount,
16698
16735
  this.#requestId,
16699
16736
  this.workId,
16700
16737
  frontier
16701
16738
  );
16702
- const pending = this.#placementFetch.start(lease);
16739
+ const pending = transfer.start(lease);
16703
16740
  if (pending) {
16704
- this.#phase = WorkspaceSyncPhase.Placement;
16705
- this.#lease = lease;
16741
+ this.#state = {
16742
+ phase: WorkspaceSyncPhase.Placement,
16743
+ transfer,
16744
+ lease,
16745
+ ...state.afterPlacement ? { afterPlacement: state.afterPlacement } : {}
16746
+ };
16706
16747
  return this.#remember({ case: "pending", value: pending });
16707
16748
  }
16708
16749
  }
16709
- if (this.#afterPlacement) return this.#finish(this.#afterPlacement);
16750
+ if (state.afterPlacement) return this.#finish(state.afterPlacement);
16710
16751
  return this.#beginMainFetch(lease);
16711
16752
  }
16712
16753
  /** The provider's placement frontier as this round knows it: what the directory named in this
@@ -16726,8 +16767,7 @@ var NomosRuntimeComponent = (() => {
16726
16767
  if (!new PlacementFetch(this.#kernel, this.#mount, this.#requestId, this.workId, frontier).wanted()) {
16727
16768
  return void 0;
16728
16769
  }
16729
- this.#afterPlacement = presented;
16730
- return this.#leaseEffect();
16770
+ return this.#leaseEffect(presented);
16731
16771
  }
16732
16772
  #acceptDiscovery(receipt) {
16733
16773
  this.#directoryAnswered?.();
@@ -16751,9 +16791,11 @@ var NomosRuntimeComponent = (() => {
16751
16791
  return this.#replaceLocalHead !== void 0 || this.#localHead === void 0 && this.#previousHead === void 0;
16752
16792
  }
16753
16793
  #beginMainFetch(lease) {
16754
- this.#phase = WorkspaceSyncPhase.Fetch;
16755
16794
  const lawProducts = this.#lawProductsAlongside();
16756
- this.#fetchStarted = this.#clock.monotonicNanoseconds();
16795
+ this.#state = {
16796
+ phase: WorkspaceSyncPhase.Fetch,
16797
+ startedAt: this.#clock.monotonicNanoseconds()
16798
+ };
16757
16799
  const haves = this.#replaceLocalHead !== void 0 ? this.#repairMissingCommit ? [] : [this.#kernel.resolveRef(this.#mount, this.#requestId, deferredRemote)].filter(
16758
16800
  (head) => !!head
16759
16801
  ) : [...new Set([
@@ -16784,7 +16826,7 @@ var NomosRuntimeComponent = (() => {
16784
16826
  })
16785
16827
  });
16786
16828
  }
16787
- #acceptFetch(receipt) {
16829
+ #acceptFetch(receipt, state) {
16788
16830
  if (receipt.outcome.case !== "gitFetch") {
16789
16831
  throw new Error("platform returned the wrong receipt for a Git object fetch");
16790
16832
  }
@@ -16794,7 +16836,7 @@ var NomosRuntimeComponent = (() => {
16794
16836
  if (fetched.pack.byteLength > 0) {
16795
16837
  this.#kernel.applyPack(this.#mount, this.#requestId, fetched.pack, fetched.head, fetched.shallow);
16796
16838
  }
16797
- const prefetchMillis = this.#fetchStarted === void 0 ? 0 : elapsedMillis(this.#clock, this.#fetchStarted);
16839
+ const prefetchMillis = elapsedMillis(this.#clock, state.startedAt);
16798
16840
  const candidateHead = this.#receiveState ? this.#kernel.resolveStatePosition?.(this.#mount, this.#requestId, fetched.head, this.#receiveState) : fetched.head;
16799
16841
  if (!candidateHead) {
16800
16842
  return this.#finish(create(SyncWorkspaceResponseSchema, {
@@ -17145,11 +17187,11 @@ var NomosRuntimeComponent = (() => {
17145
17187
  pushBytes: this.#pushBytes,
17146
17188
  pullBytes: BigInt(receivedBytes),
17147
17189
  serverMillis: this.#admissionSummary?.serverMillis ?? 0,
17148
- offerInPush: this.#offerRequestId !== void 0
17190
+ offerInPush: this.#pushBytes > 0n
17149
17191
  })
17150
17192
  });
17151
17193
  }
17152
- #finishOfferOutcome(blocked) {
17194
+ #finishOfferOutcome(blocked, reconnectRequired = true) {
17153
17195
  return this.#finish(create(SyncWorkspaceResponseSchema, {
17154
17196
  workspace: this.#mount.workspace,
17155
17197
  previousHead: this.#previousHead,
@@ -17157,7 +17199,7 @@ var NomosRuntimeComponent = (() => {
17157
17199
  admitted: BigInt(this.#admissionSummary?.admittedIntentIds.length ?? 0),
17158
17200
  refused: BigInt((this.#admissionSummary?.refusedMessages.length ?? 0) + this.#parkedLocal),
17159
17201
  deferred: BigInt(this.#admissionSummary ? this.#admissionSummary.blockedMessages.length + this.#admissionSummary.deadLetteredMessages.length + this.#admissionSummary.quarantinedMessages.length + this.#admissionSummary.deferredMessages.length : blocked ? 1 : 0),
17160
- reconnectRequired: true,
17202
+ reconnectRequired,
17161
17203
  stillAhead: this.#localHead !== this.#previousHead,
17162
17204
  directOfferDeferred: blocked,
17163
17205
  offerReceipt: this.#offerReceipt,
@@ -17171,15 +17213,16 @@ var NomosRuntimeComponent = (() => {
17171
17213
  }));
17172
17214
  }
17173
17215
  #transportFailure(message, offline, status = -1) {
17174
- const pushFailed = this.#phase === WorkspaceSyncPhase.Offer;
17216
+ const state = this.#state;
17217
+ const pushFailed = state.phase === WorkspaceSyncPhase.Offer;
17175
17218
  const failedEndpoint = this.#offerEndpoint();
17176
17219
  const failure = create(RuntimeTransportFailureSchema, {
17177
17220
  endpoint: pushFailed ? failedEndpoint : this.#binding.cloud ?? "",
17178
17221
  status,
17179
17222
  message
17180
17223
  });
17181
- if (pushFailed) {
17182
- this.#pushMillis = this.#offerStarted === void 0 ? 0 : elapsedMillis(this.#clock, this.#offerStarted);
17224
+ if (state.phase === WorkspaceSyncPhase.Offer) {
17225
+ this.#pushMillis = state.exchange.startedAt === void 0 ? 0 : elapsedMillis(this.#clock, state.exchange.startedAt);
17183
17226
  this.#pushError = failure;
17184
17227
  }
17185
17228
  return this.#finish(create(SyncWorkspaceResponseSchema, {
@@ -17196,7 +17239,7 @@ var NomosRuntimeComponent = (() => {
17196
17239
  pushMillis: this.#pushMillis,
17197
17240
  pushBytes: this.#pushBytes,
17198
17241
  prefetchMillis: elapsedMillis(this.#clock, this.#started),
17199
- offerInPush: this.#offerRequestId !== void 0
17242
+ offerInPush: this.#pushBytes > 0n
17200
17243
  })
17201
17244
  }));
17202
17245
  }
@@ -17206,7 +17249,7 @@ var NomosRuntimeComponent = (() => {
17206
17249
  return step;
17207
17250
  }
17208
17251
  #finish(value) {
17209
- this.#phase = WorkspaceSyncPhase.Done;
17252
+ this.#state = { phase: WorkspaceSyncPhase.Done };
17210
17253
  this.#current = void 0;
17211
17254
  return this.#remember({ case: "synced", value });
17212
17255
  }