Expand description
Task 19 (Commit B) — session-scoped exact MCP runtime leases (spec §7.4).
Deferred descriptor-backed MCP tools execute ONLY through this manager,
AFTER the ExecutionGate has already authorized the exact call. The
manager owns every live MCP child for the runtime:
- a lease is keyed by (session, server) and PINNED to the config
fingerprint it was acquired under; per-key SINGLE-FLIGHT acquisition
(a
Startingplaceholder holding awatchreceiver, whose stored state makes wakeups lost-proof) guarantees concurrent first calls never spawn duplicate children, and the manager map lock is NEVER held across process/pipe I/O; - acquisition starts exactly one child (
kill_on_drop), initializes and lists ONCE, and pins the bounded listing; every call validates the selected exact runtime name and canonical schema digest against the cached expectation BEFOREtools/call— a mismatch terminates the poisoned lease without calling; - revocation/termination semantics (exact and honest): revocation
marks the lease cancelled under the per-lease call gate. A call that
already passed the gate check (taken while holding the connection
lock) MAY still complete; NO call passes the gate after revocation
returns, and a completing call that observes cancellation kills the
child before releasing the connection. Teardown is guaranteed by
kill_on_droponce the lastArcdrops (map removal plus bailing callers make that inevitable) with an immediate best-effortstart_killaccelerator — the manager retains nothing; - idle leases are reaped opportunistically with a CONSTANT per-pass
scan cap; session end is the drop of the LAST owner of the shared
durable
McpSessionEndGuardscope (runtime clones + in-flight streams hold it; no per-turn guard exists). No PID signalling, no long-lived task, no unbounded channel; - a server configured
shared: true(daemon mode, opt-in) is keyed underSHARED_SESSION_KEYinstead of the session: one child serves every session,terminate_sessionspares it,reap_idleandterminate_allstill reap it. Every call still validates exact name + digest; sharing widens the CHILD, never the grant.
Structs§
- McpLease
Capability - Typed per-session lease capability handed to tool contexts: the exact session identity plus the shared manager. Never widens to a server grant — every call re-validates the exact tool and fingerprint.
- McpRuntime
Manager - Session-scoped exact MCP runtime lease manager. See module docs.
- McpSession
EndGuard - Durable last-owner session scope. The Runtime mints ONE of these per
tool session (wrapped in an
Arcshared by every runtime clone and in-flight stream); streams HOLD it, never construct or drop their own. Leases therefore survive across provider turns, and only the drop of the LAST owner — true session end — terminates the session’s leases.
Enums§
- McpLease
Error - Typed lease failures. Provider-controlled content never appears here — only static text, local identities, and numeric metadata.
Constants§
- DEFAULT_
IDLE_ MAX - Default idle bound for opportunistic reaping.
- MAX_
LIVE_ LEASES - Hard cap on simultaneously live leases per manager, so termination fanout (and cleanup-task count) is always bounded.
- REAP_
SCAN_ MAX - Reap passes scan up to the FULL capped map (equal to the live-lease cap), so idle entries can never starve behind an active HashMap iteration prefix.
- SHARED_
SESSION_ KEY - Lease-map session key for
shared: trueservers (one child per process, not per session). Never a real session’s key:terminate_sessionskips it explicitly.
Functions§
- config_
source_ from_ disk - Production config source: profile-resolved
mcp.jsonlookup. - lease_
session_ key - Session component of the lease key for
serverunderconfig.
Type Aliases§
- Config
Source - Injectable current-config lookup: production reads
mcp.jsonper acquisition (bounded local file read); tests inject a mutable map.