dsh-wsr-execution 0.2.7 → 0.2.9
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.
- package/package.json +1 -1
- package/src/intake/binding-repository.js +34 -0
- package/src/intake/plugin.js +11 -2
package/package.json
CHANGED
|
@@ -214,6 +214,40 @@ export class IntakeSessionBindingRepository {
|
|
|
214
214
|
return candidate;
|
|
215
215
|
}
|
|
216
216
|
|
|
217
|
+
async archiveTerminalResult(sessionKey, result) {
|
|
218
|
+
this.#ready();
|
|
219
|
+
if (typeof sessionKey !== "string" || sessionKey.length === 0
|
|
220
|
+
|| result === null || typeof result !== "object" || Array.isArray(result)
|
|
221
|
+
|| result.kind !== "TERMINAL"
|
|
222
|
+
|| typeof result.deliveryId !== "string" || result.deliveryId.length === 0
|
|
223
|
+
|| typeof result.worktree !== "string" || !isAbsolute(result.worktree)
|
|
224
|
+
|| !["SUCCEEDED", "FAILED", "CANCELLED"].includes(result.outcome)) {
|
|
225
|
+
throw new IntakeBindingError("INTAKE_BINDING_INVARIANT_VIOLATION");
|
|
226
|
+
}
|
|
227
|
+
const worktree = resolve(result.worktree);
|
|
228
|
+
const historical = this.#historical.find((entry) => entry.deliveryId === result.deliveryId);
|
|
229
|
+
if (historical !== undefined) {
|
|
230
|
+
if (historical.sessionKey === sessionKey && historical.worktree === worktree) return historical;
|
|
231
|
+
throw new IntakeBindingError("INTAKE_BINDING_INVARIANT_VIOLATION");
|
|
232
|
+
}
|
|
233
|
+
const active = this.#active.find((entry) => entry.deliveryId === result.deliveryId);
|
|
234
|
+
if (active === undefined || active.sessionKey !== sessionKey || active.worktree !== worktree) {
|
|
235
|
+
throw new IntakeBindingError("INTAKE_BINDING_INVARIANT_VIOLATION");
|
|
236
|
+
}
|
|
237
|
+
const candidate = exactHistorical({
|
|
238
|
+
sessionKey: active.sessionKey,
|
|
239
|
+
correlation: active.correlation,
|
|
240
|
+
deliveryId: active.deliveryId,
|
|
241
|
+
deliveryBindingIdentity: active.deliveryBindingIdentity,
|
|
242
|
+
worktree: active.worktree,
|
|
243
|
+
});
|
|
244
|
+
this.#active.splice(this.#active.indexOf(active), 1);
|
|
245
|
+
this.#historical.push(candidate);
|
|
246
|
+
validateTogether(this.#active, this.#historical);
|
|
247
|
+
await this.#persist();
|
|
248
|
+
return candidate;
|
|
249
|
+
}
|
|
250
|
+
|
|
217
251
|
async markDetached(deliveryId) {
|
|
218
252
|
this.#ready();
|
|
219
253
|
const index = this.#active.findIndex((entry) => entry.deliveryId === deliveryId);
|
package/src/intake/plugin.js
CHANGED
|
@@ -271,7 +271,16 @@ export async function createPluginRuntime(config, options = {}) {
|
|
|
271
271
|
const ownerProjection = options.ownerProjection ?? api.getExecutionControlPlaneProjection(application);
|
|
272
272
|
const bindingInventory = () => typeof control.bindingInventory === "function" ? control.bindingInventory() : control.list();
|
|
273
273
|
const archiveTerminal = async (sessionKey, correlation, deliveryId) => {
|
|
274
|
-
|
|
274
|
+
let snapshot;
|
|
275
|
+
for (let attempt = 0; attempt < 100; attempt += 1) {
|
|
276
|
+
try {
|
|
277
|
+
snapshot = await ownerProjection.snapshot();
|
|
278
|
+
break;
|
|
279
|
+
} catch (cause) {
|
|
280
|
+
if (cause?.code !== "DELIVERY_PROJECTION_STALE_BINDING" || attempt === 99) throw cause;
|
|
281
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
282
|
+
}
|
|
283
|
+
}
|
|
275
284
|
const matches = snapshot.deliveries.filter((delivery) => delivery.lifecycle === "TERMINAL"
|
|
276
285
|
&& delivery.navigation?.sessionCorrelation === correlation
|
|
277
286
|
&& (deliveryId === undefined || delivery.deliveryId === deliveryId));
|
|
@@ -456,7 +465,7 @@ export async function createPluginRuntime(config, options = {}) {
|
|
|
456
465
|
const result = await service.invoke(Object.freeze({ operation: "abandon", deliveryId, correlation }));
|
|
457
466
|
if (result.kind === "TERMINAL") {
|
|
458
467
|
const detached = await bindings.byDelivery(deliveryId);
|
|
459
|
-
if (detached !== undefined) await
|
|
468
|
+
if (detached !== undefined) await bindings.archiveTerminalResult(detached.sessionKey, result);
|
|
460
469
|
if (detached !== undefined) sessionByCorrelation.delete(detached.correlation);
|
|
461
470
|
}
|
|
462
471
|
return result;
|