Repository navigation
Description
Part of #384. Implements spec §5's capability and settlement, §7's admission and attribution; decisions the execution service (the callback path, the contracts), identity points 1–5, the reference CRM (a tier 2 page's direct call is a bypass). The shared lifetime every later handler ticket stands on.
What to build
server.callas one runtime operation for all kinds: validated args, the handler resolved from the loaded version's descriptors, dispatched through Runtime'sExecutor(the supervised local executor in tests).- Invocation admission, once per call: session live, viewer may open the patch, the patch live, the loaded version eligible (retained, not revoked), scope not public (a
server.callfrom a public-scope document is refused), and the per-kind limits from the registry (actions in flight: 8 per company, 2 per viewer per patch). The breaker'spatch_pausedcheck lands with the fleet controller. - A tier 2 page never gets name-based direct primitives: every direct
tables.*,files.*by name,shared.*and connection operation from a document whose loaded version is tier 2 is refused, whatever tier is served. - The invocation capability: an opaque per-attempt reference minted by the host, resolvable only by the issuing replica, naming invocation, attempt, company, patch, version, initiating viewer, kind, deadline and process generation. It ends on return, deadline, supersession or kill. A replay is refused, with its reason, from a 5 min tombstone. Attempt identity is immutable: a late call from attempt one never acquires attempt two's authority.
- The callback gateway: a private listener, distinct from the public API, that admits callbacks by capability, checks scope and generation, enforces the kind rules host-side, and resolves the effective principal per callback (the patch for own primitives, which inherit admission; the viewer for everything else, re-checked live). Refusals return as data. Callback bounds from the registry: 1,000 per invocation, 8 outstanding (queued, not refused), 64 MiB per call tree, 20 MiB of file bytes per callback.
- Settlement never depends on the caller: at the deadline the host fences effects and begins cancellation whether or not the client is connected, then settles within the cleanup bound (
tier2.settlement.cleanup, 5 s after the deadline, in the registry). A connection whose cancellation or commit outcome is unresolved at that bound is destroyed, never returned to the pool, and the invocation staysunknown_outcomeuntil reconciliation by its mutation key establishes the outcome; it is never reported ashandler_timeout. A late guest return cannot restore eligibility. Departure gates starting, not finishing. - Migration
runtime_invocations(Runtime record):runtime_calls.user_idnullable, pluseffective_principal,invocation_idand thehandler_erroroutcome; aruntime_invocationstable (handler, kind, initiating viewer, patch, version, parent, outcome, timing, log lines, and the metering columns the metering ticket fills,db_msincluded); aruntime_query_rollupstable keyed by company, patch, version, handler and UTC minute. Mutations and actions always get an invocation row; queries only onctx.logor failure. The per-connection recent-calls reader keeps working unchanged. - Errors:
HandlerErrorenforced against the declared list;handler_failedcarries a correlation id, with message and stack in the log only.
Admitted at merge
A test handler that reads its own table runs end to end through the gateway on the local executor. The server still refuses tier 2 publish.
Done when
A replayed capability is refused with its reason; a late callback from a finished attempt is refused; a tier 2 page's direct tables.list is refused; an admitted call whose client disconnects is fenced and settled at its deadline (fault-injected through an executor that never returns); a public-scope document's server.call is refused.
Surfaces
Migrations (three call sites, ADR-0003, CLAUDE.md), the wire (docs/API.md), ADR-0012 (the gateway, the capability, settlement), the Runtime glossary (Invocation, Effective principal replaces Acting identity, Initiating viewer replaces Principal, Invocation admission, Callback authorisation, Patch identity moved from Serving), docs/product.md § Tier 2 (the two identities).
Activity
feat(runtime): admit and settle handler invocations