@opengeni/worker-bundle 2.2.1-canary.36927100590001 → 2.2.1

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 (36) hide show
  1. package/dist/activities/agent-turn/run-credentials.d.ts +0 -2
  2. package/dist/activities/scheduled-tasks.d.ts +35 -4
  3. package/dist/activities/types.d.ts +0 -3
  4. package/dist/activities/workspace-capture.d.ts +0 -2
  5. package/dist/{activities-control-4F2A734B.js → activities-control-55ECL47G.js} +20 -102
  6. package/dist/activities-control-55ECL47G.js.map +1 -0
  7. package/dist/{activities-turn-TESOIOEX.js → activities-turn-T7Y3BWYO.js} +7 -20
  8. package/dist/activities-turn-T7Y3BWYO.js.map +1 -0
  9. package/dist/{chunk-YG27NEMX.js → chunk-IJZU752L.js} +1 -34
  10. package/dist/chunk-IJZU752L.js.map +1 -0
  11. package/dist/{chunk-4PJTUBWQ.js → chunk-OWNLATJL.js} +11 -34
  12. package/dist/chunk-OWNLATJL.js.map +1 -0
  13. package/dist/index.js +2 -2
  14. package/dist/observability-metrics.d.ts +1 -16
  15. package/dist/workflow-bundle.js +12 -18
  16. package/dist/workflows/scheduled-tasks.d.ts +0 -4
  17. package/package.json +21 -21
  18. package/src/activities/agent-turn/claim.ts +1 -13
  19. package/src/activities/agent-turn/run-credentials.ts +0 -5
  20. package/src/activities/agent-turn/run.ts +0 -1
  21. package/src/activities/agent-turn/tool-environment.ts +0 -4
  22. package/src/activities/automations.ts +1 -23
  23. package/src/activities/goals.ts +8 -33
  24. package/src/activities/sandbox-lease.ts +0 -22
  25. package/src/activities/scheduled-tasks.ts +25 -89
  26. package/src/activities/site-auth-maintenance.ts +0 -1
  27. package/src/activities/types.ts +0 -3
  28. package/src/activities/workspace-capture.ts +2 -13
  29. package/src/observability-metrics.ts +1 -55
  30. package/src/workflows/scheduled-tasks.ts +13 -26
  31. package/dist/activities/agent-turn/credential-restriction.d.ts +0 -3
  32. package/dist/activities-control-4F2A734B.js.map +0 -1
  33. package/dist/activities-turn-TESOIOEX.js.map +0 -1
  34. package/dist/chunk-4PJTUBWQ.js.map +0 -1
  35. package/dist/chunk-YG27NEMX.js.map +0 -1
  36. package/src/activities/agent-turn/credential-restriction.ts +0 -14
@@ -1,5 +1,4 @@
1
1
  import type { TurnInitiator } from "@opengeni/contracts";
2
- import type { DispatchScheduledTaskRunInput } from "../activities/types.js";
3
2
  type ScheduledTaskFireWorkflowBase = {
4
3
  accountId: string;
5
4
  workspaceId: string;
@@ -9,13 +8,10 @@ export type ScheduledTaskFireWorkflowInput = ScheduledTaskFireWorkflowBase & ({
9
8
  triggerType: "scheduled";
10
9
  agentRunUsageIdempotencyKey?: never;
11
10
  initiator?: never;
12
- credentialRestriction?: never;
13
11
  } | {
14
12
  triggerType: "manual" | "initial" | "provider_event" | "retry" | "repair";
15
13
  agentRunUsageIdempotencyKey: string;
16
14
  initiator: TurnInitiator;
17
- credentialRestriction?: "developer_setup";
18
15
  });
19
- export declare function scheduledTaskDispatchInput(input: ScheduledTaskFireWorkflowInput, producerKey: string): DispatchScheduledTaskRunInput;
20
16
  export declare function scheduledTaskFireWorkflow(input: ScheduledTaskFireWorkflowInput): Promise<void>;
21
17
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengeni/worker-bundle",
3
- "version": "2.2.1-canary.36927100590001",
3
+ "version": "2.2.1",
4
4
  "description": "OpenGeni worker entry and reusable embedded lifecycle, shipped with a release-coherent pre-bundled Temporal workflow artifact.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -54,26 +54,26 @@
54
54
  },
55
55
  "dependencies": {
56
56
  "@llamaindex/liteparse": "2.14.2",
57
- "@opengeni/agent-proto": "^0.6.1-canary.36927100590001",
58
- "@opengeni/capabilities": "^0.3.5-canary.36927100590001",
59
- "@opengeni/codemode": "^0.6.6-canary.36927100590001",
60
- "@opengeni/codex": "^0.2.30-canary.36927100590001",
61
- "@opengeni/config": "^3.2.0-canary.36927100590001",
62
- "@opengeni/contracts": "^5.5.0-canary.36927100590001",
63
- "@opengeni/core": "^5.0.1-canary.36927100590001",
64
- "@opengeni/db": "^6.3.0-canary.36927100590001",
65
- "@opengeni/documents": "^0.8.38-canary.36927100590001",
66
- "@opengeni/events": "^0.4.36-canary.36927100590001",
67
- "@opengeni/github": "^0.8.1-canary.36927100590001",
68
- "@opengeni/interaction": "^0.4.44-canary.36927100590001",
69
- "@opengeni/jev": "^0.2.1-canary.36927100590001",
70
- "@opengeni/network": "^0.3.1-canary.36927100590001",
71
- "@opengeni/observability": "^0.8.36-canary.36927100590001",
72
- "@opengeni/runtime": "^4.4.0-canary.36927100590001",
73
- "@opengeni/sdk": "^7.5.0-canary.36927100590001",
74
- "@opengeni/storage": "^0.2.137-canary.36927100590001",
75
- "@opengeni/tool-gateway": "^0.1.17-canary.36927100590001",
76
- "@opengeni/xai-subscription": "^0.1.5-canary.36927100590001",
57
+ "@opengeni/agent-proto": "^0.6.1",
58
+ "@opengeni/capabilities": "^0.3.5",
59
+ "@opengeni/codemode": "^0.6.6",
60
+ "@opengeni/codex": "^0.2.30",
61
+ "@opengeni/config": "^3.2.0",
62
+ "@opengeni/contracts": "^5.5.0",
63
+ "@opengeni/core": "^5.0.1",
64
+ "@opengeni/db": "^6.3.0",
65
+ "@opengeni/documents": "^0.8.38",
66
+ "@opengeni/events": "^0.4.36",
67
+ "@opengeni/github": "^0.8.1",
68
+ "@opengeni/interaction": "^0.4.44",
69
+ "@opengeni/jev": "^0.2.1",
70
+ "@opengeni/network": "^0.3.1",
71
+ "@opengeni/observability": "^0.8.36",
72
+ "@opengeni/runtime": "^4.4.0",
73
+ "@opengeni/sdk": "^7.5.0",
74
+ "@opengeni/storage": "^0.2.137",
75
+ "@opengeni/tool-gateway": "^0.1.17",
76
+ "@opengeni/xai-subscription": "^0.1.5",
77
77
  "@temporalio/activity": "^1.17.0",
78
78
  "@temporalio/client": "^1.17.0",
79
79
  "@temporalio/worker": "^1.17.0",
@@ -56,7 +56,6 @@ import {
56
56
  import { createTurnCredentialLeases } from "./credential-leases";
57
57
  import { createTurnMediaArtifacts } from "./media-artifacts";
58
58
  import { readTurnExecutionPolicyV1 } from "@opengeni/contracts";
59
- import { turnCredentialRestriction } from "./credential-restriction";
60
59
 
61
60
  import {
62
61
  credentialSubjectIdForTurnInitiator,
@@ -291,21 +290,10 @@ export async function claimTurnAttempt(deps: ClaimTurnDeps): Promise<ClaimTurnOu
291
290
  const codexAppsCredentialId = capabilitySettings.codexConnectedAppsEnabled
292
291
  ? await resolveCodexAppsCredentialIdForRun(db, input.workspaceId)
293
292
  : null;
294
- const candidatePolicy =
293
+ const policyForAbsent =
295
294
  claimedPolicy.kind === "valid"
296
295
  ? claimedPolicy.policy
297
296
  : resolveTurnExecutionPolicyV1(capabilitySettings, legacyTurnExecutionPolicyInput(turn));
298
- // This context is frozen by the accepted-turn writer from the exact source
299
- // turn. Its reserved restriction field cannot come from public service JSON.
300
- const credentialRestriction =
301
- claimedPolicy.kind === "absent"
302
- ? turn.initiatorContext?.credentialRestriction === "developer_setup"
303
- ? "developer_setup"
304
- : turnCredentialRestriction(candidatePolicy, session.metadata)
305
- : undefined;
306
- const policyForAbsent = credentialRestriction
307
- ? { ...candidatePolicy, credentialRestriction }
308
- : candidatePolicy;
309
297
  const installedPolicy = await installOrReadTurnExecutionPolicyForAttempt(db, {
310
298
  accountId: input.accountId,
311
299
  workspaceId: input.workspaceId,
@@ -65,7 +65,6 @@ import {
65
65
  sandboxSettingsForRoute,
66
66
  } from "./sandbox-route";
67
67
  import type { ClaimTurnOk } from "./claim";
68
- import { turnCredentialRestriction } from "./credential-restriction";
69
68
  import type { GovernanceModelOk } from "./governance-model";
70
69
  import type { SandboxTurnRuntime } from "./sandbox-runtime";
71
70
  import type {
@@ -92,7 +91,6 @@ export type PrepareRunCredentialsDeps = {
92
91
  sandboxRuntime: SandboxTurnRuntime;
93
92
  turn: ClaimTurnOk["turn"];
94
93
  session: ClaimTurnOk["session"];
95
- turnExecutionPolicy: ClaimTurnOk["turnExecutionPolicy"];
96
94
  fileAuthoritySubjectId: ClaimTurnOk["fileAuthoritySubjectId"];
97
95
  runSettings: GovernanceModelOk["runSettings"];
98
96
  workspaceVariableSet: Awaited<ReturnType<typeof loadWorkspaceEnvironmentForRunWithCredentials>>;
@@ -131,7 +129,6 @@ export async function prepareRunCredentials(deps: PrepareRunCredentialsDeps) {
131
129
  sandboxState,
132
130
  turn,
133
131
  session,
134
- turnExecutionPolicy,
135
132
  fileAuthoritySubjectId,
136
133
  runSettings,
137
134
  workspaceVariableSet,
@@ -349,13 +346,11 @@ export async function prepareRunCredentials(deps: PrepareRunCredentialsDeps) {
349
346
  turn,
350
347
  })
351
348
  : undefined;
352
- const credentialRestriction = turnCredentialRestriction(turnExecutionPolicy, session.metadata);
353
349
  const codemodeAuthority = {
354
350
  sessionId: input.sessionId,
355
351
  turnId: turn.id,
356
352
  attemptId: input.attemptId,
357
353
  executionGeneration: turn.executionGeneration,
358
- ...(credentialRestriction ? { credentialRestriction } : {}),
359
354
  };
360
355
  const sandboxArtifactRuntime = sandboxArtifactRuntimeAdmission(
361
356
  settings,
@@ -1226,7 +1226,6 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
1226
1226
  sandboxRuntime,
1227
1227
  turn,
1228
1228
  session,
1229
- turnExecutionPolicy,
1230
1229
  fileAuthoritySubjectId,
1231
1230
  runSettings,
1232
1231
  workspaceVariableSet,
@@ -127,7 +127,6 @@ import { codeSearchToolDefinitions, codeSearchWorkspaceFromChannel } from "./cod
127
127
  import { createWorkspaceSkillTools } from "./skill-tools";
128
128
  import { loadConfiguredBundledSkills } from "./skill-selection";
129
129
  import { guardSkillFilesystem } from "./skill-transfer";
130
- import { turnCredentialRestriction } from "./credential-restriction";
131
130
 
132
131
  export type PrepareTurnToolPolicyDeps = {
133
132
  input: RunAgentTurnInput;
@@ -423,7 +422,6 @@ export async function prepareTurnToolRuntime(deps: PrepareTurnToolRuntimeDeps) {
423
422
  });
424
423
  const runSettings = accountRoutes.settings;
425
424
  const turnTools = accountRoutes.tools;
426
- const credentialRestriction = turnCredentialRestriction(turnExecutionPolicy, session.metadata);
427
425
  const toolContextPreparationStartedAt = performance.now();
428
426
  throwIfWorkerShuttingDown();
429
427
  throwIfTurnCancelled();
@@ -1011,7 +1009,6 @@ export async function prepareTurnToolRuntime(deps: PrepareTurnToolRuntimeDeps) {
1011
1009
  : []),
1012
1010
  ...createFirstPartyInteractionAttemptToolDefinitions({
1013
1011
  settings: runSettings,
1014
- ...(credentialRestriction ? { credentialRestriction } : {}),
1015
1012
  scope: {
1016
1013
  accountId: input.accountId,
1017
1014
  workspaceId: input.workspaceId,
@@ -1107,7 +1104,6 @@ export async function prepareTurnToolRuntime(deps: PrepareTurnToolRuntimeDeps) {
1107
1104
  try {
1108
1105
  eventing.preparedTools = await waitForTurnOperation(
1109
1106
  runtime.prepareTools(githubRestMcp.settings, githubRestMcp.tools, {
1110
- ...(credentialRestriction ? { credentialRestriction } : {}),
1111
1107
  mcpAccountLabels: accountRoutes.accountLabels,
1112
1108
  accountId: input.accountId,
1113
1109
  workspaceId: input.workspaceId,
@@ -13,7 +13,6 @@ import {
13
13
  recordWorkspaceUsage,
14
14
  resolveCatalogSettings,
15
15
  resolveWorkspaceCatalogSettings,
16
- isDeveloperSetupDelegatedPermissionAllowed,
17
16
  } from "@opengeni/core";
18
17
  import {
19
18
  AutomationAuthorityRevokedError,
@@ -108,20 +107,6 @@ export function createAutomationActivities(
108
107
  }
109
108
 
110
109
  const template = accepted.sessionTemplate;
111
- if (
112
- template.credentialRestriction === "developer_setup" &&
113
- template.firstPartyMcpPermissions.some(
114
- (permission) => !isDeveloperSetupDelegatedPermissionAllowed(permission),
115
- )
116
- ) {
117
- await settle(service.db, {
118
- workspaceId: input.workspaceId,
119
- runId: run.id,
120
- status: "failed",
121
- errorCode: "credential_restriction_violation",
122
- });
123
- return { action: "failed", reason: "credential_restriction_violation" };
124
- }
125
110
  const requestedModel = template.model ?? deploymentCatalogSettings.openaiModel;
126
111
  const catalogSettings =
127
112
  requestedModel.startsWith(WORKSPACE_GATEWAY_MODEL_ID_PREFIX) ||
@@ -224,7 +209,7 @@ export function createAutomationActivities(
224
209
  });
225
210
  return { action: "failed", reason: "dispatch_failed" };
226
211
  }
227
- const resolvedTurnExecutionPolicy = resolveTurnExecutionPolicyV1(catalogSettings, {
212
+ const turnExecutionPolicy = resolveTurnExecutionPolicyV1(catalogSettings, {
228
213
  modelId: model,
229
214
  requestedModelId: template.model,
230
215
  modelSource: template.model ? "explicit" : "deployment",
@@ -233,12 +218,6 @@ export function createAutomationActivities(
233
218
  latencyMode: "standard",
234
219
  latencyModeSource: "deployment",
235
220
  });
236
- const turnExecutionPolicy = template.credentialRestriction
237
- ? {
238
- ...resolvedTurnExecutionPolicy,
239
- credentialRestriction: template.credentialRestriction,
240
- }
241
- : resolvedTurnExecutionPolicy;
242
221
  const created = await createSession({
243
222
  db: service.db,
244
223
  bus: service.bus,
@@ -262,7 +241,6 @@ export function createAutomationActivities(
262
241
  workspaceId: input.workspaceId,
263
242
  initialMessage: accepted.initialMessage,
264
243
  surface: "automation",
265
- metrics: service.observability,
266
244
  resources: template.resources,
267
245
  skills: SessionSkills.parse(template.skills),
268
246
  bundledSkillIds: template.bundledSkillIds,
@@ -14,7 +14,6 @@ import {
14
14
  import {
15
15
  evaluateWorkspaceModelPolicy,
16
16
  mergeToolRefs,
17
- readTurnExecutionPolicyV1,
18
17
  type SessionGoal,
19
18
  type ToolRef,
20
19
  } from "@opengeni/contracts";
@@ -23,7 +22,6 @@ import {
23
22
  enqueueSessionWorkflowWakeIfRunnable,
24
23
  getWorkspaceModelPolicy,
25
24
  getSessionGoal,
26
- getSessionTurn,
27
25
  materializeGoalContinuation,
28
26
  requireSession,
29
27
  } from "@opengeni/db";
@@ -38,7 +36,6 @@ import {
38
36
  resolveWorkspaceCatalogSettings,
39
37
  } from "@opengeni/core";
40
38
  import { agentRunAdmissionDenial } from "./agent-run-admission";
41
- import { turnCredentialRestriction } from "./agent-turn/credential-restriction";
42
39
 
43
40
  export function createGoalActivities(services: () => Promise<ControlActivityServices>) {
44
41
  async function enqueueGoalRetryWake(input: MaybeContinueGoalInput): Promise<void> {
@@ -127,16 +124,6 @@ export function createGoalActivities(services: () => Promise<ControlActivityServ
127
124
  latencyMode: continuationLatencyMode,
128
125
  latencyModeSource: "continuation",
129
126
  });
130
- const continuationPolicy: NonNullable<
131
- Parameters<typeof materializeGoalContinuation>[1]["policy"]
132
- > = {
133
- model: continuationModel,
134
- reasoningEffort: continuationReasoningEffort,
135
- latencyMode: continuationLatencyMode,
136
- ...(turnExecutionPolicy ? { turnExecutionPolicy } : {}),
137
- tools: withFirstPartyTools(settings, session.tools),
138
- sandboxBackend: session.sandboxBackend,
139
- };
140
127
  const decision = await materializeGoalContinuation(db, {
141
128
  accountId: input.accountId,
142
129
  workspaceId: input.workspaceId,
@@ -153,25 +140,6 @@ export function createGoalActivities(services: () => Promise<ControlActivityServ
153
140
  // pause can clear on its own; a policy pause needs a model/policy change)
154
141
  // and rides the same visible-pause channel.
155
142
  admission: async (tx, causalTurn) => {
156
- // The materializer selects this exact causal row under its session/goal
157
- // locks and freezes policy only after admission returns. Never infer
158
- // credential authority from the generated continuation's payload.
159
- const sourceTurn = causalTurn
160
- ? await getSessionTurn(tx, input.workspaceId, causalTurn.id)
161
- : null;
162
- if (causalTurn && (!sourceTurn || sourceTurn.sessionId !== input.sessionId)) {
163
- throw new Error("Goal continuation source turn is unavailable");
164
- }
165
- const sourcePolicy = readTurnExecutionPolicyV1(sourceTurn?.metadata);
166
- if (turnExecutionPolicy) {
167
- const credentialRestriction = turnCredentialRestriction(
168
- sourcePolicy.kind === "valid" ? sourcePolicy.policy : turnExecutionPolicy,
169
- session.metadata,
170
- );
171
- continuationPolicy.turnExecutionPolicy = credentialRestriction
172
- ? { ...turnExecutionPolicy, credentialRestriction }
173
- : turnExecutionPolicy;
174
- }
175
143
  const budgetBlocked = modelPolicyBlocked
176
144
  ? null
177
145
  : await goalRunBudgetBlocked(
@@ -190,7 +158,14 @@ export function createGoalActivities(services: () => Promise<ControlActivityServ
190
158
  : (budgetBlocked?.pausedReason ?? "limits"),
191
159
  };
192
160
  },
193
- policy: continuationPolicy,
161
+ policy: {
162
+ model: continuationModel,
163
+ reasoningEffort: continuationReasoningEffort,
164
+ latencyMode: continuationLatencyMode,
165
+ ...(turnExecutionPolicy ? { turnExecutionPolicy } : {}),
166
+ tools: withFirstPartyTools(settings, session.tools),
167
+ sandboxBackend: session.sandboxBackend,
168
+ },
194
169
  // Long-wait guidance is only given when `wait_for_input` is actually in this
195
170
  // session's effective first-party selection (the same source the worker
196
171
  // signs into the delegated token and the API uses to register tools), so
@@ -41,8 +41,6 @@ import {
41
41
  deferRetainedProcessReconciliation,
42
42
  forceDrainOverLimitViewerOnlyBoxes,
43
43
  listCreditBalancesByAccount,
44
- countActiveUsers,
45
- readCreditGrantTotals,
46
44
  readVerifiedSignupTrialSwitch,
47
45
  listLegacyModalCheckpointSlots,
48
46
  listLiveModalSandboxLeaseAttributions,
@@ -152,9 +150,7 @@ import { assertSandboxDrainInputTiming, sandboxDrainTiming } from "../sandbox-re
152
150
  import type { ControlActivityServices as ActivityServices } from "./types";
153
151
  import { reconcilePendingParentSystemUpdates } from "./parent-wake";
154
152
  import {
155
- recordActiveUserGauges,
156
153
  recordCreditBalanceGauges,
157
- recordCreditGrantGauges,
158
154
  recordCreditMicros,
159
155
  recordExpiredDrainingSandboxLeaseGauges,
160
156
  recordOpenSandboxKubernetesInventoryGauges,
@@ -2529,24 +2525,6 @@ async function refreshQueueLeaseAndCreditGauges(
2529
2525
  });
2530
2526
  }
2531
2527
  })(),
2532
- (async () => {
2533
- try {
2534
- recordActiveUserGauges(observability, await countActiveUsers(db));
2535
- } catch (error) {
2536
- observability.warn("sandbox reaper: active-user gauge refresh failed", {
2537
- error: error instanceof Error ? error.message : String(error),
2538
- });
2539
- }
2540
- })(),
2541
- (async () => {
2542
- try {
2543
- recordCreditGrantGauges(observability, await readCreditGrantTotals(db));
2544
- } catch (error) {
2545
- observability.warn("sandbox reaper: credit-grant gauge refresh failed", {
2546
- error: error instanceof Error ? error.message : String(error),
2547
- });
2548
- }
2549
- })(),
2550
2528
  (async () => {
2551
2529
  recordVerifiedSignupTrialDeploymentFlagGauge(
2552
2530
  observability,
@@ -10,7 +10,6 @@ import {
10
10
  SessionAgentAccess,
11
11
  SessionMemoryScope,
12
12
  normalizeAutomaticSessionTitle,
13
- metadataWithTurnExecutionPolicyV1,
14
13
  scheduledOccurrencePayloadUtf8Bytes,
15
14
  stableJson,
16
15
  TurnExecutionPolicyV1,
@@ -39,9 +38,6 @@ import {
39
38
  agentConfigMayResolve,
40
39
  applySessionAgentConfigWriteThrough,
41
40
  resolveSessionAgentConfigForCreate,
42
- recordSessionCreated,
43
- recordUserMessageAccepted,
44
- type ProductUsageMetricsSink,
45
41
  } from "@opengeni/core";
46
42
  import {
47
43
  appendSessionEvents,
@@ -130,30 +126,6 @@ type ScheduledTemporalActivityIdentity = {
130
126
  activityId: string;
131
127
  };
132
128
 
133
- export function scheduledTaskRunExecutionPolicy(
134
- policy: TurnExecutionPolicyV1,
135
- input: DispatchScheduledTaskRunInput,
136
- creatorRestriction?: "developer_setup",
137
- ): TurnExecutionPolicyV1 {
138
- return creatorRestriction === "developer_setup" ||
139
- (input.triggerType !== "scheduled" && input.credentialRestriction === "developer_setup")
140
- ? { ...policy, credentialRestriction: "developer_setup" }
141
- : policy;
142
- }
143
-
144
- /** Only a creator ceiling is standing; a manual caller ceiling is per-run. */
145
- export function scheduledSessionExecutionPolicyMetadata(
146
- policy: unknown,
147
- creatorRestriction?: "developer_setup",
148
- ): Record<string, unknown> {
149
- if (policy === undefined || policy === null) return {};
150
- const acceptedPolicy = TurnExecutionPolicyV1.parse(policy);
151
- return creatorRestriction === "developer_setup" &&
152
- acceptedPolicy.credentialRestriction === "developer_setup"
153
- ? metadataWithTurnExecutionPolicyV1({}, acceptedPolicy)
154
- : {};
155
- }
156
-
157
129
  export function scheduledTaskRunProducerKey(
158
130
  input: DispatchScheduledTaskRunInput,
159
131
  suppliedActivityIdentity?: ScheduledTemporalActivityIdentity,
@@ -223,15 +195,6 @@ export function scheduledTaskGeneratedSessionCreateIdempotencyKey(producerKey: s
223
195
  * alone, with no Intl call and so no host ICU or tzdata build to make the two
224
196
  * texts differ.
225
197
  */
226
- /** A scheduler-generated run session: a service-created root session. */
227
- function recordScheduledSessionCreated(observability: ProductUsageMetricsSink | undefined): void {
228
- recordSessionCreated(observability, {
229
- surface: "scheduled",
230
- createdByKind: "service",
231
- parentSessionId: null,
232
- });
233
- }
234
-
235
198
  export function scheduledTaskSessionTitle(taskName: string): string {
236
199
  return normalizeAutomaticSessionTitle(taskName) ?? "Scheduled run";
237
200
  }
@@ -371,7 +334,6 @@ export function createScheduledTaskActivities(services: () => Promise<ControlAct
371
334
  try {
372
335
  return await recoverBoundScheduledTaskDispatch({
373
336
  db,
374
- observability: baseService.observability,
375
337
  bus,
376
338
  settings,
377
339
  wakeSessionWorkflow,
@@ -1032,28 +994,23 @@ export function createScheduledTaskActivities(services: () => Promise<ControlAct
1032
994
  }
1033
995
  }
1034
996
  : undefined;
1035
- const turnExecutionPolicy = scheduledTaskRunExecutionPolicy(
1036
- resolveTurnExecutionPolicyV1(settings, {
1037
- modelId: acceptedModel,
1038
- requestedModelId:
1039
- generatedTarget && task.agentConfig.model ? task.agentConfig.model : null,
1040
- modelSource: generatedTarget
1041
- ? task.agentConfig.model
1042
- ? "explicit"
1043
- : "deployment"
1044
- : "session",
1045
- reasoningEffort: acceptedReasoningEffort,
1046
- reasoningSource: generatedTarget
1047
- ? task.agentConfig.reasoningEffort
1048
- ? "explicit"
1049
- : "deployment"
1050
- : "session",
1051
- latencyMode: acceptedLatencyMode,
1052
- latencyModeSource: generatedTarget ? "deployment" : "session",
1053
- }),
1054
- input,
1055
- creatorPolicy?.credentialRestriction,
1056
- );
997
+ const turnExecutionPolicy: TurnExecutionPolicyV1 = resolveTurnExecutionPolicyV1(settings, {
998
+ modelId: acceptedModel,
999
+ requestedModelId: generatedTarget && task.agentConfig.model ? task.agentConfig.model : null,
1000
+ modelSource: generatedTarget
1001
+ ? task.agentConfig.model
1002
+ ? "explicit"
1003
+ : "deployment"
1004
+ : "session",
1005
+ reasoningEffort: acceptedReasoningEffort,
1006
+ reasoningSource: generatedTarget
1007
+ ? task.agentConfig.reasoningEffort
1008
+ ? "explicit"
1009
+ : "deployment"
1010
+ : "session",
1011
+ latencyMode: acceptedLatencyMode,
1012
+ latencyModeSource: generatedTarget ? "deployment" : "session",
1013
+ });
1057
1014
  const deferredEvents: Array<{
1058
1015
  sessionId: string;
1059
1016
  events: Awaited<ReturnType<typeof appendSessionEvents>>;
@@ -1312,10 +1269,6 @@ export function createScheduledTaskActivities(services: () => Promise<ControlAct
1312
1269
  : {}),
1313
1270
  metadata: {
1314
1271
  ...taskMetadata,
1315
- ...scheduledSessionExecutionPolicyMetadata(
1316
- turnExecutionPolicy,
1317
- creatorPolicy?.credentialRestriction,
1318
- ),
1319
1272
  model,
1320
1273
  reasoningEffort,
1321
1274
  scheduledTaskId: task.id,
@@ -1411,7 +1364,6 @@ export function createScheduledTaskActivities(services: () => Promise<ControlAct
1411
1364
  }
1412
1365
  session = created.session;
1413
1366
  sessionCreated = created.created;
1414
- if (sessionCreated) recordScheduledSessionCreated(baseService.observability);
1415
1367
  if (!sessionCreated) {
1416
1368
  await bindScheduledTaskRunSessionInTransaction(dispatchDb, {
1417
1369
  accountId: task.accountId,
@@ -1696,9 +1648,6 @@ export function createScheduledTaskActivities(services: () => Promise<ControlAct
1696
1648
  run: { ...run, status: "skipped" as const, error },
1697
1649
  };
1698
1650
  }
1699
- if (scheduledUpdate.added) {
1700
- recordUserMessageAccepted(baseService.observability, { surface: "scheduled" });
1701
- }
1702
1651
  if (scheduledUpdate.added && scheduledUpdate.events.length > 0) {
1703
1652
  if (deferPublications) {
1704
1653
  deferredEvents.push({
@@ -1842,9 +1791,6 @@ export function createScheduledTaskActivities(services: () => Promise<ControlAct
1842
1791
  run: { ...run, status: "skipped" as const, error },
1843
1792
  };
1844
1793
  }
1845
- if (bundled.added) {
1846
- recordUserMessageAccepted(baseService.observability, { surface: "scheduled" });
1847
- }
1848
1794
  if (bundled.added && bundled.events.length > 0) {
1849
1795
  if (deferPublications) {
1850
1796
  deferredEvents.push({
@@ -2256,7 +2202,6 @@ async function seedScheduledGeneratedSessionRoute(input: {
2256
2202
 
2257
2203
  async function recoverBoundScheduledTaskDispatch(input: {
2258
2204
  db: Database;
2259
- observability?: ProductUsageMetricsSink | undefined;
2260
2205
  bus: ControlActivityServices["bus"];
2261
2206
  settings: ControlActivityServices["settings"];
2262
2207
  wakeSessionWorkflow: WakeSessionWorkflowSignal | null;
@@ -2271,11 +2216,6 @@ async function recoverBoundScheduledTaskDispatch(input: {
2271
2216
  const generatedSession =
2272
2217
  task.runMode === "new_session_per_run" ||
2273
2218
  (task.runMode === "reusable_session" && task.reusableSessionId === null);
2274
- // The immutable creator policy determines standing session authority, not
2275
- // a manual caller's per-run ceiling. Read it for creation and recovery checks.
2276
- const recoveredCreatorPolicy = generatedSession
2277
- ? await getScheduledTaskCreatorPolicy(input.db, task.workspaceId, task.id)
2278
- : null;
2279
2219
  const frozenSlack = input.acceptedExecution.resolvedSlackBotConnection;
2280
2220
  if (frozenSlack) {
2281
2221
  const currentSlack = await requireOpenGeniSlackBotConnection(
@@ -2344,6 +2284,14 @@ async function recoverBoundScheduledTaskDispatch(input: {
2344
2284
  }
2345
2285
  const taskMetadata = { ...task.agentConfig.metadata };
2346
2286
  delete taskMetadata[OPENGENI_SLACK_BOT_SESSION_METADATA_KEY];
2287
+ // Tools and permissions were frozen into the accepted execution. The
2288
+ // creator session policy is immutable on the task row (a tombstoned task
2289
+ // still answers), so re-reading it here is deterministic for the same run.
2290
+ const recoveredCreatorPolicy = await getScheduledTaskCreatorPolicy(
2291
+ input.db,
2292
+ task.workspaceId,
2293
+ task.id,
2294
+ );
2347
2295
  const created = await createSessionWithIdempotencyKeyResult(input.db, {
2348
2296
  accountId: task.accountId,
2349
2297
  workspaceId: task.workspaceId,
@@ -2368,10 +2316,6 @@ async function recoverBoundScheduledTaskDispatch(input: {
2368
2316
  : {}),
2369
2317
  metadata: {
2370
2318
  ...taskMetadata,
2371
- ...scheduledSessionExecutionPolicyMetadata(
2372
- input.acceptedExecution.turnExecutionPolicy,
2373
- recoveredCreatorPolicy?.credentialRestriction,
2374
- ),
2375
2319
  model: input.acceptedExecution.resolvedModel,
2376
2320
  reasoningEffort: input.acceptedExecution.resolvedReasoningEffort,
2377
2321
  scheduledTaskId: task.id,
@@ -2430,7 +2374,6 @@ async function recoverBoundScheduledTaskDispatch(input: {
2430
2374
  });
2431
2375
  if (created.denied) throw new SessionSpawnDeniedDbError(created.denial);
2432
2376
  session = created.session;
2433
- if (created.created) recordScheduledSessionCreated(input.observability);
2434
2377
  if (!created.created) {
2435
2378
  await bindScheduledTaskRunSessionInTransaction(input.db, {
2436
2379
  accountId: task.accountId,
@@ -2504,10 +2447,6 @@ async function recoverBoundScheduledTaskDispatch(input: {
2504
2447
  const expectedMetadata = metadataWithAgentConfigCreateIdentity(
2505
2448
  {
2506
2449
  ...expectedTaskMetadata,
2507
- ...scheduledSessionExecutionPolicyMetadata(
2508
- input.acceptedExecution.turnExecutionPolicy,
2509
- recoveredCreatorPolicy?.credentialRestriction,
2510
- ),
2511
2450
  model: input.acceptedExecution.resolvedModel,
2512
2451
  reasoningEffort: input.acceptedExecution.resolvedReasoningEffort,
2513
2452
  scheduledTaskId: task.id,
@@ -2730,9 +2669,6 @@ async function recoverBoundScheduledTaskDispatch(input: {
2730
2669
  ) {
2731
2670
  return { action: "blocked", reason: "scheduled_run_terminal" };
2732
2671
  }
2733
- if (scheduledUpdate.added) {
2734
- recordUserMessageAccepted(input.observability, { surface: "scheduled" });
2735
- }
2736
2672
  if (scheduledUpdate.added && scheduledUpdate.events.length > 0) {
2737
2673
  await publishDurableSessionEvents(
2738
2674
  input.bus,
@@ -176,7 +176,6 @@ async function dispatchMaintenanceSession(
176
176
  initialMessage: maintenancePrompt(maintenance),
177
177
  // OpenGeni's own periodic check: no human or product surface entered it.
178
178
  surface: "system",
179
- metrics: service.observability,
180
179
  resources: [],
181
180
  tools: [{ kind: "mcp", id: "opengeni" }],
182
181
  toolPolicy: { mode: "explicit", inheritedFromSessionId: null },
@@ -436,7 +436,6 @@ export type DispatchScheduledTaskRunInput = {
436
436
  triggerType: Extract<ScheduledTaskTriggerType, "scheduled">;
437
437
  agentRunUsageIdempotencyKey?: never;
438
438
  initiator?: never;
439
- credentialRestriction?: never;
440
439
  }
441
440
  | {
442
441
  triggerType: Extract<
@@ -446,8 +445,6 @@ export type DispatchScheduledTaskRunInput = {
446
445
  agentRunUsageIdempotencyKey: string;
447
446
  /** Exact identity used by the API-side charge for this same trigger. */
448
447
  initiator: TurnInitiator;
449
- /** Trusted API-side caller ceiling for this occurrence, not the schedule. */
450
- credentialRestriction?: "developer_setup";
451
448
  }
452
449
  );
453
450
 
@@ -947,24 +947,13 @@ async function runCapture(
947
947
  }
948
948
 
949
949
  // ── 10. observe completion ────────────────────────────────────────────────
950
- recordWorkspaceCaptureCompleted(observability, Date.now() - startedAt);
951
- }
952
-
953
- /** Count one committed logical capture and observe its end-to-end duration. */
954
- export function recordWorkspaceCaptureCompleted(
955
- observability: Pick<Observability, "incrementCounter" | "observeHistogram">,
956
- durationMs: number,
957
- ): void {
950
+ const durationMs = Date.now() - startedAt;
958
951
  observability.incrementCounter({
959
952
  name: "opengeni_workspace_capture_total",
960
953
  labels: { result: "ok" },
961
954
  });
962
- // Distinct from the physical `opengeni_workspace_capture_duration_seconds`
963
- // {backend,outcome} histogram the runtime hook records in this same
964
- // registry: one name cannot carry two label sets.
965
955
  observability.observeHistogram({
966
- name: "opengeni_workspace_capture_revision_duration_seconds",
967
- help: "Turn-end logical workspace revision capture duration for committed revisions.",
956
+ name: "opengeni_workspace_capture_duration_seconds",
968
957
  value: durationMs / 1000,
969
958
  });
970
959
  }