@opengeni/worker-bundle 6.5.2-canary.41607687019001 → 6.7.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 (44) hide show
  1. package/dist/activities/agent-turn/prompt-tool-availability.d.ts +12 -1
  2. package/dist/activities/agent-turn/provider-dispatch-barrier.d.ts +11 -0
  3. package/dist/activities/agent-turn/sandbox-runtime.d.ts +21 -2
  4. package/dist/activities/agent-turn/sandbox-setup-agent-failure.d.ts +39 -0
  5. package/dist/activities/agent-turn/stream-attempt.d.ts +2 -1
  6. package/dist/activities/agent-turn/tool-environment.d.ts +3 -1
  7. package/dist/activities/agent-turn/turn-context.d.ts +11 -0
  8. package/dist/{activities-control-SZIXMQR2.js → activities-control-LJVIL5FP.js} +4 -4
  9. package/dist/{activities-turn-KAFMA5CX.js → activities-turn-GTZPMF6T.js} +178 -72
  10. package/dist/activities-turn-GTZPMF6T.js.map +1 -0
  11. package/dist/artifact-materializer-entry.js +0 -0
  12. package/dist/artifact-outbox-entry.js +0 -0
  13. package/dist/{chunk-6AMYPT2B.js → chunk-C5RYXGXF.js} +2 -2
  14. package/dist/{chunk-ESC7J52Z.js → chunk-Q4KXCK36.js} +104 -2
  15. package/dist/chunk-Q4KXCK36.js.map +1 -0
  16. package/dist/{chunk-LQ352XGC.js → chunk-W2IHRF7L.js} +8 -1
  17. package/dist/chunk-W2IHRF7L.js.map +1 -0
  18. package/dist/github-rest-mcp.d.ts +13 -1
  19. package/dist/index.js +3 -3
  20. package/dist/{sandbox-lease-GIEUWXRI.js → sandbox-lease-ILEZ6RVI.js} +3 -3
  21. package/dist/workflow-bundle.js +1 -1
  22. package/package.json +29 -30
  23. package/src/activities/agent-turn/agent-build.ts +38 -0
  24. package/src/activities/agent-turn/errors.ts +28 -0
  25. package/src/activities/agent-turn/finalization.ts +4 -0
  26. package/src/activities/agent-turn/owned-sandbox-setup.ts +29 -19
  27. package/src/activities/agent-turn/prompt-tool-availability.ts +50 -2
  28. package/src/activities/agent-turn/provider-dispatch-barrier.ts +19 -0
  29. package/src/activities/agent-turn/run.ts +3 -4
  30. package/src/activities/agent-turn/sandbox-establish.ts +30 -18
  31. package/src/activities/agent-turn/sandbox-runtime.ts +51 -4
  32. package/src/activities/agent-turn/sandbox-setup-agent-failure.ts +110 -0
  33. package/src/activities/agent-turn/skill-selection.ts +2 -1
  34. package/src/activities/agent-turn/stream-attempt.ts +15 -1
  35. package/src/activities/agent-turn/tool-environment.ts +6 -0
  36. package/src/activities/agent-turn/turn-context.ts +13 -0
  37. package/src/github-rest-mcp.ts +61 -6
  38. package/src/observability-metrics.ts +7 -0
  39. package/dist/activities-turn-KAFMA5CX.js.map +0 -1
  40. package/dist/chunk-ESC7J52Z.js.map +0 -1
  41. package/dist/chunk-LQ352XGC.js.map +0 -1
  42. /package/dist/{activities-control-SZIXMQR2.js.map → activities-control-LJVIL5FP.js.map} +0 -0
  43. /package/dist/{chunk-6AMYPT2B.js.map → chunk-C5RYXGXF.js.map} +0 -0
  44. /package/dist/{sandbox-lease-GIEUWXRI.js.map → sandbox-lease-ILEZ6RVI.js.map} +0 -0
@@ -12,6 +12,7 @@ import {
12
12
  SubscriptionCoreCodexTurnError,
13
13
  TURN_FINALIZER_STEP_TIMEOUT_MS,
14
14
  XAI_CORE_WAIT_BINDING,
15
+ activeRouteSessionForBoundary,
15
16
  agentRunFailurePayload,
16
17
  agentRunRecoveryFailurePayload,
17
18
  armTurnQuiescenceWatchdog,
@@ -38,6 +39,7 @@ import {
38
39
  createCodexCreditGuard,
39
40
  createModelHistoryAttachmentProjector,
40
41
  createRuntimeBatcher,
42
+ createSandboxSetupReplayGuard,
41
43
  createSharedActivityServices,
42
44
  createTurnSandboxProvisioner,
43
45
  currentActivityContext,
@@ -58,6 +60,7 @@ import {
58
60
  modelPreparationFailureEventPayload,
59
61
  modelSocketFallbackRecoveryLimit,
60
62
  nextStreamEvent,
63
+ ownedTurnSandboxForAgent,
61
64
  persistOrSignalSessionAttemptQuiescence,
62
65
  postClaimDatabaseRecoveryFailure,
63
66
  preClaimAdmissionFailure,
@@ -79,12 +82,14 @@ import {
79
82
  releaseTurnSandboxAfterWriterDrain,
80
83
  requesterUnavailableReceiptText,
81
84
  requireAgentStreamFinalOutput,
85
+ resolveTurnSandboxAccess,
82
86
  runMandatoryHistoryPersistenceStep,
83
87
  safeErrorDiagnostic,
84
88
  safeErrorForTelemetry,
85
89
  sandboxDeadlineRotationRecoveryDelayMs,
86
90
  sandboxLifecycleTransitionDiagnostic,
87
91
  sandboxRouteTransitionCode,
92
+ sandboxSetupFailure,
88
93
  servingCatalog,
89
94
  sessionUsageCustodyPending,
90
95
  shouldRecoverCompactionProviderFailure,
@@ -115,7 +120,7 @@ import {
115
120
  wakeSubscriptionCoreWaitersAndDeliver,
116
121
  withFirstPartyTools,
117
122
  withModelRoutePresentation
118
- } from "./chunk-ESC7J52Z.js";
123
+ } from "./chunk-Q4KXCK36.js";
119
124
  import "./chunk-5E7CLEQM.js";
120
125
  import {
121
126
  agentBackgroundCommandDeps,
@@ -168,7 +173,7 @@ import {
168
173
  runtimeMetricsHooksForObservability,
169
174
  sandboxAutomaticRecoveryOutcome,
170
175
  turnLifecycleMetricsFor
171
- } from "./chunk-LQ352XGC.js";
176
+ } from "./chunk-W2IHRF7L.js";
172
177
  import {
173
178
  deliverChildRequiresActionToParent,
174
179
  deliverFailedChildTurnToParent
@@ -2076,24 +2081,6 @@ function createSharedRigSetupCoordinator(options) {
2076
2081
  };
2077
2082
  }
2078
2083
 
2079
- // src/activities/agent-turn/turn-sandbox-access.ts
2080
- function ownedTurnSandboxForAgent(sandboxState) {
2081
- return sandboxState.lazyOwnedSandbox ?? sandboxState.resolvedSandbox?.established;
2082
- }
2083
- async function resolveTurnSandboxAccess(sandboxState, sdkOwnedSandboxSession, unavailableMessage) {
2084
- let sandbox = sandboxState.resolvedSandbox;
2085
- if (!sandbox && sandboxState.turnSandboxProvisioner) {
2086
- sandbox = await sandboxState.turnSandboxProvisioner.get();
2087
- }
2088
- const session = ownedTurnSandboxForAgent(sandboxState)?.session ?? sandbox?.established.session ?? sdkOwnedSandboxSession;
2089
- if (!session) throw new Error(unavailableMessage);
2090
- return {
2091
- sandbox,
2092
- session,
2093
- leaseEpoch: sandbox?.leaseEpoch ?? 0
2094
- };
2095
- }
2096
-
2097
2084
  // src/activities/agent-turn/sandbox-startup-phase.ts
2098
2085
  function sandboxStartupPhaseObserver(input) {
2099
2086
  const receipts = [];
@@ -2179,6 +2166,7 @@ async function runEagerOwnedSandboxSetup(deps, options) {
2179
2166
  });
2180
2167
  const ownedSandboxSetupStartedAt = performance.now();
2181
2168
  let ownedSandboxSetupOutcome = "completed";
2169
+ const setupReplayGuard = createSandboxSetupReplayGuard();
2182
2170
  try {
2183
2171
  const eagerSetupSession = sandboxState.setupBoxSession ?? ownedEstablished.session;
2184
2172
  await measure(
@@ -2190,6 +2178,7 @@ async function runEagerOwnedSandboxSetup(deps, options) {
2190
2178
  )
2191
2179
  );
2192
2180
  const eagerCredentialSetupSession = deps.initialRunCredentialMaterial ? withRunCredentialsSession(eagerSetupSession, input.sessionId) : eagerSetupSession;
2181
+ const setupCommandFence = eventing.toolCancellationFenceRef.current;
2193
2182
  await deps.runWorkspaceMutationForSandbox(
2194
2183
  eagerResolvedSandbox,
2195
2184
  "eagerOwnedSandboxSetup",
@@ -2210,26 +2199,28 @@ async function runEagerOwnedSandboxSetup(deps, options) {
2210
2199
  }
2211
2200
  await eventing.publish([{ type: event.type, payload: event.payload }], true);
2212
2201
  },
2213
- ...eventing.toolCancellationFenceRef.current ? {
2214
- commandRunner: eventing.toolCancellationFenceRef.current.runSandboxCommand.bind(
2215
- eventing.toolCancellationFenceRef.current
2216
- )
2202
+ ...setupCommandFence ? {
2203
+ commandRunner: setupCommandFence.runSandboxCommand.bind(setupCommandFence)
2217
2204
  } : {},
2218
2205
  ...sandboxState.sandboxGroupId && sandboxState.sandboxHolderId ? {
2219
- coordinateSharedRigSetup: createSharedRigSetupCoordinator({
2220
- db: deps.db,
2221
- accountId: input.accountId,
2222
- workspaceId: input.workspaceId,
2223
- sandboxGroupId: sandboxState.sandboxGroupId,
2224
- attemptId: input.attemptId,
2225
- holderId: sandboxState.sandboxHolderId,
2226
- sandbox: eagerResolvedSandbox,
2227
- ...deps.runtimeCancellationSignal ? { signal: deps.runtimeCancellationSignal } : {},
2228
- observe: (measurement) => recordSandboxSharedPreparation(observability, measurement)
2229
- })
2206
+ coordinateSharedRigSetup: setupReplayGuard.trackRigSetup(
2207
+ createSharedRigSetupCoordinator({
2208
+ db: deps.db,
2209
+ accountId: input.accountId,
2210
+ workspaceId: input.workspaceId,
2211
+ sandboxGroupId: sandboxState.sandboxGroupId,
2212
+ attemptId: input.attemptId,
2213
+ holderId: sandboxState.sandboxHolderId,
2214
+ sandbox: eagerResolvedSandbox,
2215
+ ...deps.runtimeCancellationSignal ? { signal: deps.runtimeCancellationSignal } : {},
2216
+ observe: (measurement) => recordSandboxSharedPreparation(observability, measurement)
2217
+ })
2218
+ )
2230
2219
  } : {}
2231
2220
  }
2232
- )
2221
+ ),
2222
+ void 0,
2223
+ setupCommandFence ? { commandFence: setupCommandFence } : {}
2233
2224
  );
2234
2225
  await deps.attachGitCredentialRenewal(
2235
2226
  eagerSetupSession,
@@ -2237,7 +2228,7 @@ async function runEagerOwnedSandboxSetup(deps, options) {
2237
2228
  );
2238
2229
  } catch (error51) {
2239
2230
  ownedSandboxSetupOutcome = "failed";
2240
- throw error51;
2231
+ throw sandboxSetupFailure(setupReplayGuard, error51);
2241
2232
  } finally {
2242
2233
  await measure.flush();
2243
2234
  recordTurnStartupPhase(observability, {
@@ -5075,6 +5066,7 @@ function createTurnContext(input) {
5075
5066
  sandboxState: {
5076
5067
  resolvedSandbox: null,
5077
5068
  attemptWritersDrained: false,
5069
+ drainedCommandFence: null,
5078
5070
  lateSandboxesAwaitingWriterDrain: /* @__PURE__ */ new Set(),
5079
5071
  machinePrimarySession: null,
5080
5072
  lazyOwnedSandbox: null,
@@ -5131,7 +5123,8 @@ function createTurnContext(input) {
5131
5123
  initialModelWireDispatch: new InitialModelWireDispatchClock(),
5132
5124
  companyBrainContextContributions: null,
5133
5125
  modelVisibleSkillIds: null,
5134
- appActionApprovalCards: /* @__PURE__ */ new Map()
5126
+ appActionApprovalCards: /* @__PURE__ */ new Map(),
5127
+ commandCompletionNotices: /* @__PURE__ */ new Set()
5135
5128
  },
5136
5129
  workspaceRefs: {
5137
5130
  rigId: "",
@@ -7537,6 +7530,7 @@ async function finalizeTurnAttemptSteps(deps, monitor) {
7537
7530
  }
7538
7531
  });
7539
7532
  }
7533
+ sandboxState.drainedCommandFence = toolCancellationFence ?? null;
7540
7534
  sandboxState.attemptWritersDrained = true;
7541
7535
  if (control.acknowledgeQuiescence) {
7542
7536
  physicalToolQuiescenceConfirmed = true;
@@ -11370,7 +11364,8 @@ import {
11370
11364
  isOpeningToolLoadResponse,
11371
11365
  isPreemptedModelResponse,
11372
11366
  preemptedResponseCutOffText,
11373
- secretValueModelInputFilter
11367
+ secretValueModelInputFilter,
11368
+ withoutAppendedCommandCompletions
11374
11369
  } from "@opengeni/runtime";
11375
11370
  import {
11376
11371
  environmentsEncryptionKeyBytes as environmentsEncryptionKeyBytes5,
@@ -31053,6 +31048,14 @@ async function runTurnStreamAttempt(deps) {
31053
31048
  } : retainedToolImages ? {
31054
31049
  messagePhases,
31055
31050
  toolOutputTransform: (output) => retainedToolImagesEventOutput(output, retainedToolImages)
31051
+ } : eventing.commandCompletionNotices && eventing.commandCompletionNotices.size > 0 ? {
31052
+ // The model reads finished commands after this tool's
31053
+ // result; the timeline shows the tool's own output.
31054
+ messagePhases,
31055
+ toolOutputTransform: (output) => withoutAppendedCommandCompletions(
31056
+ output,
31057
+ eventing.commandCompletionNotices ?? /* @__PURE__ */ new Set()
31058
+ )
31056
31059
  } : { messagePhases }
31057
31060
  );
31058
31061
  const normalizedToolOutput = normalizedSdkEvents.find(
@@ -33688,6 +33691,13 @@ import {
33688
33691
  sandboxWarmRateMicrosPerSecond
33689
33692
  } from "@opengeni/config";
33690
33693
  import { ChannelAPartialMutationError } from "@opengeni/runtime/sandbox";
33694
+ function pendingMutationsCoveredByWriterDrain(pending, drainedCommandFence) {
33695
+ if (!drainedCommandFence) return false;
33696
+ for (const mutation of pending) {
33697
+ if ("cause" in mutation || mutation.commandFence !== drainedCommandFence) return false;
33698
+ }
33699
+ return true;
33700
+ }
33691
33701
  var retainInternalProviderCommand = createProviderCommandRetainer(
33692
33702
  retainWorkspaceMutationProcess,
33693
33703
  (error51) => error51 instanceof SandboxRetainedProcessPromotionFencedError ? error51.process : null
@@ -33798,7 +33808,7 @@ function createSandboxTurnRuntime(deps) {
33798
33808
  if (!guard) {
33799
33809
  const pending = /* @__PURE__ */ new Map();
33800
33810
  const release = async (options) => {
33801
- if (options?.workspaceWritersQuiesced && pending.size) {
33811
+ if (options?.workspaceWritersQuiesced && pending.size && !pendingMutationsCoveredByWriterDrain(pending.values(), sandboxState.drainedCommandFence)) {
33802
33812
  await original();
33803
33813
  throw new RoutingMutationOutcomeUnknownError(
33804
33814
  "internalWorkspaceMutationDrain",
@@ -33880,7 +33890,7 @@ function createSandboxTurnRuntime(deps) {
33880
33890
  ...rebound.established.restoredArchive ? { restoredArchive: rebound.established.restoredArchive } : {}
33881
33891
  } : rebound.established;
33882
33892
  };
33883
- const runWorkspaceMutationForSandbox = async (sandbox, operation, mutation, observePhase) => {
33893
+ const runWorkspaceMutationForSandbox = async (sandbox, operation, mutation, observePhase, options = {}) => {
33884
33894
  const observeMutationPhase = (phase, outcome, durationMs) => {
33885
33895
  try {
33886
33896
  observePhase?.({
@@ -33978,7 +33988,10 @@ function createSandboxTurnRuntime(deps) {
33978
33988
  };
33979
33989
  let result;
33980
33990
  const releaseGuard = guardSandboxRelease(sandbox);
33981
- releaseGuard?.pending.set(admission.id, { operation });
33991
+ releaseGuard?.pending.set(admission.id, {
33992
+ operation,
33993
+ ...options.commandFence ? { commandFence: options.commandFence } : {}
33994
+ });
33982
33995
  const providerStartedAt = performance.now();
33983
33996
  let providerOutcome = "failed";
33984
33997
  try {
@@ -35319,6 +35332,7 @@ async function bindLazySandboxProvisioner(deps) {
35319
35332
  publish: eventing.publish,
35320
35333
  publishInBackground: eventing.publishInBackground
35321
35334
  });
35335
+ const setupReplayGuard = createSandboxSetupReplayGuard();
35322
35336
  try {
35323
35337
  const [credentials, clientDownload, materialization] = await Promise.allSettled([
35324
35338
  measure("credential_mint", async () => {
@@ -35355,6 +35369,7 @@ async function bindLazySandboxProvisioner(deps) {
35355
35369
  provisioned.established.session,
35356
35370
  input.sessionId
35357
35371
  ) : provisioned.established.session;
35372
+ const setupCommandFence = eventing.toolCancellationFenceRef.current;
35358
35373
  await runWorkspaceMutationForSandbox(
35359
35374
  provisioned,
35360
35375
  "lazyOwnedSandboxSetup",
@@ -35381,23 +35396,23 @@ async function bindLazySandboxProvisioner(deps) {
35381
35396
  codemodeTokenSeedOverride: lazyCodemodeToken.token,
35382
35397
  ...lazyCodemodeClientDownload ? { codemodeClientDownloadOverride: lazyCodemodeClientDownload } : {}
35383
35398
  } : {},
35384
- ...eventing.toolCancellationFenceRef.current ? {
35385
- commandRunner: eventing.toolCancellationFenceRef.current.runSandboxCommand.bind(
35386
- eventing.toolCancellationFenceRef.current
35387
- )
35399
+ ...setupCommandFence ? {
35400
+ commandRunner: setupCommandFence.runSandboxCommand.bind(setupCommandFence)
35388
35401
  } : {},
35389
35402
  ...sandboxState.sandboxGroupId && sandboxState.sandboxHolderId ? {
35390
- coordinateSharedRigSetup: createSharedRigSetupCoordinator({
35391
- db,
35392
- accountId: input.accountId,
35393
- workspaceId: input.workspaceId,
35394
- sandboxGroupId: sandboxState.sandboxGroupId,
35395
- attemptId: input.attemptId,
35396
- holderId: sandboxState.sandboxHolderId,
35397
- sandbox: provisioned,
35398
- ...runtimeCancellationSignal ? { signal: runtimeCancellationSignal } : {},
35399
- observe: (measurement) => recordSandboxSharedPreparation(observability, measurement)
35400
- })
35403
+ coordinateSharedRigSetup: setupReplayGuard.trackRigSetup(
35404
+ createSharedRigSetupCoordinator({
35405
+ db,
35406
+ accountId: input.accountId,
35407
+ workspaceId: input.workspaceId,
35408
+ sandboxGroupId: sandboxState.sandboxGroupId,
35409
+ attemptId: input.attemptId,
35410
+ holderId: sandboxState.sandboxHolderId,
35411
+ sandbox: provisioned,
35412
+ ...runtimeCancellationSignal ? { signal: runtimeCancellationSignal } : {},
35413
+ observe: (measurement) => recordSandboxSharedPreparation(observability, measurement)
35414
+ })
35415
+ )
35401
35416
  } : {}
35402
35417
  }
35403
35418
  ),
@@ -35405,7 +35420,8 @@ async function bindLazySandboxProvisioner(deps) {
35405
35420
  if (eventing.firstModelRequestPreparationRecorded) return;
35406
35421
  sandboxState.firstModelPreparationNestedSandboxMs += measurement.durationSeconds * 1e3;
35407
35422
  sandboxState.firstModelPreparationNestedSandboxPhases.push(measurement);
35408
- }
35423
+ },
35424
+ setupCommandFence ? { commandFence: setupCommandFence } : {}
35409
35425
  );
35410
35426
  await attachCodemodeTokenRenewal(
35411
35427
  provisioned.established.session,
@@ -35426,6 +35442,8 @@ async function bindLazySandboxProvisioner(deps) {
35426
35442
  }
35427
35443
  await toolResultSpill.materializeDeferred();
35428
35444
  throwIfTurnOperationCancelled(sandboxResumeSignal);
35445
+ } catch (error51) {
35446
+ throw sandboxSetupFailure(setupReplayGuard, error51);
35429
35447
  } finally {
35430
35448
  await measure.flush();
35431
35449
  }
@@ -37354,7 +37372,9 @@ import {
37354
37372
  } from "@opengeni/contracts";
37355
37373
  import {
37356
37374
  isPersonalGitHubConnection,
37357
- PersonalGitHubConnectionMetadata
37375
+ PERSONAL_GITHUB_RECONNECT_MESSAGE,
37376
+ PersonalGitHubConnectionMetadata,
37377
+ personalGitHubConnectionNeedsReconnect
37358
37378
  } from "@opengeni/contracts/personal-github";
37359
37379
  import { personalGitHubRepositoryResources as personalGitHubRepositoryResources2 } from "@opengeni/core";
37360
37380
  import {
@@ -37628,11 +37648,17 @@ function personalAuthorityResolver(input) {
37628
37648
  repository,
37629
37649
  forceRefresh
37630
37650
  }) => {
37631
- const current = await validatePersonalRepository(
37632
- input,
37633
- repository,
37634
- toolName === "repositories_list"
37635
- );
37651
+ const reconnectOr = (error51) => personalReconnectOr(error51, () => personalConnectionNeedsReconnect(input));
37652
+ let current;
37653
+ try {
37654
+ current = await validatePersonalRepository(
37655
+ input,
37656
+ repository,
37657
+ toolName === "repositories_list"
37658
+ );
37659
+ } catch (error51) {
37660
+ throw error51 instanceof GitHubRestAuthorityError ? await reconnectOr(error51) : error51;
37661
+ }
37636
37662
  if (toolName === "repositories_list") {
37637
37663
  return {
37638
37664
  headers: {},
@@ -37666,7 +37692,9 @@ function personalAuthorityResolver(input) {
37666
37692
  forceRefresh
37667
37693
  });
37668
37694
  if (resolution.status !== "ok" || resolution.connectionId !== repository.connectionId) {
37669
- throw new GitHubRestAuthorityError("Personal GitHub credential is unavailable");
37695
+ throw await reconnectOr(
37696
+ new GitHubRestAuthorityError("Personal GitHub credential is unavailable")
37697
+ );
37670
37698
  }
37671
37699
  return {
37672
37700
  headers: githubAuthorizationHeaders(resolution.headers),
@@ -37686,6 +37714,24 @@ function personalAuthorityResolver(input) {
37686
37714
  };
37687
37715
  };
37688
37716
  }
37717
+ async function personalReconnectOr(error51, needsReconnect) {
37718
+ return await needsReconnect().catch(() => false) ? new GitHubRestAuthorityError(PERSONAL_GITHUB_RECONNECT_MESSAGE) : error51;
37719
+ }
37720
+ async function personalConnectionNeedsReconnect(input, readConnection = getConnectionMetadata) {
37721
+ try {
37722
+ const delegation = exactPersonalDelegation(input.turn.personalConnectionDelegations);
37723
+ if (!delegation.originWorkspaceId) return false;
37724
+ const connection = await readConnection(
37725
+ input.db,
37726
+ delegation.originWorkspaceId,
37727
+ delegation.connectionId,
37728
+ delegation.ownerSubjectId
37729
+ );
37730
+ return connection !== null && connection.accountId === input.accountId && connection.subjectId === delegation.ownerSubjectId && personalGitHubConnectionNeedsReconnect(connection);
37731
+ } catch {
37732
+ return false;
37733
+ }
37734
+ }
37689
37735
  async function validatePersonalRepository(input, repository, validateAcceptedUse) {
37690
37736
  await assertRepositoryStillAttached(input, repository);
37691
37737
  const delegation = exactPersonalDelegation(input.turn.personalConnectionDelegations);
@@ -38046,12 +38092,34 @@ import {
38046
38092
  import {
38047
38093
  deriveAgentPromptToolAvailability
38048
38094
  } from "@opengeni/runtime";
38095
+ var KNOWLEDGE_AUTHORING_TOOLS = [
38096
+ "knowledge_save",
38097
+ "knowledge_prepare_save",
38098
+ "knowledge_retain_message",
38099
+ "knowledge_retain_file",
38100
+ "knowledge_archive",
38101
+ "task_note_promote_knowledge"
38102
+ ];
38103
+ var INSTRUCTION_AUTHORING_TOOLS = [
38104
+ "instruction_policy_save"
38105
+ ];
38049
38106
  function promptToolAvailabilityForTurn(input) {
38050
38107
  if (!input.agentConfig) return void 0;
38051
- return deriveAgentPromptToolAvailability({
38108
+ const availability = deriveAgentPromptToolAvailability({
38052
38109
  selectedFirstPartyTools: input.selectedFirstPartyMcpTools,
38053
- firstPartyPermissions: input.firstPartyPermissions
38110
+ firstPartyPermissions: input.firstPartyPermissions,
38111
+ nestedAgentDepth: input.nestedAgentDepth,
38112
+ effectiveMaxNestedAgentDepth: input.effectiveMaxNestedAgentDepth
38054
38113
  });
38114
+ const refused = [
38115
+ ...input.learning?.knowledge === "off" ? KNOWLEDGE_AUTHORING_TOOLS : [],
38116
+ ...input.learning?.instructions === "off" ? INSTRUCTION_AUTHORING_TOOLS : []
38117
+ ];
38118
+ if (refused.length === 0) return availability;
38119
+ return {
38120
+ ...availability,
38121
+ unavailable: [.../* @__PURE__ */ new Set([...availability.unavailable, ...refused])].sort()
38122
+ };
38055
38123
  }
38056
38124
 
38057
38125
  // src/activities/agent-turn/tool-environment.ts
@@ -40520,7 +40588,8 @@ function configuredBundledSkillNames(context) {
40520
40588
  { name: "visualize", include: () => true },
40521
40589
  { name: "document-parsing", include: () => true },
40522
40590
  { name: "skill-management", include: () => true },
40523
- { name: "projects", include: () => true },
40591
+ // The Skill only explains the project tools; without them it is noise.
40592
+ { name: "projects", include: () => tools.has("project_list") },
40524
40593
  { name: "schedules", include: () => tools.has("scheduled_tasks_create") },
40525
40594
  {
40526
40595
  name: "event-triggers",
@@ -40833,7 +40902,10 @@ async function prepareTurnToolRuntime(deps) {
40833
40902
  const promptToolAvailability = promptToolAvailabilityForTurn({
40834
40903
  agentConfig: session.agent,
40835
40904
  selectedFirstPartyMcpTools,
40836
- firstPartyPermissions: effectiveFirstPartyPermissions
40905
+ firstPartyPermissions: effectiveFirstPartyPermissions,
40906
+ nestedAgentDepth: session.nestedAgentDepth,
40907
+ effectiveMaxNestedAgentDepth: session.effectiveMaxNestedAgentDepth,
40908
+ learning: deps.learningModes
40837
40909
  });
40838
40910
  const needsTitle = shouldRequestMissingSessionTitle({
40839
40911
  agentConfig: session.agent,
@@ -41997,8 +42069,11 @@ async function withSubscriptionCoreVideoConnection(db, settings, provider, opera
41997
42069
  // src/activities/agent-turn/agent-build.ts
41998
42070
  import {
41999
42071
  formatSkillCatalog,
42000
- skillCatalogEntryIds
42072
+ skillCatalogEntryIds,
42073
+ CommandCompletionDelivery,
42074
+ modelToolTextBudgetBytes
42001
42075
  } from "@opengeni/runtime";
42076
+ import { claimPendingBackgroundCommandResults } from "@opengeni/db/session-background-commands";
42002
42077
  import {
42003
42078
  serviceTierForLatencyMode as serviceTierForLatencyMode2,
42004
42079
  WORKSPACE_GATEWAY_PROVIDER_ID,
@@ -43453,6 +43528,36 @@ async function buildTurnAgent(deps) {
43453
43528
  }),
43454
43529
  // Every tool result is masked with the attempt's known secret values.
43455
43530
  secretValueMemory: currentAttemptSecretValues() ?? null,
43531
+ // Commands that finish while the model works arrive with its next
43532
+ // plain-text tool result instead of waiting for a read or a later turn.
43533
+ ...eventing.modelRunSettings.sandboxBackend !== "none" ? {
43534
+ commandCompletionDelivery: new CommandCompletionDelivery({
43535
+ take: async ({ maxBytes }) => await claimPendingBackgroundCommandResults(db, {
43536
+ accountId: input.accountId,
43537
+ workspaceId: input.workspaceId,
43538
+ sessionId: input.sessionId,
43539
+ maxBytes
43540
+ }),
43541
+ maxTextBytes: () => modelToolTextBudgetBytes(
43542
+ eventing.modelRunSettings.modelToolOutputTruncationTokens
43543
+ ),
43544
+ // Masked here too: `apply_patch` results bypass the function-tool masking.
43545
+ mask: async (text) => {
43546
+ const memory = currentAttemptSecretValues();
43547
+ if (!memory) return text;
43548
+ await memory.refresh();
43549
+ await memory.captureShapes(text, "tool_result");
43550
+ return memory.maskToolOutputText(text, "tool_result");
43551
+ },
43552
+ signal: cancellationSignal,
43553
+ onDelivered: (appended) => {
43554
+ (eventing.commandCompletionNotices ??= /* @__PURE__ */ new Set()).add(appended);
43555
+ },
43556
+ onError: (error51) => observability.warn("Finished background commands were not attached", {
43557
+ error: error51 instanceof Error ? error51.message : String(error51)
43558
+ })
43559
+ })
43560
+ } : {},
43456
43561
  onToolCancellationFence: (fence) => {
43457
43562
  eventing.toolCancellationFenceRef.current = fence;
43458
43563
  },
@@ -43863,7 +43968,7 @@ function createRunAgentTurnActivity(services) {
43863
43968
  recoveryStartedAt: attempt.providerRecoveryStartedAt
43864
43969
  });
43865
43970
  const activeRoute = new ActiveRouteDispatchBoundary({
43866
- session: () => sandboxState.resolvedSandbox?.established.session,
43971
+ session: () => activeRouteSessionForBoundary(sandboxState),
43867
43972
  isRouteTransition: (error51) => sandboxRouteTransitionCode(error51) !== null
43868
43973
  });
43869
43974
  const checkpointBeforeProviderDispatch = async () => {
@@ -44932,6 +45037,7 @@ These are publication receipts for the human's earlier answer. Do not call the r
44932
45037
  });
44933
45038
  const toolRuntime = await prepareTurnToolRuntime({
44934
45039
  independentSessionTitles: !!startSessionTitleWorkflow,
45040
+ learningModes: learning.effective,
44935
45041
  vaultAccess,
44936
45042
  runCredentialRenewals: runCredentialResolver ? renewals : void 0,
44937
45043
  runMcpCredentials,
@@ -46650,4 +46756,4 @@ export {
46650
46756
  createTurnActivities,
46651
46757
  createTurnActivitiesFromServices
46652
46758
  };
46653
- //# sourceMappingURL=activities-turn-KAFMA5CX.js.map
46759
+ //# sourceMappingURL=activities-turn-GTZPMF6T.js.map