@opengeni/worker-bundle 0.22.1-canary.0 → 0.22.4-canary.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 (43) hide show
  1. package/dist/activities/agent-turn/agent-build.d.ts +1 -0
  2. package/dist/activities/agent-turn/sandbox-establish.d.ts +1 -0
  3. package/dist/activities/agent-turn/session-title.d.ts +24 -0
  4. package/dist/activities/agent-turn/tool-environment.d.ts +1 -0
  5. package/dist/activities/agent-turn/tool-policy.d.ts +2 -1
  6. package/dist/activities/incident-telemetry-authority.d.ts +1 -0
  7. package/dist/activities/parent-wake.d.ts +25 -2
  8. package/dist/activities/rig-verification.d.ts +22 -7
  9. package/dist/activities/scheduled-tasks.d.ts +49 -3
  10. package/dist/{activities-control-DKG22ONJ.js → activities-control-4XVBA3Q5.js} +168 -70
  11. package/dist/activities-control-4XVBA3Q5.js.map +1 -0
  12. package/dist/activities-control.d.ts +16 -12
  13. package/dist/{activities-turn-4IMC3MAA.js → activities-turn-J3CR27E6.js} +164 -44
  14. package/dist/activities-turn-J3CR27E6.js.map +1 -0
  15. package/dist/activities.d.ts +16 -12
  16. package/dist/{chunk-CE7TPKBS.js → chunk-FA35XBBC.js} +3 -3
  17. package/dist/{chunk-CE7TPKBS.js.map → chunk-FA35XBBC.js.map} +1 -1
  18. package/dist/{chunk-CNYGVRKF.js → chunk-XWQPS6GG.js} +76 -17
  19. package/dist/chunk-XWQPS6GG.js.map +1 -0
  20. package/dist/http.d.ts +1 -1
  21. package/dist/index.d.ts +8 -6
  22. package/dist/index.js +9 -3
  23. package/dist/index.js.map +1 -1
  24. package/package.json +17 -17
  25. package/src/activities/agent-turn/agent-build.ts +8 -6
  26. package/src/activities/agent-turn/governance-model.ts +13 -15
  27. package/src/activities/agent-turn/run.ts +3 -0
  28. package/src/activities/agent-turn/sandbox-establish.ts +6 -1
  29. package/src/activities/agent-turn/session-title.ts +106 -0
  30. package/src/activities/agent-turn/tool-environment.ts +68 -19
  31. package/src/activities/agent-turn/tool-policy.ts +5 -2
  32. package/src/activities/incident-telemetry-authority.ts +7 -0
  33. package/src/activities/parent-wake.ts +65 -1
  34. package/src/activities/rig-verification.ts +156 -47
  35. package/src/activities/scheduled-tasks.ts +38 -35
  36. package/src/activities/workflow-wake.ts +30 -9
  37. package/src/http.ts +2 -1
  38. package/src/index.ts +6 -1
  39. package/src/observability-metrics.ts +2 -2
  40. package/src/pr-review-credentials.ts +42 -14
  41. package/dist/activities-control-DKG22ONJ.js.map +0 -1
  42. package/dist/activities-turn-4IMC3MAA.js.map +0 -1
  43. package/dist/chunk-CNYGVRKF.js.map +0 -1
@@ -4,7 +4,6 @@ import {
4
4
  resolveXaiProviderAccountAuthoritySnapshotForAcceptance,
5
5
  getXaiSessionAccountPin,
6
6
  setXaiSessionAccountPin,
7
- countSessionHistoryItems,
8
7
  getWorkspaceVideoGenerationPolicy,
9
8
  loadWorkspaceVercelAiGatewayCredentialLease,
10
9
  beginConnectorActionExecution,
@@ -74,6 +73,7 @@ import type {
74
73
  RecordingState,
75
74
  SandboxRuntimeState,
76
75
  } from "./turn-context";
76
+ import { SESSION_TITLE_MODEL_TOOL_NAME } from "./session-title";
77
77
 
78
78
  export type BuildTurnAgentDeps = {
79
79
  input: RunAgentTurnInput;
@@ -137,6 +137,7 @@ export type BuildTurnAgentDeps = {
137
137
  executionGeneration: number;
138
138
  initiator: Pick<ClaimTurnOk["turn"]["initiator"], "kind" | "subjectId">;
139
139
  };
140
+ preparationIndependentToolNames: readonly string[];
140
141
  videoGenerationAcceptancesByCallId: Map<string, { operationId: string; requestDigest: string }>;
141
142
  activeSandboxBackend: Settings["sandboxBackend"] | undefined;
142
143
  groupBoxBackend: Settings["sandboxBackend"];
@@ -154,7 +155,6 @@ export async function buildTurnAgent(deps: BuildTurnAgentDeps) {
154
155
  cancellationSignal,
155
156
  runtimeCancellationSignal,
156
157
  eventing,
157
- attempt,
158
158
  sandboxState,
159
159
  recordingState,
160
160
  maybeStartOnTurnRecording,
@@ -197,6 +197,7 @@ export async function buildTurnAgent(deps: BuildTurnAgentDeps) {
197
197
  fileResourceDownloads,
198
198
  attemptConnectorActionBindings,
199
199
  connectorActionIdentity,
200
+ preparationIndependentToolNames,
200
201
  videoGenerationAcceptancesByCallId,
201
202
  activeSandboxBackend,
202
203
  groupBoxBackend,
@@ -205,9 +206,9 @@ export async function buildTurnAgent(deps: BuildTurnAgentDeps) {
205
206
  } = deps;
206
207
  const preparedTools = eventing.preparedTools!;
207
208
 
208
- const isGenesisTurn =
209
- attempt.triggerType === "user.message" &&
210
- (await countSessionHistoryItems(db, input.workspaceId, input.sessionId)) === 0;
209
+ const missingSessionTitleHint = preparationIndependentToolNames.includes(
210
+ SESSION_TITLE_MODEL_TOOL_NAME,
211
+ );
211
212
  // Clone-onto-real-disk hazard (Case B). A session keeps its CLOUD HOME
212
213
  // backend (runSettings.sandboxBackend, e.g. "modal") but its ACTIVE sandbox
213
214
  // may have been swapped to a connected machine (active_sandbox_id → a
@@ -612,7 +613,7 @@ export async function buildTurnAgent(deps: BuildTurnAgentDeps) {
612
613
  ...(serviceTier ? { serviceTier } : {}),
613
614
  ...(humanInputResume ? { humanInputResponse: humanInputResume } : {}),
614
615
  humanInputEnabled: agentHumanInputEnabled,
615
- genesisTitleHint: isGenesisTurn,
616
+ missingSessionTitleHint,
616
617
  sandboxEnvironment,
617
618
  ...(preparedTools.attemptToolCatalog
618
619
  ? { attemptToolCatalog: preparedTools.attemptToolCatalog }
@@ -681,6 +682,7 @@ export async function buildTurnAgent(deps: BuildTurnAgentDeps) {
681
682
  ...(eventing.toolPreparationReady
682
683
  ? { toolPreparationReady: eventing.toolPreparationReady }
683
684
  : {}),
685
+ preparationIndependentToolNames,
684
686
  supportsImageInput,
685
687
  inputFileMediaTypes: modelInputPolicy.inputFileMediaTypes,
686
688
  ...(resolvedModel
@@ -26,7 +26,6 @@ import {
26
26
  resolveWorkspacePackRuntime,
27
27
  resolveWorkspaceInstalledSkillRuntime,
28
28
  settingsWithPackSandboxImage,
29
- settingsWithRigImage,
30
29
  } from "../packs";
31
30
  import { createModelHistoryAttachmentProjector } from "../run-input";
32
31
  import type {
@@ -263,14 +262,15 @@ export async function prepareGovernanceAndModel(
263
262
  } catch {
264
263
  // Contribution telemetry must never change model execution semantics.
265
264
  }
266
- const logicalSandboxSettings = settingsWithRigImage(
267
- settingsWithPackSandboxImage(
268
- capabilitySettings,
269
- packRuntime.sandboxImage,
270
- packRuntime.sandboxProviderImages,
271
- ),
272
- rigVersion?.image ?? null,
273
- );
265
+ // A Rig is always a setup/check layer over the deployment platform sandbox.
266
+ // The pre-v2 Pack image path remains only for rig-less compatibility sessions.
267
+ const logicalSandboxSettings = rigVersion
268
+ ? capabilitySettings
269
+ : settingsWithPackSandboxImage(
270
+ capabilitySettings,
271
+ packRuntime.sandboxImage,
272
+ packRuntime.sandboxProviderImages,
273
+ );
274
274
  const providerImageSelection = await resolveRigProviderImageForRun(
275
275
  logicalSandboxSettings,
276
276
  rigVersion,
@@ -282,12 +282,10 @@ export async function prepareGovernanceAndModel(
282
282
  ? (providerImageSelection.imageId ?? undefined)
283
283
  : undefined;
284
284
  const baseRunSettings = {
285
- // IMAGE PRECEDENCE: rig > pre-V2 Pack compatibility > deployment.
286
- // resolveWorkspacePackRuntime returns no image for V2 Pack rows, so
287
- // settingsWithRigImage runs outermost over only the intentionally
288
- // retained legacy fallback. A matching verified provider-native ID is
289
- // then applied only to fresh creation without changing the logical
290
- // lease image.
285
+ // IMAGE PRECEDENCE: a Rig uses the deployment platform base; a rig-less
286
+ // pre-v2 Pack may retain its compatibility image. A matching verified
287
+ // provider-native ID is then applied only to fresh creation without
288
+ // changing the logical lease image.
291
289
  ...providerImageSettings,
292
290
  openaiModel: turn.model,
293
291
  openaiReasoningEffort: turn.reasoningEffort,
@@ -861,6 +861,7 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
861
861
  media,
862
862
  fileAuthoritySubjectId,
863
863
  runSettings,
864
+ logicalSandboxSettings,
864
865
  });
865
866
  const {
866
867
  routingOn,
@@ -1090,6 +1091,7 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
1090
1091
  attemptConnectorActionBindings,
1091
1092
  connectorActionIdentity,
1092
1093
  postToolPreparationStartedAt,
1094
+ preparationIndependentToolNames,
1093
1095
  } = toolRuntime;
1094
1096
 
1095
1097
  const builtAgent = await buildTurnAgent({
@@ -1144,6 +1146,7 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
1144
1146
  fileResourceDownloads,
1145
1147
  attemptConnectorActionBindings,
1146
1148
  connectorActionIdentity,
1149
+ preparationIndependentToolNames,
1147
1150
  videoGenerationAcceptancesByCallId,
1148
1151
  activeSandboxBackend,
1149
1152
  groupBoxBackend,
@@ -77,6 +77,7 @@ export type SandboxRouteDeps = {
77
77
  media: ReturnType<typeof createTurnMediaArtifacts>;
78
78
  fileAuthoritySubjectId: ClaimTurnOk["fileAuthoritySubjectId"];
79
79
  runSettings: GovernanceModelOk["runSettings"];
80
+ logicalSandboxSettings: GovernanceModelOk["logicalSandboxSettings"];
80
81
  };
81
82
 
82
83
  export type SandboxRouteOk = {
@@ -163,6 +164,7 @@ export async function resolveSandboxRoute(deps: SandboxRouteDeps): Promise<Sandb
163
164
  sandboxState,
164
165
  fileAuthoritySubjectId,
165
166
  runSettings,
167
+ logicalSandboxSettings,
166
168
  } = deps;
167
169
 
168
170
  // EFFECTIVE compute backend, resolved ONCE at turn start (Case B + Stage D
@@ -253,7 +255,10 @@ export async function resolveSandboxRoute(deps: SandboxRouteDeps): Promise<Sandb
253
255
  : runSettings.sandboxBackend;
254
256
  sandboxState.startupMilestoneBackend = activeSandboxBackend ?? groupBoxBackend;
255
257
  media.sandboxFileDownloadBackend = sandboxState.startupMilestoneBackend;
256
- const groupBoxImage = rigProviderImageSourceImage(runSettings, groupBoxBackend);
258
+ // Durable lease identity is always the logical OCI/base image. A provider
259
+ // image id in runSettings is only a physical cold-create optimization and
260
+ // must never become cross-surface shared-state fencing.
261
+ const groupBoxImage = rigProviderImageSourceImage(logicalSandboxSettings, groupBoxBackend);
257
262
  const sandboxCreationBackend: Settings["sandboxBackend"] =
258
263
  settings.sandboxOwnershipEnabled && runSettings.sandboxBackend !== "none"
259
264
  ? groupBoxBackend
@@ -0,0 +1,106 @@
1
+ import { hasPermission } from "@opengeni/core";
2
+ import type { AttemptToolDefinition } from "@opengeni/codemode";
3
+ import {
4
+ AUTOMATIC_SESSION_TITLE_FALLBACK,
5
+ DEFAULT_FIRST_PARTY_MCP_PERMISSIONS,
6
+ type FirstPartyMcpToolName,
7
+ type Permission,
8
+ type ToolRef,
9
+ } from "@opengeni/contracts";
10
+
11
+ export const SESSION_TITLE_MODEL_TOOL_NAME = "opengeni__set_session_title";
12
+
13
+ const SESSION_TITLE_DESCRIPTION =
14
+ "Set this session's display title to a concise 3-7 word topic label. Use a stable noun phrase about the actual task or subject, never a quote/prefix of a prompt, greeting, request boilerplate, URL, identifier, credential, token, or other sensitive value. Call once on a new session, then only when the topic materially changes. Never call it as routine setup after a continuation, resume, or interruption, or merely to reassert the same title. A human-set title cannot be replaced.";
15
+
16
+ export function shouldRequestMissingSessionTitle(input: {
17
+ title: string | null;
18
+ titleSource: "user" | "agent" | null;
19
+ firstPartyMcpTools: readonly FirstPartyMcpToolName[];
20
+ firstPartyMcpPermissions: readonly Permission[] | null;
21
+ }): boolean {
22
+ const title = input.title?.trim() ?? "";
23
+ const needsSemanticTitle =
24
+ input.titleSource !== "user" && (!title || title === AUTOMATIC_SESSION_TITLE_FALLBACK);
25
+ if (!needsSemanticTitle) return false;
26
+ if (!input.firstPartyMcpTools.includes("set_session_title")) return false;
27
+ const permissions = input.firstPartyMcpPermissions ?? DEFAULT_FIRST_PARTY_MCP_PERMISSIONS;
28
+ return hasPermission([...permissions], "sessions:control");
29
+ }
30
+
31
+ export function sessionTitleToolPlan(input: {
32
+ tools: readonly ToolRef[];
33
+ selectedFirstPartyMcpTools: readonly FirstPartyMcpToolName[];
34
+ shouldRequestTitle: boolean;
35
+ }): {
36
+ promoteTitleTool: boolean;
37
+ remoteFirstPartyMcpTools: FirstPartyMcpToolName[];
38
+ preparationIndependentToolNames: string[];
39
+ } {
40
+ const promoteTitleTool =
41
+ input.shouldRequestTitle &&
42
+ input.tools.some((tool) => tool.kind === "mcp" && tool.id === "opengeni");
43
+ return {
44
+ promoteTitleTool,
45
+ remoteFirstPartyMcpTools: promoteTitleTool
46
+ ? input.selectedFirstPartyMcpTools.filter((tool) => tool !== "set_session_title")
47
+ : [...input.selectedFirstPartyMcpTools],
48
+ preparationIndependentToolNames: promoteTitleTool ? [SESSION_TITLE_MODEL_TOOL_NAME] : [],
49
+ };
50
+ }
51
+
52
+ export function createSessionTitleAttemptToolDefinition(input: {
53
+ updateTitle: (title: string) => Promise<{ updated: boolean; title: string | null }>;
54
+ }): AttemptToolDefinition {
55
+ return {
56
+ identity: { serverId: "opengeni", toolName: "set_session_title" },
57
+ modelName: SESSION_TITLE_MODEL_TOOL_NAME,
58
+ codemodePath: ["opengeni", "set_session_title"],
59
+ title: "Set session title",
60
+ description: SESSION_TITLE_DESCRIPTION,
61
+ inputSchema: {
62
+ type: "object",
63
+ properties: {
64
+ title: { type: "string", minLength: 1, maxLength: 200 },
65
+ },
66
+ required: ["title"],
67
+ additionalProperties: false,
68
+ },
69
+ outputSchema: {
70
+ type: "object",
71
+ properties: {
72
+ ok: { type: "boolean", const: true },
73
+ updated: { type: "boolean" },
74
+ title: { type: "string" },
75
+ },
76
+ required: ["ok", "updated", "title"],
77
+ additionalProperties: false,
78
+ },
79
+ annotations: {
80
+ title: "Set session title",
81
+ readOnlyHint: false,
82
+ destructiveHint: false,
83
+ idempotentHint: true,
84
+ openWorldHint: false,
85
+ },
86
+ source: "opengeni",
87
+ approval: "none",
88
+ execute: async (args) => {
89
+ const title = args.title;
90
+ if (typeof title !== "string") {
91
+ throw new Error("set_session_title requires a title string");
92
+ }
93
+ const result = await input.updateTitle(title);
94
+ const output = {
95
+ ok: true as const,
96
+ updated: result.updated,
97
+ title: result.title ?? title,
98
+ };
99
+ return {
100
+ isError: false,
101
+ content: [{ type: "text", text: JSON.stringify(output) }],
102
+ structuredContent: output,
103
+ };
104
+ },
105
+ };
106
+ }
@@ -2,8 +2,10 @@ import {
2
2
  getScheduledVariableSetExpectedGenerationForAttempt,
3
3
  persistAttemptToolCatalog,
4
4
  namedSubjectHasLiveWorkspaceAuthority,
5
+ updateSessionTitleWithEvent,
5
6
  withCodexAppsRequestAuthorization,
6
7
  } from "@opengeni/db";
8
+ import { publishDurableSessionEvents } from "@opengeni/events";
7
9
  import {
8
10
  type OpenGeniRuntime,
9
11
  type AttemptConnectorActionBinding,
@@ -57,6 +59,11 @@ import type {
57
59
  SandboxRuntimeState,
58
60
  WorkspaceRefState,
59
61
  } from "./turn-context";
62
+ import {
63
+ createSessionTitleAttemptToolDefinition,
64
+ sessionTitleToolPlan,
65
+ shouldRequestMissingSessionTitle,
66
+ } from "./session-title";
60
67
 
61
68
  export type PrepareTurnToolPolicyDeps = {
62
69
  input: RunAgentTurnInput;
@@ -176,11 +183,13 @@ export async function prepareTurnToolPolicy(deps: PrepareTurnToolPolicyDeps) {
176
183
  workspaceId: input.workspaceId,
177
184
  };
178
185
  const rigDefaultVariableSetIds = rigVersion?.defaultVariableSetIds ?? [];
186
+ const sessionVariableSetIds = session.variableSetIds;
179
187
  let workspaceVariableSet: Awaited<
180
188
  ReturnType<typeof loadWorkspaceEnvironmentForRunWithCredentials>
181
189
  > = null;
190
+ const explicitEnvironmentValues: Record<string, string> = {};
182
191
  const rigDefaultEnvironmentValues: Record<string, string> = {};
183
- if (session.variableSetId !== null || rigDefaultVariableSetIds.length > 0) {
192
+ if (sessionVariableSetIds.length > 0 || rigDefaultVariableSetIds.length > 0) {
184
193
  const variableSetAuthority = {
185
194
  sessionId: input.sessionId,
186
195
  turnId: turn.id,
@@ -205,22 +214,30 @@ export async function prepareTurnToolPolicy(deps: PrepareTurnToolPolicyDeps) {
205
214
  executionGeneration: turn.executionGeneration,
206
215
  variableSetId: candidateVariableSetId,
207
216
  });
208
- workspaceVariableSet = await waitForTurnOperation(
209
- (async () =>
210
- loadWorkspaceEnvironmentForRunWithCredentials(
211
- db,
212
- runSettings,
213
- connectionScope,
214
- session.variableSetId,
215
- variableSetAuthority,
216
- connectionCredentials?.sandboxSecrets,
217
- session.variableSetId && connectionCredentials?.sandboxSecrets
218
- ? { expectedGeneration: await expectedVariableSetGeneration(session.variableSetId) }
219
- : {},
220
- ))(),
221
- cancellationSignal,
222
- undefined,
223
- );
217
+ for (const variableSetId of sessionVariableSetIds) {
218
+ const selected = await waitForTurnOperation(
219
+ (async () =>
220
+ loadWorkspaceEnvironmentForRunWithCredentials(
221
+ db,
222
+ runSettings,
223
+ connectionScope,
224
+ variableSetId,
225
+ variableSetAuthority,
226
+ connectionCredentials?.sandboxSecrets,
227
+ connectionCredentials?.sandboxSecrets
228
+ ? { expectedGeneration: await expectedVariableSetGeneration(variableSetId) }
229
+ : {},
230
+ ))(),
231
+ cancellationSignal,
232
+ undefined,
233
+ );
234
+ if (!selected) continue;
235
+ Object.assign(explicitEnvironmentValues, selected.values);
236
+ // Preserve the legacy single-set metadata view as the final,
237
+ // highest-precedence explicit selection while its values represent the
238
+ // complete ordered explicit layer.
239
+ workspaceVariableSet = { ...selected, values: { ...explicitEnvironmentValues } };
240
+ }
224
241
  // RIG DEFAULT VARIABLE SETS (M3): decrypt the frozen rig version's default
225
242
  // variable sets and layer them BELOW the session's own set — the session's
226
243
  // values WIN on any key collision. Loaded through the SAME host-secrets
@@ -262,7 +279,7 @@ export async function prepareTurnToolPolicy(deps: PrepareTurnToolPolicyDeps) {
262
279
  // Session set wins collisions with the rig defaults (explicit precedence).
263
280
  const sandboxWorkspaceEnvironmentValues = mergeRigDefaultVariableSetEnvironment(
264
281
  rigDefaultEnvironmentValues,
265
- workspaceVariableSet?.values ?? {},
282
+ explicitEnvironmentValues,
266
283
  );
267
284
  return {
268
285
  turnResources,
@@ -461,6 +478,16 @@ export async function prepareTurnToolRuntime(deps: PrepareTurnToolRuntimeDeps) {
461
478
  runSettings,
462
479
  session.firstPartyMcpTools,
463
480
  );
481
+ const titleToolPlan = sessionTitleToolPlan({
482
+ tools: turnTools,
483
+ selectedFirstPartyMcpTools,
484
+ shouldRequestTitle: shouldRequestMissingSessionTitle({
485
+ title: session.title,
486
+ titleSource: session.titleSource,
487
+ firstPartyMcpTools: selectedFirstPartyMcpTools,
488
+ firstPartyMcpPermissions: session.firstPartyMcpPermissions,
489
+ }),
490
+ });
464
491
  const googleDrivePublicationAllowed =
465
492
  selectedFirstPartyMcpTools.includes("editable_artifact_export") &&
466
493
  selectedFirstPartyMcpTools.includes("editable_artifact_export_status") &&
@@ -482,6 +509,27 @@ export async function prepareTurnToolRuntime(deps: PrepareTurnToolRuntimeDeps) {
482
509
  ]
483
510
  : [];
484
511
  const attemptToolDefinitions = [
512
+ ...(titleToolPlan.promoteTitleTool
513
+ ? [
514
+ createSessionTitleAttemptToolDefinition({
515
+ updateTitle: async (title) => {
516
+ const result = await updateSessionTitleWithEvent(db, {
517
+ workspaceId: input.workspaceId,
518
+ sessionId: input.sessionId,
519
+ title,
520
+ source: "agent",
521
+ });
522
+ await publishDurableSessionEvents(
523
+ bus,
524
+ input.workspaceId,
525
+ input.sessionId,
526
+ result.events,
527
+ );
528
+ return result;
529
+ },
530
+ }),
531
+ ]
532
+ : []),
485
533
  ...createFirstPartyInteractionAttemptToolDefinitions({
486
534
  settings: runSettings,
487
535
  scope: {
@@ -612,7 +660,7 @@ export async function prepareTurnToolRuntime(deps: PrepareTurnToolRuntimeDeps) {
612
660
  ...(session.firstPartyMcpPermissions?.length
613
661
  ? { firstPartyPermissions: session.firstPartyMcpPermissions }
614
662
  : {}),
615
- firstPartyTools: selectedFirstPartyMcpTools,
663
+ firstPartyTools: titleToolPlan.remoteFirstPartyMcpTools,
616
664
  nestedAgentDepth: session.nestedAgentDepth,
617
665
  effectiveMaxNestedAgentDepth: session.effectiveMaxNestedAgentDepth,
618
666
  attemptToolDefinitions,
@@ -722,6 +770,7 @@ export async function prepareTurnToolRuntime(deps: PrepareTurnToolRuntimeDeps) {
722
770
  ],
723
771
  connectorActionIdentity,
724
772
  postToolPreparationStartedAt,
773
+ preparationIndependentToolNames: titleToolPlan.preparationIndependentToolNames,
725
774
  };
726
775
  }
727
776
 
@@ -61,11 +61,14 @@ export function computerToolModeForTurn(
61
61
  return "function-image";
62
62
  }
63
63
 
64
- /** Gateway models do not advertise OpenAI's hosted apply_patch/view_image tool types. */
64
+ /** Chat wires and Gateway models do not advertise OpenAI's hosted sandbox tool types. */
65
65
  export function structuredToolTransportForTurn(
66
- resolvedModel: { provider: { kind: RegistryProviderKind } } | null,
66
+ resolvedModel: {
67
+ provider: { kind: RegistryProviderKind; api: ModelProviderApi };
68
+ } | null,
67
69
  ): boolean {
68
70
  if (!resolvedModel) return true;
71
+ if (resolvedModel.provider.api === "chat") return false;
69
72
  return ![
70
73
  "codex-subscription",
71
74
  "xai-subscription",
@@ -46,6 +46,7 @@ export async function resolveIncidentTelemetryResponderMetadata(input: {
46
46
  firstPartyMcpPermissions:
47
47
  | ScheduledTaskRunAcceptedExecution["resolvedFirstPartyMcpPermissions"]
48
48
  | null;
49
+ variableSetIds?: readonly string[];
49
50
  variableSetId: string | null;
50
51
  rigId: string | null;
51
52
  rigVersionId: string | null;
@@ -88,6 +89,9 @@ export async function resolveIncidentTelemetryResponderMetadata(input: {
88
89
  let rig: IncidentTelemetryResponderMetadata["rig"] = null;
89
90
  const variableSetIds = new Set<string>();
90
91
  if (input.executionPolicy ?? input.session) {
92
+ for (const id of input.executionPolicy?.variableSetIds ?? input.session?.variableSetIds ?? []) {
93
+ variableSetIds.add(id);
94
+ }
91
95
  const variableSetId = input.executionPolicy?.variableSetId ?? input.session?.variableSetId;
92
96
  const rigId = input.executionPolicy?.rigId ?? input.session?.rigId ?? null;
93
97
  const rigVersionId = input.executionPolicy?.rigVersionId ?? input.session?.rigVersionId ?? null;
@@ -286,6 +290,9 @@ export async function validateIncidentTelemetrySystemUpdateAuthority(input: {
286
290
  firstPartyMcpTools: acceptedExecution.targetSessionExecution.firstPartyMcpTools,
287
291
  firstPartyMcpPermissions:
288
292
  acceptedExecution.targetSessionExecution.firstPartyMcpPermissions,
293
+ variableSetIds: acceptedExecution.targetSessionExecution.variableSets.map(
294
+ (variableSet) => variableSet.id,
295
+ ),
289
296
  variableSetId: acceptedExecution.targetSessionExecution.variableSetId,
290
297
  rigId: acceptedExecution.targetSessionExecution.rigId,
291
298
  rigVersionId: acceptedExecution.targetSessionExecution.rigVersionId,
@@ -11,14 +11,17 @@ import {
11
11
  childRequiresActionDedupeKey,
12
12
  getSessionSystemUpdateOutboxByDedupeKey,
13
13
  getOrCreateSessionSystemUpdateOutbox,
14
+ claimAutomaticSessionTitleFanout,
14
15
  markSessionWorkflowWakeFailed,
15
16
  markSessionSystemUpdateOutboxDeliveredInTransaction,
16
17
  markSessionSystemUpdateOutboxFailed,
18
+ markAutomaticSessionTitleFanoutDelivered,
19
+ markAutomaticSessionTitleFanoutFailed,
17
20
  sessionSystemUpdateOutboxKindPayload,
18
21
  type Database,
19
22
  type SessionSystemUpdateOutboxDelivery,
20
23
  } from "@opengeni/db";
21
- import type { EventBus } from "@opengeni/events";
24
+ import { requireSessionEventDurableFanoutCapability, type EventBus } from "@opengeni/events";
22
25
  import type { ActivityServices, WakeSessionWorkflowSignal } from "./types";
23
26
 
24
27
  export type NotifyServices = {
@@ -37,6 +40,12 @@ export type ReconcileSessionWorkflowWakeOverrides = Partial<{
37
40
  claimPendingSessionWorkflowWakes: typeof claimPendingSessionWorkflowWakes;
38
41
  }>;
39
42
 
43
+ export type ReconcileAutomaticSessionTitleFanoutOverrides = Partial<{
44
+ claimAutomaticSessionTitleFanout: typeof claimAutomaticSessionTitleFanout;
45
+ markAutomaticSessionTitleFanoutDelivered: typeof markAutomaticSessionTitleFanoutDelivered;
46
+ markAutomaticSessionTitleFanoutFailed: typeof markAutomaticSessionTitleFanoutFailed;
47
+ }>;
48
+
40
49
  /**
41
50
  * Enrich and deliver the durable idle-boundary row committed by
42
51
  * settleSessionIdleWithParentOutbox. Idle has no single owning turn, so its
@@ -267,6 +276,61 @@ export async function reconcilePendingParentSystemUpdates(
267
276
  return { claimed: rows.length, delivered, failed };
268
277
  }
269
278
 
279
+ /**
280
+ * Publish migration-created safe title events through the configured session
281
+ * event bus. The outbox is durable and deployment-global; a crash after publish
282
+ * but before acknowledgement can duplicate a notification, which is safe
283
+ * because SSE consumers sequence-fence and gap-fill from the durable log.
284
+ *
285
+ * Managed NATS exposes the stronger bounded flush acknowledgement through
286
+ * publishConfirmed. Embedding buses predate that optional capability, so their
287
+ * required publish promise remains the delivery acknowledgement: resolve only
288
+ * after accepting the batch, and reject a real transport failure so the durable
289
+ * row stays retryable. Every supported bus also provides the mandatory paired
290
+ * recovery capability used by API SSE streams after subscriber reconnect.
291
+ */
292
+ export async function reconcileAutomaticSessionTitleFanout(
293
+ svc: NotifyServices,
294
+ limit = 100,
295
+ overrides: ReconcileAutomaticSessionTitleFanoutOverrides = {},
296
+ ): Promise<{ claimed: number; delivered: number; failed: number }> {
297
+ requireSessionEventDurableFanoutCapability(svc.bus);
298
+ const claim = overrides.claimAutomaticSessionTitleFanout ?? claimAutomaticSessionTitleFanout;
299
+ const markDelivered =
300
+ overrides.markAutomaticSessionTitleFanoutDelivered ?? markAutomaticSessionTitleFanoutDelivered;
301
+ const markFailed =
302
+ overrides.markAutomaticSessionTitleFanoutFailed ?? markAutomaticSessionTitleFanoutFailed;
303
+ const rows = await claim(svc.db, limit);
304
+ let delivered = 0;
305
+ let failed = 0;
306
+ const queue = [...rows];
307
+ const workers = Array.from({ length: Math.min(20, queue.length) }, async () => {
308
+ for (;;) {
309
+ const row = queue.shift();
310
+ if (!row) return;
311
+ try {
312
+ if (svc.bus.isConnected?.() === false) {
313
+ throw new Error("session event bus is disconnected");
314
+ }
315
+ if (svc.bus.publishConfirmed) {
316
+ await svc.bus.publishConfirmed(row.event.workspaceId, row.event.sessionId, [row.event]);
317
+ } else {
318
+ await svc.bus.publish(row.event.workspaceId, row.event.sessionId, [row.event]);
319
+ }
320
+ await markDelivered(svc.db, row);
321
+ delivered += 1;
322
+ } catch (error) {
323
+ failed += 1;
324
+ await markFailed(svc.db, row, error instanceof Error ? error.message : String(error)).catch(
325
+ () => undefined,
326
+ );
327
+ }
328
+ }
329
+ });
330
+ await Promise.all(workers);
331
+ return { claimed: rows.length, delivered, failed };
332
+ }
333
+
270
334
  export async function reconcilePendingSessionWorkflowWakes(
271
335
  svc: NotifyServices,
272
336
  limit = 1_000,