feat: harden orchestrator execution runtime

This commit is contained in:
john
2026-07-24 23:53:32 +08:00
parent 396bb78200
commit f6f2cd0933
55 changed files with 5122 additions and 194 deletions
+19 -8
View File
@@ -7,11 +7,11 @@ import {
normalizeWorkflowName,
stableRolloutBucket,
} from './contracts.mjs';
import { listPhase3ExecutorAdapters } from './executor-gateway.mjs';
import { listPhase5ExecutorAdapters } from './executor-gateway.mjs';
const CONFIG_TABLE = 'h5_orchestrator_admin_config';
const CONFIG_SCOPE = 'global';
const EXECUTION_HANDOFF_IMPLEMENTED = false;
const EXECUTION_HANDOFF_IMPLEMENTED = true;
function normalizeBoolean(value, fallback = false) {
if (value == null || value === '') return fallback;
@@ -75,6 +75,7 @@ export function defaultOrchestratorConfig() {
workflowAllowlist: [...DEFAULT_ORCHESTRATED_WORKFLOWS],
fallbackToNative: true,
requireHealthy: true,
executionEnabled: false,
};
}
@@ -105,11 +106,16 @@ export function normalizeOrchestratorConfig(input = {}, fallback = defaultOrches
: [...DEFAULT_ORCHESTRATED_WORKFLOWS],
fallbackToNative: normalizeBoolean(source.fallbackToNative, base.fallbackToNative),
requireHealthy: normalizeBoolean(source.requireHealthy, base.requireHealthy),
executionEnabled: normalizeBoolean(source.executionEnabled, base.executionEnabled),
};
}
function runtimeState(config, env = process.env) {
const killSwitch = normalizeBoolean(env.MEMIND_ORCHESTRATOR_KILL_SWITCH, false);
const environmentExecutionGate = normalizeBoolean(
env.MEMIND_ORCHESTRATOR_EXECUTION_HANDOFF_ENABLED,
false,
);
const configured = config.primaryEngine !== WORKFLOW_ENGINE.LANGGRAPH || Boolean(config.serviceUrl);
let reason = null;
if (killSwitch) reason = 'kill_switch';
@@ -117,10 +123,12 @@ function runtimeState(config, env = process.env) {
else if (!configured) reason = 'service_url_missing';
const executionModeSelected = [ORCHESTRATOR_MODE.CANARY, ORCHESTRATOR_MODE.ACTIVE]
.includes(config.mode);
const executionHandoffRequested = executionModeSelected
const executionHandoffRequested = config.executionEnabled
&& executionModeSelected
&& config.primaryEngine === WORKFLOW_ENGINE.LANGGRAPH;
const executionHandoffEnabled = !reason
&& EXECUTION_HANDOFF_IMPLEMENTED
&& environmentExecutionGate
&& executionHandoffRequested
&& config.primaryEngine === WORKFLOW_ENGINE.LANGGRAPH;
return {
@@ -147,9 +155,12 @@ function runtimeState(config, env = process.env) {
enabled: executionHandoffEnabled,
reason: executionHandoffEnabled
? null
: EXECUTION_HANDOFF_IMPLEMENTED
? 'execution_handoff_not_requested'
: 'phase3_dry_run_only',
: !EXECUTION_HANDOFF_IMPLEMENTED
? 'execution_handoff_not_implemented'
: !environmentExecutionGate
? 'environment_execution_gate_disabled'
: 'execution_handoff_not_requested',
environmentGate: environmentExecutionGate,
},
};
}
@@ -312,7 +323,7 @@ export function createOrchestratorAdminConfigService(pool, {
...state,
runtime: runtimeState(state.config, env),
engines: engineCatalog(state.config),
executors: listPhase3ExecutorAdapters(),
executors: listPhase5ExecutorAdapters(),
};
},
@@ -345,7 +356,7 @@ export function createOrchestratorAdminConfigService(pool, {
...state,
runtime: runtimeState(state.config, env),
engines: engineCatalog(state.config),
executors: listPhase3ExecutorAdapters(),
executors: listPhase5ExecutorAdapters(),
...(probe ? { serviceHealth: await probeServiceHealth(state.config, { fetchImpl }) } : {}),
};
},