@opengeni/worker-bundle 0.17.2 → 0.20.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/activities/agent-run-admission.d.ts +12 -0
- package/dist/activities/agent-turn.d.ts +49 -1
- package/dist/activities/browser-state-artifact-reaper.d.ts +29 -0
- package/dist/activities/capabilities.d.ts +6 -0
- package/dist/activities/codex-capacity.d.ts +1 -0
- package/dist/activities/environment.d.ts +7 -1
- package/dist/activities/packs.d.ts +8 -10
- package/dist/activities/run-input.d.ts +8 -0
- package/dist/activities/session-state.d.ts +7 -3
- package/dist/activities/site-auth-maintenance.d.ts +27 -0
- package/dist/activities/types.d.ts +43 -0
- package/dist/activities/video-generation-admission.d.ts +9 -4
- package/dist/activities/video-generation-credential.d.ts +17 -0
- package/dist/activities/video-reference-staging.d.ts +7 -1
- package/dist/activities/xai-auth.d.ts +23 -0
- package/dist/activities/xai-image-generation.d.ts +26 -0
- package/dist/activities/xai-video-generation.d.ts +18 -0
- package/dist/{activities-control-44KBWLSM.js → activities-control-SMKF2OBE.js} +438 -55
- package/dist/activities-control-SMKF2OBE.js.map +1 -0
- package/dist/activities-control.d.ts +10 -2
- package/dist/{activities-turn-K4CEDEGJ.js → activities-turn-IDS3WEHA.js} +6704 -4847
- package/dist/activities-turn-IDS3WEHA.js.map +1 -0
- package/dist/activities.d.ts +11 -3
- package/dist/{chunk-E3RI3I33.js → chunk-N5TJIFCE.js} +156 -10
- package/dist/chunk-N5TJIFCE.js.map +1 -0
- package/dist/{chunk-KKCRGAGZ.js → chunk-P6Z2SLAA.js} +99 -98
- package/dist/chunk-P6Z2SLAA.js.map +1 -0
- package/dist/index.d.ts +14 -1
- package/dist/index.js +49 -2
- package/dist/index.js.map +1 -1
- package/dist/model-checkpoint-memory-collector.d.ts +1 -0
- package/dist/model-context-contributions.d.ts +40 -0
- package/dist/observability-metrics.d.ts +57 -1
- package/dist/sandbox-routing.d.ts +4 -0
- package/dist/workflow-bundle.js +232 -18
- package/dist/workflows/activities.d.ts +1 -1
- package/dist/workflows/session.d.ts +17 -1
- package/dist/workflows/site-auth-maintenance.d.ts +2 -0
- package/dist/workflows.d.ts +1 -0
- package/package.json +16 -15
- package/src/activities/agent-run-admission.ts +76 -0
- package/src/activities/agent-turn.ts +2777 -1241
- package/src/activities/browser-state-artifact-reaper.ts +120 -0
- package/src/activities/capabilities.ts +10 -0
- package/src/activities/codex-capacity.ts +48 -1
- package/src/activities/environment.ts +14 -8
- package/src/activities/goals.ts +2 -1
- package/src/activities/packs.ts +45 -122
- package/src/activities/parent-wake.ts +13 -1
- package/src/activities/run-input.ts +137 -45
- package/src/activities/scheduled-tasks.ts +30 -73
- package/src/activities/session-state.ts +87 -5
- package/src/activities/site-auth-maintenance.ts +269 -0
- package/src/activities/types.ts +44 -0
- package/src/activities/video-generation-admission.ts +37 -4
- package/src/activities/video-generation-credential.ts +84 -6
- package/src/activities/video-generation-reconciliation.ts +212 -19
- package/src/activities/video-media-validation.ts +8 -2
- package/src/activities/video-reference-staging.ts +121 -34
- package/src/activities/xai-auth.ts +122 -0
- package/src/activities/xai-image-generation.ts +86 -0
- package/src/activities/xai-video-generation.ts +69 -0
- package/src/activities-control.ts +4 -0
- package/src/activities.ts +7 -0
- package/src/index.ts +51 -0
- package/src/model-checkpoint-memory-collector.ts +8 -1
- package/src/model-context-contributions.ts +159 -0
- package/src/observability-metrics.ts +282 -12
- package/src/sandbox-routing.ts +13 -0
- package/src/workflows/activities.ts +1 -0
- package/src/workflows/file-upload-reaper.ts +8 -2
- package/src/workflows/session.ts +219 -14
- package/src/workflows/site-auth-maintenance.ts +14 -0
- package/src/workflows.ts +1 -0
- package/dist/activities-control-44KBWLSM.js.map +0 -1
- package/dist/activities-turn-K4CEDEGJ.js.map +0 -1
- package/dist/chunk-E3RI3I33.js.map +0 -1
- package/dist/chunk-KKCRGAGZ.js.map +0 -1
|
@@ -3,6 +3,7 @@ import { errorCodeToJSON } from "@opengeni/agent-proto";
|
|
|
3
3
|
import { SandboxBackend, type SessionEventType } from "@opengeni/contracts";
|
|
4
4
|
import type { EventLogger } from "@opengeni/events";
|
|
5
5
|
import type { Attributes, AttributeValue, Observability } from "@opengeni/observability";
|
|
6
|
+
import type { CompanyBrainContributionReceipt } from "./model-context-contributions";
|
|
6
7
|
import {
|
|
7
8
|
SELFHOSTED_INFRASTRUCTURE_FAULT_CLASSES,
|
|
8
9
|
modelUsageTokenCountOrNull,
|
|
@@ -175,7 +176,12 @@ export function selfhostedOpObserverForMetrics(hooks: RuntimeMetricsHooks): Self
|
|
|
175
176
|
/** A session-scoped `machine.op.*` event mapped from a completed-op observation. */
|
|
176
177
|
export type MachineOpSessionEvent = {
|
|
177
178
|
type: "machine.op.failed" | "machine.op.recovered";
|
|
178
|
-
payload: {
|
|
179
|
+
payload: {
|
|
180
|
+
op: string;
|
|
181
|
+
faultClass: string;
|
|
182
|
+
attempts: number;
|
|
183
|
+
machineId?: string;
|
|
184
|
+
};
|
|
179
185
|
};
|
|
180
186
|
|
|
181
187
|
/** Map an observation to a `machine.op.*` session event, or null if it is not
|
|
@@ -248,24 +254,34 @@ export function turnLifecycleMetricsFor(observability: Observability): TurnLifec
|
|
|
248
254
|
}
|
|
249
255
|
|
|
250
256
|
export class TurnLifecycleMetrics {
|
|
251
|
-
private readonly
|
|
257
|
+
private readonly turns = new Map<string, { startedAt: number; lastProgressAt: number }>();
|
|
252
258
|
private timer: ReturnType<typeof setInterval> | null = null;
|
|
253
259
|
|
|
254
260
|
constructor(
|
|
255
261
|
private readonly observability: Observability,
|
|
256
|
-
private readonly options: {
|
|
262
|
+
private readonly options: {
|
|
263
|
+
now?: () => number;
|
|
264
|
+
refreshIntervalMs?: number;
|
|
265
|
+
} = {},
|
|
257
266
|
) {}
|
|
258
267
|
|
|
259
268
|
start(turnId: string): void {
|
|
260
|
-
|
|
269
|
+
const now = this.now();
|
|
270
|
+
this.turns.set(turnId, { startedAt: now, lastProgressAt: now });
|
|
261
271
|
this.ensureTimer();
|
|
262
272
|
this.refreshGauges();
|
|
263
273
|
}
|
|
264
274
|
|
|
275
|
+
progress(turnId: string): void {
|
|
276
|
+
const turn = this.turns.get(turnId);
|
|
277
|
+
if (!turn) return;
|
|
278
|
+
turn.lastProgressAt = this.now();
|
|
279
|
+
}
|
|
280
|
+
|
|
265
281
|
finish(turnId: string, outcome: TurnOutcome | null, durationSeconds?: number): void {
|
|
266
|
-
const startedAt = this.
|
|
282
|
+
const startedAt = this.turns.get(turnId)?.startedAt;
|
|
267
283
|
if (startedAt !== undefined) {
|
|
268
|
-
this.
|
|
284
|
+
this.turns.delete(turnId);
|
|
269
285
|
}
|
|
270
286
|
if (outcome) {
|
|
271
287
|
const observedDuration =
|
|
@@ -284,7 +300,7 @@ export class TurnLifecycleMetrics {
|
|
|
284
300
|
});
|
|
285
301
|
}
|
|
286
302
|
this.refreshGauges();
|
|
287
|
-
if (this.
|
|
303
|
+
if (this.turns.size === 0) {
|
|
288
304
|
this.stopTimer();
|
|
289
305
|
}
|
|
290
306
|
}
|
|
@@ -293,32 +309,46 @@ export class TurnLifecycleMetrics {
|
|
|
293
309
|
this.observability.setGauge({
|
|
294
310
|
name: "opengeni_turns_inflight",
|
|
295
311
|
help: "Current number of in-flight agent turns in this worker process.",
|
|
296
|
-
value: this.
|
|
312
|
+
value: this.turns.size,
|
|
297
313
|
});
|
|
298
314
|
this.observability.setGauge({
|
|
299
315
|
name: "opengeni_turn_oldest_inflight_age_seconds",
|
|
300
316
|
help: "Age in seconds of the oldest in-flight agent turn in this worker process.",
|
|
301
317
|
value: this.oldestInflightAgeSeconds(),
|
|
302
318
|
});
|
|
319
|
+
this.observability.setGauge({
|
|
320
|
+
name: "opengeni_turn_oldest_no_progress_age_seconds",
|
|
321
|
+
help: "Seconds since durable progress for the least recently progressing in-flight turn.",
|
|
322
|
+
value: this.oldestNoProgressAgeSeconds(),
|
|
323
|
+
});
|
|
303
324
|
}
|
|
304
325
|
|
|
305
326
|
stop(): void {
|
|
306
|
-
this.
|
|
327
|
+
this.turns.clear();
|
|
307
328
|
this.refreshGauges();
|
|
308
329
|
this.stopTimer();
|
|
309
330
|
}
|
|
310
331
|
|
|
311
332
|
private oldestInflightAgeSeconds(): number {
|
|
312
|
-
if (this.
|
|
333
|
+
if (this.turns.size === 0) {
|
|
313
334
|
return 0;
|
|
314
335
|
}
|
|
315
336
|
let oldest = Number.POSITIVE_INFINITY;
|
|
316
|
-
for (const startedAt of this.
|
|
337
|
+
for (const { startedAt } of this.turns.values()) {
|
|
317
338
|
oldest = Math.min(oldest, startedAt);
|
|
318
339
|
}
|
|
319
340
|
return Math.max(0, (this.now() - oldest) / 1000);
|
|
320
341
|
}
|
|
321
342
|
|
|
343
|
+
private oldestNoProgressAgeSeconds(): number {
|
|
344
|
+
if (this.turns.size === 0) return 0;
|
|
345
|
+
let leastRecentProgress = Number.POSITIVE_INFINITY;
|
|
346
|
+
for (const { lastProgressAt } of this.turns.values()) {
|
|
347
|
+
leastRecentProgress = Math.min(leastRecentProgress, lastProgressAt);
|
|
348
|
+
}
|
|
349
|
+
return Math.max(0, (this.now() - leastRecentProgress) / 1000);
|
|
350
|
+
}
|
|
351
|
+
|
|
322
352
|
private ensureTimer(): void {
|
|
323
353
|
if (this.timer) {
|
|
324
354
|
return;
|
|
@@ -693,7 +723,11 @@ const RETAINED_PROCESS_OWNER_STATE_SET = new Set<string>(RETAINED_PROCESS_OWNER_
|
|
|
693
723
|
|
|
694
724
|
export function recordRetainedProcessInventoryGauges(
|
|
695
725
|
observability: Observability,
|
|
696
|
-
counts: Array<{
|
|
726
|
+
counts: Array<{
|
|
727
|
+
ownerState: string;
|
|
728
|
+
activeCount: number;
|
|
729
|
+
terminalOwnerCount: number;
|
|
730
|
+
}>,
|
|
697
731
|
): void {
|
|
698
732
|
const normalized = new Map<string, { active: number; terminal: number }>();
|
|
699
733
|
for (const ownerState of RETAINED_PROCESS_OWNER_STATES) {
|
|
@@ -806,6 +840,208 @@ export function recordCreditMicros(
|
|
|
806
840
|
});
|
|
807
841
|
}
|
|
808
842
|
|
|
843
|
+
const MODEL_REQUEST_PHASE_BUCKETS = [
|
|
844
|
+
0.005, 0.01, 0.025, 0.05, 0.1, 0.2, 0.35, 0.5, 1, 2, 5, 10, 30, 60, 300,
|
|
845
|
+
];
|
|
846
|
+
|
|
847
|
+
/**
|
|
848
|
+
* Record provider lifecycle diagnostics from the synchronous transport observer.
|
|
849
|
+
* Provider ids come from the resolved provider registry; phase/outcome are closed
|
|
850
|
+
* enums. This function never performs I/O outside the in-memory metrics registry.
|
|
851
|
+
*/
|
|
852
|
+
export function recordModelRequestPhase(
|
|
853
|
+
observability: Observability,
|
|
854
|
+
input: {
|
|
855
|
+
provider: string;
|
|
856
|
+
phase: "headers" | "first_byte" | "terminal";
|
|
857
|
+
outcome?: "completed" | "failed" | "timed_out";
|
|
858
|
+
durationSeconds: number;
|
|
859
|
+
},
|
|
860
|
+
): void {
|
|
861
|
+
const outcome = input.outcome ?? "";
|
|
862
|
+
observability.incrementCounter({
|
|
863
|
+
name: "opengeni_model_request_phases_total",
|
|
864
|
+
help: "Provider model-request lifecycle phases by bounded phase and outcome.",
|
|
865
|
+
labels: { provider: input.provider, phase: input.phase, outcome },
|
|
866
|
+
});
|
|
867
|
+
observability.observeHistogram({
|
|
868
|
+
name: "opengeni_model_request_phase_duration_seconds",
|
|
869
|
+
help: "Monotonic seconds from provider dispatch to a model-request lifecycle phase.",
|
|
870
|
+
buckets: MODEL_REQUEST_PHASE_BUCKETS,
|
|
871
|
+
labels: { provider: input.provider, phase: input.phase },
|
|
872
|
+
value: Math.max(0, input.durationSeconds),
|
|
873
|
+
});
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
export type TurnStartupPhase =
|
|
877
|
+
| "claim_and_policy"
|
|
878
|
+
| "turn_start_settlement"
|
|
879
|
+
| "credential_selection"
|
|
880
|
+
| "runtime_preparation"
|
|
881
|
+
| "sandbox_establish"
|
|
882
|
+
| "file_resolution"
|
|
883
|
+
| "tool_context_preparation"
|
|
884
|
+
| "tool_preparation"
|
|
885
|
+
| "tool_server_construction"
|
|
886
|
+
| "tool_required_connect"
|
|
887
|
+
| "tool_optional_connect"
|
|
888
|
+
| "tool_attempt_catalog_build"
|
|
889
|
+
| "tool_attempt_catalog_persist"
|
|
890
|
+
| "post_tool_preparation"
|
|
891
|
+
| "agent_construction"
|
|
892
|
+
| "post_agent_preparation"
|
|
893
|
+
| "file_materialization"
|
|
894
|
+
| "history_preparation"
|
|
895
|
+
| "history_system_update_load"
|
|
896
|
+
| "history_current_attachment_resolution"
|
|
897
|
+
| "history_durable_history_load"
|
|
898
|
+
| "history_sandbox_envelope_load"
|
|
899
|
+
| "history_canonical_projection"
|
|
900
|
+
| "history_provider_projection"
|
|
901
|
+
| "history_attachment_ref_projection"
|
|
902
|
+
| "history_screenshot_materialization"
|
|
903
|
+
| "history_model_attachment_projection"
|
|
904
|
+
| "history_runtime_input_assembly"
|
|
905
|
+
| "history_artifact_candidate_scan"
|
|
906
|
+
| "history_generated_image_materialization"
|
|
907
|
+
| "history_position_load"
|
|
908
|
+
| "owned_sandbox_setup"
|
|
909
|
+
| "provider_dispatch"
|
|
910
|
+
| "model_request_preparation"
|
|
911
|
+
| "model_sdk_serialization"
|
|
912
|
+
| "model_prepare_sandbox_agent_preparation"
|
|
913
|
+
| "model_prepare_sandbox_agent_manifest_inventory"
|
|
914
|
+
| "model_prepare_sandbox_session_manifest_inventory"
|
|
915
|
+
| "model_prepare_sandbox_manifest_apply"
|
|
916
|
+
| "model_prepare_sandbox_entry_materialization"
|
|
917
|
+
| "model_prepare_sandbox_running_check"
|
|
918
|
+
| "model_prepare_sandbox_start"
|
|
919
|
+
| "model_prepare_sandbox_client_create"
|
|
920
|
+
| "model_prepare_sandbox_client_resume"
|
|
921
|
+
| "model_prepare_sandbox_client_delete"
|
|
922
|
+
| "model_prepare_sandbox_client_state_serialize"
|
|
923
|
+
| "model_prepare_sandbox_client_reuse_check"
|
|
924
|
+
| "model_prepare_runner_before_mcp_tools"
|
|
925
|
+
| "model_prepare_mcp_tools_snapshot"
|
|
926
|
+
| "model_prepare_mcp_tools_before_input_filter"
|
|
927
|
+
| "model_prepare_input_filter_base"
|
|
928
|
+
| "model_prepare_input_filter_genesis"
|
|
929
|
+
| "model_prepare_input_filter_host"
|
|
930
|
+
| "model_prepare_input_filter_tool_output"
|
|
931
|
+
| "model_prepare_input_filter_modality"
|
|
932
|
+
| "model_prepare_input_filter_context"
|
|
933
|
+
| "model_prepare_responses_input_conversion"
|
|
934
|
+
| "model_prepare_responses_request_build"
|
|
935
|
+
| "model_credential_resolution"
|
|
936
|
+
| "model_wire_normalization"
|
|
937
|
+
| "model_request_audit"
|
|
938
|
+
| "stream_bootstrap";
|
|
939
|
+
|
|
940
|
+
export type TurnStartupOutcome = "completed" | "failed";
|
|
941
|
+
export type TurnStartupCache = "hit" | "miss" | "disabled" | "none";
|
|
942
|
+
export type TurnStartupCountBucket = "0" | "1" | "2-5" | "6-20" | "21+" | "unknown";
|
|
943
|
+
export type TurnSandboxEstablishPolicy = "eager" | "on-demand";
|
|
944
|
+
export type TurnSandboxEstablishReason =
|
|
945
|
+
| "eligible"
|
|
946
|
+
| "lazy_disabled"
|
|
947
|
+
| "machine_primary"
|
|
948
|
+
| "backend_none"
|
|
949
|
+
| "initial_run_credentials"
|
|
950
|
+
| "generated_video_files"
|
|
951
|
+
| "signed_file_resources";
|
|
952
|
+
|
|
953
|
+
const TURN_STARTUP_PHASE_BUCKETS = [
|
|
954
|
+
0.001, 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2, 5, 10, 30, 60, 120,
|
|
955
|
+
];
|
|
956
|
+
|
|
957
|
+
export function turnStartupCountBucket(count: number | null): TurnStartupCountBucket {
|
|
958
|
+
if (count === null || !Number.isFinite(count) || count < 0) return "unknown";
|
|
959
|
+
if (count === 0) return "0";
|
|
960
|
+
if (count === 1) return "1";
|
|
961
|
+
if (count <= 5) return "2-5";
|
|
962
|
+
if (count <= 20) return "6-20";
|
|
963
|
+
return "21+";
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
/**
|
|
967
|
+
* Measure the critical path from a durable turn start to provider dispatch.
|
|
968
|
+
* Every label is a closed or configuration-derived enum; high-cardinality turn,
|
|
969
|
+
* session, credential, connection, file, and model identifiers are forbidden.
|
|
970
|
+
*/
|
|
971
|
+
export function recordTurnStartupPhase(
|
|
972
|
+
observability: Observability,
|
|
973
|
+
input: {
|
|
974
|
+
phase: TurnStartupPhase;
|
|
975
|
+
provider: string;
|
|
976
|
+
backend: string;
|
|
977
|
+
outcome: TurnStartupOutcome;
|
|
978
|
+
durationSeconds: number;
|
|
979
|
+
count?: number | null;
|
|
980
|
+
cache?: TurnStartupCache;
|
|
981
|
+
},
|
|
982
|
+
): void {
|
|
983
|
+
observability.observeHistogram({
|
|
984
|
+
name: "opengeni_turn_startup_phase_duration_seconds",
|
|
985
|
+
help: "Turn startup phase duration before the model response stream begins.",
|
|
986
|
+
buckets: TURN_STARTUP_PHASE_BUCKETS,
|
|
987
|
+
labels: {
|
|
988
|
+
phase: input.phase,
|
|
989
|
+
provider: input.provider,
|
|
990
|
+
backend: input.backend,
|
|
991
|
+
outcome: input.outcome,
|
|
992
|
+
count_bucket: turnStartupCountBucket(input.count ?? null),
|
|
993
|
+
cache: input.cache ?? "none",
|
|
994
|
+
},
|
|
995
|
+
value: Math.max(0, input.durationSeconds),
|
|
996
|
+
});
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
/**
|
|
1000
|
+
* Explain why a turn did or did not keep provider sandbox work off the
|
|
1001
|
+
* pre-model critical path. The reason is a closed enum: never attach session,
|
|
1002
|
+
* sandbox, credential, or file identifiers here.
|
|
1003
|
+
*/
|
|
1004
|
+
export function recordTurnSandboxEstablishPolicy(
|
|
1005
|
+
observability: Observability,
|
|
1006
|
+
input: {
|
|
1007
|
+
policy: TurnSandboxEstablishPolicy;
|
|
1008
|
+
reason: TurnSandboxEstablishReason;
|
|
1009
|
+
backend: string;
|
|
1010
|
+
},
|
|
1011
|
+
): void {
|
|
1012
|
+
observability.incrementCounter({
|
|
1013
|
+
name: "opengeni_turn_sandbox_establish_policy_total",
|
|
1014
|
+
help: "Turn sandbox establish policy decisions by bounded reason.",
|
|
1015
|
+
labels: {
|
|
1016
|
+
policy: input.policy,
|
|
1017
|
+
reason: input.reason,
|
|
1018
|
+
backend: input.backend,
|
|
1019
|
+
},
|
|
1020
|
+
});
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
export function recordTurnWorkerPreparationTotal(
|
|
1024
|
+
observability: Observability,
|
|
1025
|
+
input: {
|
|
1026
|
+
provider: string;
|
|
1027
|
+
backend: string;
|
|
1028
|
+
outcome: TurnStartupOutcome;
|
|
1029
|
+
durationSeconds: number;
|
|
1030
|
+
},
|
|
1031
|
+
): void {
|
|
1032
|
+
observability.observeHistogram({
|
|
1033
|
+
name: "opengeni_turn_worker_preparation_duration_seconds",
|
|
1034
|
+
help: "Worker preparation from the durable turn-start boundary until entering the runtime; lazy SDK request preparation and model-request audit are separate phases.",
|
|
1035
|
+
buckets: TURN_STARTUP_PHASE_BUCKETS,
|
|
1036
|
+
labels: {
|
|
1037
|
+
provider: input.provider,
|
|
1038
|
+
backend: input.backend,
|
|
1039
|
+
outcome: input.outcome,
|
|
1040
|
+
},
|
|
1041
|
+
value: Math.max(0, input.durationSeconds),
|
|
1042
|
+
});
|
|
1043
|
+
}
|
|
1044
|
+
|
|
809
1045
|
// ── Streaming SLIs ────────────────────────────────────────────────────────────
|
|
810
1046
|
// Instruments the token-streaming pipeline so "streaming is sluggish" is a number,
|
|
811
1047
|
// not a vibe. Split across the three attributable stages so an operator can tell
|
|
@@ -992,6 +1228,40 @@ export function recordContextCompaction(observability: Observability, trigger: s
|
|
|
992
1228
|
});
|
|
993
1229
|
}
|
|
994
1230
|
|
|
1231
|
+
const MODEL_CONTEXT_CONTRIBUTION_TOKEN_BUCKETS = [1, 8, 32, 128, 512, 2_048, 8_192];
|
|
1232
|
+
|
|
1233
|
+
/**
|
|
1234
|
+
* Metadata-only Company Brain exposure telemetry. Labels are closed enums and
|
|
1235
|
+
* never include tenant ids, record ids, titles, descriptions, or content.
|
|
1236
|
+
*/
|
|
1237
|
+
export function recordCompanyBrainContributions(
|
|
1238
|
+
observability: Observability,
|
|
1239
|
+
receipt: CompanyBrainContributionReceipt,
|
|
1240
|
+
): void {
|
|
1241
|
+
for (const contribution of receipt.contributions) {
|
|
1242
|
+
const labels = {
|
|
1243
|
+
category: contribution.category,
|
|
1244
|
+
source: contribution.source,
|
|
1245
|
+
inclusion_reason: contribution.inclusionReason,
|
|
1246
|
+
authority_scope: contribution.authorityScope,
|
|
1247
|
+
session_role: receipt.sessionRole,
|
|
1248
|
+
memory_prompt_mode: receipt.memoryPromptMode,
|
|
1249
|
+
};
|
|
1250
|
+
observability.incrementCounter({
|
|
1251
|
+
name: "opengeni_model_context_contributions_total",
|
|
1252
|
+
help: "Company Brain contributions exposed to a model, by bounded reason and authority.",
|
|
1253
|
+
labels,
|
|
1254
|
+
});
|
|
1255
|
+
observability.observeHistogram({
|
|
1256
|
+
name: "opengeni_model_context_contribution_estimated_tokens",
|
|
1257
|
+
help: "Estimated tokens per model-visible Company Brain contribution.",
|
|
1258
|
+
buckets: MODEL_CONTEXT_CONTRIBUTION_TOKEN_BUCKETS,
|
|
1259
|
+
labels,
|
|
1260
|
+
value: contribution.estimatedTokens,
|
|
1261
|
+
});
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
|
|
995
1265
|
// ── Prompt-cache efficiency ─────────────────────────────────────────────────
|
|
996
1266
|
// Per model-call prompt-cache signal, provider-labelled only (bounded
|
|
997
1267
|
// cardinality — never a session id or account). `cached_tokens` is the slice of
|
package/src/sandbox-routing.ts
CHANGED
|
@@ -141,6 +141,8 @@ export type RoutingWiringIds = {
|
|
|
141
141
|
* manifest environment variables." Optional → the resolver defaults to `{}`.
|
|
142
142
|
*/
|
|
143
143
|
environment?: Record<string, string>;
|
|
144
|
+
/** Attempt-local values projected only onto Connected Machine child execs. */
|
|
145
|
+
transientExecEnvironment?: () => Readonly<Record<string, string>>;
|
|
144
146
|
/**
|
|
145
147
|
* Stage D machine-primary: PIN the already-established turn SelfhostedSession
|
|
146
148
|
* (the `established` arg's session) for THIS machine pointer `(sandboxId, epoch)`
|
|
@@ -721,6 +723,9 @@ export function wrapTurnBoxWithRouting(
|
|
|
721
723
|
// environment variables" throw when the turn pins to a vm). Mirrors the group
|
|
722
724
|
// box, which is created WITH this same environment (resumeBoxForTurn).
|
|
723
725
|
...(ids.environment !== undefined ? { environment: ids.environment } : {}),
|
|
726
|
+
...(ids.transientExecEnvironment !== undefined
|
|
727
|
+
? { transientExecEnvironment: ids.transientExecEnvironment }
|
|
728
|
+
: {}),
|
|
724
729
|
// Stage D machine-primary: pin THIS established SelfhostedSession for the machine
|
|
725
730
|
// pointer so the resolver returns the SAME instance (no two-instance manifest
|
|
726
731
|
// divergence). `established.session` is the SelfhostedSession the establish branch
|
|
@@ -907,6 +912,9 @@ export function wrapLazyTurnBoxWithRouting(
|
|
|
907
912
|
...selfhostedResolverTimeouts(settings),
|
|
908
913
|
...(onOp !== undefined ? { selfhostedOnOp: onOp } : {}),
|
|
909
914
|
...(ids.environment !== undefined ? { environment: ids.environment } : {}),
|
|
915
|
+
...(ids.transientExecEnvironment !== undefined
|
|
916
|
+
? { transientExecEnvironment: ids.transientExecEnvironment }
|
|
917
|
+
: {}),
|
|
910
918
|
});
|
|
911
919
|
|
|
912
920
|
const proxy = new RoutingSandboxSession({
|
|
@@ -1022,6 +1030,8 @@ export type SelfhostedTurnSessionArgs = {
|
|
|
1022
1030
|
* the manifest), threaded so the SDK's per-turn provided-session env delta is
|
|
1023
1031
|
* empty. */
|
|
1024
1032
|
environment: Record<string, string>;
|
|
1033
|
+
/** Attempt-local values projected only onto this machine's child execs. */
|
|
1034
|
+
transientExecEnvironment?: () => Readonly<Record<string, string>>;
|
|
1025
1035
|
/** The session working directory (per-session pointer). Null ⇒ workspace_root. */
|
|
1026
1036
|
workingDir: string | null;
|
|
1027
1037
|
};
|
|
@@ -1078,6 +1088,9 @@ export async function establishSelfhostedTurnSession(
|
|
|
1078
1088
|
controlRpcFactory: controlRpcFactory(bus),
|
|
1079
1089
|
epoch: args.epoch,
|
|
1080
1090
|
environment: args.environment,
|
|
1091
|
+
...(args.transientExecEnvironment !== undefined
|
|
1092
|
+
? { transientExecEnvironment: args.transientExecEnvironment }
|
|
1093
|
+
: {}),
|
|
1081
1094
|
workingDir: args.workingDir,
|
|
1082
1095
|
// Give this turn's exec ops the long deadline (control ops stay short) so a real
|
|
1083
1096
|
// command is not killed at the control wall.
|
|
@@ -2,8 +2,13 @@ import { proxyActivities } from "@temporalio/workflow";
|
|
|
2
2
|
import type * as activities from "../activities";
|
|
3
3
|
|
|
4
4
|
const reaperActivity = proxyActivities<
|
|
5
|
-
Pick<
|
|
6
|
-
|
|
5
|
+
Pick<
|
|
6
|
+
typeof activities,
|
|
7
|
+
| "reapExpiredFileUploads"
|
|
8
|
+
| "maintainRetainedScreenshots"
|
|
9
|
+
| "maintainBrowserStateArtifacts"
|
|
10
|
+
| "recoverVideoGenerationWorkflows"
|
|
11
|
+
>
|
|
7
12
|
>({
|
|
8
13
|
startToCloseTimeout: "5 minutes",
|
|
9
14
|
retry: { maximumAttempts: 1 },
|
|
@@ -13,5 +18,6 @@ const reaperActivity = proxyActivities<
|
|
|
13
18
|
export async function fileUploadReaperWorkflow(): Promise<void> {
|
|
14
19
|
await reaperActivity.reapExpiredFileUploads();
|
|
15
20
|
await reaperActivity.maintainRetainedScreenshots();
|
|
21
|
+
await reaperActivity.maintainBrowserStateArtifacts();
|
|
16
22
|
await reaperActivity.recoverVideoGenerationWorkflows();
|
|
17
23
|
}
|