Repository navigation
Description
Problem or use case
Epic #837 Stage B ("Define the generic handoff") needs a contract PR that settles the section-12 decision table before core/extension implementation starts. This issue tracks settling those decisions; implementation is a separate, subsequent PR once the decisions below are agreed.
Per #837's own inventory (see comment): every typed exports contract (AuthExports, StoreExports, FormsExports, MailExports, AuditExports, AbuseExports) is wired exclusively through HostContext.get inside composeHost, extension-to-extension, resolved once at host() time. The one carve-out is auth's sessionUserId() — a narrow, one-field, one-way x-urlcode-context-* header projection. Stage B has to decide how ordinary function/middleware routes get a typed, request-scoped, capability-limited accessor without core importing any extension.
Decisions to settle (from #837 §12, adopting its recommended starting points as the working baseline)
| Decision | Working baseline | Revisit only when |
|---|---|---|
| Distribution | Extension-owned facades + a generic core handoff; no mandatory new adapter package | A shared package demonstrably reduces duplication without pulling extensions into core |
| Application exposure | Explicit per-route/operation logical bindings using existing schema/policy metadata where feasible | Existing mechanisms can't represent the contract cleanly |
| Principal binding | Bind internally from the verified invocation; expose only minimal read-only facts by default | A separate reviewed actor mode is required |
| Sandbox | Pure projections only; refuse host-backed facades before serving | A bounded RPC design has its own contract and adversarial fixtures |
| Custom auth wire format | Keep native lifecycle by default; #830 stays auth-owned | A fixed external API needs a reviewed auth-owned mapping |
Also settle, per #837 §17 ("gaps found in plan review") — priority: settle these four before publishing the generalized binding API:
- Transitive authority/policy parity — when one facade calls another service, which policies apply (ownership, quota, audit, recipient checks)? Define caller attribution/delegation; an explicit target user must never replace the acting principal.
- Aggregate resource budgets/backpressure — deadlines, bounded concurrency, result/page/byte limits, queue saturation for host-backed facades; how nested calls share budgets.
- Discovery content as untrusted input — provenance/revision pins identify content but don't make its prose safe instructions; inert discovery vs. trusted host-module execution must be distinguishable.
- Cross-transport value semantics — the portable value subset shared across HTTP/MCP/other targets (absent vs. null, timestamp/decimal/bigint, byte payloads, pagination tokens, error serialization).
Concrete mechanism question this issue must answer
Given the sessionUserId precedent (one-way header projection, one field, no verification burden on core), choose one:
- (a) Generalize the header-projection pattern per declared capability (core stays purely a byte-forwarder; each extension defines its own projected fields), or
- (b) Give ordinary routes a typed, request-scoped accessor equivalent to
HostContext.get, scoped to the route's own declared capability grants (core owns binding/lifecycle/refusal; extensions still own their facade's behavior).
Exit evidence (per #837's Stage B row): an external test provider works without a core import of any first-party extension; two simultaneous users/requests stay isolated; missing/unsupported/reload cases fail deterministically before serving.
Depends on
- [Re-scoped; legacy expansion on hold]: Ecosystem integration, discovery and AI authoring #837 (epic)
- Stage A (docs(store): correct conditional-write limitations prose (epic #837 Stage A) #838, [Request]: Correct store limitations prose to acknowledge conditional writes #836) landing first for the baseline inventory
- Expose native session identity to application function routes #833 landing (the
sessionUserIdprecedent this generalizes)
Alternatives
Do nothing further and leave sessionUserId as the only precedent — rejected by the epic's own scope (§1, §5) which calls for closing this gap across auth/store/forms/mail/audit/abuse, not just auth.
Activity
jimhoyd commentedon Sep 28, 2026
Decision (proceeding with implementation)
Choosing mechanism (b): a typed, request-scoped accessor equivalent to
HostContext.get, scoped to the route's own declared capability grants — not a generalized version of the header-projection trick.Reasoning: the header-projection channel (
x-urlcode-context-*) only works for bounded, string-serializable, pre-computed-at-authorize-time facts (that's whatsessionUserIdis). Store/mail/audit/abuse facades need live method calls bound to the current invocation (records.update(id, {ifMatch}),mail.send(...)), which can't be precomputed into a header before the handler runs. Generalizing (a) would mean re-inventing RPC-over-headers for every capability; (b) reuses the exact lifecycle/activation machineryHostContext.getalready has, just re-scoped from "another extension'shost()" to "this route's declared grants, resolved per invocation."Concrete shape landing in the Stage B PR
packages/core/src/extensions.tsgains a genericApplicationProvidercontract and anInvocationContext(request id, transport, route/operation, principal{provider, id} | null, cancellation/deadline). Core never imports auth/store/etc.; it only knows "an extension registered a provider under capability name X" and "this route declared it wants X."ExtensionDefinition.host()may return an additionalprovide?: (capability: string) => ApplicationProvider | undefinedalongsideexports. Nothing changes for extensions that don't provide one.capabilities:) lists declared capability names, analogous to how extensions already declarerequires/uses— reusing that existing metadata shape rather than inventing new syntax where avoidable.provide(name).forInvocation(ctx), and only then hands the bound facade to the handler viacontext. A missing/incompatible/denied capability refuses before the handler runs (not a thrown exception mid-handler).sandbox: true+ a declared capability that isn't marked as a pure projection fails activation, not silently at first call.This generalizes the identity precedent without deciding auth/store's own facade method names yet — those stay Stage C's job. Implementation starting now on a branch off main; will open the contract PR referencing this issue and #837.
jimhoyd commentedon Sep 28, 2026
Implementation landing
The generic handoff described above is implemented, tested and documented; opening the contract PR against main next (branch
claude/epic-837-stage-b-handoff).What shipped, generalizing
sessionUserId's one-way header projection into a live, per-invocation call, with zero new YAML:RuntimeExtension.capabilities?: readonly string[]— a registration's pure availability signal (parallel toprovidesPrincipal/streams), validated atprepareExtensions(≤32 distinct lowercase names).ExtensionInstance.provide?(capability, invocation): unknown|Promise<unknown>— called once per declared name, per request, only for an extension the route already names inpolicies.extensions(so it's still gated by that extension's ownauthorize()/middleware()— no side door around existing admission, per the transitive-authority-parity gap in §17).InvocationContext— frozen, request-scoped:requestId,route.pattern, the committedprincipal(never caller-supplied), and the request'sAbortSignaloff the sandbox path.context.capabilities.<extension>.<capability>, built right afterFunctionContext, alongsidecontext.signal.sandbox: true+ a route naming a capability-declaring extension fails route compilation withcapability-in-sandbox, the same place and pattern as the existingstream-in-sandboxcheck — a live object can't cross the QuickJS worker's JSON boundary.provide()returningundefinedjust omits that one entry (e.g., an anonymous request asking for a capability that needs a principal) — not an error.Exit evidence (
test/extension-capability.test.ts, 8 cases): a synthetic, non-first-party "vault" provider proves core needs no import of any real extension; two sequential requests get distinctrequestIds and never share a bound object; a route not naming the extension gets nothing; an extension with no declared capabilities, or noprovide()method, is a no-op not a crash;sandbox: truerefuses activation deterministically when capabilities are named, and still activates cleanly when they aren't; registration-time validation rejects malformed/duplicate/oversized capability lists.Docs: new "Request-bound capabilities" section in EXTENSIONS.md and a
RIM-EXT-CAPABILITY-001contract card in RUNTIME-IMPLEMENTATION.md.Deliberately left out of this PR (Stage C+ per the epic's sequencing): no store/auth/mail/audit/abuse package actually declares a capability yet — that's each package's own facade-naming decision. The other three priority gaps from §17 (aggregate budgets/backpressure, discovery-as-untrusted-input, cross-transport value semantics) are also out of scope here; they don't block this mechanism and can land incrementally.
jimhoyd commentedon Sep 28, 2026
Implementation opened as PR #840;
npm run verifypasses in full, auto-merge enabled — will land once CI is green.