@opengeni/worker-bundle 0.11.8 → 0.12.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.
- package/dist/index.js +78 -8
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
- package/src/activities/scheduled-tasks.ts +53 -1
- package/src/concurrency.ts +58 -6
- package/src/index.ts +12 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opengeni/worker-bundle",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
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": {
|
|
@@ -41,16 +41,16 @@
|
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@opengeni/agent-proto": "^0.3.0",
|
|
43
43
|
"@opengeni/codex": "^0.2.7",
|
|
44
|
-
"@opengeni/config": "^0.7.
|
|
45
|
-
"@opengeni/contracts": "^0.
|
|
46
|
-
"@opengeni/core": "^0.
|
|
47
|
-
"@opengeni/db": "^0.
|
|
48
|
-
"@opengeni/documents": "^0.2.
|
|
49
|
-
"@opengeni/events": "^0.3.
|
|
50
|
-
"@opengeni/github": "^0.3.
|
|
44
|
+
"@opengeni/config": "^0.7.7",
|
|
45
|
+
"@opengeni/contracts": "^0.20.0",
|
|
46
|
+
"@opengeni/core": "^0.12.0",
|
|
47
|
+
"@opengeni/db": "^0.13.0",
|
|
48
|
+
"@opengeni/documents": "^0.2.37",
|
|
49
|
+
"@opengeni/events": "^0.3.28",
|
|
50
|
+
"@opengeni/github": "^0.3.19",
|
|
51
51
|
"@opengeni/observability": "^0.3.0",
|
|
52
|
-
"@opengeni/runtime": "^0.13.
|
|
53
|
-
"@opengeni/storage": "^0.2.
|
|
52
|
+
"@opengeni/runtime": "^0.13.11",
|
|
53
|
+
"@opengeni/storage": "^0.2.31",
|
|
54
54
|
"@temporalio/activity": "^1.17.0",
|
|
55
55
|
"@temporalio/client": "^1.17.0",
|
|
56
56
|
"@temporalio/worker": "^1.17.0",
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OPENGENI_SLACK_BOT_CREDENTIAL_LABEL,
|
|
3
|
+
OPENGENI_SLACK_BOT_CREDENTIAL_ROLE,
|
|
4
|
+
OPENGENI_SLACK_BOT_SESSION_METADATA_KEY,
|
|
5
|
+
} from "@opengeni/contracts";
|
|
6
|
+
import {
|
|
7
|
+
openGeniSlackBotMetadata,
|
|
8
|
+
requireOpenGeniSlackBotConnection,
|
|
9
|
+
scheduledSlackBotConnectionId,
|
|
10
|
+
} from "@opengeni/core";
|
|
1
11
|
import {
|
|
2
12
|
appendSessionEventsWithLockedSessionUpdate,
|
|
3
13
|
addSessionSystemUpdateWithSourceMutation,
|
|
@@ -41,6 +51,23 @@ export function createScheduledTaskActivities(services: () => Promise<ActivitySe
|
|
|
41
51
|
): Promise<DispatchScheduledTaskRunResult> => {
|
|
42
52
|
const { settings, db, bus, wakeSessionWorkflow } = await services();
|
|
43
53
|
const task = await requireScheduledTask(db, input.workspaceId, input.taskId);
|
|
54
|
+
// A scheduled bot selection was authorized when the task was written,
|
|
55
|
+
// but connection status and tenant/role binding are mutable. Revalidate
|
|
56
|
+
// before any session/model cost and never fall back to a personal Slack
|
|
57
|
+
// OAuth grant when the selected bot has been revoked or changed.
|
|
58
|
+
const slackBotConnection = task.agentConfig.slackBotConnectionId
|
|
59
|
+
? await requireOpenGeniSlackBotConnection(
|
|
60
|
+
db,
|
|
61
|
+
task.workspaceId,
|
|
62
|
+
task.agentConfig.slackBotConnectionId,
|
|
63
|
+
)
|
|
64
|
+
: null;
|
|
65
|
+
const slackBotMetadata = slackBotConnection
|
|
66
|
+
? openGeniSlackBotMetadata(slackBotConnection.metadata)
|
|
67
|
+
: null;
|
|
68
|
+
if (slackBotConnection && !slackBotMetadata) {
|
|
69
|
+
throw new Error("OpenGeni Slack bot connection metadata is invalid");
|
|
70
|
+
}
|
|
44
71
|
// The scheduled task's model can be codex/<slug>; resolve it here so the
|
|
45
72
|
// admission gate can skip the credit/cost gates for a codex-billed run
|
|
46
73
|
// (paid by the user's ChatGPT/Codex plan). This file uses BASE settings (no
|
|
@@ -160,6 +187,8 @@ export function createScheduledTaskActivities(services: () => Promise<ActivitySe
|
|
|
160
187
|
frozenRigVersionId = rig.activeVersion.id;
|
|
161
188
|
}
|
|
162
189
|
let session: Awaited<ReturnType<typeof createSession>>;
|
|
190
|
+
const taskMetadata = { ...task.agentConfig.metadata };
|
|
191
|
+
delete taskMetadata[OPENGENI_SLACK_BOT_SESSION_METADATA_KEY];
|
|
163
192
|
try {
|
|
164
193
|
session = await createSession(db, {
|
|
165
194
|
accountId: task.accountId,
|
|
@@ -168,11 +197,16 @@ export function createScheduledTaskActivities(services: () => Promise<ActivitySe
|
|
|
168
197
|
resources: task.agentConfig.resources,
|
|
169
198
|
tools: taskTools,
|
|
170
199
|
metadata: {
|
|
171
|
-
...
|
|
200
|
+
...taskMetadata,
|
|
172
201
|
model,
|
|
173
202
|
reasoningEffort,
|
|
174
203
|
scheduledTaskId: task.id,
|
|
175
204
|
scheduledTaskRunId: run.id,
|
|
205
|
+
...(slackBotConnection
|
|
206
|
+
? {
|
|
207
|
+
[OPENGENI_SLACK_BOT_SESSION_METADATA_KEY]: slackBotConnection.id,
|
|
208
|
+
}
|
|
209
|
+
: {}),
|
|
176
210
|
},
|
|
177
211
|
createdBy: {
|
|
178
212
|
kind: "service",
|
|
@@ -231,6 +265,16 @@ export function createScheduledTaskActivities(services: () => Promise<ActivitySe
|
|
|
231
265
|
...(variableSet
|
|
232
266
|
? { variableSetId: variableSet.id, variableSetName: variableSet.name }
|
|
233
267
|
: {}),
|
|
268
|
+
...(slackBotConnection && slackBotMetadata
|
|
269
|
+
? {
|
|
270
|
+
slackBotConnection: {
|
|
271
|
+
credentialRole: OPENGENI_SLACK_BOT_CREDENTIAL_ROLE,
|
|
272
|
+
credentialLabel: OPENGENI_SLACK_BOT_CREDENTIAL_LABEL,
|
|
273
|
+
connectionId: slackBotConnection.id,
|
|
274
|
+
slackTeamId: slackBotMetadata.slackTeamId,
|
|
275
|
+
},
|
|
276
|
+
}
|
|
277
|
+
: {}),
|
|
234
278
|
},
|
|
235
279
|
},
|
|
236
280
|
...(goal
|
|
@@ -316,6 +360,14 @@ export function createScheduledTaskActivities(services: () => Promise<ActivitySe
|
|
|
316
360
|
"scheduled task variableSet attachment does not match its reusable session",
|
|
317
361
|
);
|
|
318
362
|
}
|
|
363
|
+
if (
|
|
364
|
+
scheduledSlackBotConnectionId(session.metadata) !==
|
|
365
|
+
(task.agentConfig.slackBotConnectionId ?? null)
|
|
366
|
+
) {
|
|
367
|
+
throw new Error(
|
|
368
|
+
"scheduled task OpenGeni Slack bot binding does not match its reusable session",
|
|
369
|
+
);
|
|
370
|
+
}
|
|
319
371
|
// A recurring "maintain X" task re-establishes its objective on every
|
|
320
372
|
// fire: replace the goal text, reactivate it, and reset the counters.
|
|
321
373
|
const reusableGoal =
|
package/src/concurrency.ts
CHANGED
|
@@ -1,11 +1,63 @@
|
|
|
1
|
+
import type { Settings } from "@opengeni/config";
|
|
2
|
+
import type { WorkerOptions } from "@temporalio/worker";
|
|
3
|
+
|
|
4
|
+
export type TurnWorkerConcurrencySettings = Pick<
|
|
5
|
+
Settings,
|
|
6
|
+
| "turnWorkerConcurrencyMode"
|
|
7
|
+
| "turnWorkerMaxConcurrentTurns"
|
|
8
|
+
| "turnWorkerTargetCpuUsage"
|
|
9
|
+
| "turnWorkerTargetMemoryUsage"
|
|
10
|
+
>;
|
|
11
|
+
|
|
12
|
+
export type TurnWorkerConcurrencyOptions = Pick<
|
|
13
|
+
WorkerOptions,
|
|
14
|
+
"maxConcurrentActivityTaskExecutions" | "tuner"
|
|
15
|
+
>;
|
|
16
|
+
|
|
1
17
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* production and the real Temporal integration harness exercise one topology.
|
|
18
|
+
* Ordinary multi-worker deployments keep a fixed per-process ceiling so HPA or
|
|
19
|
+
* an operator owns horizontal capacity. The single-machine profile selects the
|
|
20
|
+
* resource tuner instead: Temporal admits activity slots while whole-system CPU
|
|
21
|
+
* and memory remain below the configured targets, then stops polling more work.
|
|
7
22
|
*/
|
|
8
|
-
export
|
|
23
|
+
export function turnWorkerConcurrencyOptions(
|
|
24
|
+
settings: TurnWorkerConcurrencySettings,
|
|
25
|
+
): TurnWorkerConcurrencyOptions {
|
|
26
|
+
if (settings.turnWorkerConcurrencyMode === "fixed") {
|
|
27
|
+
return {
|
|
28
|
+
maxConcurrentActivityTaskExecutions: settings.turnWorkerMaxConcurrentTurns,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return {
|
|
33
|
+
tuner: {
|
|
34
|
+
tunerOptions: {
|
|
35
|
+
targetCpuUsage: settings.turnWorkerTargetCpuUsage,
|
|
36
|
+
targetMemoryUsage: settings.turnWorkerTargetMemoryUsage,
|
|
37
|
+
},
|
|
38
|
+
activityTaskSlotOptions: {
|
|
39
|
+
minimumSlots: 1,
|
|
40
|
+
maximumSlots: settings.turnWorkerMaxConcurrentTurns,
|
|
41
|
+
rampThrottle: "50ms",
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function turnWorkerConcurrencyLogFields(settings: TurnWorkerConcurrencySettings): {
|
|
48
|
+
concurrencyMode: "fixed" | "resource-based";
|
|
49
|
+
maxConcurrentTurns: number;
|
|
50
|
+
targetCpuUsage: number | null;
|
|
51
|
+
targetMemoryUsage: number | null;
|
|
52
|
+
} {
|
|
53
|
+
const resourceBased = settings.turnWorkerConcurrencyMode === "resource-based";
|
|
54
|
+
return {
|
|
55
|
+
concurrencyMode: settings.turnWorkerConcurrencyMode,
|
|
56
|
+
maxConcurrentTurns: settings.turnWorkerMaxConcurrentTurns,
|
|
57
|
+
targetCpuUsage: resourceBased ? settings.turnWorkerTargetCpuUsage : null,
|
|
58
|
+
targetMemoryUsage: resourceBased ? settings.turnWorkerTargetMemoryUsage : null,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
9
61
|
|
|
10
62
|
export const CONTROL_WORKER_MAX_CONCURRENT_ACTIVITIES = 32;
|
|
11
63
|
export const CONTROL_WORKER_MAX_CONCURRENT_WORKFLOW_TASKS = 40;
|
package/src/index.ts
CHANGED
|
@@ -57,7 +57,8 @@ import {
|
|
|
57
57
|
import {
|
|
58
58
|
CONTROL_WORKER_MAX_CONCURRENT_ACTIVITIES,
|
|
59
59
|
CONTROL_WORKER_MAX_CONCURRENT_WORKFLOW_TASKS,
|
|
60
|
-
|
|
60
|
+
turnWorkerConcurrencyLogFields,
|
|
61
|
+
turnWorkerConcurrencyOptions,
|
|
61
62
|
} from "./concurrency";
|
|
62
63
|
import {
|
|
63
64
|
constructWithOwnedConnection,
|
|
@@ -179,13 +180,10 @@ export async function createOpenGeniWorker(options: WorkerOptions): Promise<{
|
|
|
179
180
|
? { workflowBundle: options.workflowBundle }
|
|
180
181
|
: resolveOpenGeniWorkflowDefinition()),
|
|
181
182
|
maxConcurrentWorkflowTaskExecutions: CONTROL_WORKER_MAX_CONCURRENT_WORKFLOW_TASKS,
|
|
183
|
+
maxConcurrentActivityTaskExecutions: CONTROL_WORKER_MAX_CONCURRENT_ACTIVITIES,
|
|
182
184
|
}
|
|
183
|
-
:
|
|
185
|
+
: turnWorkerConcurrencyOptions(settings)),
|
|
184
186
|
activities,
|
|
185
|
-
maxConcurrentActivityTaskExecutions:
|
|
186
|
-
options.role === "turn"
|
|
187
|
-
? TURN_WORKER_MAX_CONCURRENT_TURNS
|
|
188
|
-
: CONTROL_WORKER_MAX_CONCURRENT_ACTIVITIES,
|
|
189
187
|
// Cancellation is delivered through an activity heartbeat. The SDK would
|
|
190
188
|
// otherwise throttle a two-minute heartbeat timeout to its 60-second cap,
|
|
191
189
|
// making Pause/Steer take roughly a minute even though runAgentTurn emits a
|
|
@@ -642,10 +640,14 @@ export async function createOpenGeniWorkerService(
|
|
|
642
640
|
options.role === "control"
|
|
643
641
|
? settings.temporalTaskQueue
|
|
644
642
|
: turnTaskQueue(settings.temporalTaskQueue),
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
643
|
+
...(options.role === "turn"
|
|
644
|
+
? turnWorkerConcurrencyLogFields(settings)
|
|
645
|
+
: {
|
|
646
|
+
concurrencyMode: "fixed",
|
|
647
|
+
maxConcurrentTurns: CONTROL_WORKER_MAX_CONCURRENT_ACTIVITIES,
|
|
648
|
+
targetCpuUsage: null,
|
|
649
|
+
targetMemoryUsage: null,
|
|
650
|
+
}),
|
|
649
651
|
maxConcurrentWorkflowTaskExecutions:
|
|
650
652
|
options.role === "control" ? CONTROL_WORKER_MAX_CONCURRENT_WORKFLOW_TASKS : 0,
|
|
651
653
|
httpPort: options.http === false ? null : settings.workerHttpPort,
|