Skip to content

refactor!: port the simulation onto Clockwork's Microsoft.Orleans.Testing.Simulation - #25

Merged
ReubenBond merged 4 commits into
mainfrom
rb-port-simulation-to-orleans-packages
Nov 18, 2026
Merged

ReubenBond merged 4 commits into
mainfrom
rb-port-simulation-to-orleans-packages

Conversation

@ReubenBond

@ReubenBond ReubenBond commented Nov 18, 2026 •

Copy link
Copy Markdown
Owner

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: 4dad617353f6251e3c2030872e5bb5f4a5560df9

Dimension Assessment Rationale
Change confidence 9/10 Every suite passes in push and pull-request CI at this head, as do Porcupine (200 histories), all 20 scenarios, forking-string, the 16-configuration sweep, the source boundary with the Native AOT client, and the duplicate-assembly check. Same-seed artifacts are identical to both earlier Clockwork pins, with log prefixes normalized. Remaining risk: per-seed traces differ from the embedded kernel by design, and Clog's use of Orleans.Consensus.CasPaxos.Testing is unverified until Clog moves its pins.
Diagnosis confidence 9.5/10 Reproduced at the fixture level (30 s and 11 min link delays) and with a Clockwork-only program: a stopped member's queued work drained during disposal, advancing virtual time or failing with the quiescence timeout. With the discard, all three disposal test cases pass; without it, they fail.

Closes #20. Targets main, where #21 has landed, and is meant to land by fast-forward to this head.

What changes

The simulation, scenario, runner and Testing projects now run on Clockwork's Microsoft.Orleans.Testing.Simulation kernel, built from source. The embedded csharp/src/Clockwork snapshot is deleted. Production projects (core, Server, Grpc, Sqlite, Rest, Host) reference no simulation package.

  • Clockwork from source. vendor/Clockwork is a submodule pinned at 65f5be6. That commit includes worker reuse (perf: reuse simulation operation workers Clockwork#72), the Testing/MTP split (fix: decouple simulation test support from MTP Clockwork#71), and member-work discard (feat: discard stopped member work Clockwork#74).
    • Projects reference packages by ID: Microsoft.Orleans.Testing.Simulation, plus the framework-neutral .Testing in the scenario library.
    • csharp/eng/OrleansSimulation.targets reads Clockwork's eng/Microsoft.Orleans.Testing.Simulation.SourceBuild.props and swaps each package reference for its source project, so nothing is restored from a feed. Library packages become project references, and the analyzers an analyzer reference.
    • Two errors guard the swap: OCCP0001 for an unmapped Microsoft.Orleans.Testing.Simulation* package, and OCCP0002 for a package whose role this build doesn't supply (instrumentation build, MTP integration, tool).
  • One kernel when embedded. OrleansSimulationSourceRoot defaults to vendor/Clockwork/. A repository that builds this one from source, such as Clog, overrides it with Orleans.Consensus.CasPaxos.Embedding.props, placed in the directory containing this checkout. That file is the only import from outside this repository's build boundary. Boundary files under vendor/ keep Clockwork's own build policy separate.
  • Port to the upstream APIs. FastCasSimulationCluster now wraps a sealed SimulationCluster instead of deriving from it. Nodes attach with AddCustomNode, and transport delivery goes through SimulationSchedulerLane. RunFor replaces RunForDuration and stops exactly at the target time.
    • The fast-path delay switch, EnableDelays, moves to the transport, because upstream's network has none. The historical 1 ms base and 5 ms jitter defaults are kept.
    • RegisterSimulationCluster keeps Run, CreateClient, CrashNode, DelayAsync and Trace, and adds IsSimulationThread.
  • Disposal. FastCasSimulationCluster.DisposeAsync crashes each host, then calls SimulationNodeContext.DiscardPendingWork() on its node, then disposes the Clockwork cluster.
    • Messages in flight to a member and its scheduled callbacks never run, and disposal leaves virtual time where the scenario ended.
    • The fixture's own deadlines, cancellations and delays live on the cluster lane, so they complete nothing once disposal begins. A client message already due is ignored.
    • Before the discard, Clockwork drained each member's queue during disposal. Disposal then advanced virtual time to each item's due time, and failed with "Node attachment cleanup did not reach quiescence" once an item was due more than 10 minutes out.
  • Logging. Scenarios uses Clockwork's InMemoryLoggerProvider, as it did before the port. Run logs.txt lines carry the provider's wall-clock timestamp and thread prefix, as before.
  • CI. Checkouts include submodules, and path filters include vendor/** and .gitmodules. A new step fails if the build output contains any Clockwork*.dll, or two different builds of the same simulation assembly.
  • Docs.
    • The root README covers the submodule.
    • The Testing README covers the "Clockwork source build" section and embedding hook, the logical-thread wording, and disposal.
    • just csharp-fmt excludes vendor/.

Importing Clockwork: list every Clockwork project in the solution

csharp/Orleans.Consensus.CasPaxos.slnx lists, under /vendor/, each Clockwork source project this repository builds: the kernel, the analyzers and .Testing. When a solution build reaches a referenced project the solution doesn't list, MSBuild builds it without the solution's configuration, so in Debug.

Before .Testing was listed, a clean dotnet build -c Release of the solution copied a Debug Orleans.Testing.Simulation.Testing.dll into the Release outputs of Scenarios, Runner and Simulation.Tests. A project-level build produced Release, and tests passed either way.

Adding a reference to another Clockwork package (for example .Instrumentation) means adding its source project to /vendor/. CI's "One build of each simulation assembly" step fails when a project is missing from the solution this way.

Equivalence evidence

The base is the embedded kernel at 24da806. The "port" columns are this branch at the initial Clockwork pin 9736589d and at the final pin 65f5be6.

Per-seed traces differ between the embedded kernel and Clockwork by design, because Clockwork derives node randomness per address and gives the network its own seed domain. Verdicts and distributions match. Across the Clockwork pins (9736589d, the intermediate b7e831d, and 65f5be6), same-seed artifacts are identical.

Check Embedded (24da806) Port at 9736589d Port at 65f5be6
Simulation.Tests 169/169 172/172 (3 new) 174/174 (disposal theory at 30 s and 11 min)
gRPC tests 535/535 535/535 535/535
Porcupine, validate_porcupine.ps1 -Seed 424242 -Rounds 100 200/200 linearizable 200/200 linearizable 200 passed, 200 histories checked
All 20 scenarios, seed 7001 20/20 20/20 20/20
Forking-string, 200 rounds 200/200 200/200, same aggregates 200/200
Benchmark sweep (4 modes × lan/geo5 × none/suspend) 16/16 16/16, within seed variance 16/16, latencies identical to 9736589d
LAN classic, 20 seeds, mean latency 16.1 ms 15.5 ms —
Leader with suspend, 20 seeds 90.5 ms 89.3 ms 20/20, artifacts identical
Geo leader-local gap, 40 seeds 22.9 ms 23.1 ms —
Same-seed artifacts — 141 files byte-identical across two runs identical to 9736589d (3,087 files) and to b7e831d (3,192 files, all 16 sweep configurations); two runs at this pin match (140 files)
Source boundary with Native AOT client — pass pass

"Identical" means every artifact is byte-identical except logs.txt. Those lines start with a wall-clock timestamp and thread id, and the logs are equal once that prefix is removed.

New tests cover the following:

  • Same-seed replay under drops, a partition, suspend, crash/restart and per-link latency, plus a check that a different seed changes the trace.
  • A link-latency override, which turns on default delays for the other links.
  • Disposal stopping hosts without running the protocol, reporting to observers, or advancing virtual time.
  • Abandoned operations and delays staying incomplete through disposal, with virtual time unchanged, for link delays of 30 s and 11 minutes.

One margin in BenchmarkWorkloadTests moved from 20 ms to 10 ms. Over 40 seeds, both kernels produce identical gap distributions; the rationale is in a comment.

Single kernel and duplicate assemblies

  • csharp/scripts/Test-SourceBoundary.ps1 builds this repository inside an isolated embedding repository that has its own Clockwork and the embedding hook. It asserts the following:
    • The consumer and Orleans.Consensus.CasPaxos.Testing each resolve exactly one Orleans.Testing.Simulation, from the embedder's project.
    • Grpc resolves none.
    • No Clockwork*.dll exists anywhere, including the Native AOT client's output.
    • With no hook and a nested Clockwork, the check fails.
  • A clean Release solution build gives the kernel ×10, .Testing ×4 and the analyzers ×1. Each has a single hash, and all are Release builds.
    • There is no Clockwork*.dll and no Microsoft.Testing.Platform*.dll.
    • No project is a Microsoft Testing Platform application.

Performance

Embedded 9736589d 65f5be6
One scheduled callback (5 nodes, 50k chained) 1.27 µs 238.8 µs 8.42–8.54 µs
Simulation.Tests, local 4 s 48 s 9 s
Simulation.Tests, CI — 30 s 12–21 s
Porcupine runner, 200 runs 2.1 s 19.3 s 3.2 s
Forking-string, 200 rounds 1.9 s 14.3 s 2.6 s

CI at this head

All runs at this head pass:

The three-process smoke passes, and every job checks out Clockwork 65f5be6.

For Clog

Clog's API surface is unchanged: RegisterSimulationCluster (Run, CreateClient, CrashNode, DelayAsync, Trace) and RecordingFatalErrorHandler. To adopt this, in one PR that moves both pins:

  1. Pin fast-caspaxos to this head and Clockwork to 65f5be6. Use the Orleans.Consensus.CasPaxos.* project names from refactor!: rename the C# projects to Orleans.Consensus.CasPaxos #21.
  2. Add vendor/Orleans.Consensus.CasPaxos.Embedding.props beside vendor/fast-caspaxos, with <OrleansSimulationSourceRoot>$(MSBuildThisFileDirectory)Clockwork/</OrleansSimulationSourceRoot>.
  3. Move eng/Clockwork.targets to the OrleansSimulation* properties, the ORLEANS_SIMULATION* variables and the Microsoft.Orleans.Testing.Simulation.* IDs. That includes .Testing.MTP for MTP test apps.
  4. A recursive clone also checks out vendor/fast-caspaxos/vendor/Clockwork, which the embedding hook leaves unbuilt.

FastCasSimulationCluster is no longer a SimulationCluster subclass, and RunForDuration is now RunFor; Clog uses neither. Instrumenting Clog.CasPaxos.Tests may need fixture work, because Run's first segment executes on the control-scope thread.

Out of scope

Pre-existing failures, unchanged by this PR, are filed separately:

The configuration section, telemetry names (#19), wire formats and persisted formats are unchanged.

…ting.Simulation

The simulation, scenario, runner, and testing projects now consume Clockwork's
prepared Microsoft.Orleans.Testing.Simulation kernel, built from the vendor/Clockwork
submodule pinned at 9736589d, instead of the embedded csharp/src/Clockwork snapshot,
which this change deletes.

- The simulation projects reference the package by ID; eng/OrleansSimulation.targets
  redirects every package in Clockwork's source-build map to its project in the checkout
  OrleansSimulationSourceRoot names, so a build has one simulation kernel. An embedding
  repository names its own Clockwork in Orleans.Consensus.CasPaxos.Embedding.props beside
  this repository's checkout.
- FastCasSimulationCluster composes Clockwork's sealed SimulationCluster and attaches its
  hosts with AddCustomNode. Node and network randomness come from Clockwork's stable seed
  domains. Disposal stops the hosts and clients before Clockwork drains pending work.
- Delivery delay remains opt-in through FastCasSimulationTransport.EnableDelays, with the
  historical 1 ms + 5 ms jitter default; Clockwork's network has no such switch.
- Node identity in runner logs is the entry's structured ProposerId; the node-prefixing
  logger factory is gone, and runner logs carry no wall-clock timestamps, so they replay.
- RegisterSimulationCluster keeps Run, CreateClient, and CrashNode; Run joins the calling
  thread to the scheduler's logical thread, and IsSimulationThread exposes that thread.
- Test-SourceBoundary.ps1 builds the fixture against an embedding repository's own
  Clockwork, checks the testing closure resolves exactly that kernel and the gRPC closure
  none, and that no Clockwork.dll remains in any output.

Equivalence: with seed domains changed, per-seed traces differ by design; verdicts and
distributions match. Simulation tests, Porcupine (200/200 linearizable), the scenario
suite, forking-string corpus, and benchmark sweeps pass on both kernels, and a seed
replays to byte-identical artifacts. A benchmark latency margin tuned to one seed of the
old stream is set from the topology's spread instead.

Implements #20.
Clockwork's cluster disposal runs the work still pending on each node, advancing virtual time past it, so an abandoned operation's deadline or delay could fire after the fixture was disposed and run a consumer continuation that throws ObjectDisposedException on the thread pool. From the start of disposal the fixture's deadlines, cancellations, and delays complete nothing.
… support

Clockwork b7e831d adds two fixes: simulation operations reuse a bounded
pool of workers instead of starting a thread each (#72), and the
Microsoft Testing Platform hooks move out of
Microsoft.Orleans.Testing.Simulation.Testing into a separate
.Testing.MTP package (#71). With MTP gone from .Testing, the scenario
library references .Testing for Clockwork's InMemoryLoggerProvider, as it
did before the port. That replaces the buffering logger which only
existed to keep MTP out of the library and the runner. Run logs again
carry the provider's wall-clock timestamp and thread prefix.

The solution now lists .Testing beside the kernel and analyzers. When a
solution build reaches a referenced project the solution doesn't list,
it builds that project without the solution's configuration. Here that
put a Debug .Testing assembly into the Release outputs of the scenario
library, the runner, and the simulation tests. CI now checks that the
build output holds one build of each simulation assembly and no
embedded Clockwork assembly.

The MTP integration package stays unsupported in this repository's
source build (OCCP0002), because none of its test projects is an MTP
application.
@ReubenBond
ReubenBond changed the base branch from rb-build-target-net11-only to main November 18, 2026 16:43
Clockwork's cluster disposal drained every member's pending work to
quiescence, advancing virtual time to each item's due time. A message
still in flight to a member therefore ran during disposal and moved
virtual time forward. A message due more than MaxSimulatedTimeAdvance
(10 minutes) away failed disposal with "Node attachment cleanup did not
reach quiescence", which a consumer could not configure around.

Clockwork 65f5be6 (#74) adds SimulationNodeContext.DiscardPendingWork().
FastCasSimulationCluster.DisposeAsync crashes each host and then discards
its node's work. Messages and callbacks pending on a member never run,
and disposal leaves virtual time where the scenario ended. The fixture's
own deadlines and delays live on the cluster lane, so its guards keep
those incomplete from the start of disposal.

The disposal test becomes a theory over 30-second and 11-minute link
delays and asserts virtual time does not advance, as does the
cluster-level disposal test. Without the discard, all three cases fail
on this pin: the 11-minute case with the quiescence timeout, and the
others because virtual time advances by 30 s and 1 s.
@ReubenBond
ReubenBond merged commit 4dad617 into main Nov 18, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Port the CASPaxos simulation and Testing projects onto Microsoft.Orleans.Testing.Simulation

1 participant