Deterministic simulation testing (DST) for the async, networked parts of the agent and the Werkbank runner, with turmoil.
Why turmoil, not madsim
madsim swaps tokio out at compile time (--cfg madsim) and needs a shim for every I/O crate. We depend on mongodb, reqwest, axum, libgit2 and subprocess tools, and madsim has no shims for mongodb or reqwest. turmoil simulates hosts, network and time on top of real tokio, and we opt in per boundary (axum on a turmoil listener, hyper over a turmoil connector). So we can put exactly one protocol under simulation at a time.
What it gives: seeded, reproducible exploration of interleavings, crashes, partitions and latency. A failing seed is an exact reproducer. It is still sampling, not proof: a clean run means no counterexample across N seeds.
Targets, in priority order
1. Werkbank lease protocol (agent ↔ runners) — R1, before Werkbank touches a customer's OT network
werkbank/queue.rs is correctly fenced for results: every lease mints a fresh token, and heartbeat/complete only match on it. Properties to check under simulation:
No job executes on two runners at once. Tokens stop duplicate results, not duplicate execution. A partitioned runner keeps working while the sweeper re-leases its job to another runner. For an ICS probe against a live controller, that is a safety property. It holds only if a runner stops work once its heartbeat has failed for longer than the lease TTL. Check whether the runner (werkbank repo) self-fences.
The retry budget survives network flaps.attempts is incremented at lease time, so a lease lost to a partition burns an attempt, and flaps alone could exhaust max_attempts = 3 and expire a healthy job.
No result lost or double-recorded across runner crash, agent restart and partition.
2. SSRF guard under adversarial DNS and redirects — MVP-relevant
GuardedResolver already implements reqwest's Resolve, so it is a ready seam. turmoil hosts carry private and public addresses, and the simulated network records every connect. Property: for any DNS answer sequence (including rebinding between check and connect) and any redirect chain, no connection ever reaches a private, loopback or metadata address. Subprocess egress (npm, cargo — #330) is invisible here, which is the argument for network-level egress policy.
#301's shutdown grace and orphaned-run recovery, plus the planned SCAN_CONCURRENCY semaphore and per-target lock. Using turmoil's host crash and restart:
no run stays running forever after any crash sequence;
at most one scan per target;
concurrency stays bounded.
4. Usage outbox (MVP-1) — design simulation-first
"Batched, retried under the same idempotency key, nothing lost across a restart" is a textbook DST property. Build it on the store seam below and ship it with a simulation test from day one.
5. ICS probes (werkbank-exec) — R1
These use raw tokio::net::TcpStream to Modbus and EtherNet/IP. A simulated device that stalls mid-frame or resets must not wedge the runner.
The cost: a storage seam
Mongo cannot run inside turmoil, and nothing in the agent sits behind a storage trait today. Targets 1, 3 and 4 need a narrow trait (e.g. JobStore with the five queue transitions) with the Mongo implementation and an in-memory one. The queue already takes now as a parameter, which is what simulated time needs.
First slice
Add the JobStore seam and an in-memory store. Write one turmoil test (agent + two runners, with partition and crash) run across seeds 0–1000 in CI, which takes seconds since everything is in memory. It asserts:
every job ends terminal, or queued with attempts ≤ max;
a result is never recorded twice;
once self-fencing exists, execution intervals never overlap (checked by an oracle the runners report to).
Out of scope
Whether SAST, DAST or pentest detect correctly. That is not an interleaving problem; it is covered by the nightly corpus (#309), a known-vulnerable target benchmark when DAST returns, and the PLC verification track.
Deterministic simulation testing (DST) for the async, networked parts of the agent and the Werkbank runner, with **turmoil**.
## Why turmoil, not madsim
madsim swaps tokio out at compile time (`--cfg madsim`) and needs a shim for every I/O crate. We depend on mongodb, reqwest, axum, libgit2 and subprocess tools, and madsim has no shims for mongodb or reqwest. turmoil simulates hosts, network and time on top of real tokio, and we opt in per boundary (axum on a turmoil listener, hyper over a turmoil connector). So we can put exactly one protocol under simulation at a time.
**What it gives:** seeded, reproducible exploration of interleavings, crashes, partitions and latency. A failing seed is an exact reproducer. It is still sampling, not proof: a clean run means no counterexample across N seeds.
## Targets, in priority order
### 1. Werkbank lease protocol (agent ↔ runners) — R1, before Werkbank touches a customer's OT network
`werkbank/queue.rs` is correctly fenced for **results**: every lease mints a fresh token, and `heartbeat`/`complete` only match on it. Properties to check under simulation:
- **No job executes on two runners at once.** Tokens stop duplicate results, not duplicate *execution*. A partitioned runner keeps working while the sweeper re-leases its job to another runner. For an ICS probe against a live controller, that is a safety property. It holds only if a runner stops work once its heartbeat has failed for longer than the lease TTL. **Check whether the runner (werkbank repo) self-fences.**
- **The retry budget survives network flaps.** `attempts` is incremented at lease time, so a lease lost to a partition burns an attempt, and flaps alone could exhaust `max_attempts = 3` and expire a healthy job.
- No result lost or double-recorded across runner crash, agent restart and partition.
### 2. SSRF guard under adversarial DNS and redirects — MVP-relevant
`GuardedResolver` already implements reqwest's `Resolve`, so it is a ready seam. turmoil hosts carry private and public addresses, and the simulated network records every connect. Property: **for any DNS answer sequence (including rebinding between check and connect) and any redirect chain, no connection ever reaches a private, loopback or metadata address.** Subprocess egress (npm, cargo — #330) is invisible here, which is the argument for network-level egress policy.
### 3. Scan lifecycle: crash, recovery, limits — MVP-relevant
#301's shutdown grace and orphaned-run recovery, plus the planned `SCAN_CONCURRENCY` semaphore and per-target lock. Using turmoil's host crash and restart:
- no run stays `running` forever after any crash sequence;
- at most one scan per target;
- concurrency stays bounded.
### 4. Usage outbox (MVP-1) — design simulation-first
"Batched, retried under the same idempotency key, nothing lost across a restart" is a textbook DST property. Build it on the store seam below and ship it with a simulation test from day one.
### 5. ICS probes (`werkbank-exec`) — R1
These use raw `tokio::net::TcpStream` to Modbus and EtherNet/IP. A simulated device that stalls mid-frame or resets must not wedge the runner.
## The cost: a storage seam
Mongo cannot run inside turmoil, and nothing in the agent sits behind a storage trait today. Targets 1, 3 and 4 need a narrow trait (e.g. `JobStore` with the five queue transitions) with the Mongo implementation and an in-memory one. The queue already takes `now` as a parameter, which is what simulated time needs.
## First slice
Add the `JobStore` seam and an in-memory store. Write one turmoil test (agent + two runners, with partition and crash) run across seeds 0–1000 in CI, which takes seconds since everything is in memory. It asserts:
- every job ends terminal, or queued with `attempts ≤ max`;
- a result is never recorded twice;
- once self-fencing exists, execution intervals never overlap (checked by an oracle the runners report to).
## Out of scope
Whether SAST, DAST or pentest **detect** correctly. That is not an interleaving problem; it is covered by the nightly corpus (#309), a known-vulnerable target benchmark when DAST returns, and the PLC verification track.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Deterministic simulation testing (DST) for the async, networked parts of the agent and the Werkbank runner, with turmoil.
Why turmoil, not madsim
madsim swaps tokio out at compile time (
--cfg madsim) and needs a shim for every I/O crate. We depend on mongodb, reqwest, axum, libgit2 and subprocess tools, and madsim has no shims for mongodb or reqwest. turmoil simulates hosts, network and time on top of real tokio, and we opt in per boundary (axum on a turmoil listener, hyper over a turmoil connector). So we can put exactly one protocol under simulation at a time.What it gives: seeded, reproducible exploration of interleavings, crashes, partitions and latency. A failing seed is an exact reproducer. It is still sampling, not proof: a clean run means no counterexample across N seeds.
Targets, in priority order
1. Werkbank lease protocol (agent ↔ runners) — R1, before Werkbank touches a customer's OT network
werkbank/queue.rsis correctly fenced for results: every lease mints a fresh token, andheartbeat/completeonly match on it. Properties to check under simulation:attemptsis incremented at lease time, so a lease lost to a partition burns an attempt, and flaps alone could exhaustmax_attempts = 3and expire a healthy job.2. SSRF guard under adversarial DNS and redirects — MVP-relevant
GuardedResolveralready implements reqwest'sResolve, so it is a ready seam. turmoil hosts carry private and public addresses, and the simulated network records every connect. Property: for any DNS answer sequence (including rebinding between check and connect) and any redirect chain, no connection ever reaches a private, loopback or metadata address. Subprocess egress (npm, cargo — #330) is invisible here, which is the argument for network-level egress policy.3. Scan lifecycle: crash, recovery, limits — MVP-relevant
#301's shutdown grace and orphaned-run recovery, plus the planned
SCAN_CONCURRENCYsemaphore and per-target lock. Using turmoil's host crash and restart:runningforever after any crash sequence;4. Usage outbox (MVP-1) — design simulation-first
"Batched, retried under the same idempotency key, nothing lost across a restart" is a textbook DST property. Build it on the store seam below and ship it with a simulation test from day one.
5. ICS probes (
werkbank-exec) — R1These use raw
tokio::net::TcpStreamto Modbus and EtherNet/IP. A simulated device that stalls mid-frame or resets must not wedge the runner.The cost: a storage seam
Mongo cannot run inside turmoil, and nothing in the agent sits behind a storage trait today. Targets 1, 3 and 4 need a narrow trait (e.g.
JobStorewith the five queue transitions) with the Mongo implementation and an in-memory one. The queue already takesnowas a parameter, which is what simulated time needs.First slice
Add the
JobStoreseam and an in-memory store. Write one turmoil test (agent + two runners, with partition and crash) run across seeds 0–1000 in CI, which takes seconds since everything is in memory. It asserts:attempts ≤ max;Out of scope
Whether SAST, DAST or pentest detect correctly. That is not an interleaving problem; it is covered by the nightly corpus (#309), a known-vulnerable target benchmark when DAST returns, and the PLC verification track.