@opengeni/worker-bundle 0.11.8 → 0.12.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.
- package/dist/index.js +174 -72
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
- package/src/activities/scheduled-tasks.ts +53 -1
- package/src/activities/workspace-capture.ts +124 -72
- package/src/concurrency.ts +58 -6
- package/src/index.ts +12 -10
package/dist/index.js
CHANGED
|
@@ -5227,6 +5227,35 @@ function classifyCaptureEntryError(error) {
|
|
|
5227
5227
|
}
|
|
5228
5228
|
var TREE_MAX_ENTRIES = 2e4;
|
|
5229
5229
|
var TREE_MAX_DEPTH = 600;
|
|
5230
|
+
async function readCaptureRepository(svc, root) {
|
|
5231
|
+
let status;
|
|
5232
|
+
try {
|
|
5233
|
+
status = await svc.gitStatus({ path: root });
|
|
5234
|
+
} catch (error) {
|
|
5235
|
+
const boxExiting = classifyCaptureEntryError(error);
|
|
5236
|
+
if (boxExiting) throw boxExiting;
|
|
5237
|
+
return { complete: false, degradedReason: "repository_read_unavailable" };
|
|
5238
|
+
}
|
|
5239
|
+
if (!status.isRepo) {
|
|
5240
|
+
return { complete: false, degradedReason: "repository_read_unavailable" };
|
|
5241
|
+
}
|
|
5242
|
+
try {
|
|
5243
|
+
const diff = await svc.gitDiff({
|
|
5244
|
+
path: root,
|
|
5245
|
+
staged: false,
|
|
5246
|
+
includeUntracked: true,
|
|
5247
|
+
fromRef: "HEAD",
|
|
5248
|
+
pathspec: [],
|
|
5249
|
+
contextLines: 3,
|
|
5250
|
+
maxBytesPerFile: PER_FILE_DIFF_GUARD_BYTES
|
|
5251
|
+
});
|
|
5252
|
+
return { complete: true, status, diff };
|
|
5253
|
+
} catch (error) {
|
|
5254
|
+
const boxExiting = classifyCaptureEntryError(error);
|
|
5255
|
+
if (boxExiting) throw boxExiting;
|
|
5256
|
+
return { complete: false, degradedReason: "repository_read_unavailable" };
|
|
5257
|
+
}
|
|
5258
|
+
}
|
|
5230
5259
|
var loggedStorageNullOnce = false;
|
|
5231
5260
|
async function captureWorkspaceRevision(input) {
|
|
5232
5261
|
const { observability } = input;
|
|
@@ -5333,46 +5362,15 @@ async function runCapture(input, ctx, startedAt, signal) {
|
|
|
5333
5362
|
);
|
|
5334
5363
|
}
|
|
5335
5364
|
if (!discovery.complete) {
|
|
5336
|
-
const capturedAt2 = /* @__PURE__ */ new Date();
|
|
5337
5365
|
const reason = captureDegradedReason(discovery.degradedReason);
|
|
5338
|
-
|
|
5339
|
-
|
|
5340
|
-
|
|
5341
|
-
|
|
5342
|
-
};
|
|
5343
|
-
const inserted2 = await insertFailedWorkspaceCapture(input.db, {
|
|
5344
|
-
accountId: input.accountId,
|
|
5345
|
-
workspaceId: input.workspaceId,
|
|
5346
|
-
sessionId: input.sessionId,
|
|
5347
|
-
turnId: input.turnId,
|
|
5348
|
-
attemptId: input.attemptId,
|
|
5349
|
-
sandboxGroupId: input.sandboxGroupId,
|
|
5350
|
-
expectedEpoch: input.leaseEpoch,
|
|
5366
|
+
await persistDegradedCapture(
|
|
5367
|
+
input,
|
|
5368
|
+
startedAt,
|
|
5369
|
+
signal,
|
|
5351
5370
|
revision,
|
|
5352
|
-
|
|
5353
|
-
|
|
5354
|
-
|
|
5355
|
-
throwIfCaptureAborted(signal);
|
|
5356
|
-
if (!inserted2) {
|
|
5357
|
-
observability.incrementCounter({
|
|
5358
|
-
name: "opengeni_workspace_capture_total",
|
|
5359
|
-
labels: { result: "superseded" }
|
|
5360
|
-
});
|
|
5361
|
-
return;
|
|
5362
|
-
}
|
|
5363
|
-
observability.warn("workspace capture degraded \u2014 repository discovery incomplete", {
|
|
5364
|
-
"opengeni.session_id": input.sessionId,
|
|
5365
|
-
"opengeni.turn_id": input.turnId ?? "",
|
|
5366
|
-
"workspace_capture.degraded_reason": reason,
|
|
5367
|
-
"workspace_capture.discovered_repo_count": discovery.repos.length
|
|
5368
|
-
});
|
|
5369
|
-
observability.incrementCounter({
|
|
5370
|
-
name: "opengeni_workspace_capture_total",
|
|
5371
|
-
labels: { result: "degraded_repository_discovery" }
|
|
5372
|
-
});
|
|
5373
|
-
if (input.publish) {
|
|
5374
|
-
await input.publish(inserted2.events).catch(() => void 0);
|
|
5375
|
-
}
|
|
5371
|
+
reason,
|
|
5372
|
+
discovery.repos.length
|
|
5373
|
+
);
|
|
5376
5374
|
return;
|
|
5377
5375
|
}
|
|
5378
5376
|
const repoRoots = discovery.repos;
|
|
@@ -5382,33 +5380,20 @@ async function runCapture(input, ctx, startedAt, signal) {
|
|
|
5382
5380
|
let deletions = 0;
|
|
5383
5381
|
for (const root of repoRoots) {
|
|
5384
5382
|
throwIfCaptureAborted(signal);
|
|
5385
|
-
|
|
5386
|
-
|
|
5387
|
-
|
|
5388
|
-
|
|
5389
|
-
|
|
5390
|
-
|
|
5391
|
-
|
|
5392
|
-
|
|
5393
|
-
|
|
5394
|
-
|
|
5395
|
-
|
|
5396
|
-
|
|
5397
|
-
diff = await svc.gitDiff({
|
|
5398
|
-
path: root,
|
|
5399
|
-
staged: false,
|
|
5400
|
-
includeUntracked: true,
|
|
5401
|
-
fromRef: "HEAD",
|
|
5402
|
-
pathspec: [],
|
|
5403
|
-
contextLines: 3,
|
|
5404
|
-
maxBytesPerFile: PER_FILE_DIFF_GUARD_BYTES
|
|
5405
|
-
});
|
|
5406
|
-
throwIfCaptureAborted(signal);
|
|
5407
|
-
} catch (error) {
|
|
5408
|
-
const boxExiting = classifyCaptureEntryError(error);
|
|
5409
|
-
if (boxExiting) throw boxExiting;
|
|
5410
|
-
diff = { files: [], revision: 0 };
|
|
5383
|
+
const repository = await readCaptureRepository(svc, root);
|
|
5384
|
+
throwIfCaptureAborted(signal);
|
|
5385
|
+
if (!repository.complete) {
|
|
5386
|
+
await persistDegradedCapture(
|
|
5387
|
+
input,
|
|
5388
|
+
startedAt,
|
|
5389
|
+
signal,
|
|
5390
|
+
revision,
|
|
5391
|
+
repository.degradedReason,
|
|
5392
|
+
repoRoots.length
|
|
5393
|
+
);
|
|
5394
|
+
return;
|
|
5411
5395
|
}
|
|
5396
|
+
const { status, diff } = repository;
|
|
5412
5397
|
const diffFiles = diff.files.filter((f) => !isUnderResidueDir(joinRepoPath(root, f.path)));
|
|
5413
5398
|
const statusFiles = status.files.filter((f) => !isUnderResidueDir(joinRepoPath(root, f.path)));
|
|
5414
5399
|
repos.push({
|
|
@@ -5757,6 +5742,53 @@ function captureDegradedReason(reason) {
|
|
|
5757
5742
|
return "repository_discovery_command_failed";
|
|
5758
5743
|
}
|
|
5759
5744
|
}
|
|
5745
|
+
async function persistDegradedCapture(input, startedAt, signal, revision, reason, discoveredRepoCount) {
|
|
5746
|
+
const capturedAt = /* @__PURE__ */ new Date();
|
|
5747
|
+
const stats = {
|
|
5748
|
+
degradedReason: reason,
|
|
5749
|
+
discoveredRepoCount,
|
|
5750
|
+
durationMs: Date.now() - startedAt
|
|
5751
|
+
};
|
|
5752
|
+
const inserted = await insertFailedWorkspaceCapture(input.db, {
|
|
5753
|
+
accountId: input.accountId,
|
|
5754
|
+
workspaceId: input.workspaceId,
|
|
5755
|
+
sessionId: input.sessionId,
|
|
5756
|
+
turnId: input.turnId,
|
|
5757
|
+
attemptId: input.attemptId,
|
|
5758
|
+
sandboxGroupId: input.sandboxGroupId,
|
|
5759
|
+
expectedEpoch: input.leaseEpoch,
|
|
5760
|
+
revision,
|
|
5761
|
+
stats,
|
|
5762
|
+
capturedAt
|
|
5763
|
+
});
|
|
5764
|
+
throwIfCaptureAborted(signal);
|
|
5765
|
+
if (!inserted) {
|
|
5766
|
+
input.observability.incrementCounter({
|
|
5767
|
+
name: "opengeni_workspace_capture_total",
|
|
5768
|
+
labels: { result: "superseded" }
|
|
5769
|
+
});
|
|
5770
|
+
return;
|
|
5771
|
+
}
|
|
5772
|
+
const discoveryFailure = reason.startsWith("repository_discovery_");
|
|
5773
|
+
input.observability.warn(
|
|
5774
|
+
discoveryFailure ? "workspace capture degraded \u2014 repository discovery incomplete" : "workspace capture degraded \u2014 repository read incomplete",
|
|
5775
|
+
{
|
|
5776
|
+
"opengeni.session_id": input.sessionId,
|
|
5777
|
+
"opengeni.turn_id": input.turnId ?? "",
|
|
5778
|
+
"workspace_capture.degraded_reason": reason,
|
|
5779
|
+
"workspace_capture.discovered_repo_count": discoveredRepoCount
|
|
5780
|
+
}
|
|
5781
|
+
);
|
|
5782
|
+
input.observability.incrementCounter({
|
|
5783
|
+
name: "opengeni_workspace_capture_total",
|
|
5784
|
+
labels: {
|
|
5785
|
+
result: discoveryFailure ? "degraded_repository_discovery" : "degraded_repository_read"
|
|
5786
|
+
}
|
|
5787
|
+
});
|
|
5788
|
+
if (input.publish) {
|
|
5789
|
+
await input.publish(inserted.events).catch(() => void 0);
|
|
5790
|
+
}
|
|
5791
|
+
}
|
|
5760
5792
|
function throwIfCaptureAborted(signal) {
|
|
5761
5793
|
if (signal.aborted) {
|
|
5762
5794
|
throw new Error("workspace capture cancelled after its deadline");
|
|
@@ -12511,6 +12543,16 @@ async function terminateProviderBox(settings, lease, observability, persistArchi
|
|
|
12511
12543
|
}
|
|
12512
12544
|
|
|
12513
12545
|
// src/activities/scheduled-tasks.ts
|
|
12546
|
+
import {
|
|
12547
|
+
OPENGENI_SLACK_BOT_CREDENTIAL_LABEL,
|
|
12548
|
+
OPENGENI_SLACK_BOT_CREDENTIAL_ROLE,
|
|
12549
|
+
OPENGENI_SLACK_BOT_SESSION_METADATA_KEY
|
|
12550
|
+
} from "@opengeni/contracts";
|
|
12551
|
+
import {
|
|
12552
|
+
openGeniSlackBotMetadata,
|
|
12553
|
+
requireOpenGeniSlackBotConnection,
|
|
12554
|
+
scheduledSlackBotConnectionId
|
|
12555
|
+
} from "@opengeni/core";
|
|
12514
12556
|
import {
|
|
12515
12557
|
appendSessionEventsWithLockedSessionUpdate,
|
|
12516
12558
|
addSessionSystemUpdateWithSourceMutation as addSessionSystemUpdateWithSourceMutation2,
|
|
@@ -12540,6 +12582,15 @@ function createScheduledTaskActivities(services) {
|
|
|
12540
12582
|
dispatchScheduledTaskRun: async (input) => {
|
|
12541
12583
|
const { settings, db, bus, wakeSessionWorkflow } = await services();
|
|
12542
12584
|
const task = await requireScheduledTask(db, input.workspaceId, input.taskId);
|
|
12585
|
+
const slackBotConnection = task.agentConfig.slackBotConnectionId ? await requireOpenGeniSlackBotConnection(
|
|
12586
|
+
db,
|
|
12587
|
+
task.workspaceId,
|
|
12588
|
+
task.agentConfig.slackBotConnectionId
|
|
12589
|
+
) : null;
|
|
12590
|
+
const slackBotMetadata = slackBotConnection ? openGeniSlackBotMetadata(slackBotConnection.metadata) : null;
|
|
12591
|
+
if (slackBotConnection && !slackBotMetadata) {
|
|
12592
|
+
throw new Error("OpenGeni Slack bot connection metadata is invalid");
|
|
12593
|
+
}
|
|
12543
12594
|
const model = task.agentConfig.model ?? settings.openaiModel;
|
|
12544
12595
|
const isCodexRun = await isCodexBilledTurn2({
|
|
12545
12596
|
db,
|
|
@@ -12640,6 +12691,8 @@ function createScheduledTaskActivities(services) {
|
|
|
12640
12691
|
frozenRigVersionId = rig.activeVersion.id;
|
|
12641
12692
|
}
|
|
12642
12693
|
let session;
|
|
12694
|
+
const taskMetadata = { ...task.agentConfig.metadata };
|
|
12695
|
+
delete taskMetadata[OPENGENI_SLACK_BOT_SESSION_METADATA_KEY];
|
|
12643
12696
|
try {
|
|
12644
12697
|
session = await createSession(db, {
|
|
12645
12698
|
accountId: task.accountId,
|
|
@@ -12648,11 +12701,14 @@ function createScheduledTaskActivities(services) {
|
|
|
12648
12701
|
resources: task.agentConfig.resources,
|
|
12649
12702
|
tools: taskTools,
|
|
12650
12703
|
metadata: {
|
|
12651
|
-
...
|
|
12704
|
+
...taskMetadata,
|
|
12652
12705
|
model,
|
|
12653
12706
|
reasoningEffort,
|
|
12654
12707
|
scheduledTaskId: task.id,
|
|
12655
|
-
scheduledTaskRunId: run.id
|
|
12708
|
+
scheduledTaskRunId: run.id,
|
|
12709
|
+
...slackBotConnection ? {
|
|
12710
|
+
[OPENGENI_SLACK_BOT_SESSION_METADATA_KEY]: slackBotConnection.id
|
|
12711
|
+
} : {}
|
|
12656
12712
|
},
|
|
12657
12713
|
createdBy: {
|
|
12658
12714
|
kind: "service",
|
|
@@ -12706,7 +12762,15 @@ function createScheduledTaskActivities(services) {
|
|
|
12706
12762
|
scheduledTaskId: task.id,
|
|
12707
12763
|
scheduledTaskRunId: run.id,
|
|
12708
12764
|
// Names/ids only; never values.
|
|
12709
|
-
...variableSet ? { variableSetId: variableSet.id, variableSetName: variableSet.name } : {}
|
|
12765
|
+
...variableSet ? { variableSetId: variableSet.id, variableSetName: variableSet.name } : {},
|
|
12766
|
+
...slackBotConnection && slackBotMetadata ? {
|
|
12767
|
+
slackBotConnection: {
|
|
12768
|
+
credentialRole: OPENGENI_SLACK_BOT_CREDENTIAL_ROLE,
|
|
12769
|
+
credentialLabel: OPENGENI_SLACK_BOT_CREDENTIAL_LABEL,
|
|
12770
|
+
connectionId: slackBotConnection.id,
|
|
12771
|
+
slackTeamId: slackBotMetadata.slackTeamId
|
|
12772
|
+
}
|
|
12773
|
+
} : {}
|
|
12710
12774
|
}
|
|
12711
12775
|
},
|
|
12712
12776
|
...goal ? [
|
|
@@ -12783,6 +12847,11 @@ function createScheduledTaskActivities(services) {
|
|
|
12783
12847
|
"scheduled task variableSet attachment does not match its reusable session"
|
|
12784
12848
|
);
|
|
12785
12849
|
}
|
|
12850
|
+
if (scheduledSlackBotConnectionId(session.metadata) !== (task.agentConfig.slackBotConnectionId ?? null)) {
|
|
12851
|
+
throw new Error(
|
|
12852
|
+
"scheduled task OpenGeni Slack bot binding does not match its reusable session"
|
|
12853
|
+
);
|
|
12854
|
+
}
|
|
12786
12855
|
const reusableGoal = goalSpec && run.status === "queued" ? await upsertSessionGoal(db, {
|
|
12787
12856
|
accountId: task.accountId,
|
|
12788
12857
|
workspaceId: task.workspaceId,
|
|
@@ -14286,7 +14355,35 @@ import {
|
|
|
14286
14355
|
} from "@opengeni/core";
|
|
14287
14356
|
|
|
14288
14357
|
// src/concurrency.ts
|
|
14289
|
-
|
|
14358
|
+
function turnWorkerConcurrencyOptions(settings) {
|
|
14359
|
+
if (settings.turnWorkerConcurrencyMode === "fixed") {
|
|
14360
|
+
return {
|
|
14361
|
+
maxConcurrentActivityTaskExecutions: settings.turnWorkerMaxConcurrentTurns
|
|
14362
|
+
};
|
|
14363
|
+
}
|
|
14364
|
+
return {
|
|
14365
|
+
tuner: {
|
|
14366
|
+
tunerOptions: {
|
|
14367
|
+
targetCpuUsage: settings.turnWorkerTargetCpuUsage,
|
|
14368
|
+
targetMemoryUsage: settings.turnWorkerTargetMemoryUsage
|
|
14369
|
+
},
|
|
14370
|
+
activityTaskSlotOptions: {
|
|
14371
|
+
minimumSlots: 1,
|
|
14372
|
+
maximumSlots: settings.turnWorkerMaxConcurrentTurns,
|
|
14373
|
+
rampThrottle: "50ms"
|
|
14374
|
+
}
|
|
14375
|
+
}
|
|
14376
|
+
};
|
|
14377
|
+
}
|
|
14378
|
+
function turnWorkerConcurrencyLogFields(settings) {
|
|
14379
|
+
const resourceBased = settings.turnWorkerConcurrencyMode === "resource-based";
|
|
14380
|
+
return {
|
|
14381
|
+
concurrencyMode: settings.turnWorkerConcurrencyMode,
|
|
14382
|
+
maxConcurrentTurns: settings.turnWorkerMaxConcurrentTurns,
|
|
14383
|
+
targetCpuUsage: resourceBased ? settings.turnWorkerTargetCpuUsage : null,
|
|
14384
|
+
targetMemoryUsage: resourceBased ? settings.turnWorkerTargetMemoryUsage : null
|
|
14385
|
+
};
|
|
14386
|
+
}
|
|
14290
14387
|
var CONTROL_WORKER_MAX_CONCURRENT_ACTIVITIES = 32;
|
|
14291
14388
|
var CONTROL_WORKER_MAX_CONCURRENT_WORKFLOW_TASKS = 40;
|
|
14292
14389
|
|
|
@@ -14422,10 +14519,10 @@ async function createOpenGeniWorker(options) {
|
|
|
14422
14519
|
taskQueue: options.role === "control" ? settings.temporalTaskQueue : turnTaskQueue(settings.temporalTaskQueue),
|
|
14423
14520
|
...options.role === "control" ? {
|
|
14424
14521
|
...options.workflowBundle ? { workflowBundle: options.workflowBundle } : resolveOpenGeniWorkflowDefinition(),
|
|
14425
|
-
maxConcurrentWorkflowTaskExecutions: CONTROL_WORKER_MAX_CONCURRENT_WORKFLOW_TASKS
|
|
14426
|
-
|
|
14522
|
+
maxConcurrentWorkflowTaskExecutions: CONTROL_WORKER_MAX_CONCURRENT_WORKFLOW_TASKS,
|
|
14523
|
+
maxConcurrentActivityTaskExecutions: CONTROL_WORKER_MAX_CONCURRENT_ACTIVITIES
|
|
14524
|
+
} : turnWorkerConcurrencyOptions(settings),
|
|
14427
14525
|
activities,
|
|
14428
|
-
maxConcurrentActivityTaskExecutions: options.role === "turn" ? TURN_WORKER_MAX_CONCURRENT_TURNS : CONTROL_WORKER_MAX_CONCURRENT_ACTIVITIES,
|
|
14429
14526
|
// Cancellation is delivered through an activity heartbeat. The SDK would
|
|
14430
14527
|
// otherwise throttle a two-minute heartbeat timeout to its 60-second cap,
|
|
14431
14528
|
// making Pause/Steer take roughly a minute even though runAgentTurn emits a
|
|
@@ -14757,7 +14854,12 @@ async function createOpenGeniWorkerService(options) {
|
|
|
14757
14854
|
observability.info("OpenGeni worker listening", {
|
|
14758
14855
|
role: options.role,
|
|
14759
14856
|
temporalTaskQueue: options.role === "control" ? settings.temporalTaskQueue : turnTaskQueue(settings.temporalTaskQueue),
|
|
14760
|
-
|
|
14857
|
+
...options.role === "turn" ? turnWorkerConcurrencyLogFields(settings) : {
|
|
14858
|
+
concurrencyMode: "fixed",
|
|
14859
|
+
maxConcurrentTurns: CONTROL_WORKER_MAX_CONCURRENT_ACTIVITIES,
|
|
14860
|
+
targetCpuUsage: null,
|
|
14861
|
+
targetMemoryUsage: null
|
|
14862
|
+
},
|
|
14761
14863
|
maxConcurrentWorkflowTaskExecutions: options.role === "control" ? CONTROL_WORKER_MAX_CONCURRENT_WORKFLOW_TASKS : 0,
|
|
14762
14864
|
httpPort: options.http === false ? null : settings.workerHttpPort
|
|
14763
14865
|
});
|