This guide is for contributors to the current Orleans.FSharp functional runtime. Application-facing
usage belongs in docs/; this file describes the architecture, change workflow, and invariants
that maintainers need.
The functional runtime separates four concerns:
- A
GrainContract<'Actor,'Key,'Api>declares durable identity, key encoding, protocol version, operation IDs, and delivery policy. - A
FunctionalGrainDefinition<...>orFunctionalJournaledGrainDefinition<...>binds that contract to state and handlers. - Runtime hosting registers a definition and the fixed functional transport with Orleans.
FunctionalGrain.refbinds the same contract to anIGrainFactoryand returns the typed API record used by callers.
The actor-brand type keeps unrelated contracts distinct at compile time. The API record describes the callable surface. The contract owns wire compatibility; the definition owns behavior. Callers cannot tell whether the hosted definition uses ordinary state or an event journal.
| Project | Responsibility |
|---|---|
Orleans.FSharp |
Contracts, definition builders, typed references, observers, state descriptors, serialization, and shared helpers |
Orleans.FSharp.Runtime |
Functional activation/dispatch, silo registration, and siloConfig / clientConfig |
Orleans.FSharp.Abstractions |
Fixed C# transport interfaces and generated Orleans proxies |
Orleans.FSharp.Testing |
TestingHost, web-host, FsCheck, mock-factory, and log-capture helpers |
Orleans.FSharp.Analyzers |
F# analyzer rules |
Orleans.FSharp.EventSourcing |
Legacy compatibility package; current journals are in Orleans.FSharp |
Orleans.FSharp.CodeGen |
Legacy per-grain CodeGen compatibility |
typed API field
-> contract operation metadata
-> fixed Orleans proxy
-> functional request envelope
-> hosted definition registry
-> typed handler
-> encoded reply
The wire operation ID is the record-field name unless operationId overrides it. Contract
version admission happens before handler dispatch. Key codecs must round-trip and are part of the
grain's durable identity.
The public builders are staged:
grainContractstarts with an empty contract draft and seals aGrainContract.grainFor contractrequiresdefaultStateorinitialStatebefore state-dependent operations become available.journaledGrainFor contractrequiresinitialEventStatefirst andapplysecond so the state and event types are established before handlers are accepted.
This staging is deliberate API validation, not just implementation detail. A new custom operation must preserve type inference and should reject invalid combinations while the definition is sealed, before a silo accepts traffic.
When adding a keyword:
- Decide whether it changes the wire contract, delivery policy, or only hosted behavior.
- Add it to the narrowest builder stage that has all required type information.
- Validate nulls, ranges, duplicate declarations, and incompatible combinations at sealing.
- Add reflection-based surface coverage so the public keyword set cannot drift silently.
- Add semantic tests for the behavior and a startup/integration test when Orleans configuration is involved.
- Update
docs/api-reference.md, the relevant guide, its website mirror, andQUICK-REFERENCE.md.
For a selector-based contract operation, retain the one-argument API-field invariant:
[<NoEquality; NoComparison>]
type ExampleApi =
{ update: (string * int) -> Task<unit>
read: unit -> Task<int> }Multiple logical inputs are one tuple argument. Curried fields are not a supported wire shape.
State-changing handlers return replacement state explicitly:
let increment _context count () =
task {
let next = count + 1
return next, next
}Reply-only handleQuery callbacks do not return state and require a contract operation declared
readOnly. Streaming handlers return IAsyncEnumerable<'Item> directly. Journaled handlers
return 'Event list * 'Reply; the runtime confirms the batch before releasing the reply.
PersistentState.create stateName providerName produces an immutable descriptor. stateFrom
attaches the primary state; usePersistentState attaches additional named facets. Descriptor
identity includes state name, provider name, and stored type. Two provider writes are not an atomic
transaction.
TransactionalState.create stateName storageName plus transactionalStateFrom attaches an
Orleans transactional facet. The contract's transactional operation takes
Orleans.TransactionOption. The invocation-bound FunctionalTransactionalState exposes
read, readWith, update, and updateWith.
IFunctionalJournalStorage<'Key,'State,'Event> is the application-owned custom-storage seam:
Readreturns an optional snapshot and the ordered retained tail after it.AppendcomparesExpectedVersion, writes the entire event batch atomically, and may persist the resulting snapshot in the same operation.Cleardeletes the complete journal for one storage identity.
Ordinary storage exceptions raised through Orleans' CustomStorage adaptor remain transient to its
retry protocol. A custom store throws FunctionalJournalPermanentStorageException only for a
failure that retry cannot repair; the functional runtime fails the operation and requests
activation deactivation. A zero-event manual snapshot calls Append directly: an ordinary
exception fails that call without implicit retry or deactivation, while the permanent marker keeps
the same fail-and-deactivate meaning.
Snapshot precedence is fixed:
context.snapshotNow()for a successful callback;- the definition's
snapshotPolicy; - the silo-wide
FunctionalJournalSnapshotOptions.PolicyforInheritor no local policy; Disabled.
FunctionalJournalSnapshotOptions.ManualSnapshotMaxConflictRetries is non-negative and defaults
to 3. It counts retries after the first CAS attempt for a zero-event manual snapshot, so the
default allows four total attempts; every retry refreshes and recomputes from confirmed state.
Snapshots are available only with customStorage. LogStorage keeps and replays the event log;
StateStorage writes the latest folded view and retains no event history.
AddFunctionalGrain and AddFunctionalJournaledGrain register definitions by value and install
the client transport. Client-only processes call AddFunctionalGrainClient.
A standalone F# host must make definition and payload assemblies visible before Orleans snapshots
its application manifest. Use SiloConfig.applyToHost / applyToSiloBuilder and the functional
registration methods in the order shown by docs/getting-started.md.
Dashboard is optional. addDashboard uses package defaults;
addDashboardWithOptions counterUpdateIntervalMs historyLength hideTrace configures the three
runtime options. The host must reference Microsoft.Orleans.Dashboard and map the ASP.NET Core
endpoint.
Keep pure folds and context-free handlers as named functions and test them directly. Test contract and definition sealing for invalid combinations and exact diagnostics.
Use Orleans TestCluster for activation, persistence, serializer, reminder, stream, transaction,
and journal behavior. Register the same definition value as production and call it through
FunctionalGrain.ref. Do not fabricate FunctionalGrainContext; its constructor is
runtime-owned.
dotnet build
dotnet test
python3 scripts/check-deprecation-signal.py
python3 scripts/check-docs-mirror.py
python3 scripts/check-current-docs-api.py
python3 scripts/generate-llms-full.py --check
cd website
npm run build
cd ..
python3 scripts/check-docs-links.pyUse focused project or test filters while iterating, then run the checks proportional to the changed surface.
docs/**/*.md is the repository rendering; website/src/content/docs/**/*.md is the published
mirror with Starlight frontmatter and site-form links. Content changes must land in both. Run the
mirror check before handing off.
Current pages teach only grainContract, grainFor, journaledGrainFor, typed functional
references, and helpers that compose with them. Compatibility examples belong under docs/legacy.
website/public/llms-full.txt is generated as a full concatenation of current docs followed by a
clearly marked Legacy section; run python3 scripts/generate-llms-full.py after changing a source
page. llms.txt remains the short navigation index.
Examples should either compile on their own or say explicitly which immediately preceding
definition they continue. Prefer immutable record updates, lowercase record fields for API
operations, task { }, explicit ignore on fluent builders, and typed selectors such as
(_.increment).
The functional transport registers FSharpBinaryCodec for F# records, unions, tuples, options,
lists, maps, and sets. Stored and wire types still need deterministic, evolvable shapes. Do not
mutate a state object behind the runtime's replacement-state checks. Security-sensitive deployments
must treat the binary codec as a trusted-data format; see docs/security.md.
MinVer derives package versions from v* Git tags; there is no version field to edit in
Directory.Build.props.
- Move release notes from Unreleased to a dated version section.
- Build and test Release configuration on
main. - Tag the intended semantic version.
- CI publishes packages through the configured trusted publisher.
Do not put a major-version wildcard from an old release line in package README examples. Use the
ordinary dotnet add package Package.Name command, or Version="*" when an XML example needs a
placeholder.
- Confirm the exact definition value was passed to
AddFunctionalGrainorAddFunctionalJournaledGrain. - Confirm client-only hosts called
AddFunctionalGrainClient. - Confirm the contract key codec matches the supplied domain key.
- Confirm definition and payload assemblies were loaded before the Orleans manifest snapshot.
- Confirm the argument, reply, state, and event types have supported serializers.
- Confirm a stored type is constructible by Orleans' activation path.
- Confirm client and silo installed the same functional transport/codec configuration.
- Confirm
logProvidernames a registered log-consistency adaptor. - Confirm
journalStoragenames anIGrainStorage, or register the default storage. - For
customStorage, register Orleans' CustomStorage provider with the same name and make the typed storage implementation resolvable from DI. - Do not combine
journalStoragewithcustomStorage.
The obsolete universal grain, per-grain CodeGen, and original event-sourcing implementations are still maintained for compatibility. Their architecture and examples live under docs/legacy. Changes to those subsystems must not reintroduce their APIs into current guides or package quick starts.