feat(companion-phase-4): runtime manager decision core — pure lifecycle, integrity, backpressure, resource limits
Phase 4 of the Companion App build plan (feat/companion-app). Scope: pure-then-bind — NO runtime spawned, NO download performed, NO socket bound.
## Deliverables
lib/companion-runtime-manager.mjs — pure, I/O-free decision core: - Supply-chain integrity: SHA-256 + size verification with constant-time digest comparison (hash-of-hash via crypto.timingSafeEqual); source allowlist + HTTPS-only enforcement at spec-validation time; createIntegrityAccumulator (streaming) and verifyModelBytes (in-memory); fail-closed on any ambiguous spec field. - Lifecycle state machine: stopped→starting→ready→draining→stopped; canServeInference returns true ONLY for ready state; invalid transitions fail-closed; pure (no mutation). - Backpressure/concurrency admission: maxInFlight + queueBound hard caps; evaluateAdmission returns at_capacity/queue_full; recordInFlight/recordCompletion pure state advancement; evaluateRuntimeRequest is the single gate. - Resource-limit policy: RAM/VRAM/CPU ceilings; evaluateResourceLimits; injected ResourceObservation from Phase 5 adapter.statResources(). - Top-level gate (evaluateRuntimeRequest): lifecycle → admission → resource in order; never throws on any input; no secret/path/URL in any reason string. - RuntimeAdapterFns typedef: spawn/download/healthCheck/statResources — no vault, canister, JWT, or keychain in the adapter interface (ambient authority boundary).
test/companion-runtime-manager-*.test.mjs — 7-tier suite (219 cases, all green): unit(84) integration(20) e2e(7) stress(12) data-integrity(47) performance(11) security(38) Security tier covers: wrong/missing digest rejects before execution; 1-bit corruption detected; oversized download rejected; HTTP source banned structurally; foreign source rejected; empty allowlist fail-closed; lifecycle gate blocks all non-ready states; backpressure trips at exact bound (100 in-flight, 1000-request flood blocked); RAM/VRAM/CPU over-limit rejected; no ambient authority in exports; verdict shape is { ok, reason } only; no secret/URL/digest in any reason string; constant-time comparison timing-ratio bound; global fail-closed posture (null on any input → deny, no throw).
docs/COMPANION-APP-PHASE-4-RUNTIME-MANAGER.md — accepted design, module contract, adversarial threat note (supply-chain/resource exhaustion/ambient authority), integrity/backpressure/lifecycle rules, Phase 5 bind-gate obligations, remaining blockers to Phase 5 (G1: OAuth gate, G2: Phase 5 bind-gate design), recommended order.
Gate compliance: - No bundled runtime shipped (gate DOES NOT approve list). - No new local HTTP listener bound. - No binary/installer/auto-updater. - Phase 1 seam: companionAvailable flips true only after real health-check (Phase 5). - Owner policy: no docs-only PR to main.
Refs: docs/COMPANION-APP-DESIGN-AND-AUTHORIZATION-GATE.md §7/§10/§12 phase 4 docs/COMPANION-APP-PHASE-1-ADAPTER-SEAM.md (companionAvailable seam) docs/COMPANION-APP-PHASE-2-LOOPBACK-SECURITY.md (ambient authority boundary) docs/COMPANION-APP-PHASE-3-OAUTH-PKCE.md (pure-then-bind discipline)
Semantic Changes
81 symbols
0 comments
muse hub commit comment sha256:3c71452a68bfee676b1e54695a6d54acb254b3271bb2b31f727090f9618d3f27 --body "your comment"
No comments yet. Be the first to start the discussion.