@opengeni/worker-bundle 6.7.0 → 6.8.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.
@@ -1731,7 +1731,10 @@ import {
1731
1731
  markWarmLeaseInstanceLost as markWarmLeaseInstanceLost2,
1732
1732
  readLease as readLease2,
1733
1733
  readActiveSandbox,
1734
+ nestedPostgresMessage,
1735
+ nestedPostgresSqlState,
1734
1736
  resolvePersonalMachineConnectionForAttempt,
1737
+ safeDatabaseErrorFacts,
1735
1738
  SandboxRetainedProcessPromotionFencedError,
1736
1739
  SandboxRetainedProcessTerminalError,
1737
1740
  SandboxWorkspaceMutationOutputRejectedError
@@ -2292,7 +2295,7 @@ function wrapTurnBoxWithRouting(services, ids, established) {
2292
2295
  controlRpcFactory: controlRpcFactory(bus),
2293
2296
  resolveSelfhostedConnection: async (sandbox) => {
2294
2297
  if (!sandbox.enrollmentId) return null;
2295
- const enrollment = await resolveRoutedMachineConnection(db, ids, sandbox);
2298
+ const enrollment = await resolveRoutedMachineConnection(services, ids, sandbox);
2296
2299
  return connectionBindingFor(services, enrollment);
2297
2300
  },
2298
2301
  relay: relayConfigFromSettings(settings),
@@ -2378,11 +2381,14 @@ function wrapTurnBoxWithRouting(services, ids, established) {
2378
2381
  // session points at a sibling modal box the turn cannot resume here) and the
2379
2382
  // op surfaces unresolvable — never a silent wrong-box landing.
2380
2383
  //
2381
- // For a machine-primary turn of a Modal-HOME session (pinned to a machine, no
2382
- // group box established this turn), a mid-turn clear-to-null must NOT fall back to
2383
- // the pinned machine — passing defaultIsHome:false makes the null branch throw typed
2384
- // `home_unavailable_this_turn` instead. Forward the explicit boolean (including false).
2385
- ...ids.defaultIsHome !== void 0 ? { defaultIsHome: ids.defaultIsHome } : {},
2384
+ // A pinned machine is never this turn's home. A null pointer means the chat's
2385
+ // own managed box, for machine-home chats too: turn start never resolves null to
2386
+ // a machine. So a mid-turn move home must not keep dispatching to the pinned
2387
+ // machine (whose per-operation authority now refuses it, because the machine is
2388
+ // no longer the active sandbox). The null branch throws the typed
2389
+ // `home_unavailable_this_turn` transition, and failure settlement continues the
2390
+ // same logical turn on the home box in a fresh attempt.
2391
+ ...ids.pinnedSelfhosted ? { defaultIsHome: false } : {},
2386
2392
  ...ids.homeLease ? {
2387
2393
  resolveDefaultBackend: () => resolveCurrentHomeBackend(
2388
2394
  services,
@@ -2558,7 +2564,7 @@ function wrapLazyTurnBoxWithRouting(services, ids, args) {
2558
2564
  controlRpcFactory: controlRpcFactory(bus),
2559
2565
  resolveSelfhostedConnection: async (sandbox) => {
2560
2566
  if (!sandbox.enrollmentId) return null;
2561
- const enrollment = await resolveRoutedMachineConnection(db, ids, sandbox);
2567
+ const enrollment = await resolveRoutedMachineConnection(services, ids, sandbox);
2562
2568
  return connectionBindingFor(services, enrollment);
2563
2569
  },
2564
2570
  relay: relayConfigFromSettings(settings),
@@ -2777,14 +2783,38 @@ function connectionBindingFor(services, enrollment) {
2777
2783
  runAsSupported: enrollment.agentCapabilities.runAs === true
2778
2784
  };
2779
2785
  }
2780
- async function resolveRoutedMachineConnection(db, ids, sandbox) {
2786
+ function machineAuthorityFailureLog(error) {
2787
+ const sqlState = nestedPostgresSqlState(error);
2788
+ const reason = nestedPostgresMessage(error);
2789
+ const functions = safeDatabaseErrorFacts(error).plpgsql?.join(",");
2790
+ return `Connected Machine authority check failed: sqlState=${sqlState ?? "none"}` + (reason ? ` reason=${reason}` : "") + (functions ? ` functions=${functions}` : "") + (sqlState ? "" : ` error=${error instanceof Error ? error.name : typeof error}`);
2791
+ }
2792
+ async function resolvePersonalMachineConnectionWithDiagnostics(services, input) {
2793
+ try {
2794
+ return await resolvePersonalMachineConnectionForAttempt(services.db, input);
2795
+ } catch (error) {
2796
+ try {
2797
+ services.observability?.warn(machineAuthorityFailureLog(error), {
2798
+ workspaceId: input.workspaceId,
2799
+ sessionId: input.sessionId,
2800
+ turnId: input.turnId,
2801
+ attemptId: input.attemptId,
2802
+ enrollmentId: input.enrollmentId
2803
+ });
2804
+ } catch {
2805
+ }
2806
+ throw error;
2807
+ }
2808
+ }
2809
+ async function resolveRoutedMachineConnection(services, ids, sandbox) {
2810
+ const { db } = services;
2781
2811
  if (!sandbox.enrollmentId) return null;
2782
2812
  const current = await getLiveEnrollmentConnection(db, sandbox.workspaceId, sandbox.enrollmentId);
2783
2813
  if (!current) return null;
2784
2814
  if (current.scope === "user") {
2785
2815
  const authority = ids.personalMachineAttempt;
2786
2816
  if (!authority) return null;
2787
- return await resolvePersonalMachineConnectionForAttempt(db, {
2817
+ return await resolvePersonalMachineConnectionWithDiagnostics(services, {
2788
2818
  accountId: authority.accountId,
2789
2819
  workspaceId: ids.workspaceId,
2790
2820
  subjectId: authority.subjectId,
@@ -2839,7 +2869,7 @@ async function establishSelfhostedTurnSession(services, args) {
2839
2869
  args.controlWorkspaceId ?? args.workspaceId,
2840
2870
  args.agentId
2841
2871
  );
2842
- const enrollment = current?.scope !== "user" ? current : args.personalMachineAttempt ? await resolvePersonalMachineConnectionForAttempt(db, {
2872
+ const enrollment = current?.scope !== "user" ? current : args.personalMachineAttempt ? await resolvePersonalMachineConnectionWithDiagnostics(services, {
2843
2873
  accountId: args.personalMachineAttempt.accountId,
2844
2874
  workspaceId: args.workspaceId,
2845
2875
  subjectId: args.personalMachineAttempt.subjectId,
@@ -2913,4 +2943,4 @@ export {
2913
2943
  agentBackgroundCommandDeps2 as agentBackgroundCommandDeps,
2914
2944
  captureConnectedCommandOutput2 as captureConnectedCommandOutput
2915
2945
  };
2916
- //# sourceMappingURL=chunk-XTG32O4Q.js.map
2946
+ //# sourceMappingURL=chunk-YJDTWP6V.js.map