Skip to content

Call and resource invocation

A call reaches block code as two integers and a set of typed values. Every dispatch frame names an export ordinal and a method ordinal, both fixed when the interface was compiled, and the provider routes on those. Method names are documentation and SDK names; the ordinals are the ABI. This page covers how a dispatch frame becomes a call, how a call on a live resource differs, and what the provider returns.

From frame to call

flowchart TB
  FR["Dispatch frame<br/>export ordinal, method ordinal,<br/>typed arguments"]
  subgraph PROV["CPYTHON PROVIDER"]
    direction TB
    M{{"Method from the prepared<br/>compiled interface"}}
    ARG["Arguments projected<br/>by parameter id"]
    AD["Generated capsule adapter<br/>bound to the interface hash"]
    TAB[("Provider resource table")]
    CALL["Block callable"]
    M --> ARG --> AD --> CALL
    TAB -.->|"held object, for a resource method"| AD
  end
  OUT["Typed outcome"]
  FR --> M
  CALL --> OUT

For each frame the provider looks the method up in the prepared compiled interface by its ordinals, projects the typed arguments by parameter id, and calls the generated capsule adapter, which is bound to the admitted interface hash. The adapter calls the block.

Calls on a resource

A caller first presents its cell-local handle to its own monitor. That monitor validates the handle's table, cell epoch, slot, generation and Invoke right, then derives a call-scoped borrow. It selects the one installed ChannelGrant whose caller, owner, channel epoch, interface hash, method right, expiry and credit all match the call. Once both monitors have installed the grant, subsequent resource calls use this delegated hot path without a synchronous nucleus round trip.

flowchart TB
  subgraph CALLER["CALLER CELL"]
    direction TB
    BMON{{"Caller monitor<br/>local handle, scoped borrow,<br/>channel credit"}}
  end
  subgraph OWNER["OWNER CELL"]
    direction TB
    AMON{{"Owner monitor<br/>resolves the owner-local slot"}}
    PROV["Owner provider<br/>held object"]
  end
  BMON -->|"1. resource slot, generation,<br/>interface, call identity"| AMON
  AMON -->|"2. provider-local resource id"| PROV
  PROV -.->|"3. typed outcome"| AMON
  AMON -.->|"4. receipt and outcome<br/>for the exact attempt"| BMON

Caller monitor validates the handle and spends channel credit before anything leaves the caller cell. The message to Owner monitor names the kernel slot and generation, and only the owner monitor can turn that slot into the provider-local id Owner provider holds. On the return the caller monitor settles credit and closes the borrow scope.

The provider checks its own epoch and passes the held Python object to the ordinal adapter. A stale resource generation or provider epoch is refused. See Provider resource table and Handle import and export.

Concurrency and recursive calls

The compiled kernel capability interface seals one concurrency mode for each resource. The owner monitor admits a call against that sealed declaration before dispatching it to the runtime provider.

flowchart TB
  subgraph MON["OWNER MONITOR"]
    direction TB
    SLOT[("Active resource slot<br/>mode and reentrant bound")]
    LIVE[("Live calls<br/>task, call and attempt ancestry")]
    GATE{{"Concurrency and call-cycle admission"}}
    STATE[("Call state<br/>active, yielded or waiting")]
    SLOT --> GATE
    LIVE --> GATE
    GATE -->|"admitted"| STATE
  end
  PROVIDER["Runtime provider adapter"]
  FAULT(["Typed fault<br/>CallCycle or ResourceBusy"])
  STATE -->|"dispatch"| PROVIDER
  GATE -->|"refused"| FAULT

serial admits one active call. A recursive entry whose ancestor already owns the resource returns CallCycle before waiting; unrelated contention returns ResourceBusy. read_concurrent admits concurrent observing calls only when the compiled method effect is pure or read_only. parallel admits calls without resource-level serialisation. reentrant admits only a recursive ancestor chain and stops at the sealed max_reentrant_depth.

An adapter releases active occupancy through an explicit yield transition. A wait transition names an existing attempt, and resume repeats concurrency admission before the call becomes active. The owner monitor detects a complete wait cycle before deadlock recovery terminates a member. Deadlock recovery is a terminal outcome applied only after cycle detection.

Every completed, refused, recovered or resource-terminated call emits terminal evidence that binds task, call, attempt, resource slot and generation, concurrency declaration and terminal cause. The return lane preserves that evidence for run audit. See Evidence effects.

Resource termination reconciles calls by the same resource slot and generation used for dispatch. The caller monitor returns channel credit, invalidates the borrow scope and records the affected attempt. A live owner monitor removes the owner slot and sends release for the provider-local resource. Calls presented after cleanup receive the terminal fault stored with the local handle: stale_handle, owner_lost, revoked or transfer_failed.

Imported kernel references, buffers and invocation bindings each arrive through their own delivery channel. A frame that carries one before its channel is installed is refused with a typed fault.

What the provider returns

Outcome Meaning
Value The method's result, encoded as the declared return type
Declared error An error variant the interface declares for this method
Guest fault One of the closed fault kinds
Resource or stream proposal A provider-local object offered for promotion

A stateless method returns unit, a typed value, a declared error or a guest fault. A proposal becomes a caller-visible kernel handle in four stages: proposed by the provider, validated by the owner monitor, authorised by the nucleus, and installed for the caller. See Exception adaptation and result classification and Handle import and export.

For a resource call, the owner monitor binds its completion to the exact task, call and attempt from the admitted dispatch. The receipt sequence distinguishes dispatch commitment, channel dispatch, provider dispatch, monitor-accepted completion and caller acknowledgement. A receipt with a changed task, call, attempt, closure or capsule identity is refused. The caller receives only the declared typed result; a call-scoped borrow cannot turn a returned live object into durable kernel authority. Caller acknowledgement settles the caller monitor atomically: it returns channel credit, retires the terminal credit reservation, releases the call-scoped borrow and removes the attempt-to-resource binding. If any part is refused, the pre-settlement authority remains intact.

Caller acknowledgement is also the reclamation boundary for an ordinary non-idempotent invocation. After its terminal evidence has been projected, the nucleus removes the completed task, attempt, retry intent, terminal effects, cancellation and settled credit reservation as one state transition. A live idempotency claim and an ambiguous outcome are kept, so they remain available for deduplication or recovery. The evidence in the return lane remains the durable audit history after in-memory invocation authority is reclaimed.