Governed Opt-In Execution Architecture (v4.3 Sprint D Hardened)
Overview
MultiModel Dev OS v4.3 Sprint D introduces an explicit opt-in execution gate and single-attempt governed executor (src/gateway/execution/) enforcing strict preflight policy, trusted endpoint binding, capability consistency, byte budgets, and secret safety before any provider execution attempt.
Architectural Principles & Boundaries
- Disabled by Default: External provider execution is strictly disabled unless
policy.enabled === trueand the provider ID is explicitly allowlisted inpolicy.allowed_provider_ids. - Preflight Gate Evaluation:
evaluateExecutionGate()validates policies, trusted endpoint bindings, adapter type compatibility (openai-compatible), capabilities, streaming/tool flags, HTTPS protocols, and credential references. - No Built-in Network Transport: The execution layer contains zero network primitives (
fetch,http,https,net,tls,dns). Execution requires an explicitly injected transport contract (transport.execute(...)). - Single-Attempt Execution: Governed execution allows exactly one attempt (
max_attempts: 1). Retries and fallback transitions are strictly forbidden at the single-attempt executor level. - Short-Lived Credential Scope & Destruction: Resolved credentials exist inside opaque
ResolvedCredentialcontainers during transport invocation and are guaranteed to be destroyed in thefinallyblock after execution completes or fails. - Output Redaction & Trusted Transport Boundary: Any transport result or thrown error is sanitized using
redactSensitiveValue(target, [credential])before the credential container is destroyed. Note: an injected transport is in-process trusted code and could copy a raw secret during its callback; the framework guarantees container lifecycle destruction and result/error output redaction, not in-process memory isolation against malicious code. - No Authorization Header Construction: Transport selection and authorization header generation remain deferred. Zero
AuthorizationorBearerstrings are constructed in production gateway execution code. - No Gateway HTTP Server Integration: The execution gate and executor are pure internal utilities. Integration into the local gateway HTTP server routes remains deferred to Sprint E.
Governed Execution Lifecycle Ordering
Execution proceeds deterministically in 11 steps:
- Basic request contract validation (
validateExecutionRequest) - Execution gate preflight evaluation (
evaluateExecutionGate) - Abort signal cancellation pre-check (
signal.aborted) - Injected transport contract validation (
validateTransport) - Credential resolution (
resolveEnvironmentCredential) - Request normalization (
normalizeOpenAIExecutionRequest) and request byte limit check (max_request_bytes) - Exactly one transport invocation (
await transport.execute(...)) - Secret-aware transport result/error sanitization (
redactSensitiveValue) - Credential container destruction (
resolvedCredential.destroy()infinally) - Response/error normalization (
normalizeOpenAIResponse/normalizeOpenAIError) and payload byte limit check (max_response_bytes) - Validated
ExecutionResultoutput (validateExecutionResult)
Attempt Count Semantics
- Failures occurring before
transport.execute()begins (gate denial, invalid request, invalid transport, credential error, request_too_large, pre-aborted signal):attempt_count: 0. - Failures occurring after
transport.execute()begins (transport crash, provider error, response_too_large, post-invocation timeout):attempt_count: 1. - Completed execution results:
attempt_count: 1.
Trusted Endpoint Binding Rules
validateEndpointBinding() binds request endpoints strictly to provider_adapter.base_url:
- Protocol must be
https: - Same hostname and same effective port
- Forbidden: embedded userinfo (
user:pass@), URL fragments (#hash), query parameters (?key=val), and encoded path traversal (%2e,/..) - Endpoint path must equal the trusted base path or be a true path-segment descendant (rejecting prefix tricks like
/v10matching/v1)
API Usage
javascript
import {
evaluateExecutionGate,
executeGovernedRequest,
createExecutionPolicy,
createExecutionRequest,
} from './src/gateway/index.js';
// 1. Evaluate Preflight Gate
const gateResult = evaluateExecutionGate({
policy,
provider_id: 'openai',
provider_adapter: openAIAdapter,
request: executionRequest,
endpoint,
capability,
});
if (!gateResult.allowed) {
console.log('Execution denied:', gateResult.reason);
}
// 2. Execute via Injected Transport
const result = await executeGovernedRequest({
execution_request: executionRequest,
provider_adapter: openAIAdapter,
transport: {
async execute({ payload, credential }) {
// Injected transport implementation
return { ... };
},
},
environment: process.env,
});Signal & Timeout Behavior
- The executor races
transport.execute(...)against the suppliedAbortSignal. - An uncooperative in-process transport may continue its own work after abort, but MultiModel Dev OS returns the cancellation result (
timed_out/ HTTP 504 orcancelled/ HTTP 499), destroys its credential container, and discards late output. - External streaming remains explicitly deferred to Sprint E2.
