@opengeni/worker-bundle 0.22.0-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.
- package/dist/activities/agent-turn/agent-build.d.ts +1 -0
- package/dist/activities/agent-turn/sandbox-establish.d.ts +1 -0
- package/dist/activities/agent-turn/session-title.d.ts +24 -0
- package/dist/activities/agent-turn/tool-environment.d.ts +1 -0
- package/dist/activities/agent-turn/tool-policy.d.ts +2 -1
- package/dist/activities/incident-telemetry-authority.d.ts +1 -0
- package/dist/activities/parent-wake.d.ts +25 -2
- package/dist/activities/rig-verification.d.ts +22 -7
- package/dist/activities/scheduled-tasks.d.ts +49 -3
- package/dist/{activities-control-DKG22ONJ.js → activities-control-4XVBA3Q5.js} +168 -70
- package/dist/activities-control-4XVBA3Q5.js.map +1 -0
- package/dist/activities-control.d.ts +16 -12
- package/dist/{activities-turn-4IMC3MAA.js → activities-turn-J3CR27E6.js} +164 -44
- package/dist/activities-turn-J3CR27E6.js.map +1 -0
- package/dist/activities.d.ts +16 -12
- package/dist/{chunk-CE7TPKBS.js → chunk-FA35XBBC.js} +3 -3
- package/dist/{chunk-CE7TPKBS.js.map → chunk-FA35XBBC.js.map} +1 -1
- package/dist/{chunk-CNYGVRKF.js → chunk-XWQPS6GG.js} +76 -17
- package/dist/chunk-XWQPS6GG.js.map +1 -0
- package/dist/http.d.ts +1 -1
- package/dist/index.d.ts +8 -6
- package/dist/index.js +9 -3
- package/dist/index.js.map +1 -1
- package/package.json +17 -17
- package/src/activities/agent-turn/agent-build.ts +8 -6
- package/src/activities/agent-turn/governance-model.ts +13 -15
- package/src/activities/agent-turn/run.ts +3 -0
- package/src/activities/agent-turn/sandbox-establish.ts +6 -1
- package/src/activities/agent-turn/session-title.ts +106 -0
- package/src/activities/agent-turn/tool-environment.ts +68 -19
- package/src/activities/agent-turn/tool-policy.ts +5 -2
- package/src/activities/incident-telemetry-authority.ts +7 -0
- package/src/activities/parent-wake.ts +65 -1
- package/src/activities/rig-verification.ts +156 -47
- package/src/activities/scheduled-tasks.ts +38 -35
- package/src/activities/workflow-wake.ts +30 -9
- package/src/http.ts +2 -1
- package/src/index.ts +6 -1
- package/src/observability-metrics.ts +2 -2
- package/src/pr-review-credentials.ts +42 -14
- package/dist/activities-control-DKG22ONJ.js.map +0 -1
- package/dist/activities-turn-4IMC3MAA.js.map +0 -1
- package/dist/chunk-CNYGVRKF.js.map +0 -1
|
@@ -2,6 +2,7 @@ import type {
|
|
|
2
2
|
AccessGrant,
|
|
3
3
|
Rig,
|
|
4
4
|
RigChange,
|
|
5
|
+
RigCheck,
|
|
5
6
|
RigProviderImage,
|
|
6
7
|
RigVersion,
|
|
7
8
|
SandboxBackend,
|
|
@@ -58,11 +59,7 @@ import {
|
|
|
58
59
|
} from "@opengeni/runtime/sandbox";
|
|
59
60
|
import type { Context } from "@temporalio/activity";
|
|
60
61
|
import type { ControlActivityServices } from "./types";
|
|
61
|
-
import {
|
|
62
|
-
rigProviderImageSourceImage,
|
|
63
|
-
settingsWithPackSandboxImage,
|
|
64
|
-
settingsWithRigImage,
|
|
65
|
-
} from "./sandbox-images";
|
|
62
|
+
import { rigProviderImageSourceImage } from "./sandbox-images";
|
|
66
63
|
import { resolveWorkspacePackRuntime, type WorkspacePackRuntime } from "./packs";
|
|
67
64
|
import { currentActivityContext } from "./streaming";
|
|
68
65
|
|
|
@@ -89,6 +86,83 @@ type CommandResult = {
|
|
|
89
86
|
output: string;
|
|
90
87
|
};
|
|
91
88
|
|
|
89
|
+
export type RigPlatformCheckResult = CommandResult & RigCheck;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Platform-owned checks run after Rig setup and independently of user-declared
|
|
93
|
+
* checks. They prove that a Rig layered on the deployment image did not remove
|
|
94
|
+
* or replace the Browser, Terminal, or Computer/Desktop services. The commands
|
|
95
|
+
* start each enabled service on its canonical loopback port, wait for its own
|
|
96
|
+
* readiness contract, probe it, and tear it down before provider snapshotting.
|
|
97
|
+
*/
|
|
98
|
+
export function rigPlatformChecksForSettings(
|
|
99
|
+
settings: ControlActivityServices["settings"],
|
|
100
|
+
): RigCheck[] {
|
|
101
|
+
const backend = settings.sandboxBackend as SandboxBackend;
|
|
102
|
+
if (!rigProviderImageSourceImage(settings, backend)) return [];
|
|
103
|
+
|
|
104
|
+
const checks: RigCheck[] = [
|
|
105
|
+
{
|
|
106
|
+
name: "opengeni-platform-browser",
|
|
107
|
+
command: [
|
|
108
|
+
"set -eu",
|
|
109
|
+
"test -x /usr/local/bin/opengeni-browserd",
|
|
110
|
+
"test -x /usr/local/bin/opengeni-browserd-up",
|
|
111
|
+
"test -x /usr/local/bin/opengeni-browserd-down",
|
|
112
|
+
"test -r /etc/opengeni/browser-engine",
|
|
113
|
+
'__og_browser_engine="$(head -n 1 /etc/opengeni/browser-engine)"',
|
|
114
|
+
'test -n "$__og_browser_engine"',
|
|
115
|
+
'test -x "$__og_browser_engine"',
|
|
116
|
+
'__og_browser_token="$(mktemp)"',
|
|
117
|
+
"trap 'opengeni-browserd-down >/dev/null 2>&1 || true; rm -f \"$__og_browser_token\"' EXIT",
|
|
118
|
+
"printf '%s\\n' 'rig-platform-check' > \"$__og_browser_token\"",
|
|
119
|
+
'chmod 0600 "$__og_browser_token"',
|
|
120
|
+
'OPENGENI_BROWSERD_ADMIN_TOKEN_FILE="$__og_browser_token" OPENGENI_BROWSERD_PORT=7682 OPENGENI_BROWSERD_ALLOWED_ORIGINS= opengeni-browserd-up',
|
|
121
|
+
"curl --noproxy '*' -fsS http://127.0.0.1:7682/healthz >/dev/null",
|
|
122
|
+
"curl --noproxy '*' -fsS -H 'Authorization: Bearer rig-platform-check' http://127.0.0.1:7682/v1/browser-sessions >/dev/null",
|
|
123
|
+
].join("\n"),
|
|
124
|
+
},
|
|
125
|
+
];
|
|
126
|
+
|
|
127
|
+
if (settings.sandboxTerminalEnabled) {
|
|
128
|
+
checks.push({
|
|
129
|
+
name: "opengeni-platform-terminal",
|
|
130
|
+
command: [
|
|
131
|
+
"set -eu",
|
|
132
|
+
"test -x /usr/local/bin/opengeni-terminal-up",
|
|
133
|
+
"test -x /usr/local/bin/opengeni-terminal-down",
|
|
134
|
+
"command -v ttyd >/dev/null",
|
|
135
|
+
"trap 'opengeni-terminal-down >/dev/null 2>&1 || true' EXIT",
|
|
136
|
+
"TERMINAL_PORT=7681 opengeni-terminal-up",
|
|
137
|
+
"curl --noproxy '*' -fsS http://127.0.0.1:7681/ >/dev/null",
|
|
138
|
+
].join("\n"),
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (settings.sandboxDesktopEnabled) {
|
|
143
|
+
checks.push({
|
|
144
|
+
name: "opengeni-platform-computer-desktop",
|
|
145
|
+
command: [
|
|
146
|
+
"set -eu",
|
|
147
|
+
"test -x /usr/local/bin/opengeni-desktop-up",
|
|
148
|
+
"test -x /usr/local/bin/opengeni-desktop-down",
|
|
149
|
+
"command -v Xvfb >/dev/null",
|
|
150
|
+
"command -v x11vnc >/dev/null",
|
|
151
|
+
"command -v websockify >/dev/null",
|
|
152
|
+
"command -v scrot >/dev/null",
|
|
153
|
+
"command -v xdotool >/dev/null",
|
|
154
|
+
'__og_desktop_home="$(mktemp -d)"',
|
|
155
|
+
"trap 'opengeni-desktop-down >/dev/null 2>&1 || true; rm -rf \"$__og_desktop_home\"' EXIT",
|
|
156
|
+
'HOME="$__og_desktop_home" STREAM_PORT=6080 DESKTOP_W=1280 DESKTOP_H=800 opengeni-desktop-up',
|
|
157
|
+
"curl --noproxy '*' -fsS http://127.0.0.1:6080/vnc.html >/dev/null",
|
|
158
|
+
"nc -z 127.0.0.1 5900",
|
|
159
|
+
].join("\n"),
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return checks;
|
|
164
|
+
}
|
|
165
|
+
|
|
92
166
|
const RIG_VERIFICATION_CLEANUP_RESERVE_MAX_MS = 2 * 60_000;
|
|
93
167
|
const RIG_VERIFICATION_CLEANUP_OPERATION_MAX_MS = 60_000;
|
|
94
168
|
const RIG_VERIFICATION_HEARTBEAT_MAX_INTERVAL_MS = 10_000;
|
|
@@ -750,6 +824,23 @@ async function runCommand(
|
|
|
750
824
|
};
|
|
751
825
|
}
|
|
752
826
|
|
|
827
|
+
async function runRigChecks(
|
|
828
|
+
session: TurnSandboxCommandSession,
|
|
829
|
+
checks: readonly RigCheck[],
|
|
830
|
+
timeoutMs: number,
|
|
831
|
+
commandRunner: SandboxLifecycleCommandRunner,
|
|
832
|
+
): Promise<RigPlatformCheckResult[]> {
|
|
833
|
+
const results: RigPlatformCheckResult[] = [];
|
|
834
|
+
for (const check of checks) {
|
|
835
|
+
results.push({
|
|
836
|
+
name: check.name,
|
|
837
|
+
command: check.command,
|
|
838
|
+
...(await runCommand(session, check.command, timeoutMs, commandRunner)),
|
|
839
|
+
});
|
|
840
|
+
}
|
|
841
|
+
return results;
|
|
842
|
+
}
|
|
843
|
+
|
|
753
844
|
function setupAppendCommand(change: RigChange): string | null {
|
|
754
845
|
if (change.kind !== "setup_append") {
|
|
755
846
|
return null;
|
|
@@ -760,10 +851,9 @@ function setupAppendCommand(change: RigChange): string | null {
|
|
|
760
851
|
|
|
761
852
|
function candidateVersionForChange(baseVersion: RigVersion, change: RigChange): RigVersion {
|
|
762
853
|
if (change.kind !== "definition_edit") {
|
|
763
|
-
return { ...baseVersion, providerImages: {} };
|
|
854
|
+
return { ...baseVersion, image: null, providerImages: {} };
|
|
764
855
|
}
|
|
765
856
|
const payload = change.payload as {
|
|
766
|
-
image?: unknown;
|
|
767
857
|
setupScript?: unknown;
|
|
768
858
|
checks?: unknown;
|
|
769
859
|
credentialHooks?: unknown;
|
|
@@ -772,7 +862,7 @@ function candidateVersionForChange(baseVersion: RigVersion, change: RigChange):
|
|
|
772
862
|
};
|
|
773
863
|
return {
|
|
774
864
|
...baseVersion,
|
|
775
|
-
image:
|
|
865
|
+
image: null,
|
|
776
866
|
setupScript:
|
|
777
867
|
payload.setupScript === undefined
|
|
778
868
|
? baseVersion.setupScript
|
|
@@ -799,7 +889,6 @@ function providerImageDefinitionForChange(
|
|
|
799
889
|
if (change.kind !== "setup_append") return candidateVersion;
|
|
800
890
|
const command = setupAppendCommand(change);
|
|
801
891
|
return {
|
|
802
|
-
image: baseVersion.image,
|
|
803
892
|
setupScript: command
|
|
804
893
|
? appendRigSetupCommand(baseVersion.setupScript, command)
|
|
805
894
|
: baseVersion.setupScript,
|
|
@@ -889,6 +978,19 @@ export async function verifyRigProviderImageColdBoot(
|
|
|
889
978
|
if (markerResult.exitCode !== 0) {
|
|
890
979
|
throw new Error("built provider image is missing its exact rig-content marker");
|
|
891
980
|
}
|
|
981
|
+
for (const check of rigPlatformChecksForSettings(input.settings)) {
|
|
982
|
+
const result = await runCommand(
|
|
983
|
+
established.session as TurnSandboxCommandSession,
|
|
984
|
+
check.command,
|
|
985
|
+
input.settings.rigSetupTimeoutMs,
|
|
986
|
+
runContext.commandRunner,
|
|
987
|
+
);
|
|
988
|
+
if (result.exitCode !== 0) {
|
|
989
|
+
throw new Error(
|
|
990
|
+
`built provider image failed mandatory platform check ${JSON.stringify(check.name)}: ${result.output.slice(-2000)}`,
|
|
991
|
+
);
|
|
992
|
+
}
|
|
993
|
+
}
|
|
892
994
|
for (const check of input.checks) {
|
|
893
995
|
const result = await runCommand(
|
|
894
996
|
established.session as TurnSandboxCommandSession,
|
|
@@ -1175,14 +1277,12 @@ export function settingsForRigVerification(
|
|
|
1175
1277
|
packRuntime: WorkspacePackRuntime,
|
|
1176
1278
|
rigImage: string | null,
|
|
1177
1279
|
): ControlActivityServices["settings"] {
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
rigImage,
|
|
1185
|
-
);
|
|
1280
|
+
// Rig verification must prove setup and provider-image materialization on
|
|
1281
|
+
// the deployment-owned platform base. Legacy Pack and historical Rig image
|
|
1282
|
+
// values are intentionally ignored here.
|
|
1283
|
+
void packRuntime;
|
|
1284
|
+
void rigImage;
|
|
1285
|
+
return settings;
|
|
1186
1286
|
}
|
|
1187
1287
|
|
|
1188
1288
|
async function loadChangeTarget(
|
|
@@ -1353,22 +1453,23 @@ export function createRigVerificationActivities(services: () => Promise<ControlA
|
|
|
1353
1453
|
`Failed to seal rig provider image content marker: ${markerResult.output.slice(-2000)}`,
|
|
1354
1454
|
);
|
|
1355
1455
|
}
|
|
1356
|
-
const
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
}
|
|
1456
|
+
const platformCheckResults = await runRigChecks(
|
|
1457
|
+
established.session as TurnSandboxCommandSession,
|
|
1458
|
+
rigPlatformChecksForSettings(runSettings),
|
|
1459
|
+
settings.rigSetupTimeoutMs,
|
|
1460
|
+
runContext.commandRunner,
|
|
1461
|
+
);
|
|
1462
|
+
verification.platformCheckResults = platformCheckResults;
|
|
1463
|
+
const checkResults = await runRigChecks(
|
|
1464
|
+
established.session as TurnSandboxCommandSession,
|
|
1465
|
+
candidateVersion.checks,
|
|
1466
|
+
settings.rigSetupTimeoutMs,
|
|
1467
|
+
runContext.commandRunner,
|
|
1468
|
+
);
|
|
1370
1469
|
verification.checkResults = checkResults;
|
|
1371
|
-
const passed =
|
|
1470
|
+
const passed =
|
|
1471
|
+
platformCheckResults.every((result) => result.exitCode === 0) &&
|
|
1472
|
+
checkResults.every((result) => result.exitCode === 0);
|
|
1372
1473
|
if (passed) {
|
|
1373
1474
|
verification.providerImage = await buildVerifiedRigProviderImage({
|
|
1374
1475
|
settings: runSettings,
|
|
@@ -1515,20 +1616,21 @@ export function createRigVerificationActivities(services: () => Promise<ControlA
|
|
|
1515
1616
|
`Failed to seal rig provider image content marker: ${markerResult.output.slice(-2000)}`,
|
|
1516
1617
|
);
|
|
1517
1618
|
}
|
|
1518
|
-
const
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1619
|
+
const platformCheckResults = await runRigChecks(
|
|
1620
|
+
established.session as TurnSandboxCommandSession,
|
|
1621
|
+
rigPlatformChecksForSettings(runSettings),
|
|
1622
|
+
settings.rigSetupTimeoutMs,
|
|
1623
|
+
runContext.commandRunner,
|
|
1624
|
+
);
|
|
1625
|
+
const checkResults = await runRigChecks(
|
|
1626
|
+
established.session as TurnSandboxCommandSession,
|
|
1627
|
+
version.checks,
|
|
1628
|
+
settings.rigSetupTimeoutMs,
|
|
1629
|
+
runContext.commandRunner,
|
|
1630
|
+
);
|
|
1631
|
+
const passed =
|
|
1632
|
+
platformCheckResults.every((result) => result.exitCode === 0) &&
|
|
1633
|
+
checkResults.every((result) => result.exitCode === 0);
|
|
1532
1634
|
const providerImage = passed
|
|
1533
1635
|
? await buildVerifiedRigProviderImage({
|
|
1534
1636
|
settings: runSettings,
|
|
@@ -1554,11 +1656,18 @@ export function createRigVerificationActivities(services: () => Promise<ControlA
|
|
|
1554
1656
|
startedAt,
|
|
1555
1657
|
finishedAt: new Date().toISOString(),
|
|
1556
1658
|
passed,
|
|
1659
|
+
platformCheckResults,
|
|
1557
1660
|
checkResults,
|
|
1558
1661
|
providerImage,
|
|
1559
1662
|
},
|
|
1560
1663
|
});
|
|
1561
|
-
return {
|
|
1664
|
+
return {
|
|
1665
|
+
versionId: version.id,
|
|
1666
|
+
passed,
|
|
1667
|
+
platformCheckResults,
|
|
1668
|
+
checkResults,
|
|
1669
|
+
providerImage,
|
|
1670
|
+
};
|
|
1562
1671
|
},
|
|
1563
1672
|
);
|
|
1564
1673
|
} catch (error) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
AUTOMATIC_SESSION_TITLE_FALLBACK,
|
|
2
3
|
DEFAULT_FIRST_PARTY_MCP_PERMISSIONS,
|
|
3
4
|
OPENGENI_SLACK_BOT_CREDENTIAL_LABEL,
|
|
4
5
|
OPENGENI_SLACK_BOT_CREDENTIAL_ROLE,
|
|
@@ -6,6 +7,7 @@ import {
|
|
|
6
7
|
resolveWorkspaceCodexCompactionDefault,
|
|
7
8
|
SCHEDULED_TASK_OCCURRENCE_PAYLOAD_MAX_BYTES,
|
|
8
9
|
ScheduledTaskRunAcceptedExecution,
|
|
10
|
+
normalizeAutomaticSessionTitle,
|
|
9
11
|
scheduledOccurrencePayloadUtf8Bytes,
|
|
10
12
|
stableJson,
|
|
11
13
|
type ScheduledTask,
|
|
@@ -56,7 +58,7 @@ import {
|
|
|
56
58
|
settleScheduledTaskRunInTransaction,
|
|
57
59
|
SessionSpawnDeniedDbError,
|
|
58
60
|
updateScheduledTaskRun,
|
|
59
|
-
|
|
61
|
+
updateSessionTitleWithEvent,
|
|
60
62
|
upsertScheduledSessionGoalForRun,
|
|
61
63
|
withSessionActivityRlsContext,
|
|
62
64
|
} from "@opengeni/db";
|
|
@@ -122,16 +124,12 @@ export function scheduledTaskRunProducerKey(
|
|
|
122
124
|
})}`;
|
|
123
125
|
}
|
|
124
126
|
|
|
125
|
-
// Same bound the manual rename field and the set_session_title tool enforce.
|
|
126
|
-
const SCHEDULED_SESSION_TITLE_MAX_LENGTH = 200;
|
|
127
|
-
|
|
128
127
|
/**
|
|
129
128
|
* Display title for a session the scheduler generates for a task.
|
|
130
129
|
*
|
|
131
130
|
* A scheduled session's `initialMessage` is the task prompt, byte-identical for
|
|
132
|
-
* every run
|
|
133
|
-
*
|
|
134
|
-
* short human-chosen label that actually identifies it, so that is the title.
|
|
131
|
+
* every run. The task name is the short human-chosen label that actually
|
|
132
|
+
* identifies it, so that is the title.
|
|
135
133
|
*
|
|
136
134
|
* The title is the task name and NOTHING else. It deliberately does not name the
|
|
137
135
|
* run's fire instant, for two independent reasons:
|
|
@@ -162,24 +160,21 @@ const SCHEDULED_SESSION_TITLE_MAX_LENGTH = 200;
|
|
|
162
160
|
* texts differ.
|
|
163
161
|
*/
|
|
164
162
|
export function scheduledTaskSessionTitle(taskName: string): string {
|
|
165
|
-
|
|
166
|
-
// to the same ceiling a human rename and set_session_title are held to.
|
|
167
|
-
const name = taskName.trim() || "Scheduled run";
|
|
168
|
-
if (name.length <= SCHEDULED_SESSION_TITLE_MAX_LENGTH) return name;
|
|
169
|
-
return `${name.slice(0, SCHEDULED_SESSION_TITLE_MAX_LENGTH - 1).trimEnd()}…`;
|
|
163
|
+
return normalizeAutomaticSessionTitle(taskName) ?? "Scheduled run";
|
|
170
164
|
}
|
|
171
165
|
|
|
172
166
|
/**
|
|
173
167
|
* Title a session the scheduler generated, and emit the same `session.title_set`
|
|
174
168
|
* event every other title write in the product emits.
|
|
175
169
|
*
|
|
176
|
-
* This
|
|
177
|
-
* `updateSessionTitle`: the
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
170
|
+
* This uses the same database operation as `@opengeni/core`
|
|
171
|
+
* `updateSessionTitle`: the clobber/CAS guarded row update and its identical
|
|
172
|
+
* `session.title_set` append commit together under the session event lock. A
|
|
173
|
+
* newer writer therefore cannot land between the authoritative row change and
|
|
174
|
+
* an older event. Without the event a live subscriber sees nothing:
|
|
175
|
+
* `packages/react/src/hooks/use-session.ts` patches an open session's title
|
|
176
|
+
* exclusively on `session.title_set`, so a bare row write leaves the viewer on
|
|
177
|
+
* the stale title until an unrelated refetch.
|
|
183
178
|
*
|
|
184
179
|
* The core wrapper itself is not called, because its only additional behavior is
|
|
185
180
|
* `requireSessionAuthorization(grant, ...)` - a check on an HTTP/MCP caller's
|
|
@@ -191,10 +186,12 @@ export function scheduledTaskSessionTitle(taskName: string): string {
|
|
|
191
186
|
* session into a way to fail a dispatch. Authorization belongs to callers with
|
|
192
187
|
* grants; the durable write and its event are the part that is shared.
|
|
193
188
|
*
|
|
194
|
-
* Only
|
|
195
|
-
* that has already run, and recovery re-enters this path for a
|
|
196
|
-
* dispatch may already have titled; in both cases whatever the
|
|
197
|
-
* chose is newer truth than this stamp.
|
|
189
|
+
* Only the neutral create fallback is replaced. A keyed create replay can hand
|
|
190
|
+
* back a session that has already run, and recovery re-enters this path for a
|
|
191
|
+
* session the dead dispatch may already have titled; in both cases whatever the
|
|
192
|
+
* agent or a human chose is newer truth than this stamp. The fallback check is
|
|
193
|
+
* part of the UPDATE itself, not a stale session-object precheck, so a title
|
|
194
|
+
* committed between dispatch read and stamp cannot be overwritten.
|
|
198
195
|
*
|
|
199
196
|
* `source: "agent"` is deliberate, and is the only system-assigned value the
|
|
200
197
|
* schema offers (`Session.titleSource` is "user" | "agent" | null). The database
|
|
@@ -206,26 +203,26 @@ export function scheduledTaskSessionTitle(taskName: string): string {
|
|
|
206
203
|
* Returns the appended events so the caller can route them through the same
|
|
207
204
|
* defer-or-publish path as every other event this dispatch produces.
|
|
208
205
|
*/
|
|
209
|
-
async function stampScheduledSessionTitle(
|
|
206
|
+
export async function stampScheduledSessionTitle(
|
|
210
207
|
db: Database,
|
|
211
208
|
input: {
|
|
212
209
|
workspaceId: string;
|
|
213
|
-
|
|
210
|
+
sessionId: string;
|
|
214
211
|
taskName: string;
|
|
215
212
|
},
|
|
216
|
-
): Promise<Awaited<ReturnType<typeof
|
|
217
|
-
if (input.session.title !== null) return [];
|
|
213
|
+
): Promise<Awaited<ReturnType<typeof updateSessionTitleWithEvent>>["events"]> {
|
|
218
214
|
const title = scheduledTaskSessionTitle(input.taskName);
|
|
219
|
-
const result = await
|
|
215
|
+
const result = await updateSessionTitleWithEvent(db, {
|
|
220
216
|
workspaceId: input.workspaceId,
|
|
221
|
-
sessionId: input.
|
|
217
|
+
sessionId: input.sessionId,
|
|
222
218
|
title,
|
|
223
219
|
source: "agent",
|
|
220
|
+
expectedCurrent: {
|
|
221
|
+
title: AUTOMATIC_SESSION_TITLE_FALLBACK,
|
|
222
|
+
source: "agent",
|
|
223
|
+
},
|
|
224
224
|
});
|
|
225
|
-
|
|
226
|
-
return await appendSessionEvents(db, input.workspaceId, input.session.id, [
|
|
227
|
-
{ type: "session.title_set", payload: { title: result.title ?? title, source: "agent" } },
|
|
228
|
-
]);
|
|
225
|
+
return result.events;
|
|
229
226
|
}
|
|
230
227
|
|
|
231
228
|
export function createScheduledTaskActivities(services: () => Promise<ControlActivityServices>) {
|
|
@@ -618,6 +615,9 @@ export function createScheduledTaskActivities(services: () => Promise<ControlAct
|
|
|
618
615
|
tools: targetSessionExecution.tools,
|
|
619
616
|
firstPartyMcpTools: targetSessionExecution.firstPartyMcpTools,
|
|
620
617
|
firstPartyMcpPermissions: targetSessionExecution.firstPartyMcpPermissions,
|
|
618
|
+
variableSetIds: targetSessionExecution.variableSets.map(
|
|
619
|
+
(variableSet) => variableSet.id,
|
|
620
|
+
),
|
|
621
621
|
variableSetId: targetSessionExecution.variableSetId,
|
|
622
622
|
rigId: targetSessionExecution.rigId,
|
|
623
623
|
rigVersionId: targetSessionExecution.rigVersionId,
|
|
@@ -1221,7 +1221,7 @@ export function createScheduledTaskActivities(services: () => Promise<ControlAct
|
|
|
1221
1221
|
// into the rail, and this lands on its heels.
|
|
1222
1222
|
const titleEvents = await stampScheduledSessionTitle(dispatchDb, {
|
|
1223
1223
|
workspaceId: task.workspaceId,
|
|
1224
|
-
session,
|
|
1224
|
+
sessionId: session.id,
|
|
1225
1225
|
taskName: task.name,
|
|
1226
1226
|
});
|
|
1227
1227
|
if (titleEvents.length > 0) {
|
|
@@ -1704,6 +1704,9 @@ async function prepareIncidentTelemetrySource(input: {
|
|
|
1704
1704
|
input.acceptedExecution.targetSessionExecution.firstPartyMcpTools,
|
|
1705
1705
|
firstPartyMcpPermissions:
|
|
1706
1706
|
input.acceptedExecution.targetSessionExecution.firstPartyMcpPermissions,
|
|
1707
|
+
variableSetIds: input.acceptedExecution.targetSessionExecution.variableSets.map(
|
|
1708
|
+
(variableSet) => variableSet.id,
|
|
1709
|
+
),
|
|
1707
1710
|
variableSetId: input.acceptedExecution.targetSessionExecution.variableSetId,
|
|
1708
1711
|
rigId: input.acceptedExecution.targetSessionExecution.rigId,
|
|
1709
1712
|
rigVersionId: input.acceptedExecution.targetSessionExecution.rigVersionId,
|
|
@@ -2084,7 +2087,7 @@ async function recoverBoundScheduledTaskDispatch(input: {
|
|
|
2084
2087
|
// already titled is left alone.
|
|
2085
2088
|
const titleEvents = await stampScheduledSessionTitle(input.db, {
|
|
2086
2089
|
workspaceId: task.workspaceId,
|
|
2087
|
-
session,
|
|
2090
|
+
sessionId: session.id,
|
|
2088
2091
|
taskName: task.name,
|
|
2089
2092
|
});
|
|
2090
2093
|
if (titleEvents.length > 0) {
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import type { ControlActivityServices } from "./types";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
reconcileAutomaticSessionTitleFanout,
|
|
4
|
+
reconcilePendingSessionWorkflowWakes,
|
|
5
|
+
} from "./parent-wake";
|
|
3
6
|
|
|
4
7
|
const BATCH_SIZE = 1_000;
|
|
5
8
|
const MAX_DELIVERIES_PER_ACTIVITY = 10_000;
|
|
9
|
+
const MAX_TITLE_FANOUT_PER_ACTIVITY = 1_000;
|
|
6
10
|
|
|
7
11
|
export type DispatchSessionWorkflowWakesResult = {
|
|
8
12
|
claimed: number;
|
|
@@ -23,22 +27,39 @@ export function createWorkflowWakeActivities(services: () => Promise<ControlActi
|
|
|
23
27
|
let claimed = 0;
|
|
24
28
|
let delivered = 0;
|
|
25
29
|
let failed = 0;
|
|
30
|
+
let exhaustedBatchLimit = false;
|
|
26
31
|
for (;;) {
|
|
27
32
|
const remaining = MAX_DELIVERIES_PER_ACTIVITY - claimed;
|
|
28
33
|
if (remaining <= 0) {
|
|
29
|
-
|
|
34
|
+
exhaustedBatchLimit = true;
|
|
35
|
+
break;
|
|
30
36
|
}
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
Math.min(BATCH_SIZE, remaining),
|
|
34
|
-
);
|
|
37
|
+
const limit = Math.min(BATCH_SIZE, remaining);
|
|
38
|
+
const batch = await reconcilePendingSessionWorkflowWakes(service, limit);
|
|
35
39
|
claimed += batch.claimed;
|
|
36
40
|
delivered += batch.delivered;
|
|
37
41
|
failed += batch.failed;
|
|
38
|
-
if (batch.claimed <
|
|
39
|
-
|
|
40
|
-
|
|
42
|
+
if (batch.claimed < limit) break;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Migration fanout is lower priority than ordinary workflow wakes and is
|
|
46
|
+
// independently capped. Delivery acknowledgements run with bounded
|
|
47
|
+
// concurrency in the reconciler, so a broker timeout cannot occupy the
|
|
48
|
+
// five-minute activity budget once per quarantined session. Managed NATS
|
|
49
|
+
// uses its bounded confirmed publish; embedding buses use their required
|
|
50
|
+
// publish promise.
|
|
51
|
+
const titleFanout = await reconcileAutomaticSessionTitleFanout(
|
|
52
|
+
service,
|
|
53
|
+
MAX_TITLE_FANOUT_PER_ACTIVITY,
|
|
54
|
+
);
|
|
55
|
+
if (titleFanout.claimed > 0) {
|
|
56
|
+
service.observability.info("automatic-title migration event fanout reconciled", {
|
|
57
|
+
claimed: titleFanout.claimed,
|
|
58
|
+
delivered: titleFanout.delivered,
|
|
59
|
+
failed: titleFanout.failed,
|
|
60
|
+
});
|
|
41
61
|
}
|
|
62
|
+
return { claimed, delivered, failed, exhaustedBatchLimit };
|
|
42
63
|
},
|
|
43
64
|
};
|
|
44
65
|
}
|
package/src/http.ts
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
type Database,
|
|
6
6
|
type RuntimeDatabasePostureOptions,
|
|
7
7
|
} from "@opengeni/db";
|
|
8
|
-
import type
|
|
8
|
+
import { requireSessionEventDurableFanoutCapability, type EventBus } from "@opengeni/events";
|
|
9
9
|
import type { Observability } from "@opengeni/observability";
|
|
10
10
|
|
|
11
11
|
export type ReadinessCheckName = "db" | "nats" | "temporal";
|
|
@@ -139,6 +139,7 @@ export function dbReadyCheck(
|
|
|
139
139
|
|
|
140
140
|
export function natsReadyCheck(bus: EventBus): () => void {
|
|
141
141
|
return () => {
|
|
142
|
+
requireSessionEventDurableFanoutCapability(bus);
|
|
142
143
|
if (bus.isConnected && !bus.isConnected()) {
|
|
143
144
|
throw new Error("NATS is not connected");
|
|
144
145
|
}
|
package/src/index.ts
CHANGED
|
@@ -14,7 +14,11 @@ import {
|
|
|
14
14
|
type Database,
|
|
15
15
|
type RuntimeDatabasePostureOptions,
|
|
16
16
|
} from "@opengeni/db";
|
|
17
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
createNatsEventBus,
|
|
19
|
+
requireSessionEventDurableFanoutCapability,
|
|
20
|
+
type EventBus,
|
|
21
|
+
} from "@opengeni/events";
|
|
18
22
|
import {
|
|
19
23
|
createObservability,
|
|
20
24
|
logStartupDependencyRetry,
|
|
@@ -777,6 +781,7 @@ export function workerOwnsInternalSchedules(
|
|
|
777
781
|
export async function createOpenGeniWorkerService(
|
|
778
782
|
options: OpenGeniWorkerServiceOptions,
|
|
779
783
|
): Promise<OpenGeniWorkerService> {
|
|
784
|
+
requireSessionEventDurableFanoutCapability(options.activityDependencies.bus);
|
|
780
785
|
const settings = options.settings ?? getSettings();
|
|
781
786
|
const observability =
|
|
782
787
|
options.activityDependencies.observability ??
|
|
@@ -1606,12 +1606,12 @@ export function recordCompanyBrainContributions(
|
|
|
1606
1606
|
};
|
|
1607
1607
|
observability.incrementCounter({
|
|
1608
1608
|
name: "opengeni_model_context_contributions_total",
|
|
1609
|
-
help: "
|
|
1609
|
+
help: "Agent Knowledge contributions exposed to a model, by bounded reason and authority.",
|
|
1610
1610
|
labels,
|
|
1611
1611
|
});
|
|
1612
1612
|
observability.observeHistogram({
|
|
1613
1613
|
name: "opengeni_model_context_contribution_estimated_tokens",
|
|
1614
|
-
help: "Estimated tokens per model-visible
|
|
1614
|
+
help: "Estimated tokens per model-visible Agent Knowledge contribution.",
|
|
1615
1615
|
buckets: MODEL_CONTEXT_CONTRIBUTION_TOKEN_BUCKETS,
|
|
1616
1616
|
labels,
|
|
1617
1617
|
value: contribution.estimatedTokens,
|
|
@@ -78,7 +78,8 @@ async function resolveStandaloneGitCredentials(
|
|
|
78
78
|
...(request.providerHost ? { providerHost: request.providerHost } : {}),
|
|
79
79
|
};
|
|
80
80
|
if (request.purpose === "identity") {
|
|
81
|
-
return authority.credentialKind === "github_app"
|
|
81
|
+
return authority.credentialKind === "github_app" ||
|
|
82
|
+
authority.credentialKind === "managed_github_app"
|
|
82
83
|
? {
|
|
83
84
|
...echoes,
|
|
84
85
|
identity: {
|
|
@@ -88,22 +89,35 @@ async function resolveStandaloneGitCredentials(
|
|
|
88
89
|
}
|
|
89
90
|
: echoes;
|
|
90
91
|
}
|
|
91
|
-
if (
|
|
92
|
+
if (
|
|
93
|
+
authority.credentialKind === "github_app" ||
|
|
94
|
+
authority.credentialKind === "managed_github_app"
|
|
95
|
+
) {
|
|
92
96
|
assertGitHubMintMatchesRepositoryRefs(request);
|
|
93
|
-
|
|
94
|
-
if (!encryptionKey || !authority.appId || !authority.credentialEncrypted) {
|
|
97
|
+
if (!authority.appId) {
|
|
95
98
|
throw new Error("PR Review GitHub App credential is unavailable");
|
|
96
99
|
}
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
100
|
+
const signingSettings =
|
|
101
|
+
authority.credentialKind === "managed_github_app"
|
|
102
|
+
? {
|
|
103
|
+
githubAppId: settings.prReviewGithubAppId,
|
|
104
|
+
githubAppPrivateKey: settings.prReviewGithubAppPrivateKey,
|
|
105
|
+
}
|
|
106
|
+
: manualPrReviewGitHubSigningSettings(settings, {
|
|
107
|
+
appId: authority.appId,
|
|
108
|
+
credentialEncrypted: authority.credentialEncrypted,
|
|
109
|
+
});
|
|
110
|
+
if (
|
|
111
|
+
authority.credentialKind === "managed_github_app" &&
|
|
112
|
+
settings.prReviewGithubAppId !== authority.appId
|
|
113
|
+
) {
|
|
114
|
+
throw new Error("OpenGeni Lens App identity no longer matches this registration");
|
|
115
|
+
}
|
|
116
|
+
const minted = await createGitHubAppInstallationTokenWithSigningSettings(signingSettings, {
|
|
117
|
+
installationId: request.installationId,
|
|
118
|
+
repositoryIds: request.repositoryIds,
|
|
119
|
+
permissions: { contents: "read", pull_requests: "write" },
|
|
120
|
+
});
|
|
107
121
|
return {
|
|
108
122
|
...echoes,
|
|
109
123
|
token: minted.token,
|
|
@@ -124,6 +138,20 @@ async function resolveStandaloneGitCredentials(
|
|
|
124
138
|
};
|
|
125
139
|
}
|
|
126
140
|
|
|
141
|
+
function manualPrReviewGitHubSigningSettings(
|
|
142
|
+
settings: Settings,
|
|
143
|
+
authority: { appId: string; credentialEncrypted: string | null },
|
|
144
|
+
) {
|
|
145
|
+
const encryptionKey = environmentsEncryptionKeyBytes(settings);
|
|
146
|
+
if (!encryptionKey || !authority.credentialEncrypted) {
|
|
147
|
+
throw new Error("PR Review GitHub App credential is unavailable");
|
|
148
|
+
}
|
|
149
|
+
return {
|
|
150
|
+
githubAppId: authority.appId,
|
|
151
|
+
githubAppPrivateKey: decryptVariableSetValue(encryptionKey, authority.credentialEncrypted),
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
127
155
|
function assertGitHubMintMatchesRepositoryRefs(request: GitCredentialsRequest): void {
|
|
128
156
|
const refs = request.repositoryRefs ?? [];
|
|
129
157
|
const repositoryIds = refs.map((reference) => positiveInteger(reference.repositoryId));
|