@opengeni/worker-bundle 0.7.1 → 0.7.3
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.d.ts +184 -68
- package/dist/index.js +7099 -1643
- package/dist/index.js.map +1 -1
- package/package.json +18 -18
- package/src/activities/agent-turn.ts +4332 -1068
- package/src/activities/capabilities.ts +43 -8
- package/src/activities/codex-capacity.ts +223 -0
- package/src/activities/codex-rotation.ts +550 -54
- package/src/activities/common.ts +14 -2
- package/src/activities/context-compaction.ts +152 -118
- package/src/activities/documents.ts +32 -27
- package/src/activities/environment.ts +318 -75
- package/src/activities/file-upload-reaper.ts +79 -0
- package/src/activities/git-credential-renewal.ts +183 -0
- package/src/activities/goals.ts +142 -123
- package/src/activities/packs.ts +55 -5
- package/src/activities/parent-wake.ts +216 -42
- package/src/activities/recording.ts +154 -122
- package/src/activities/redaction.ts +3 -1
- package/src/activities/rig-verification.ts +441 -0
- package/src/activities/run-input.ts +110 -122
- package/src/activities/sandbox-lease.ts +186 -51
- package/src/activities/scheduled-tasks.ts +287 -171
- package/src/activities/session-state.ts +165 -157
- package/src/activities/streaming.ts +143 -19
- package/src/activities/turn-attempt-fenced.ts +14 -0
- package/src/activities/types.ts +106 -36
- package/src/activities/workflow-wake.ts +44 -0
- package/src/activities/workspace-capture.ts +964 -0
- package/src/activities.ts +75 -35
- package/src/concurrency.ts +11 -0
- package/src/http.ts +16 -6
- package/src/index.ts +322 -49
- package/src/observability-metrics.ts +441 -8
- package/src/op-journal.ts +46 -0
- package/src/sandbox-resume.ts +431 -201
- package/src/sandbox-routing.ts +209 -22
- package/src/workflows/activities.ts +65 -8
- package/src/workflows/file-upload-reaper.ts +12 -0
- package/src/workflows/rig-verification.ts +28 -0
- package/src/workflows/scheduled-tasks.ts +12 -26
- package/src/workflows/session.ts +330 -192
- package/src/workflows/workflow-wake.ts +13 -0
- package/src/workflows.ts +9 -7
package/src/activities.ts
CHANGED
|
@@ -6,13 +6,20 @@ import { createObservability } from "@opengeni/observability";
|
|
|
6
6
|
import { createProductionAgentRuntime } from "@opengeni/runtime";
|
|
7
7
|
import { createObjectStorage } from "@opengeni/storage";
|
|
8
8
|
import { createRunAgentTurnActivity } from "./activities/agent-turn";
|
|
9
|
+
import { createCodexCapacityActivities } from "./activities/codex-capacity";
|
|
9
10
|
import { createDocumentActivities } from "./activities/documents";
|
|
11
|
+
import { createFileUploadReaperActivities } from "./activities/file-upload-reaper";
|
|
10
12
|
import { createGoalActivities } from "./activities/goals";
|
|
11
13
|
import { createSandboxLeaseActivities } from "./activities/sandbox-lease";
|
|
12
14
|
import { createScheduledTaskActivities } from "./activities/scheduled-tasks";
|
|
13
15
|
import { createSessionStateActivities } from "./activities/session-state";
|
|
16
|
+
import { createWorkflowWakeActivities } from "./activities/workflow-wake";
|
|
17
|
+
import { createRigVerificationActivities } from "./activities/rig-verification";
|
|
14
18
|
import type { ActivityDependencies, ActivityServices } from "./activities/types";
|
|
15
|
-
import {
|
|
19
|
+
import {
|
|
20
|
+
observabilityEventLogger,
|
|
21
|
+
runtimeMetricsHooksForObservability,
|
|
22
|
+
} from "./observability-metrics";
|
|
16
23
|
|
|
17
24
|
export type {
|
|
18
25
|
ActivityDependencies,
|
|
@@ -21,29 +28,37 @@ export type {
|
|
|
21
28
|
IndexDocumentInput,
|
|
22
29
|
MaybeContinueGoalInput,
|
|
23
30
|
MaybeContinueGoalResult,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
31
|
+
CodexCapacityWaitRef,
|
|
32
|
+
GetCodexCapacityWaitInput,
|
|
33
|
+
ReconcileCodexCapacityWaitInput,
|
|
34
|
+
ReconcileCodexCapacityWaitResult,
|
|
35
|
+
RecoverDispatchInput,
|
|
36
|
+
RecoverDispatchResult,
|
|
27
37
|
RunAgentTurnInput,
|
|
28
38
|
RunAgentTurnResult,
|
|
29
39
|
} from "./activities/types";
|
|
30
40
|
|
|
31
|
-
|
|
41
|
+
function createActivityServices(
|
|
42
|
+
dependencies: ActivityDependencies,
|
|
43
|
+
): () => Promise<ActivityServices> {
|
|
32
44
|
let servicesPromise: Promise<ActivityServices> | null = null;
|
|
33
45
|
|
|
34
46
|
async function services(): Promise<ActivityServices> {
|
|
35
47
|
servicesPromise ??= (async () => {
|
|
36
48
|
const settings = dependencies.settings ?? getSettings();
|
|
37
|
-
const observability =
|
|
49
|
+
const observability =
|
|
50
|
+
dependencies.observability ?? createObservability(settings, { component: "worker" });
|
|
38
51
|
// Step I: when not injected, build the standalone handle — searchPath
|
|
39
52
|
// undefined for standalone (public), scoped to the dedicated schema +
|
|
40
53
|
// host RLS strategy when embedded config is set. An embedded host injects
|
|
41
54
|
// `dependencies.db` directly and this branch is skipped.
|
|
42
55
|
const searchPath = dbSearchPath(settings);
|
|
43
|
-
const dbClient = dependencies.db
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
56
|
+
const dbClient = dependencies.db
|
|
57
|
+
? null
|
|
58
|
+
: createDb(settings.databaseUrl, {
|
|
59
|
+
...(searchPath ? { searchPath } : {}),
|
|
60
|
+
rlsStrategy: settings.rlsStrategy,
|
|
61
|
+
});
|
|
47
62
|
// The PRIVILEGED control-plane NATS login (M-AUTH): the worker resolves the
|
|
48
63
|
// SAME static account user the API uses to request `agent.*.rpc`. Null in
|
|
49
64
|
// local dev → anonymous connect (the bus default).
|
|
@@ -68,16 +83,21 @@ export function createActivities(dependencies: ActivityDependencies = {}) {
|
|
|
68
83
|
dependencies.bus ??
|
|
69
84
|
(await createNatsEventBus(
|
|
70
85
|
settings.natsUrl,
|
|
71
|
-
controlPlaneAuth
|
|
86
|
+
controlPlaneAuth
|
|
87
|
+
? { user: controlPlaneAuth.user, pass: controlPlaneAuth.password }
|
|
88
|
+
: undefined,
|
|
72
89
|
{ logger: observabilityEventLogger(observability) },
|
|
73
90
|
)),
|
|
74
|
-
runtime:
|
|
75
|
-
|
|
76
|
-
|
|
91
|
+
runtime:
|
|
92
|
+
dependencies.runtime ??
|
|
93
|
+
createProductionAgentRuntime({
|
|
94
|
+
metrics: runtimeMetricsHooksForObservability(observability),
|
|
95
|
+
}),
|
|
77
96
|
objectStorage: dependencies.objectStorage ?? createObjectStorage(settings),
|
|
78
97
|
documentServices: dependencies.documentServices ?? createDocumentServices(settings),
|
|
79
98
|
observability,
|
|
80
99
|
wakeSessionWorkflow: dependencies.wakeSessionWorkflow ?? null,
|
|
100
|
+
signalCodexCapacityWorkflow: dependencies.signalCodexCapacityWorkflow ?? null,
|
|
81
101
|
// §7.5 P3 — host-entitlements port. No constructed default: standalone
|
|
82
102
|
// has no host meter, so unset → null → `ensureRunAllowed` reads the
|
|
83
103
|
// local ledger exactly as today (mirrors `wakeSessionWorkflow`'s
|
|
@@ -94,36 +114,56 @@ export function createActivities(dependencies: ActivityDependencies = {}) {
|
|
|
94
114
|
return servicesPromise;
|
|
95
115
|
}
|
|
96
116
|
|
|
97
|
-
|
|
117
|
+
return services;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function controlActivities(services: () => Promise<ActivityServices>) {
|
|
98
121
|
return {
|
|
99
|
-
runAgentTurn,
|
|
100
|
-
// Legacy Temporal activity name. In-flight session workflows (which can
|
|
101
|
-
// legitimately live for days) recorded ScheduleActivityTask events as
|
|
102
|
-
// "runAgentSegment"; the name must keep resolving until those histories
|
|
103
|
-
// drain. New workflow code must use runAgentTurn; migrate the session
|
|
104
|
-
// workflow call site via patched() before removing this alias.
|
|
105
|
-
runAgentSegment: runAgentTurn,
|
|
106
122
|
...createDocumentActivities(services),
|
|
107
123
|
...createSessionStateActivities(services),
|
|
108
124
|
...createScheduledTaskActivities(services),
|
|
109
125
|
...createGoalActivities(services),
|
|
126
|
+
...createCodexCapacityActivities(services),
|
|
127
|
+
...createRigVerificationActivities(services),
|
|
128
|
+
...createFileUploadReaperActivities(services),
|
|
129
|
+
...createWorkflowWakeActivities(services),
|
|
110
130
|
// P1.3: the SOLE liveness/GC/cost-stop driver. Only reapSandboxLeases — no
|
|
111
131
|
// *ForViewer activities, no ownerHeartbeat, no resolveOwnerTaskQueue.
|
|
112
132
|
...createSandboxLeaseActivities(services),
|
|
113
133
|
};
|
|
114
134
|
}
|
|
115
135
|
|
|
116
|
-
|
|
136
|
+
export function createControlActivities(dependencies: ActivityDependencies = {}) {
|
|
137
|
+
return controlActivities(createActivityServices(dependencies));
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export function createTurnActivities(dependencies: ActivityDependencies = {}) {
|
|
141
|
+
return { runAgentTurn: createRunAgentTurnActivity(createActivityServices(dependencies)) };
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Direct activity harness for tests; production workers always choose one role. */
|
|
145
|
+
export function createActivityTestHarness(dependencies: ActivityDependencies = {}) {
|
|
146
|
+
const services = createActivityServices(dependencies);
|
|
147
|
+
return { runAgentTurn: createRunAgentTurnActivity(services), ...controlActivities(services) };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const defaultControlActivities = createControlActivities();
|
|
151
|
+
const defaultTurnActivities = createTurnActivities();
|
|
117
152
|
|
|
118
|
-
export const runAgentTurn =
|
|
119
|
-
export const
|
|
120
|
-
export const
|
|
121
|
-
export const
|
|
122
|
-
export const
|
|
123
|
-
export const
|
|
124
|
-
export const
|
|
125
|
-
export const
|
|
126
|
-
export const
|
|
127
|
-
export const maybeContinueGoal =
|
|
128
|
-
export const
|
|
129
|
-
export const
|
|
153
|
+
export const runAgentTurn = defaultTurnActivities.runAgentTurn;
|
|
154
|
+
export const indexDocument = defaultControlActivities.indexDocument;
|
|
155
|
+
export const failSessionAttempt = defaultControlActivities.failSessionAttempt;
|
|
156
|
+
export const settleSessionInterruptions = defaultControlActivities.settleSessionInterruptions;
|
|
157
|
+
export const recoverDispatch = defaultControlActivities.recoverDispatch;
|
|
158
|
+
export const peekSessionWork = defaultControlActivities.peekSessionWork;
|
|
159
|
+
export const markSessionIdle = defaultControlActivities.markSessionIdle;
|
|
160
|
+
export const dispatchScheduledTaskRun = defaultControlActivities.dispatchScheduledTaskRun;
|
|
161
|
+
export const enqueueGoalRetryWake = defaultControlActivities.enqueueGoalRetryWake;
|
|
162
|
+
export const maybeContinueGoal = defaultControlActivities.maybeContinueGoal;
|
|
163
|
+
export const getCodexCapacityWait = defaultControlActivities.getCodexCapacityWait;
|
|
164
|
+
export const reconcileCodexCapacityWait = defaultControlActivities.reconcileCodexCapacityWait;
|
|
165
|
+
export const reapSandboxLeases = defaultControlActivities.reapSandboxLeases;
|
|
166
|
+
export const reapExpiredFileUploads = defaultControlActivities.reapExpiredFileUploads;
|
|
167
|
+
export const dispatchSessionWorkflowWakes = defaultControlActivities.dispatchSessionWorkflowWakes;
|
|
168
|
+
export const verifyRigChange = defaultControlActivities.verifyRigChange;
|
|
169
|
+
export const verifyRigVersion = defaultControlActivities.verifyRigVersion;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Process-local Temporal execution ceilings.
|
|
3
|
+
*
|
|
4
|
+
* Turn workers host only runAgentTurn, so this is the exact number of agent
|
|
5
|
+
* turns one worker process may own concurrently. Keep the value centralized so
|
|
6
|
+
* production and the real Temporal integration harness exercise one topology.
|
|
7
|
+
*/
|
|
8
|
+
export const TURN_WORKER_MAX_CONCURRENT_TURNS = 16;
|
|
9
|
+
|
|
10
|
+
export const CONTROL_WORKER_MAX_CONCURRENT_ACTIVITIES = 32;
|
|
11
|
+
export const CONTROL_WORKER_MAX_CONCURRENT_WORKFLOW_TASKS = 40;
|
package/src/http.ts
CHANGED
|
@@ -50,17 +50,24 @@ export function startWorkerHttpServer(input: {
|
|
|
50
50
|
});
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
export async function runReadinessChecks(
|
|
53
|
+
export async function runReadinessChecks(
|
|
54
|
+
checks: ReadinessChecks,
|
|
55
|
+
timeoutMs = 2_000,
|
|
56
|
+
): Promise<ReadinessResult> {
|
|
54
57
|
const entries = await Promise.all(
|
|
55
|
-
(Object.entries(checks) as Array<[ReadinessCheckName, () => Promise<void> | void]>)
|
|
56
|
-
|
|
58
|
+
(Object.entries(checks) as Array<[ReadinessCheckName, () => Promise<void> | void]>).map(
|
|
59
|
+
async ([name, check]) => {
|
|
57
60
|
try {
|
|
58
61
|
await withTimeout(Promise.resolve().then(check), timeoutMs);
|
|
59
62
|
return [name, { ok: true }] as const;
|
|
60
63
|
} catch (error) {
|
|
61
|
-
return [
|
|
64
|
+
return [
|
|
65
|
+
name,
|
|
66
|
+
{ ok: false, error: error instanceof Error ? error.message : String(error) },
|
|
67
|
+
] as const;
|
|
62
68
|
}
|
|
63
|
-
}
|
|
69
|
+
},
|
|
70
|
+
),
|
|
64
71
|
);
|
|
65
72
|
const result = Object.fromEntries(entries) as ReadinessResult["checks"];
|
|
66
73
|
return {
|
|
@@ -89,7 +96,10 @@ async function withTimeout<T>(promise: Promise<T>, timeoutMs: number): Promise<T
|
|
|
89
96
|
return await Promise.race([
|
|
90
97
|
promise,
|
|
91
98
|
new Promise<never>((_, reject) => {
|
|
92
|
-
timer = setTimeout(
|
|
99
|
+
timer = setTimeout(
|
|
100
|
+
() => reject(new Error(`readiness check timed out after ${timeoutMs}ms`)),
|
|
101
|
+
timeoutMs,
|
|
102
|
+
);
|
|
93
103
|
}),
|
|
94
104
|
]);
|
|
95
105
|
} finally {
|