Skip to main content
A seller begins with five units and a price of 20. Each buyer sees a quote, chooses a quantity, and pays from a dedicated balance. After a sale, the next price increases by 5 for each unit sold so far. A saved version number fences quotes: a purchase at an old quote is rejected if another sale intervenes. The whole order pays its saved unit price. This is a quantity-based price update between orders, not a marginal price increase within an order. A buys two at 20, B buys one at 30, and C buys two at 35; the seller receives 140. D arrives after stock is exhausted and never sees the purchase question.

Build and run the complete example

Execute the following four Python blocks in order in one session, or concatenate them into a script. Use an EDSL build with the Machine and Runner APIs documented in this manual. Everything is defined here: only EDSL and the Python standard library are required, with no repository example imports and no model API calls.

1. Define the Machine

The quote captures price and version. The buy command checks ownership, live version, stock, and cash before atomically moving goods and payment. A repeated filled order with the same quantity is a no-op.

2. Construct the single-pass Survey

Each buyer gets a quote before the purchase question. The computed entry gate uses ordinary Survey stop rules. It stops later buyers when stock is gone while allowing the last successful buyer to receive its receipt.

3. Define the scripted respondents

Stable IDs and the turn trait establish the demonstration order. These direct answers bypass model calls while exercising actual question rendering and rules.

4. Run and inspect settlement

Expected final accounts:

Try the boundary cases

The remaining blocks reuse this page’s build_machine and run directly under an empty Runtime() registry after JSON transport.

A stale quote cannot spend money

A stale order can also be passed with quantity zero. Passing moves no cash or stock and is allowed after closure. Reusing a completed order with a changed quantity is rejected as order_changed; an order ID belongs to its original buyer. In a concurrent race on the same version, only one positive purchase applies—even if stock would suffice for both. The losing buyer needs a fresh quote. This deliberate policy prioritizes an explicit current price.

What this probes, and what remains

The construction combines a versioned read, explicit rejection, multi-field atomic payment, and durable order replay. It needs no new market-specific Machine primitive and uses the existing Survey navigation API. The sequential demo avoids stale quotes by construction; the boundary example and concurrent SQLite tests exercise them explicitly. The Survey does not retry or requote within the same interview: if another sale intervenes after rendering, its receipt remains quoted and the host evidence reports stale_quote. A new order token and a new pass are required. Quote expiry, returns, replenishment, and multiple sellers are outside this example. All balances are simulated dedicated accounts; the example does not move real money or authenticate account owners. Combining these markets through a common wallet would require a deliberate reservation/settlement contract.

Verification

The executable tests check independent allocation and price references, cash and unit conservation, admission rejections without partial mutation, repeated settlement, concurrent SQLite commands, reopen/replay, scope isolation, fresh interpreter transport, actual Survey choices, and Results serialization. The canonical page is also executed in a fresh process with repository example imports blocked. Optional maintainer commands, from a repository checkout:
See the primitive corpus for related mechanisms and the Machine manual for execution and rejection semantics.