@opengeni/worker-bundle 0.23.4 → 0.24.2-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/admission.d.ts +17 -2
- package/dist/activities/agent-turn/claim.d.ts +1 -0
- package/dist/activities/agent-turn/codex.d.ts +2 -2
- package/dist/activities/agent-turn/list-models.d.ts +16 -0
- package/dist/activities/agent-turn/model-usage.d.ts +15 -1
- package/dist/activities/agent-turn/quiescence.d.ts +2 -0
- package/dist/activities/agent-turn/run.d.ts +9 -0
- package/dist/activities/agent-turn/sandbox-runtime.d.ts +15 -0
- package/dist/activities/agent-turn/session-title.d.ts +21 -0
- package/dist/activities/agent-turn/stream-attempt.d.ts +4 -0
- package/dist/activities/agent-turn/tool-environment.d.ts +2 -0
- package/dist/activities/agent-turn/tool-policy.d.ts +36 -5
- package/dist/activities/agent-turn/turn-context.d.ts +4 -1
- package/dist/activities/agent-turn.d.ts +1 -1
- package/dist/activities/automations.d.ts +1 -0
- package/dist/activities/capabilities.d.ts +3 -1
- package/dist/activities/context-compaction.d.ts +2 -0
- package/dist/activities/goals.d.ts +11 -0
- package/dist/activities/image-generation-references.d.ts +2 -1
- package/dist/activities/scheduled-tasks.d.ts +1 -0
- package/dist/activities/types.d.ts +8 -0
- package/dist/{activities-control-52W5IDWM.js → activities-control-ZWH7J4KZ.js} +297 -180
- package/dist/activities-control-ZWH7J4KZ.js.map +1 -0
- package/dist/activities-control.d.ts +2 -0
- package/dist/{activities-turn-A2G2KLSY.js → activities-turn-I4OPLQLS.js} +898 -333
- package/dist/activities-turn-I4OPLQLS.js.map +1 -0
- package/dist/activities.d.ts +2 -0
- package/dist/{chunk-GFNXVZVQ.js → chunk-65JEWP2Q.js} +107 -7
- package/dist/chunk-65JEWP2Q.js.map +1 -0
- package/dist/{chunk-GRFQTTSQ.js → chunk-GDCLDKSH.js} +7 -3
- package/dist/{chunk-GRFQTTSQ.js.map → chunk-GDCLDKSH.js.map} +1 -1
- package/dist/{chunk-IPVMCAW5.js → chunk-RQNH6CGR.js} +111 -62
- package/dist/chunk-RQNH6CGR.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +43 -7
- package/dist/index.js.map +1 -1
- package/dist/observability-metrics.d.ts +34 -7
- package/dist/sandbox-reaper-timeout.d.ts +2 -2
- package/dist/sandbox-resume.d.ts +6 -1
- package/dist/workflow-bundle.js +26 -3
- package/dist/workflows/activities.d.ts +5 -0
- package/dist/workflows/automations.d.ts +5 -0
- package/package.json +17 -17
- package/src/activities/agent-run-admission.ts +7 -1
- package/src/activities/agent-turn/admission.ts +47 -6
- package/src/activities/agent-turn/claim.ts +33 -5
- package/src/activities/agent-turn/codex.ts +2 -2
- package/src/activities/agent-turn/compaction-prep.ts +8 -1
- package/src/activities/agent-turn/finalization.ts +31 -17
- package/src/activities/agent-turn/list-models.ts +101 -0
- package/src/activities/agent-turn/model-usage.ts +120 -45
- package/src/activities/agent-turn/quiescence.ts +11 -2
- package/src/activities/agent-turn/run.ts +80 -4
- package/src/activities/agent-turn/sandbox-runtime.ts +78 -81
- package/src/activities/agent-turn/session-title.ts +55 -2
- package/src/activities/agent-turn/stream-attempt.ts +266 -135
- package/src/activities/agent-turn/tool-environment.ts +102 -7
- package/src/activities/agent-turn/tool-policy.ts +58 -5
- package/src/activities/agent-turn/turn-context.ts +8 -2
- package/src/activities/agent-turn.ts +5 -1
- package/src/activities/api-integrations.ts +11 -1
- package/src/activities/automations.ts +122 -67
- package/src/activities/capabilities.ts +129 -2
- package/src/activities/context-compaction.ts +3 -0
- package/src/activities/goals.ts +108 -31
- package/src/activities/image-generation-references.ts +9 -9
- package/src/activities/mcp-credentials.ts +53 -0
- package/src/activities/rig-verification.ts +5 -3
- package/src/activities/scheduled-tasks.ts +217 -110
- package/src/activities/site-auth-maintenance.ts +12 -12
- package/src/activities/types.ts +6 -0
- package/src/activities.ts +1 -0
- package/src/activity-services.ts +4 -1
- package/src/github-rest-mcp.ts +2 -1
- package/src/index.ts +34 -4
- package/src/observability-metrics.ts +154 -14
- package/src/sandbox-reaper-timeout.ts +10 -4
- package/src/sandbox-resume.ts +58 -8
- package/src/workflows/activities.ts +15 -0
- package/src/workflows/automations.ts +21 -2
- package/dist/activities-control-52W5IDWM.js.map +0 -1
- package/dist/activities-turn-A2G2KLSY.js.map +0 -1
- package/dist/chunk-GFNXVZVQ.js.map +0 -1
- package/dist/chunk-IPVMCAW5.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/concurrency.ts","../src/sandbox-reaper-contract.ts","../src/sandbox-reaper-timeout.ts"],"sourcesContent":["import type { Settings } from \"@opengeni/config\";\nimport type { Observability } from \"@opengeni/observability\";\nimport { readFileSync } from \"node:fs\";\nimport type {\n ActivitySlotInfo,\n CustomSlotSupplier,\n SlotMarkUsedContext,\n SlotPermit,\n SlotReleaseContext,\n SlotReserveContext,\n WorkerOptions,\n WorkerTuner,\n} from \"@temporalio/worker\";\n\nconst MIB = 1024 * 1024;\n\n/**\n * Default fixed/HPA turn-worker admission contract. The configured fixed-mode\n * ceiling may be lower, but every live Temporal permit reserves the complete\n * hard budget until the runAgentTurn activity promise physically completes.\n */\nexport const TURN_WORKER_MAX_CONCURRENT_TURNS = 16;\nexport const TURN_WORKER_HARD_MEMORY_BYTES_PER_TURN = 100 * MIB;\nexport const TURN_WORKER_NATIVE_HEADROOM_BYTES = 512 * MIB;\n\nexport type TurnWorkerConcurrencySettings = Pick<\n Settings,\n | \"turnWorkerConcurrencyMode\"\n | \"turnWorkerMaxConcurrentTurns\"\n | \"turnWorkerTargetCpuUsage\"\n | \"turnWorkerTargetMemoryUsage\"\n>;\n\nexport type TurnWorkerConcurrencyOptions = Pick<\n WorkerOptions,\n \"maxConcurrentActivityTaskExecutions\" | \"tuner\"\n>;\n\n/**\n * Fixed profiles keep a per-process ceiling. Resource-aware profiles retain a\n * hard per-process maximum while Temporal meters new activity admission against\n * cgroup/host CPU and memory. The ramp lets usage become visible before a burst\n * can reserve the entire ceiling.\n */\nexport function turnWorkerConcurrencyOptions(\n settings: TurnWorkerConcurrencySettings,\n): TurnWorkerConcurrencyOptions {\n if (settings.turnWorkerConcurrencyMode === \"fixed\") {\n return {\n maxConcurrentActivityTaskExecutions: settings.turnWorkerMaxConcurrentTurns,\n };\n }\n\n return {\n tuner: {\n tunerOptions: {\n targetCpuUsage: settings.turnWorkerTargetCpuUsage,\n targetMemoryUsage: settings.turnWorkerTargetMemoryUsage,\n },\n activityTaskSlotOptions: {\n minimumSlots: 1,\n maximumSlots: settings.turnWorkerMaxConcurrentTurns,\n rampThrottle: \"250ms\",\n },\n },\n };\n}\n\nexport type TurnWorkerConcurrencyPlan = {\n options: TurnWorkerConcurrencyOptions;\n admission: MemoryAwareTurnSlotSupplier | null;\n};\n\n/**\n * Build the runtime concurrency policy for a turn worker.\n *\n * Fixed/HPA deployments use the hard-reservation supplier below. The explicit\n * non-HA single-machine profile keeps Temporal's native CPU/memory resource\n * tuner because it controls whole-machine load rather than a pod cgroup; that\n * profile documents that its configured maximum is not a per-turn reservation.\n */\nexport function createTurnWorkerConcurrencyPlan(\n settings: TurnWorkerConcurrencySettings,\n options: Omit<TurnAdmissionOptions, \"maximumTurns\"> = {},\n): TurnWorkerConcurrencyPlan {\n if (settings.turnWorkerConcurrencyMode === \"resource-based\") {\n return {\n options: turnWorkerConcurrencyOptions(settings),\n admission: null,\n };\n }\n\n const fixed = createTurnWorkerTuner({\n ...options,\n maximumTurns: settings.turnWorkerMaxConcurrentTurns,\n });\n return {\n options: { tuner: fixed.tuner },\n admission: fixed.admission,\n };\n}\n\nexport function turnWorkerConcurrencyLogFields(settings: TurnWorkerConcurrencySettings): {\n concurrencyMode: \"fixed\" | \"resource-based\";\n maxConcurrentTurns: number;\n targetCpuUsage: number | null;\n targetMemoryUsage: number | null;\n} {\n const resourceBased = settings.turnWorkerConcurrencyMode === \"resource-based\";\n return {\n concurrencyMode: settings.turnWorkerConcurrencyMode,\n maxConcurrentTurns: settings.turnWorkerMaxConcurrentTurns,\n targetCpuUsage: resourceBased ? settings.turnWorkerTargetCpuUsage : null,\n targetMemoryUsage: resourceBased ? settings.turnWorkerTargetMemoryUsage : null,\n };\n}\n\nexport const CONTROL_WORKER_MAX_CONCURRENT_ACTIVITIES = 32;\nexport const CONTROL_WORKER_MAX_CONCURRENT_WORKFLOW_TASKS = 40;\n\nconst CGROUP_MEMORY_FILES = [\n {\n limit: \"/sys/fs/cgroup/memory.max\",\n current: \"/sys/fs/cgroup/memory.current\",\n },\n {\n limit: \"/sys/fs/cgroup/memory/memory.limit_in_bytes\",\n current: \"/sys/fs/cgroup/memory/memory.usage_in_bytes\",\n },\n] as const;\n\n// cgroup v1 uses enormous sentinels for \"unlimited\". Values this large are\n// host capacity rather than a meaningful container admission boundary.\nconst UNLIMITED_CGROUP_BYTES = 1n << 60n;\n\nexport type CgroupMemorySnapshot = {\n currentBytes: number;\n limitBytes: number | null;\n source: \"cgroup-v1\" | \"cgroup-v2\" | \"process\";\n};\n\nexport type TurnAdmissionSnapshot = {\n baselineBytes: number;\n currentBytes: number;\n limitBytes: number | null;\n hardBytesPerTurn: number;\n nativeHeadroomBytes: number;\n maximumTurns: number;\n memoryBoundCapacity: number;\n reservedSlots: number;\n usedSlots: number;\n availableSlots: number;\n};\n\nexport type TurnAdmissionOptions = {\n maximumTurns?: number;\n hardBytesPerTurn?: number;\n nativeHeadroomBytes?: number;\n memorySnapshot?: () => CgroupMemorySnapshot;\n retryDelayMs?: number;\n observability?: Observability;\n};\n\ntype TurnSlotPermit = SlotPermit & {\n readonly owner: symbol;\n used: boolean;\n};\n\n/**\n * Temporal custom activity-slot supplier for turn workers.\n *\n * A permit is required before Temporal polls a task. Reservation is allowed\n * only when both independent safety checks pass:\n *\n * baseline + reserved-after × hard-turn-budget + native headroom <= limit\n * current + reserved-after × hard-turn-budget + native headroom <= limit\n *\n * The first check enforces the release contract even when current RSS happens\n * to be low. The second accounts for native/retained memory observed after\n * startup and keeps the complete hard budget reserved for every live permit.\n * A used permit is not evidence that its allocation is already visible in the\n * cgroup, and unrelated native growth cannot safely be attributed to a turn.\n * Kubernetes OOM is never an admission mechanism.\n */\nexport class MemoryAwareTurnSlotSupplier implements CustomSlotSupplier<ActivitySlotInfo> {\n readonly type = \"custom\" as const;\n\n private readonly owner = Symbol(\"opengeni-turn-admission\");\n private readonly permits = new Set<TurnSlotPermit>();\n private baselineBytes: number;\n private readonly maximumTurns: number;\n private readonly hardBytesPerTurn: number;\n private readonly nativeHeadroomBytes: number;\n private readonly memorySnapshot: () => CgroupMemorySnapshot;\n private readonly retryDelayMs: number;\n private readonly observability: Observability | undefined;\n\n constructor(options: TurnAdmissionOptions = {}) {\n this.maximumTurns = positiveInteger(\n \"maximumTurns\",\n options.maximumTurns ?? TURN_WORKER_MAX_CONCURRENT_TURNS,\n );\n this.hardBytesPerTurn = positiveInteger(\n \"hardBytesPerTurn\",\n options.hardBytesPerTurn ?? TURN_WORKER_HARD_MEMORY_BYTES_PER_TURN,\n );\n this.nativeHeadroomBytes = nonnegativeInteger(\n \"nativeHeadroomBytes\",\n options.nativeHeadroomBytes ?? TURN_WORKER_NATIVE_HEADROOM_BYTES,\n );\n this.retryDelayMs = positiveInteger(\"retryDelayMs\", options.retryDelayMs ?? 100);\n this.memorySnapshot = options.memorySnapshot ?? readCgroupMemorySnapshot;\n this.observability = options.observability;\n const initial = this.memorySnapshot();\n this.baselineBytes = initial.currentBytes;\n if (initial.limitBytes !== null && this.memoryBoundCapacity(initial.limitBytes) < 1) {\n throw new Error(\n \"Turn worker memory limit cannot safely admit one turn: \" +\n `baseline=${this.baselineBytes} hardTurn=${this.hardBytesPerTurn} ` +\n `nativeHeadroom=${this.nativeHeadroomBytes} limit=${initial.limitBytes}`,\n );\n }\n this.refreshMetrics(initial);\n }\n\n async reserveSlot(_ctx: SlotReserveContext, abortSignal: AbortSignal): Promise<SlotPermit> {\n for (;;) {\n if (abortSignal.aborted) throw abortError();\n const permit = this.reserveIfSafe();\n if (permit) return permit;\n await abortableDelay(this.retryDelayMs, abortSignal);\n }\n }\n\n tryReserveSlot(_ctx: SlotReserveContext): SlotPermit | null {\n return this.reserveIfSafe();\n }\n\n markSlotUsed(ctx: SlotMarkUsedContext<ActivitySlotInfo>): void {\n const permit = this.ownedPermit(ctx.permit);\n permit.used = true;\n this.refreshMetrics();\n }\n\n releaseSlot(ctx: SlotReleaseContext<ActivitySlotInfo>): void {\n const permit = this.ownedPermit(ctx.permit);\n this.permits.delete(permit);\n this.refreshMetrics();\n }\n\n snapshot(memory = this.memorySnapshot()): TurnAdmissionSnapshot {\n const usedSlots = this.usedSlots();\n const reservedSlots = this.permits.size;\n const availableSlots = this.availableSlots(memory);\n // Never report less capacity than work already admitted. The dynamic\n // denominator is exactly reserved + what a new poll could reserve now.\n const memoryBoundCapacity = reservedSlots + availableSlots;\n return {\n baselineBytes: this.baselineBytes,\n currentBytes: memory.currentBytes,\n limitBytes: memory.limitBytes,\n hardBytesPerTurn: this.hardBytesPerTurn,\n nativeHeadroomBytes: this.nativeHeadroomBytes,\n maximumTurns: this.maximumTurns,\n memoryBoundCapacity,\n reservedSlots,\n usedSlots,\n availableSlots,\n };\n }\n\n /**\n * Finalize the admission baseline after Temporal/native construction.\n * Worker.create can retain memory after the constructor's provisional\n * sample. That initialization delta must remain in the baseline for every\n * later projection rather than competing with turn reservations.\n */\n finalizeStartupBaseline(): void {\n const memory = this.memorySnapshot();\n if (this.permits.size !== 0) {\n throw new Error(\"Turn worker startup admission check ran after slot reservation\");\n }\n const finalizedBaselineBytes = memory.currentBytes;\n const finalizedCapacity =\n memory.limitBytes === null\n ? this.maximumTurns\n : this.memoryBoundCapacity(memory.limitBytes, finalizedBaselineBytes);\n if (memory.limitBytes !== null && finalizedCapacity < 1) {\n throw new Error(\n \"Turn worker memory limit cannot safely admit one turn after worker initialization: \" +\n `provisionalBaseline=${this.baselineBytes} finalizedBaseline=${finalizedBaselineBytes} ` +\n `hardTurn=${this.hardBytesPerTurn} nativeHeadroom=${this.nativeHeadroomBytes} ` +\n `limit=${String(memory.limitBytes)}`,\n );\n }\n this.baselineBytes = finalizedBaselineBytes;\n this.refreshMetrics(memory);\n }\n\n private reserveIfSafe(): TurnSlotPermit | null {\n const memory = this.memorySnapshot();\n if (this.permits.size >= this.maximumTurns || !this.memoryAllowsAnother(memory)) {\n this.refreshMetrics(memory);\n return null;\n }\n const permit: TurnSlotPermit = { owner: this.owner, used: false };\n this.permits.add(permit);\n this.refreshMetrics(memory);\n return permit;\n }\n\n private memoryAllowsAnother(memory: CgroupMemorySnapshot): boolean {\n return this.availableSlots(memory) > 0;\n }\n\n private availableSlots(memory: CgroupMemorySnapshot): number {\n const densityRemaining = this.maximumTurns - this.permits.size;\n if (memory.limitBytes === null) return Math.max(0, densityRemaining);\n\n const baselineRemaining = this.memoryBoundCapacity(memory.limitBytes) - this.permits.size;\n const observedRemaining =\n Math.floor(\n (memory.limitBytes - memory.currentBytes - this.nativeHeadroomBytes) /\n this.hardBytesPerTurn,\n ) - this.permits.size;\n return Math.max(0, Math.min(densityRemaining, baselineRemaining, observedRemaining));\n }\n\n private memoryBoundCapacity(limitBytes: number, baselineBytes = this.baselineBytes): number {\n return Math.max(\n 0,\n Math.floor((limitBytes - baselineBytes - this.nativeHeadroomBytes) / this.hardBytesPerTurn),\n );\n }\n\n private usedSlots(): number {\n let used = 0;\n for (const permit of this.permits) {\n if (permit.used) used += 1;\n }\n return used;\n }\n\n private ownedPermit(permit: SlotPermit): TurnSlotPermit {\n const candidate = permit as Partial<TurnSlotPermit>;\n if (candidate.owner !== this.owner || !this.permits.has(permit as TurnSlotPermit)) {\n throw new Error(\"Temporal returned a turn slot permit owned by another supplier\");\n }\n return permit as TurnSlotPermit;\n }\n\n private refreshMetrics(memory = this.memorySnapshot()): void {\n if (!this.observability) return;\n const value = this.snapshot(memory);\n const set = (name: string, help: string, metricValue: number) =>\n this.observability?.setGauge({ name, help, value: metricValue });\n set(\n \"opengeni_turn_slots_capacity\",\n \"Turn slots this worker can safely support after the hard memory contract.\",\n value.memoryBoundCapacity,\n );\n set(\n \"opengeni_turn_slots_reserved\",\n \"Temporal turn activity slots reserved for polling or execution in this worker.\",\n value.reservedSlots,\n );\n set(\n \"opengeni_turn_slots_used\",\n \"Temporal turn activity slots currently executing in this worker.\",\n value.usedSlots,\n );\n set(\n \"opengeni_turn_slots_available\",\n \"Memory-safe turn activity slots still available to reserve in this worker.\",\n value.availableSlots,\n );\n set(\n \"opengeni_turn_slot_saturation_ratio\",\n \"Fraction of this worker's memory-safe turn capacity currently executing.\",\n value.memoryBoundCapacity === 0 ? 1 : value.usedSlots / value.memoryBoundCapacity,\n );\n set(\n \"opengeni_turn_admission_memory_baseline_bytes\",\n \"Turn-worker cgroup memory after Temporal/native worker initialization.\",\n value.baselineBytes,\n );\n set(\n \"opengeni_turn_admission_memory_current_bytes\",\n \"Current cgroup memory used for turn admission decisions.\",\n value.currentBytes,\n );\n set(\n \"opengeni_turn_admission_memory_limit_bytes\",\n \"Finite cgroup memory limit used for turn admission, or zero when unlimited.\",\n value.limitBytes ?? 0,\n );\n set(\n \"opengeni_turn_admission_hard_bytes_per_turn\",\n \"Hard incremental memory budget reserved for each admitted turn.\",\n value.hardBytesPerTurn,\n );\n set(\n \"opengeni_turn_admission_native_headroom_bytes\",\n \"Cgroup memory retained for runtime, native, and GC headroom.\",\n value.nativeHeadroomBytes,\n );\n }\n}\n\nexport function createTurnWorkerTuner(options: TurnAdmissionOptions = {}): {\n tuner: WorkerTuner;\n admission: MemoryAwareTurnSlotSupplier;\n} {\n const admission = new MemoryAwareTurnSlotSupplier(options);\n return {\n admission,\n tuner: {\n workflowTaskSlotSupplier: { type: \"fixed-size\", numSlots: 1 },\n activityTaskSlotSupplier: admission,\n localActivityTaskSlotSupplier: { type: \"fixed-size\", numSlots: 1 },\n nexusTaskSlotSupplier: { type: \"fixed-size\", numSlots: 1 },\n },\n };\n}\n\nexport function readCgroupMemorySnapshot(): CgroupMemorySnapshot {\n for (const [index, files] of CGROUP_MEMORY_FILES.entries()) {\n const limitRaw = readCgroupText(files.limit);\n const currentRaw = readCgroupText(files.current);\n if (limitRaw === null && currentRaw === null) continue;\n if (limitRaw === null || currentRaw === null) {\n throw new Error(\n `Incomplete cgroup memory controller: limit=${files.limit} current=${files.current}`,\n );\n }\n return {\n currentBytes: parseCgroupCurrentValue(currentRaw),\n limitBytes: parseCgroupLimitValue(limitRaw),\n source: index === 0 ? \"cgroup-v2\" : \"cgroup-v1\",\n };\n }\n return {\n currentBytes: process.memoryUsage().rss,\n limitBytes: null,\n source: \"process\",\n };\n}\n\nexport function parseCgroupLimitValue(value: string): number | null {\n if (value.trim() === \"max\") return null;\n const parsed = parseCgroupBigInt(value);\n if (parsed === null || parsed <= 0n) {\n throw new Error(`Malformed finite cgroup memory limit: ${JSON.stringify(value.trim())}`);\n }\n if (parsed >= UNLIMITED_CGROUP_BYTES) return null;\n const number = Number(parsed);\n if (!Number.isSafeInteger(number)) {\n throw new Error(\n `Finite cgroup memory limit exceeds JavaScript's safe integer range: ${parsed}`,\n );\n }\n return number;\n}\n\nexport function parseCgroupCurrentValue(value: string): number {\n const parsed = parseCgroupBigInt(value);\n if (parsed === null || parsed < 0n) {\n throw new Error(`Malformed cgroup current memory value: ${JSON.stringify(value.trim())}`);\n }\n const number = Number(parsed);\n if (!Number.isSafeInteger(number)) {\n throw new Error(`Cgroup current memory exceeds JavaScript's safe integer range: ${parsed}`);\n }\n return number;\n}\n\nfunction parseCgroupBigInt(value: string): bigint | null {\n try {\n return BigInt(value.trim());\n } catch {\n return null;\n }\n}\n\nfunction readCgroupText(path: string): string | null {\n try {\n return readFileSync(path, \"utf8\");\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === \"ENOENT\") return null;\n throw new Error(\n `Unable to read present cgroup memory controller file ${path}: ${\n error instanceof Error ? error.message : String(error)\n }`,\n { cause: error },\n );\n }\n}\n\nfunction positiveInteger(name: string, value: number): number {\n if (!Number.isSafeInteger(value) || value <= 0) {\n throw new Error(`${name} must be a positive integer`);\n }\n return value;\n}\n\nfunction nonnegativeInteger(name: string, value: number): number {\n if (!Number.isSafeInteger(value) || value < 0) {\n throw new Error(`${name} must be a non-negative integer`);\n }\n return value;\n}\n\nfunction abortError(): DOMException {\n return new DOMException(\"Turn slot reservation aborted\", \"AbortError\");\n}\n\nfunction abortableDelay(milliseconds: number, signal: AbortSignal): Promise<void> {\n return new Promise((resolve, reject) => {\n if (signal.aborted) {\n reject(abortError());\n return;\n }\n const timer = setTimeout(() => {\n signal.removeEventListener(\"abort\", onAbort);\n resolve();\n }, milliseconds);\n timer.unref?.();\n const onAbort = () => {\n clearTimeout(timer);\n reject(abortError());\n };\n signal.addEventListener(\"abort\", onAbort, { once: true });\n });\n}\n\n// Session workflows finish at idle boundaries and replay from durable history.\n// Bound sticky VM state explicitly: the SDK otherwise derives this from the\n// host heap limit (roughly 600 cached workflows/GiB), which is far above this\n// process's actual concurrent workflow-task capacity and permanently retains\n// idle workflow state in every control replica.\nexport const CONTROL_WORKER_MAX_CACHED_WORKFLOWS = 64;\n","export const SANDBOX_REAPER_SCAN_ACTIVITY_TIMEOUT_MS = 5 * 60_000;\nexport const SANDBOX_DRAIN_FAST_ACTIVITY_TIMEOUT_MS = 5 * 60_000;\nexport const SANDBOX_DRAIN_EXTENDED_ACTIVITY_TIMEOUT_MS = 65 * 60_000;\nexport const SANDBOX_DRAIN_SETTLEMENT_MARGIN_MS = 60_000;\nexport const SANDBOX_REAPER_ACTIVITY_HEARTBEAT_TIMEOUT_MS = 20_000;\nexport const SANDBOX_REAPER_ACTIVITY_HEARTBEAT_INTERVAL_MS = 5_000;\n// Match the DB inventory's fair 500-row bound so one sweep never discovers a\n// due box and then needlessly defers it for another schedule period. Five\n// hundred small StartChild commands remain far below Temporal history limits;\n// actual provider I/O stays bounded by worker activity concurrency.\nexport const SANDBOX_REAPER_CHILD_DISPATCH_LIMIT = 500;\nexport const SANDBOX_REAPER_V2_WORKFLOW_ID = \"opengeni-sandbox-lease-reaper-v2\";\nexport const SANDBOX_REAPER_MAINTENANCE_WORKFLOW_ID = \"opengeni-sandbox-lease-maintenance-v1\";\n\n// A protocol-specific queue is the rolling-deploy compatibility boundary for\n// the split reaper activities. An old control worker polls only the base queue,\n// so it can replay already-started legacy workflows but can never receive a new\n// activity type that its binary does not register.\nexport const SANDBOX_LIFECYCLE_TASK_QUEUE_SUFFIX = \"-sandbox-lifecycle-v1\";\n\nexport function sandboxLifecycleTaskQueue(baseTaskQueue: string): string {\n return baseTaskQueue.endsWith(SANDBOX_LIFECYCLE_TASK_QUEUE_SUFFIX)\n ? baseTaskQueue\n : `${baseTaskQueue}${SANDBOX_LIFECYCLE_TASK_QUEUE_SUFFIX}`;\n}\n\nexport type SandboxDrainTimeoutClass = \"fast\" | \"extended\";\n\nexport type SandboxDrainTarget = {\n workspaceId: string;\n sandboxGroupId: string;\n instanceId: string | null;\n leaseEpoch: number;\n};\n\nexport type SandboxDrainActivityInput = {\n target: SandboxDrainTarget;\n timeoutClass: SandboxDrainTimeoutClass;\n /** Provider operation budget frozen when the durable child is created. A\n * rolling config change cannot make an existing fast child retry forever. */\n snapshotTimeoutMs: number;\n captureTimeoutMs: number;\n /** Stable logical teardown operation; every Temporal activity retry keeps it\n * while receiving a distinct exact capture-attempt id. */\n operationId: string;\n};\n\nexport type SandboxDrainWorkflowInput = Omit<SandboxDrainActivityInput, \"operationId\">;\n\nexport type SandboxLeaseSweepMaintenanceInput = {\n examined: number;\n started: number;\n alreadyRunning: number;\n startFailed: number;\n rotationsRequested: number;\n};\n\nexport function sandboxDrainTimeoutClass(captureTimeoutMs: number): SandboxDrainTimeoutClass {\n return captureTimeoutMs + SANDBOX_DRAIN_SETTLEMENT_MARGIN_MS <\n SANDBOX_DRAIN_FAST_ACTIVITY_TIMEOUT_MS\n ? \"fast\"\n : \"extended\";\n}\n\nexport function sandboxDrainActivityTimeoutMs(timeoutClass: SandboxDrainTimeoutClass): number {\n return timeoutClass === \"fast\"\n ? SANDBOX_DRAIN_FAST_ACTIVITY_TIMEOUT_MS\n : SANDBOX_DRAIN_EXTENDED_ACTIVITY_TIMEOUT_MS;\n}\n\nexport function sandboxDrainWorkflowId(target: SandboxDrainTarget): string {\n return `sandbox-drain:${target.workspaceId}:${target.sandboxGroupId}:${target.leaseEpoch}`;\n}\n","import {\n SANDBOX_ARCHIVE_CAPTURE_MAX_TIMEOUT_MS,\n SANDBOX_SNAPSHOT_MAX_TIMEOUT_MS,\n sandboxArchiveCaptureTimeoutMs,\n type Settings,\n} from \"@opengeni/config\";\nimport {\n SANDBOX_DRAIN_SETTLEMENT_MARGIN_MS,\n sandboxDrainActivityTimeoutMs,\n sandboxDrainTimeoutClass,\n type SandboxDrainTimeoutClass,\n} from \"./sandbox-reaper-contract\";\n\nconst STRICT_TIMEOUT_FENCE_MS = 1;\n\nexport function sandboxDrainTiming(settings: Pick<Settings, \"sandboxSnapshotTimeoutMs\">): {\n snapshotTimeoutMs: number;\n captureTimeoutMs: number;\n timeoutClass: SandboxDrainTimeoutClass;\n activityTimeoutMs: number;\n} {\n const captureTimeoutMs = sandboxArchiveCaptureTimeoutMs(settings);\n const timeoutClass = sandboxDrainTimeoutClass(captureTimeoutMs);\n return {\n snapshotTimeoutMs: settings.sandboxSnapshotTimeoutMs,\n captureTimeoutMs,\n timeoutClass,\n activityTimeoutMs: sandboxDrainActivityTimeoutMs(timeoutClass),\n };\n}\n\nexport function assertSandboxReaperActivityTimeout(\n settings: Pick<Settings, \"sandboxSnapshotTimeoutMs\">,\n): void {\n const timing = sandboxDrainTiming(settings);\n if (timing.snapshotTimeoutMs >= timing.captureTimeoutMs) {\n throw new Error(\n `Sandbox provider snapshot timeout (${timing.snapshotTimeoutMs}) must be strictly less than ` +\n `its durable capture claim (${timing.captureTimeoutMs}).`,\n );\n }\n if (\n timing.captureTimeoutMs + SANDBOX_DRAIN_SETTLEMENT_MARGIN_MS + STRICT_TIMEOUT_FENCE_MS >=\n timing.activityTimeoutMs\n ) {\n throw new Error(\n `Sandbox ${timing.timeoutClass} drain activity timeout (${timing.activityTimeoutMs}) must ` +\n `strictly exceed one durable archive capture and settlement margin ` +\n `(${timing.captureTimeoutMs} + ${SANDBOX_DRAIN_SETTLEMENT_MARGIN_MS} milliseconds).`,\n );\n }\n}\n\nexport function assertSandboxDrainInputTiming(input: {\n timeoutClass: SandboxDrainTimeoutClass;\n snapshotTimeoutMs: number;\n captureTimeoutMs: number;\n}): void {\n if (\n !Number.isSafeInteger(input.snapshotTimeoutMs) ||\n input.snapshotTimeoutMs <= 0 ||\n input.snapshotTimeoutMs > SANDBOX_SNAPSHOT_MAX_TIMEOUT_MS ||\n !Number.isSafeInteger(input.captureTimeoutMs) ||\n input.captureTimeoutMs <= 0 ||\n input.captureTimeoutMs > SANDBOX_ARCHIVE_CAPTURE_MAX_TIMEOUT_MS\n ) {\n throw new Error(\"Sandbox drain timeout values are invalid\");\n }\n const inputActivityTimeoutMs = sandboxDrainActivityTimeoutMs(input.timeoutClass);\n if (\n sandboxDrainTimeoutClass(input.captureTimeoutMs) !== input.timeoutClass ||\n input.snapshotTimeoutMs >= input.captureTimeoutMs ||\n input.captureTimeoutMs + SANDBOX_DRAIN_SETTLEMENT_MARGIN_MS >= inputActivityTimeoutMs\n ) {\n throw new Error(\n `Sandbox drain timing is inconsistent with the ${input.timeoutClass} activity budget`,\n );\n }\n}\n"],"mappings":";AAEA,SAAS,oBAAoB;AAY7B,IAAM,MAAM,OAAO;AAOZ,IAAM,mCAAmC;AACzC,IAAM,yCAAyC,MAAM;AACrD,IAAM,oCAAoC,MAAM;AAqBhD,SAAS,6BACd,UAC8B;AAC9B,MAAI,SAAS,8BAA8B,SAAS;AAClD,WAAO;AAAA,MACL,qCAAqC,SAAS;AAAA,IAChD;AAAA,EACF;AAEA,SAAO;AAAA,IACL,OAAO;AAAA,MACL,cAAc;AAAA,QACZ,gBAAgB,SAAS;AAAA,QACzB,mBAAmB,SAAS;AAAA,MAC9B;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per-timeout.ts"],"sourcesContent":["import type { Settings } from \"@opengeni/config\";\nimport type { Observability } from \"@opengeni/observability\";\nimport { readFileSync } from \"node:fs\";\nimport type {\n ActivitySlotInfo,\n CustomSlotSupplier,\n SlotMarkUsedContext,\n SlotPermit,\n SlotReleaseContext,\n SlotReserveContext,\n WorkerOptions,\n WorkerTuner,\n} from \"@temporalio/worker\";\n\nconst MIB = 1024 * 1024;\n\n/**\n * Default fixed/HPA turn-worker admission contract. The configured fixed-mode\n * ceiling may be lower, but every live Temporal permit reserves the complete\n * hard budget until the runAgentTurn activity promise physically completes.\n */\nexport const TURN_WORKER_MAX_CONCURRENT_TURNS = 16;\nexport const TURN_WORKER_HARD_MEMORY_BYTES_PER_TURN = 100 * MIB;\nexport const TURN_WORKER_NATIVE_HEADROOM_BYTES = 512 * MIB;\n\nexport type TurnWorkerConcurrencySettings = Pick<\n Settings,\n | \"turnWorkerConcurrencyMode\"\n | \"turnWorkerMaxConcurrentTurns\"\n | \"turnWorkerTargetCpuUsage\"\n | \"turnWorkerTargetMemoryUsage\"\n>;\n\nexport type TurnWorkerConcurrencyOptions = Pick<\n WorkerOptions,\n \"maxConcurrentActivityTaskExecutions\" | \"tuner\"\n>;\n\n/**\n * Fixed profiles keep a per-process ceiling. Resource-aware profiles retain a\n * hard per-process maximum while Temporal meters new activity admission against\n * cgroup/host CPU and memory. The ramp lets usage become visible before a burst\n * can reserve the entire ceiling.\n */\nexport function turnWorkerConcurrencyOptions(\n settings: TurnWorkerConcurrencySettings,\n): TurnWorkerConcurrencyOptions {\n if (settings.turnWorkerConcurrencyMode === \"fixed\") {\n return {\n maxConcurrentActivityTaskExecutions: settings.turnWorkerMaxConcurrentTurns,\n };\n }\n\n return {\n tuner: {\n tunerOptions: {\n targetCpuUsage: settings.turnWorkerTargetCpuUsage,\n targetMemoryUsage: settings.turnWorkerTargetMemoryUsage,\n },\n activityTaskSlotOptions: {\n minimumSlots: 1,\n maximumSlots: settings.turnWorkerMaxConcurrentTurns,\n rampThrottle: \"250ms\",\n },\n },\n };\n}\n\nexport type TurnWorkerConcurrencyPlan = {\n options: TurnWorkerConcurrencyOptions;\n admission: MemoryAwareTurnSlotSupplier | null;\n};\n\n/**\n * Build the runtime concurrency policy for a turn worker.\n *\n * Fixed/HPA deployments use the hard-reservation supplier below. The explicit\n * non-HA single-machine profile keeps Temporal's native CPU/memory resource\n * tuner because it controls whole-machine load rather than a pod cgroup; that\n * profile documents that its configured maximum is not a per-turn reservation.\n */\nexport function createTurnWorkerConcurrencyPlan(\n settings: TurnWorkerConcurrencySettings,\n options: Omit<TurnAdmissionOptions, \"maximumTurns\"> = {},\n): TurnWorkerConcurrencyPlan {\n if (settings.turnWorkerConcurrencyMode === \"resource-based\") {\n return {\n options: turnWorkerConcurrencyOptions(settings),\n admission: null,\n };\n }\n\n const fixed = createTurnWorkerTuner({\n ...options,\n maximumTurns: settings.turnWorkerMaxConcurrentTurns,\n });\n return {\n options: { tuner: fixed.tuner },\n admission: fixed.admission,\n };\n}\n\nexport function turnWorkerConcurrencyLogFields(settings: TurnWorkerConcurrencySettings): {\n concurrencyMode: \"fixed\" | \"resource-based\";\n maxConcurrentTurns: number;\n targetCpuUsage: number | null;\n targetMemoryUsage: number | null;\n} {\n const resourceBased = settings.turnWorkerConcurrencyMode === \"resource-based\";\n return {\n concurrencyMode: settings.turnWorkerConcurrencyMode,\n maxConcurrentTurns: settings.turnWorkerMaxConcurrentTurns,\n targetCpuUsage: resourceBased ? settings.turnWorkerTargetCpuUsage : null,\n targetMemoryUsage: resourceBased ? settings.turnWorkerTargetMemoryUsage : null,\n };\n}\n\nexport const CONTROL_WORKER_MAX_CONCURRENT_ACTIVITIES = 32;\nexport const CONTROL_WORKER_MAX_CONCURRENT_WORKFLOW_TASKS = 40;\n\nconst CGROUP_MEMORY_FILES = [\n {\n limit: \"/sys/fs/cgroup/memory.max\",\n current: \"/sys/fs/cgroup/memory.current\",\n },\n {\n limit: \"/sys/fs/cgroup/memory/memory.limit_in_bytes\",\n current: \"/sys/fs/cgroup/memory/memory.usage_in_bytes\",\n },\n] as const;\n\n// cgroup v1 uses enormous sentinels for \"unlimited\". Values this large are\n// host capacity rather than a meaningful container admission boundary.\nconst UNLIMITED_CGROUP_BYTES = 1n << 60n;\n\nexport type CgroupMemorySnapshot = {\n currentBytes: number;\n limitBytes: number | null;\n source: \"cgroup-v1\" | \"cgroup-v2\" | \"process\";\n};\n\nexport type TurnAdmissionSnapshot = {\n baselineBytes: number;\n currentBytes: number;\n limitBytes: number | null;\n hardBytesPerTurn: number;\n nativeHeadroomBytes: number;\n maximumTurns: number;\n memoryBoundCapacity: number;\n reservedSlots: number;\n usedSlots: number;\n availableSlots: number;\n};\n\nexport type TurnAdmissionOptions = {\n maximumTurns?: number;\n hardBytesPerTurn?: number;\n nativeHeadroomBytes?: number;\n memorySnapshot?: () => CgroupMemorySnapshot;\n retryDelayMs?: number;\n observability?: Observability;\n};\n\ntype TurnSlotPermit = SlotPermit & {\n readonly owner: symbol;\n used: boolean;\n};\n\n/**\n * Temporal custom activity-slot supplier for turn workers.\n *\n * A permit is required before Temporal polls a task. Reservation is allowed\n * only when both independent safety checks pass:\n *\n * baseline + reserved-after × hard-turn-budget + native headroom <= limit\n * current + reserved-after × hard-turn-budget + native headroom <= limit\n *\n * The first check enforces the release contract even when current RSS happens\n * to be low. The second accounts for native/retained memory observed after\n * startup and keeps the complete hard budget reserved for every live permit.\n * A used permit is not evidence that its allocation is already visible in the\n * cgroup, and unrelated native growth cannot safely be attributed to a turn.\n * Kubernetes OOM is never an admission mechanism.\n */\nexport class MemoryAwareTurnSlotSupplier implements CustomSlotSupplier<ActivitySlotInfo> {\n readonly type = \"custom\" as const;\n\n private readonly owner = Symbol(\"opengeni-turn-admission\");\n private readonly permits = new Set<TurnSlotPermit>();\n private baselineBytes: number;\n private readonly maximumTurns: number;\n private readonly hardBytesPerTurn: number;\n private readonly nativeHeadroomBytes: number;\n private readonly memorySnapshot: () => CgroupMemorySnapshot;\n private readonly retryDelayMs: number;\n private readonly observability: Observability | undefined;\n\n constructor(options: TurnAdmissionOptions = {}) {\n this.maximumTurns = positiveInteger(\n \"maximumTurns\",\n options.maximumTurns ?? TURN_WORKER_MAX_CONCURRENT_TURNS,\n );\n this.hardBytesPerTurn = positiveInteger(\n \"hardBytesPerTurn\",\n options.hardBytesPerTurn ?? TURN_WORKER_HARD_MEMORY_BYTES_PER_TURN,\n );\n this.nativeHeadroomBytes = nonnegativeInteger(\n \"nativeHeadroomBytes\",\n options.nativeHeadroomBytes ?? TURN_WORKER_NATIVE_HEADROOM_BYTES,\n );\n this.retryDelayMs = positiveInteger(\"retryDelayMs\", options.retryDelayMs ?? 100);\n this.memorySnapshot = options.memorySnapshot ?? readCgroupMemorySnapshot;\n this.observability = options.observability;\n const initial = this.memorySnapshot();\n this.baselineBytes = initial.currentBytes;\n if (initial.limitBytes !== null && this.memoryBoundCapacity(initial.limitBytes) < 1) {\n throw new Error(\n \"Turn worker memory limit cannot safely admit one turn: \" +\n `baseline=${this.baselineBytes} hardTurn=${this.hardBytesPerTurn} ` +\n `nativeHeadroom=${this.nativeHeadroomBytes} limit=${initial.limitBytes}`,\n );\n }\n this.refreshMetrics(initial);\n }\n\n async reserveSlot(_ctx: SlotReserveContext, abortSignal: AbortSignal): Promise<SlotPermit> {\n for (;;) {\n if (abortSignal.aborted) throw abortError();\n const permit = this.reserveIfSafe();\n if (permit) return permit;\n await abortableDelay(this.retryDelayMs, abortSignal);\n }\n }\n\n tryReserveSlot(_ctx: SlotReserveContext): SlotPermit | null {\n return this.reserveIfSafe();\n }\n\n markSlotUsed(ctx: SlotMarkUsedContext<ActivitySlotInfo>): void {\n const permit = this.ownedPermit(ctx.permit);\n permit.used = true;\n this.refreshMetrics();\n }\n\n releaseSlot(ctx: SlotReleaseContext<ActivitySlotInfo>): void {\n const permit = this.ownedPermit(ctx.permit);\n this.permits.delete(permit);\n this.refreshMetrics();\n }\n\n snapshot(memory = this.memorySnapshot()): TurnAdmissionSnapshot {\n const usedSlots = this.usedSlots();\n const reservedSlots = this.permits.size;\n const availableSlots = this.availableSlots(memory);\n // Never report less capacity than work already admitted. The dynamic\n // denominator is exactly reserved + what a new poll could reserve now.\n const memoryBoundCapacity = reservedSlots + availableSlots;\n return {\n baselineBytes: this.baselineBytes,\n currentBytes: memory.currentBytes,\n limitBytes: memory.limitBytes,\n hardBytesPerTurn: this.hardBytesPerTurn,\n nativeHeadroomBytes: this.nativeHeadroomBytes,\n maximumTurns: this.maximumTurns,\n memoryBoundCapacity,\n reservedSlots,\n usedSlots,\n availableSlots,\n };\n }\n\n /**\n * Finalize the admission baseline after Temporal/native construction.\n * Worker.create can retain memory after the constructor's provisional\n * sample. That initialization delta must remain in the baseline for every\n * later projection rather than competing with turn reservations.\n */\n finalizeStartupBaseline(): void {\n const memory = this.memorySnapshot();\n if (this.permits.size !== 0) {\n throw new Error(\"Turn worker startup admission check ran after slot reservation\");\n }\n const finalizedBaselineBytes = memory.currentBytes;\n const finalizedCapacity =\n memory.limitBytes === null\n ? this.maximumTurns\n : this.memoryBoundCapacity(memory.limitBytes, finalizedBaselineBytes);\n if (memory.limitBytes !== null && finalizedCapacity < 1) {\n throw new Error(\n \"Turn worker memory limit cannot safely admit one turn after worker initialization: \" +\n `provisionalBaseline=${this.baselineBytes} finalizedBaseline=${finalizedBaselineBytes} ` +\n `hardTurn=${this.hardBytesPerTurn} nativeHeadroom=${this.nativeHeadroomBytes} ` +\n `limit=${String(memory.limitBytes)}`,\n );\n }\n this.baselineBytes = finalizedBaselineBytes;\n this.refreshMetrics(memory);\n }\n\n private reserveIfSafe(): TurnSlotPermit | null {\n const memory = this.memorySnapshot();\n if (this.permits.size >= this.maximumTurns || !this.memoryAllowsAnother(memory)) {\n this.refreshMetrics(memory);\n return null;\n }\n const permit: TurnSlotPermit = { owner: this.owner, used: false };\n this.permits.add(permit);\n this.refreshMetrics(memory);\n return permit;\n }\n\n private memoryAllowsAnother(memory: CgroupMemorySnapshot): boolean {\n return this.availableSlots(memory) > 0;\n }\n\n private availableSlots(memory: CgroupMemorySnapshot): number {\n const densityRemaining = this.maximumTurns - this.permits.size;\n if (memory.limitBytes === null) return Math.max(0, densityRemaining);\n\n const baselineRemaining = this.memoryBoundCapacity(memory.limitBytes) - this.permits.size;\n const observedRemaining =\n Math.floor(\n (memory.limitBytes - memory.currentBytes - this.nativeHeadroomBytes) /\n this.hardBytesPerTurn,\n ) - this.permits.size;\n return Math.max(0, Math.min(densityRemaining, baselineRemaining, observedRemaining));\n }\n\n private memoryBoundCapacity(limitBytes: number, baselineBytes = this.baselineBytes): number {\n return Math.max(\n 0,\n Math.floor((limitBytes - baselineBytes - this.nativeHeadroomBytes) / this.hardBytesPerTurn),\n );\n }\n\n private usedSlots(): number {\n let used = 0;\n for (const permit of this.permits) {\n if (permit.used) used += 1;\n }\n return used;\n }\n\n private ownedPermit(permit: SlotPermit): TurnSlotPermit {\n const candidate = permit as Partial<TurnSlotPermit>;\n if (candidate.owner !== this.owner || !this.permits.has(permit as TurnSlotPermit)) {\n throw new Error(\"Temporal returned a turn slot permit owned by another supplier\");\n }\n return permit as TurnSlotPermit;\n }\n\n private refreshMetrics(memory = this.memorySnapshot()): void {\n if (!this.observability) return;\n const value = this.snapshot(memory);\n const set = (name: string, help: string, metricValue: number) =>\n this.observability?.setGauge({ name, help, value: metricValue });\n set(\n \"opengeni_turn_slots_capacity\",\n \"Turn slots this worker can safely support after the hard memory contract.\",\n value.memoryBoundCapacity,\n );\n set(\n \"opengeni_turn_slots_reserved\",\n \"Temporal turn activity slots reserved for polling or execution in this worker.\",\n value.reservedSlots,\n );\n set(\n \"opengeni_turn_slots_used\",\n \"Temporal turn activity slots currently executing in this worker.\",\n value.usedSlots,\n );\n set(\n \"opengeni_turn_slots_available\",\n \"Memory-safe turn activity slots still available to reserve in this worker.\",\n value.availableSlots,\n );\n set(\n \"opengeni_turn_slot_saturation_ratio\",\n \"Fraction of this worker's memory-safe turn capacity currently executing.\",\n value.memoryBoundCapacity === 0 ? 1 : value.usedSlots / value.memoryBoundCapacity,\n );\n set(\n \"opengeni_turn_admission_memory_baseline_bytes\",\n \"Turn-worker cgroup memory after Temporal/native worker initialization.\",\n value.baselineBytes,\n );\n set(\n \"opengeni_turn_admission_memory_current_bytes\",\n \"Current cgroup memory used for turn admission decisions.\",\n value.currentBytes,\n );\n set(\n \"opengeni_turn_admission_memory_limit_bytes\",\n \"Finite cgroup memory limit used for turn admission, or zero when unlimited.\",\n value.limitBytes ?? 0,\n );\n set(\n \"opengeni_turn_admission_hard_bytes_per_turn\",\n \"Hard incremental memory budget reserved for each admitted turn.\",\n value.hardBytesPerTurn,\n );\n set(\n \"opengeni_turn_admission_native_headroom_bytes\",\n \"Cgroup memory retained for runtime, native, and GC headroom.\",\n value.nativeHeadroomBytes,\n );\n }\n}\n\nexport function createTurnWorkerTuner(options: TurnAdmissionOptions = {}): {\n tuner: WorkerTuner;\n admission: MemoryAwareTurnSlotSupplier;\n} {\n const admission = new MemoryAwareTurnSlotSupplier(options);\n return {\n admission,\n tuner: {\n workflowTaskSlotSupplier: { type: \"fixed-size\", numSlots: 1 },\n activityTaskSlotSupplier: admission,\n localActivityTaskSlotSupplier: { type: \"fixed-size\", numSlots: 1 },\n nexusTaskSlotSupplier: { type: \"fixed-size\", numSlots: 1 },\n },\n };\n}\n\nexport function readCgroupMemorySnapshot(): CgroupMemorySnapshot {\n for (const [index, files] of CGROUP_MEMORY_FILES.entries()) {\n const limitRaw = readCgroupText(files.limit);\n const currentRaw = readCgroupText(files.current);\n if (limitRaw === null && currentRaw === null) continue;\n if (limitRaw === null || currentRaw === null) {\n throw new Error(\n `Incomplete cgroup memory controller: limit=${files.limit} current=${files.current}`,\n );\n }\n return {\n currentBytes: parseCgroupCurrentValue(currentRaw),\n limitBytes: parseCgroupLimitValue(limitRaw),\n source: index === 0 ? \"cgroup-v2\" : \"cgroup-v1\",\n };\n }\n return {\n currentBytes: process.memoryUsage().rss,\n limitBytes: null,\n source: \"process\",\n };\n}\n\nexport function parseCgroupLimitValue(value: string): number | null {\n if (value.trim() === \"max\") return null;\n const parsed = parseCgroupBigInt(value);\n if (parsed === null || parsed <= 0n) {\n throw new Error(`Malformed finite cgroup memory limit: ${JSON.stringify(value.trim())}`);\n }\n if (parsed >= UNLIMITED_CGROUP_BYTES) return null;\n const number = Number(parsed);\n if (!Number.isSafeInteger(number)) {\n throw new Error(\n `Finite cgroup memory limit exceeds JavaScript's safe integer range: ${parsed}`,\n );\n }\n return number;\n}\n\nexport function parseCgroupCurrentValue(value: string): number {\n const parsed = parseCgroupBigInt(value);\n if (parsed === null || parsed < 0n) {\n throw new Error(`Malformed cgroup current memory value: ${JSON.stringify(value.trim())}`);\n }\n const number = Number(parsed);\n if (!Number.isSafeInteger(number)) {\n throw new Error(`Cgroup current memory exceeds JavaScript's safe integer range: ${parsed}`);\n }\n return number;\n}\n\nfunction parseCgroupBigInt(value: string): bigint | null {\n try {\n return BigInt(value.trim());\n } catch {\n return null;\n }\n}\n\nfunction readCgroupText(path: string): string | null {\n try {\n return readFileSync(path, \"utf8\");\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === \"ENOENT\") return null;\n throw new Error(\n `Unable to read present cgroup memory controller file ${path}: ${\n error instanceof Error ? error.message : String(error)\n }`,\n { cause: error },\n );\n }\n}\n\nfunction positiveInteger(name: string, value: number): number {\n if (!Number.isSafeInteger(value) || value <= 0) {\n throw new Error(`${name} must be a positive integer`);\n }\n return value;\n}\n\nfunction nonnegativeInteger(name: string, value: number): number {\n if (!Number.isSafeInteger(value) || value < 0) {\n throw new Error(`${name} must be a non-negative integer`);\n }\n return value;\n}\n\nfunction abortError(): DOMException {\n return new DOMException(\"Turn slot reservation aborted\", \"AbortError\");\n}\n\nfunction abortableDelay(milliseconds: number, signal: AbortSignal): Promise<void> {\n return new Promise((resolve, reject) => {\n if (signal.aborted) {\n reject(abortError());\n return;\n }\n const timer = setTimeout(() => {\n signal.removeEventListener(\"abort\", onAbort);\n resolve();\n }, milliseconds);\n timer.unref?.();\n const onAbort = () => {\n clearTimeout(timer);\n reject(abortError());\n };\n signal.addEventListener(\"abort\", onAbort, { once: true });\n });\n}\n\n// Session workflows finish at idle boundaries and replay from durable history.\n// Bound sticky VM state explicitly: the SDK otherwise derives this from the\n// host heap limit (roughly 600 cached workflows/GiB), which is far above this\n// process's actual concurrent workflow-task capacity and permanently retains\n// idle workflow state in every control replica.\nexport const CONTROL_WORKER_MAX_CACHED_WORKFLOWS = 64;\n","export const SANDBOX_REAPER_SCAN_ACTIVITY_TIMEOUT_MS = 5 * 60_000;\nexport const SANDBOX_DRAIN_FAST_ACTIVITY_TIMEOUT_MS = 5 * 60_000;\nexport const SANDBOX_DRAIN_EXTENDED_ACTIVITY_TIMEOUT_MS = 65 * 60_000;\nexport const SANDBOX_DRAIN_SETTLEMENT_MARGIN_MS = 60_000;\nexport const SANDBOX_REAPER_ACTIVITY_HEARTBEAT_TIMEOUT_MS = 20_000;\nexport const SANDBOX_REAPER_ACTIVITY_HEARTBEAT_INTERVAL_MS = 5_000;\n// Match the DB inventory's fair 500-row bound so one sweep never discovers a\n// due box and then needlessly defers it for another schedule period. Five\n// hundred small StartChild commands remain far below Temporal history limits;\n// actual provider I/O stays bounded by worker activity concurrency.\nexport const SANDBOX_REAPER_CHILD_DISPATCH_LIMIT = 500;\nexport const SANDBOX_REAPER_V2_WORKFLOW_ID = \"opengeni-sandbox-lease-reaper-v2\";\nexport const SANDBOX_REAPER_MAINTENANCE_WORKFLOW_ID = \"opengeni-sandbox-lease-maintenance-v1\";\n\n// A protocol-specific queue is the rolling-deploy compatibility boundary for\n// the split reaper activities. An old control worker polls only the base queue,\n// so it can replay already-started legacy workflows but can never receive a new\n// activity type that its binary does not register.\nexport const SANDBOX_LIFECYCLE_TASK_QUEUE_SUFFIX = \"-sandbox-lifecycle-v1\";\n\nexport function sandboxLifecycleTaskQueue(baseTaskQueue: string): string {\n return baseTaskQueue.endsWith(SANDBOX_LIFECYCLE_TASK_QUEUE_SUFFIX)\n ? baseTaskQueue\n : `${baseTaskQueue}${SANDBOX_LIFECYCLE_TASK_QUEUE_SUFFIX}`;\n}\n\nexport type SandboxDrainTimeoutClass = \"fast\" | \"extended\";\n\nexport type SandboxDrainTarget = {\n workspaceId: string;\n sandboxGroupId: string;\n instanceId: string | null;\n leaseEpoch: number;\n};\n\nexport type SandboxDrainActivityInput = {\n target: SandboxDrainTarget;\n timeoutClass: SandboxDrainTimeoutClass;\n /** Provider operation budget frozen when the durable child is created. A\n * rolling config change cannot make an existing fast child retry forever. */\n snapshotTimeoutMs: number;\n captureTimeoutMs: number;\n /** Stable logical teardown operation; every Temporal activity retry keeps it\n * while receiving a distinct exact capture-attempt id. */\n operationId: string;\n};\n\nexport type SandboxDrainWorkflowInput = Omit<SandboxDrainActivityInput, \"operationId\">;\n\nexport type SandboxLeaseSweepMaintenanceInput = {\n examined: number;\n started: number;\n alreadyRunning: number;\n startFailed: number;\n rotationsRequested: number;\n};\n\nexport function sandboxDrainTimeoutClass(captureTimeoutMs: number): SandboxDrainTimeoutClass {\n return captureTimeoutMs + SANDBOX_DRAIN_SETTLEMENT_MARGIN_MS <\n SANDBOX_DRAIN_FAST_ACTIVITY_TIMEOUT_MS\n ? \"fast\"\n : \"extended\";\n}\n\nexport function sandboxDrainActivityTimeoutMs(timeoutClass: SandboxDrainTimeoutClass): number {\n return timeoutClass === \"fast\"\n ? SANDBOX_DRAIN_FAST_ACTIVITY_TIMEOUT_MS\n : SANDBOX_DRAIN_EXTENDED_ACTIVITY_TIMEOUT_MS;\n}\n\nexport function sandboxDrainWorkflowId(target: SandboxDrainTarget): string {\n return `sandbox-drain:${target.workspaceId}:${target.sandboxGroupId}:${target.leaseEpoch}`;\n}\n","import {\n SANDBOX_ARCHIVE_CAPTURE_MAX_TIMEOUT_MS,\n SANDBOX_SNAPSHOT_MAX_TIMEOUT_MS,\n effectiveSandboxDrainSnapshotTimeoutMs,\n sandboxArchiveCaptureTimeoutMs,\n type Settings,\n} from \"@opengeni/config\";\nimport {\n SANDBOX_DRAIN_SETTLEMENT_MARGIN_MS,\n sandboxDrainActivityTimeoutMs,\n sandboxDrainTimeoutClass,\n type SandboxDrainTimeoutClass,\n} from \"./sandbox-reaper-contract\";\n\nconst STRICT_TIMEOUT_FENCE_MS = 1;\n\nexport function sandboxDrainTiming(\n settings: Pick<Settings, \"sandboxSnapshotTimeoutMs\" | \"sandboxDrainSnapshotTimeoutMs\">,\n): {\n snapshotTimeoutMs: number;\n captureTimeoutMs: number;\n timeoutClass: SandboxDrainTimeoutClass;\n activityTimeoutMs: number;\n} {\n const snapshotTimeoutMs = effectiveSandboxDrainSnapshotTimeoutMs(settings);\n const captureTimeoutMs = sandboxArchiveCaptureTimeoutMs({\n sandboxSnapshotTimeoutMs: snapshotTimeoutMs,\n });\n const timeoutClass = sandboxDrainTimeoutClass(captureTimeoutMs);\n return {\n snapshotTimeoutMs,\n captureTimeoutMs,\n timeoutClass,\n activityTimeoutMs: sandboxDrainActivityTimeoutMs(timeoutClass),\n };\n}\n\nexport function assertSandboxReaperActivityTimeout(\n settings: Pick<Settings, \"sandboxSnapshotTimeoutMs\" | \"sandboxDrainSnapshotTimeoutMs\">,\n): void {\n const timing = sandboxDrainTiming(settings);\n if (timing.snapshotTimeoutMs >= timing.captureTimeoutMs) {\n throw new Error(\n `Sandbox provider snapshot timeout (${timing.snapshotTimeoutMs}) must be strictly less than ` +\n `its durable capture claim (${timing.captureTimeoutMs}).`,\n );\n }\n if (\n timing.captureTimeoutMs + SANDBOX_DRAIN_SETTLEMENT_MARGIN_MS + STRICT_TIMEOUT_FENCE_MS >=\n timing.activityTimeoutMs\n ) {\n throw new Error(\n `Sandbox ${timing.timeoutClass} drain activity timeout (${timing.activityTimeoutMs}) must ` +\n `strictly exceed one durable archive capture and settlement margin ` +\n `(${timing.captureTimeoutMs} + ${SANDBOX_DRAIN_SETTLEMENT_MARGIN_MS} milliseconds).`,\n );\n }\n}\n\nexport function assertSandboxDrainInputTiming(input: {\n timeoutClass: SandboxDrainTimeoutClass;\n snapshotTimeoutMs: number;\n captureTimeoutMs: number;\n}): void {\n if (\n !Number.isSafeInteger(input.snapshotTimeoutMs) ||\n input.snapshotTimeoutMs <= 0 ||\n input.snapshotTimeoutMs > SANDBOX_SNAPSHOT_MAX_TIMEOUT_MS ||\n !Number.isSafeInteger(input.captureTimeoutMs) ||\n input.captureTimeoutMs <= 0 ||\n input.captureTimeoutMs > SANDBOX_ARCHIVE_CAPTURE_MAX_TIMEOUT_MS\n ) {\n throw new Error(\"Sandbox drain timeout values are invalid\");\n }\n const inputActivityTimeoutMs = sandboxDrainActivityTimeoutMs(input.timeoutClass);\n if (\n sandboxDrainTimeoutClass(input.captureTimeoutMs) !== input.timeoutClass ||\n input.snapshotTimeoutMs >= input.captureTimeoutMs ||\n input.captureTimeoutMs + SANDBOX_DRAIN_SETTLEMENT_MARGIN_MS >= inputActivityTimeoutMs\n ) {\n throw new Error(\n `Sandbox drain timing is inconsistent with the ${input.timeoutClass} activity budget`,\n );\n }\n}\n"],"mappings":";AAEA,SAAS,oBAAoB;AAY7B,IAAM,MAAM,OAAO;AAOZ,IAAM,mCAAmC;AACzC,IAAM,yCAAyC,MAAM;AACrD,IAAM,oCAAoC,MAAM;AAqBhD,SAAS,6BACd,UAC8B;AAC9B,MAAI,SAAS,8BAA8B,SAAS;AAClD,WAAO;AAAA,MACL,qCAAqC,SAAS;AAAA,IAChD;AAAA,EACF;AAEA,SAAO;AAAA,IACL,OAAO;AAAA,MACL,cAAc;AAAA,QACZ,gBAAgB,SAAS;AAAA,QACzB,mBAAmB,SAAS;AAAA,MAC9B;AAAA,MACA,yBAAyB;AAAA,QACvB,cAAc;AAAA,QACd,cAAc,SAAS;AAAA,QACvB,cAAc;AAAA,MAChB;AAAA,IACF;AAAA,EACF;AACF;AAeO,SAAS,gCACd,UACA,UAAsD,CAAC,GAC5B;AAC3B,MAAI,SAAS,8BAA8B,kBAAkB;AAC3D,WAAO;AAAA,MACL,SAAS,6BAA6B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,yBAAyB,gBAAgB;AAC9D,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA,mBAAmB,8BAA8B,YAAY;AAAA,EAC/D;AACF;AAEO,SAAS,mCACd,UACM;AACN,QAAM,SAAS,mBAAmB,QAAQ;AAC1C,MAAI,OAAO,qBAAqB,OAAO,kBAAkB;AACvD,UAAM,IAAI;AAAA,MACR,sCAAsC,OAAO,iBAAiB,2DAC9B,OAAO,gBAAgB;AAAA,IACzD;AAAA,EACF;AACA,MACE,OAAO,mBAAmB,qCAAqC,2BAC/D,OAAO,mBACP;AACA,UAAM,IAAI;AAAA,MACR,WAAW,OAAO,YAAY,4BAA4B,OAAO,iBAAiB,6EAE5E,OAAO,gBAAgB,MAAM,kCAAkC;AAAA,IACvE;AAAA,EACF;AACF;AAEO,SAAS,8BAA8B,OAIrC;AACP,MACE,CAAC,OAAO,cAAc,MAAM,iBAAiB,KAC7C,MAAM,qBAAqB,KAC3B,MAAM,oBAAoB,mCAC1B,CAAC,OAAO,cAAc,MAAM,gBAAgB,KAC5C,MAAM,oBAAoB,KAC1B,MAAM,mBAAmB,wCACzB;AACA,UAAM,IAAI,MAAM,0CAA0C;AAAA,EAC5D;AACA,QAAM,yBAAyB,8BAA8B,MAAM,YAAY;AAC/E,MACE,yBAAyB,MAAM,gBAAgB,MAAM,MAAM,gBAC3D,MAAM,qBAAqB,MAAM,oBACjC,MAAM,mBAAmB,sCAAsC,wBAC/D;AACA,UAAM,IAAI;AAAA,MACR,iDAAiD,MAAM,YAAY;AAAA,IACrE;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
observabilityEventLogger
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-65JEWP2Q.js";
|
|
4
4
|
|
|
5
5
|
// src/activity-services.ts
|
|
6
6
|
import { dbSearchPath, getSettings, resolveNatsControlPlaneAuth } from "@opengeni/config";
|
|
7
7
|
import { configureChildLifecycleNotices, createDb } from "@opengeni/db";
|
|
8
8
|
import { createNatsEventBus } from "@opengeni/events";
|
|
9
9
|
import { createObservability } from "@opengeni/observability";
|
|
10
|
+
import { resolveCatalogSettings } from "@opengeni/core";
|
|
10
11
|
import { createObjectStorage } from "@opengeni/storage";
|
|
11
12
|
|
|
12
13
|
// src/personal-github-git-credentials.ts
|
|
@@ -400,9 +401,11 @@ function createSharedActivityServices(dependencies) {
|
|
|
400
401
|
});
|
|
401
402
|
const controlPlaneAuth = resolveNatsControlPlaneAuth(settings);
|
|
402
403
|
const db = dependencies.db ?? dbClient.db;
|
|
404
|
+
const resolvedSettings = (await resolveCatalogSettings(db, settings)).settings;
|
|
403
405
|
configureChildLifecycleNotices({ enabled: settings.childLifecycleNoticesEnabled });
|
|
404
406
|
return {
|
|
405
|
-
settings,
|
|
407
|
+
settings: resolvedSettings,
|
|
408
|
+
catalogSourceSettings: settings,
|
|
406
409
|
db,
|
|
407
410
|
bus: dependencies.bus ?? await createNatsEventBus(
|
|
408
411
|
settings.natsUrl,
|
|
@@ -972,7 +975,13 @@ function createCodexCapacityActivities(services) {
|
|
|
972
975
|
import {
|
|
973
976
|
allowedFirstPartyMcpToolsForSession,
|
|
974
977
|
configuredStaticUsageLimits,
|
|
975
|
-
policyProviderIdForModel
|
|
978
|
+
policyProviderIdForModel,
|
|
979
|
+
resolveModelProvider,
|
|
980
|
+
resolveTurnExecutionPolicyV1,
|
|
981
|
+
withCodexCatalogProvider,
|
|
982
|
+
withXaiSubscriptionCatalogProvider,
|
|
983
|
+
WORKSPACE_GATEWAY_MODEL_ID_PREFIX,
|
|
984
|
+
WORKSPACE_OPENROUTER_MODEL_ID_PREFIX
|
|
976
985
|
} from "@opengeni/config";
|
|
977
986
|
import {
|
|
978
987
|
evaluateWorkspaceModelPolicy,
|
|
@@ -990,6 +999,11 @@ import {
|
|
|
990
999
|
requireSession,
|
|
991
1000
|
sumUsageQuantity
|
|
992
1001
|
} from "@opengeni/db";
|
|
1002
|
+
import {
|
|
1003
|
+
modelFundingForAdmission,
|
|
1004
|
+
resolveCatalogSettings as resolveCatalogSettings2,
|
|
1005
|
+
resolveWorkspaceCatalogSettings
|
|
1006
|
+
} from "@opengeni/core";
|
|
993
1007
|
function createGoalActivities(services) {
|
|
994
1008
|
async function enqueueGoalRetryWake(input) {
|
|
995
1009
|
const { db } = await services();
|
|
@@ -1005,35 +1019,40 @@ function createGoalActivities(services) {
|
|
|
1005
1019
|
});
|
|
1006
1020
|
}
|
|
1007
1021
|
async function maybeContinueGoal(input) {
|
|
1008
|
-
const
|
|
1022
|
+
const service = await services();
|
|
1023
|
+
const { db, bus } = service;
|
|
1024
|
+
const catalogSourceSettings = service.catalogSourceSettings ?? service.settings;
|
|
1009
1025
|
const existingGoal = await getSessionGoal(db, input.workspaceId, input.sessionId);
|
|
1010
1026
|
if (!existingGoal || existingGoal.status !== "active") {
|
|
1011
1027
|
return { action: "none" };
|
|
1012
1028
|
}
|
|
1029
|
+
let settings = (await resolveCatalogSettings2(db, catalogSourceSettings)).settings;
|
|
1013
1030
|
const session = await requireSession(db, input.workspaceId, input.sessionId);
|
|
1014
1031
|
const latestStartedTurn = await getLatestStartedSessionTurn(
|
|
1015
1032
|
db,
|
|
1016
1033
|
input.workspaceId,
|
|
1017
1034
|
input.sessionId
|
|
1018
1035
|
);
|
|
1019
|
-
|
|
1036
|
+
const inheritedContinuationModel = latestStartedTurn?.model ?? session.model;
|
|
1037
|
+
let continuationModel = inheritedContinuationModel;
|
|
1020
1038
|
const continuationReasoningEffort = latestStartedTurn?.reasoningEffort ?? session.reasoningEffort;
|
|
1021
1039
|
const continuationLatencyMode = latestStartedTurn?.latencyMode ?? session.latencyMode;
|
|
1022
|
-
let modelPolicyBlocked = null;
|
|
1023
1040
|
const workspaceModelPolicy = await getWorkspaceModelPolicy(db, input.workspaceId);
|
|
1024
|
-
if (
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
if (continuationModel !== session.model && !policyBlocks(session.model)) {
|
|
1031
|
-
continuationModel = session.model;
|
|
1032
|
-
} else {
|
|
1033
|
-
modelPolicyBlocked = `workspace model policy blocks model "${continuationModel}"; pick an allowed model or change the workspace model policy`;
|
|
1034
|
-
}
|
|
1035
|
-
}
|
|
1041
|
+
if (inheritedContinuationModel.startsWith(WORKSPACE_GATEWAY_MODEL_ID_PREFIX) || inheritedContinuationModel.startsWith(WORKSPACE_OPENROUTER_MODEL_ID_PREFIX) || session.model.startsWith(WORKSPACE_GATEWAY_MODEL_ID_PREFIX) || session.model.startsWith(WORKSPACE_OPENROUTER_MODEL_ID_PREFIX)) {
|
|
1042
|
+
settings = (await resolveWorkspaceCatalogSettings(db, catalogSourceSettings, {
|
|
1043
|
+
accountId: input.accountId,
|
|
1044
|
+
workspaceId: input.workspaceId,
|
|
1045
|
+
retainedProductModelIds: [inheritedContinuationModel, session.model]
|
|
1046
|
+
})).settings;
|
|
1036
1047
|
}
|
|
1048
|
+
const modelDecision = goalContinuationModelDecision({
|
|
1049
|
+
settings,
|
|
1050
|
+
workspaceModelPolicy,
|
|
1051
|
+
inheritedModel: inheritedContinuationModel,
|
|
1052
|
+
sessionModel: session.model
|
|
1053
|
+
});
|
|
1054
|
+
continuationModel = modelDecision.model;
|
|
1055
|
+
let modelPolicyBlocked = modelDecision.blocked;
|
|
1037
1056
|
if (!modelPolicyBlocked && session.codexCompactionMode === "remote_v2" && !isCodexBilledModel(continuationModel)) {
|
|
1038
1057
|
modelPolicyBlocked = `session is locked to Codex remote compaction v2; model "${continuationModel}" is not a Codex subscription model`;
|
|
1039
1058
|
}
|
|
@@ -1043,13 +1062,27 @@ function createGoalActivities(services) {
|
|
|
1043
1062
|
workspaceId: input.workspaceId,
|
|
1044
1063
|
model: continuationModel
|
|
1045
1064
|
});
|
|
1065
|
+
const fundedWithoutCredits = goalContinuationFundedWithoutCredits(
|
|
1066
|
+
settings,
|
|
1067
|
+
continuationModel,
|
|
1068
|
+
isCodexRun
|
|
1069
|
+
);
|
|
1046
1070
|
const budgetBlocked = await goalRunBudgetBlocked(
|
|
1047
1071
|
settings,
|
|
1048
1072
|
db,
|
|
1049
1073
|
input.accountId,
|
|
1050
1074
|
input.workspaceId,
|
|
1051
|
-
|
|
1075
|
+
fundedWithoutCredits
|
|
1052
1076
|
);
|
|
1077
|
+
const turnExecutionPolicy = resolveTurnExecutionPolicyV1(settings, {
|
|
1078
|
+
modelId: continuationModel,
|
|
1079
|
+
requestedModelId: null,
|
|
1080
|
+
modelSource: "continuation",
|
|
1081
|
+
reasoningEffort: continuationReasoningEffort,
|
|
1082
|
+
reasoningSource: "continuation",
|
|
1083
|
+
latencyMode: continuationLatencyMode,
|
|
1084
|
+
latencyModeSource: "continuation"
|
|
1085
|
+
});
|
|
1053
1086
|
const decision = await materializeGoalContinuation(db, {
|
|
1054
1087
|
accountId: input.accountId,
|
|
1055
1088
|
workspaceId: input.workspaceId,
|
|
@@ -1070,6 +1103,7 @@ function createGoalActivities(services) {
|
|
|
1070
1103
|
model: continuationModel,
|
|
1071
1104
|
reasoningEffort: continuationReasoningEffort,
|
|
1072
1105
|
latencyMode: continuationLatencyMode,
|
|
1106
|
+
turnExecutionPolicy,
|
|
1073
1107
|
tools: withFirstPartyTools(settings, session.tools),
|
|
1074
1108
|
sandboxBackend: session.sandboxBackend
|
|
1075
1109
|
},
|
|
@@ -1100,11 +1134,40 @@ function createGoalActivities(services) {
|
|
|
1100
1134
|
maybeContinueGoal
|
|
1101
1135
|
};
|
|
1102
1136
|
}
|
|
1137
|
+
function goalContinuationModelDecision(input) {
|
|
1138
|
+
const catalogSettings = input.settings.supergrokSubscriptionEnabled ? withXaiSubscriptionCatalogProvider(
|
|
1139
|
+
input.settings.codexSubscriptionEnabled ? withCodexCatalogProvider(input.settings) : input.settings
|
|
1140
|
+
) : input.settings.codexSubscriptionEnabled ? withCodexCatalogProvider(input.settings) : input.settings;
|
|
1141
|
+
const policyBlocks = (modelId) => input.workspaceModelPolicy !== null && !evaluateWorkspaceModelPolicy(input.workspaceModelPolicy, {
|
|
1142
|
+
providerId: policyProviderIdForModel(catalogSettings, modelId),
|
|
1143
|
+
modelId
|
|
1144
|
+
}).allowed;
|
|
1145
|
+
const candidates = [.../* @__PURE__ */ new Set([input.inheritedModel, input.sessionModel])];
|
|
1146
|
+
for (const model of candidates) {
|
|
1147
|
+
if (resolveModelProvider(catalogSettings, model) && !policyBlocks(model)) {
|
|
1148
|
+
return { model, blocked: null };
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
if (!resolveModelProvider(catalogSettings, input.inheritedModel)) {
|
|
1152
|
+
return {
|
|
1153
|
+
model: input.inheritedModel,
|
|
1154
|
+
blocked: `model "${input.inheritedModel}" is no longer in the deployment or workspace catalog; choose an available model before resuming the goal`
|
|
1155
|
+
};
|
|
1156
|
+
}
|
|
1157
|
+
return {
|
|
1158
|
+
model: input.inheritedModel,
|
|
1159
|
+
blocked: `workspace model policy blocks model "${input.inheritedModel}"; pick an allowed model or change the workspace model policy`
|
|
1160
|
+
};
|
|
1161
|
+
}
|
|
1162
|
+
function goalContinuationFundedWithoutCredits(settings, model, codexBilled) {
|
|
1163
|
+
return modelFundingForAdmission(settings, model, codexBilled).fundedWithoutCredits;
|
|
1164
|
+
}
|
|
1103
1165
|
function goalContinuationPrompt(_goal, _autoContinuation, _cap, options = {}) {
|
|
1104
1166
|
const waitingGuidance = options.goalWaitAvailable ? [
|
|
1105
1167
|
"Waiting on child sessions or external events:",
|
|
1106
1168
|
"- When the next progress depends on child sessions you spawned or on an external event, do not sleep, loop, or poll sessions_list/session_get/session_events to wait for it.",
|
|
1107
1169
|
"- Re-check sessions_list or session_get once; if the work is still in flight, call opengeni__goal_wait with a concrete reason and a deadline (untilSeconds), then end your turn immediately. You will be woken by a child result, a message, a human prompt, or at the deadline, and this goal stays active.",
|
|
1170
|
+
"- If the immediately preceding user-facing update already reported this same unchanged wait, do not restate it or produce another equivalent final answer. Call opengeni__goal_wait and end the turn. Report only material new state or a newly discovered blocker.",
|
|
1108
1171
|
"- A hold is for child/external progress only. If you are blocked on a human decision, use opengeni__goal_pause under the blocked audit below instead.",
|
|
1109
1172
|
""
|
|
1110
1173
|
] : [];
|
|
@@ -1166,8 +1229,8 @@ function withFirstPartyTools(settings, tools) {
|
|
|
1166
1229
|
}
|
|
1167
1230
|
return mergeToolRefs(tools, [{ kind: "mcp", id: "opengeni" }]);
|
|
1168
1231
|
}
|
|
1169
|
-
async function goalRunBudgetBlocked(settings, db, accountId, workspaceId,
|
|
1170
|
-
if (!
|
|
1232
|
+
async function goalRunBudgetBlocked(settings, db, accountId, workspaceId, fundedWithoutCredits) {
|
|
1233
|
+
if (!fundedWithoutCredits && (settings.billingMode === "stripe" || settings.usageLimitsMode === "managed")) {
|
|
1171
1234
|
const balance = await getBillingBalance(db, accountId);
|
|
1172
1235
|
if (balance.balanceMicros <= 0) {
|
|
1173
1236
|
return "insufficient OpenGeni credits";
|
|
@@ -1175,7 +1238,7 @@ async function goalRunBudgetBlocked(settings, db, accountId, workspaceId, isCode
|
|
|
1175
1238
|
}
|
|
1176
1239
|
if (settings.usageLimitsMode === "static" || settings.usageLimitsMode === "managed") {
|
|
1177
1240
|
const limits = configuredStaticUsageLimits(settings);
|
|
1178
|
-
if (!
|
|
1241
|
+
if (!fundedWithoutCredits && limits.maxMonthlyCostMicrosPerAccount) {
|
|
1179
1242
|
const used = await sumUsageQuantity(db, {
|
|
1180
1243
|
accountId,
|
|
1181
1244
|
eventType: "model.cost",
|
|
@@ -2662,49 +2725,35 @@ function legacyNativeArchiveFromEnvelope(envelope) {
|
|
|
2662
2725
|
existing?.version === 1 ? Date.parse(existing.capturedAt) : Date.now()
|
|
2663
2726
|
);
|
|
2664
2727
|
}
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
const reinstated = await reinstateTurnLeaseHolder(db, {
|
|
2671
|
-
accountId: ids.accountId,
|
|
2672
|
-
workspaceId: ids.workspaceId,
|
|
2673
|
-
sandboxGroupId: ids.sandboxGroupId,
|
|
2674
|
-
sessionId: ids.sessionId,
|
|
2675
|
-
attemptId: ids.attemptId,
|
|
2676
|
-
expectedEpoch: expected.leaseEpoch,
|
|
2677
|
-
expectedInstanceId: expected.instanceId,
|
|
2678
|
-
leaseTtlMs: settings.sandboxLeaseTtlMs
|
|
2728
|
+
function maybePersistWarmWorkspaceSnapshot(services, ids, session, leaseEpoch, signal, force = false) {
|
|
2729
|
+
let continuationRegistered = false;
|
|
2730
|
+
let resolvePhysicalSettlement = () => void 0;
|
|
2731
|
+
const physicalSettlement = new Promise((resolve) => {
|
|
2732
|
+
resolvePhysicalSettlement = resolve;
|
|
2679
2733
|
});
|
|
2680
|
-
|
|
2681
|
-
const message = "sandbox rotation checkpoint reinstated the live turn holder";
|
|
2682
|
-
const fields = {
|
|
2683
|
-
workspaceId: ids.workspaceId,
|
|
2684
|
-
sessionId: ids.sessionId,
|
|
2685
|
-
sandboxGroupId: ids.sandboxGroupId,
|
|
2686
|
-
leaseEpoch: expected.leaseEpoch,
|
|
2687
|
-
liveness: reinstated.lease.liveness
|
|
2688
|
-
};
|
|
2689
|
-
if (services.observability) services.observability.warn(message, fields);
|
|
2690
|
-
else console.warn(message, fields);
|
|
2691
|
-
}
|
|
2692
|
-
if (reinstated.status !== "present" && reinstated.status !== "reinstated") {
|
|
2693
|
-
return { checkpointed: false, holder: reinstated.status, lease: null };
|
|
2694
|
-
}
|
|
2695
|
-
await maybePersistWarmWorkspaceSnapshot(
|
|
2734
|
+
const result = persistWarmWorkspaceSnapshot(
|
|
2696
2735
|
services,
|
|
2697
2736
|
ids,
|
|
2698
2737
|
session,
|
|
2699
|
-
|
|
2738
|
+
leaseEpoch,
|
|
2700
2739
|
signal,
|
|
2701
|
-
|
|
2740
|
+
force,
|
|
2741
|
+
(continuation) => {
|
|
2742
|
+
continuationRegistered = true;
|
|
2743
|
+
void continuation.then(resolvePhysicalSettlement, resolvePhysicalSettlement);
|
|
2744
|
+
}
|
|
2745
|
+
);
|
|
2746
|
+
void result.then(
|
|
2747
|
+
() => {
|
|
2748
|
+
if (!continuationRegistered) resolvePhysicalSettlement();
|
|
2749
|
+
},
|
|
2750
|
+
() => {
|
|
2751
|
+
if (!continuationRegistered) resolvePhysicalSettlement();
|
|
2752
|
+
}
|
|
2702
2753
|
);
|
|
2703
|
-
|
|
2704
|
-
const checkpointed = lease?.leaseEpoch === expected.leaseEpoch && lease.instanceId === expected.instanceId && lease.rotationRequestedAt !== null && lease.archiveComplete && signal?.aborted !== true;
|
|
2705
|
-
return { checkpointed, holder: reinstated.status, lease };
|
|
2754
|
+
return Object.assign(result, { settled: physicalSettlement });
|
|
2706
2755
|
}
|
|
2707
|
-
async function
|
|
2756
|
+
async function persistWarmWorkspaceSnapshot(services, ids, session, leaseEpoch, signal, force, registerOwnedContinuation) {
|
|
2708
2757
|
const { db, settings } = services;
|
|
2709
2758
|
const intervalMs = settings.sandboxSnapshotIntervalMs;
|
|
2710
2759
|
if (intervalMs <= 0 && !force) {
|
|
@@ -2916,6 +2965,7 @@ async function maybePersistWarmWorkspaceSnapshot(services, ids, session, leaseEp
|
|
|
2916
2965
|
return { kind: "settled", persisted: false };
|
|
2917
2966
|
}
|
|
2918
2967
|
);
|
|
2968
|
+
registerOwnedContinuation(settled.then(() => void 0));
|
|
2919
2969
|
let cancelListener;
|
|
2920
2970
|
const outcome = await Promise.race([
|
|
2921
2971
|
settled,
|
|
@@ -3931,10 +3981,10 @@ function createTurnSandboxProvisioner(establish, options = {}) {
|
|
|
3931
3981
|
|
|
3932
3982
|
// src/activities/agent-turn/quiescence.ts
|
|
3933
3983
|
function shouldRunTurnEndWorkspacePersistence(input) {
|
|
3934
|
-
return input.activityStatus !== "cancelled" && !input.cancellationRequested;
|
|
3984
|
+
return input.activityStatus !== "cancelled" && !input.cancellationRequested && input.deadlineRotationRequested !== true;
|
|
3935
3985
|
}
|
|
3936
3986
|
function shouldStartPeriodicWorkspaceSnapshot(input) {
|
|
3937
|
-
return input.firstProviderRequestStarted && !input.snapshotInFlight && !input.turnEndCaptureInProgress;
|
|
3987
|
+
return input.firstProviderRequestStarted && !input.snapshotInFlight && !input.turnEndCaptureInProgress && !input.deadlineRotationRequested;
|
|
3938
3988
|
}
|
|
3939
3989
|
function assertPhysicalToolQuiescenceForCancellation(input) {
|
|
3940
3990
|
if (!input.acknowledgeQuiescence || input.physicalToolQuiescenceConfirmed) return;
|
|
@@ -4877,7 +4927,6 @@ export {
|
|
|
4877
4927
|
validateIncidentTelemetrySystemUpdateAuthority,
|
|
4878
4928
|
sandboxLeaseHolderIdForAttempt,
|
|
4879
4929
|
waitForWarmSnapshot,
|
|
4880
|
-
persistSandboxDeadlineRotationCheckpoint,
|
|
4881
4930
|
maybePersistWarmWorkspaceSnapshot,
|
|
4882
4931
|
resumeBoxForTurn,
|
|
4883
4932
|
SandboxDeadlineRotationError,
|
|
@@ -4932,4 +4981,4 @@ export {
|
|
|
4932
4981
|
codexUsageLimitFailurePayload,
|
|
4933
4982
|
CODEX_USAGE_LIMIT_MAX_RESUME_MS
|
|
4934
4983
|
};
|
|
4935
|
-
//# sourceMappingURL=chunk-
|
|
4984
|
+
//# sourceMappingURL=chunk-RQNH6CGR.js.map
|