Reference / Trade execution

Draining an account's queues

One pass of an account's worker, from what it looks at first to what it does when there is nothing left. Each sentence hands off to the article owning the behaviour it names, and the order they happen in is proved below rather than borrowed.

Contents

Starts from a worker running on an account, with work possibly waiting in either of its queues.

Ends with the pass going round again, having started at most one piece of new work — or with the account poisoned and its loop over.

Before the lines a caller writes to

  1. A worker whose account is still starting does nothing at all: it waits a tenth of a second and begins again — How waiting work is drained.

  2. The venue's own news is taken first, ahead of anything a caller asked for — How waiting work is drained.

The priority line, in one loop

  1. The priority line is then emptied completely, before any new work is begun.

  2. Each thing on it is carried out as it comes off: a cancellation takes its own route — Cancellation — and a change takes the route for changes — Changing work already sent.

  3. A change met while the account is catching up with the venue or poisoned is set aside as the loop runs, and put back only once the loop is done — A change waiting out a hold. One set aside on a pass that is then cancelled is lost with it — A change waiting out a hold.

  4. One that raises is logged and the loop carries on, leaving that instruction answered by nothing — When an update fails. A pass being called off is passed straight on instead, and ends the loop — How a worker stops.

Work already under way

  1. A cancellation whose children never finished is driven again, where its retry is due or its deadline has come — Work already under way.

  2. A poisoned account then refuses everything waiting in its ordinary queue — When an account is reconciling or poisoned.

  3. An account poisoned or catching up goes no further on this pass: it waits for something to happen and begins again — When an account is reconciling or poisoned.

  4. Otherwise work already running is moved along: a slice now due is sent, a run out of time is wound up, and one with nothing left to send is finished — Work fed out over time, Deadlines.

  5. Protection is then put up for a bracket whose opening order has ended with something filled — Protection.

  6. A scan the squaring tick asked for runs here rather than on that tick, and it carries more than protection: drains, ladder and ordinary changes, and failed closes — Work already under way. Its protection watches are the part that can take a pair as lost — When protection is lost.

At most one new thing

  1. With the ordinary queue empty, the pass waits up to a tenth of a second and begins again — How waiting work is drained.

  2. Otherwise exactly one request is taken off it, and the pass goes straight round afterwards rather than waiting — How waiting work is drained.

  3. A run or a ladder found past its deadline is reported expired rather than started — Deadlines. Anything else, and anything not past it, is started by the way of working it named: a plain order is placed, a run begins feeding out, a ladder rests its rungs, a part-shown order shows less than it is, and a bracket sends its opening order.

  4. Starting it can raise, which is logged against that one request — When an update fails. A failure escaping the pass itself poisons the account, refuses what is queued, and ends the loop — When an account is reconciling or poisoned.

Where this route is not taken

  • A worker cancelled mid-pass leaves what is still queued queued, and only what it had taken off is lost — How a worker stops.
  • A worker that has already exited takes nothing more — How a worker stops.

Created 2026-10-15 08:10 UTC · Last modified 2026-10-23 07:08 UTC

Source evidence
---
row: S-02
baseline: 49aa659
created: 2026-10-15 08:10 UTC
modified: 2026-10-23 07:08 UTC
evidence:
  - claim: "A starting account's pass does nothing and waits"
    source: "`execution_manager.py` 3903-3905"
  - claim: "The venue's news is taken before the priority line, and that before the ordinary queue"
    source: "`execution_manager.py` 3907 before 3910 before 3984"
  - claim: "The priority line is emptied in one loop, and a held change is put back only past it"
    source: "`execution_manager.py` 3910-3929 against 3954"
  - claim: "An ordinary raise inside that loop is logged and the loop carries on"
    source: "`execution_manager.py` 3944-3951"
  - claim: "A pass called off is passed straight on instead of logged"
    source: "`execution_manager.py` 3942-3943"
  - claim: "Cancellations left part done are driven before anything new starts"
    source: "`execution_manager.py` 3960 before 3973"
  - claim: "A poisoned account refuses what is queued, and either hold ends the pass"
    source: "`execution_manager.py` 3962-3967 and 3969-3971"
  - claim: "Work already running is moved along, and protection put up, before a new request is taken"
    source: "`execution_manager.py` 3973-3974 before 3984"
  - claim: "Protection goes up only for a bracket whose opening order has ended with something filled"
    source: "`execution_manager.py` 4743-4744 and 4748-4749"
  - claim: "A scan the squaring tick asked for runs on the worker, after that and before a new request"
    source: "`execution_manager.py` 3976-3978, its jobs at 7290-7300"
  - claim: "At most one request is taken off the ordinary queue, an empty one ending the pass"
    source: "`execution_manager.py` 3980-3982 against 3984"
  - claim: "The deadline is weighed for a run and a ladder, and starting is the other branch"
    source: "`execution_manager.py` 3994-3998 and 4004-4007"
---

Edit this sourceCheckout revision · 7381aa49
Reference / keep your place
Find a passage