@opengeni/worker-bundle 1.0.1-canary.0 → 1.0.1-canary.2

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.
@@ -2,7 +2,7 @@ import type { ProviderCommandPersistence } from "@opengeni/runtime";
2
2
  import { type OpStatus } from "@opengeni/agent-proto";
3
3
  import { listLiveModalSandboxLeaseAttributions, readLease, type ReapDrainable, type RetainedProcessProviderProof, type SandboxRetainedProcess, type LeaseSnapshot } from "@opengeni/db";
4
4
  import { type ConnectedMachineBackgroundCommandClaim, type ConnectedMachineBackgroundCommandProof } from "@opengeni/db/session-background-commands";
5
- import { type VerifiedHostWorkspaceArchive, createSandboxClientForBackend, inspectModalSandboxLifecycle, resolveModalCheckpointProviderBindingForSession, terminateModalSandboxById, type ModalOrphanSweepTermination, type ModalCheckpointProviderBinding, type ProviderWorkspaceCapturePolicy, type WorkspaceArchiveDescriptor, type ControlRpc } from "@opengeni/runtime/sandbox";
5
+ import { type VerifiedHostWorkspaceArchive, createSandboxClientForBackend, inspectModalSandboxLifecycle, OpStreamExecClient, resolveModalCheckpointProviderBindingForSession, terminateModalSandboxById, type ModalOrphanSweepTermination, type ModalCheckpointProviderBinding, type ProviderWorkspaceCapturePolicy, type WorkspaceArchiveDescriptor, type ControlRpc } from "@opengeni/runtime/sandbox";
6
6
  import { type SandboxDrainActivityInput, type SandboxLeaseSweepMaintenanceInput } from "../sandbox-reaper-contract.js";
7
7
  import type { ControlActivityServices as ActivityServices } from "./types.js";
8
8
  import { type RetainedProcessReconciliationOutcome } from "../observability-metrics.js";
@@ -154,6 +154,7 @@ export declare function createSandboxLeaseActivities(services: () => Promise<Act
154
154
  * adoption. A successor enrollment connection is intentionally irrelevant: no
155
155
  * query or cancellation is ever rebound to it. */
156
156
  export declare function reconcileConnectedMachineBackgroundCommands(db: ActivityServices["db"], settings: ActivityServices["settings"], observability: ActivityServices["observability"], bus: ActivityServices["bus"], controlRpcOverride?: ControlRpc): Promise<void>;
157
+ export declare function replayConnectedCommandOutput(client: Pick<OpStreamExecClient, "readExisting">, opId: string, terminalKnown: boolean, capture: Parameters<OpStreamExecClient["readExisting"]>[2]): Promise<void>;
157
158
  export declare function probeConnectedMachineBackgroundCommand(claim: ConnectedMachineBackgroundCommandClaim, controlRpc: ControlRpc, controlTimeoutMs: number, observedAt?: Date): Promise<ConnectedMachineBackgroundCommandProof | null>;
158
159
  export declare function connectedCommandProofFromStatus(status: OpStatus, observedAt: Date): ConnectedMachineBackgroundCommandProof | null;
159
160
  type RetainedProcessDeferralOutcome = Extract<RetainedProcessProbeResult, {
@@ -33,7 +33,7 @@ import {
33
33
  scheduledUserMessagePayload,
34
34
  withFirstPartyTools,
35
35
  workflowIdForSession
36
- } from "./chunk-GENYJQ5B.js";
36
+ } from "./chunk-ECDL2TV4.js";
37
37
  import {
38
38
  inspectOpenSandboxKubernetesInventory,
39
39
  recordCreditBalanceGauges,
@@ -2904,18 +2904,14 @@ async function reconcileConnectedMachineBackgroundCommands(db, settings, observa
2904
2904
  journal: { attachGeneration: () => String(Date.now()), persistSettled: () => {
2905
2905
  } }
2906
2906
  });
2907
- const replay = await client.readExisting(
2907
+ await replayConnectedCommandOutput(
2908
+ client,
2908
2909
  claim.opId,
2909
- proof ? 5e3 : 250,
2910
+ Boolean(proof),
2910
2911
  async (frames) => {
2911
2912
  await captureConnectedCommandOutput(db, claim, bus)(claim.commandId, frames);
2912
2913
  }
2913
2914
  );
2914
- if (proof && replay.status !== "completed" && !replay.terminal) {
2915
- throw new Error(
2916
- "Connected command terminal output replay has not reached its exit frontier"
2917
- );
2918
- }
2919
2915
  }
2920
2916
  if (!proof) {
2921
2917
  await deferConnectedCommandClaim(
@@ -2989,6 +2985,23 @@ async function reconcileConnectedMachineBackgroundCommands(db, settings, observa
2989
2985
  if (claims.length < CONNECTED_COMMAND_RECONCILIATION_LIMIT) break;
2990
2986
  } while (Date.now() < deadline);
2991
2987
  }
2988
+ async function replayConnectedCommandOutput(client, opId, terminalKnown, capture) {
2989
+ let capturedThrough = 0n;
2990
+ while (true) {
2991
+ const before = capturedThrough;
2992
+ const replay = await client.readExisting(opId, terminalKnown ? 5e3 : 250, async (frames) => {
2993
+ await capture(frames);
2994
+ for (const frame of frames) {
2995
+ const sequence = BigInt(frame.sequence);
2996
+ if (sequence > capturedThrough) capturedThrough = sequence;
2997
+ }
2998
+ });
2999
+ if (!terminalKnown || replay.status === "completed" || replay.terminal) return;
3000
+ if (capturedThrough === before) {
3001
+ throw new Error("Connected command terminal output replay has not reached its exit frontier");
3002
+ }
3003
+ }
3004
+ }
2992
3005
  async function probeConnectedMachineBackgroundCommand(claim, controlRpc, controlTimeoutMs, observedAt = /* @__PURE__ */ new Date()) {
2993
3006
  const input = {
2994
3007
  controlRpc,
@@ -7304,4 +7317,4 @@ export {
7304
7317
  createControlActivities,
7305
7318
  createControlActivitiesFromServices
7306
7319
  };
7307
- //# sourceMappingURL=activities-control-O5U6OLT2.js.map
7320
+ //# sourceMappingURL=activities-control-FNC52DPR.js.map