Where the boundaries moved, what was decided and what it costs, what is proven and what is not, and where to look by hand. github.com/povio/lrbo3/pull/75
Before, a backtest was computed inside the request or the chat turn that asked for it. A long one held the process that also answers the health check, the sockets and the job queue: the client saw a 502 and the run left nothing behind. After, a run is on the record the moment it is requested, a job computes it, and on the self-hosted server that computation, from reading the data to the result, happens on a thread of its own. A run that loses its container is back in the queue within about two minutes, a trader can cancel a run, and asking twice for the same run gives one run.
Not in it: batch runs (a base strategy plus N changes), which are designed only, and making runs faster, which is the next pull request.
| Layer | What is new | Files | Added |
|---|---|---|---|
packages/engine | Both engines tell an optional listener each trading day they finish. Results are unchanged. | 8 | 61 |
packages/record | The run lifecycle: queued, running, then succeeded, failed or cancelled; every write over a pending run names the execution it expects; heartbeat, cancel, one pending run per request, and the sweep of runs nothing reports on; a run summary without its result. | 14 | 1035 |
packages/agent | run_backtest takes a launcher that can wait for a queued run; a run_progress signal to the browser, outside the audit chain; the export leaves the status out. | 11 | 112 |
apps/robodev-be | The runs/execute job with its heartbeat, the runs/requeue-stale job every minute, the one computeRun function, the two ends of a run thread, the cancel route, the wait-by-polling for the assistant, three columns on the runs table. About 980 of these lines are the OpenAPI snapshot. | 22 | 1716 |
apps/server | The module a run thread loads, which builds that thread's own Postgres pool and storage client and calls a function of the backend build; pools opened at a given size; tests against a real Postgres, two of them on Parquet read through DuckDB. | 13 | 514 |
apps/fe | Queued, running, failed and cancelled runs in Results, with a Cancel button; live progress in the Run bar and the chat step; polling while a run is pending. About 260 of these lines are API tests. | 37 | 613 |
| Docs and rules | ADR-0014, the layout and assistant docs, the vocabulary, the server README, the Robodev API rule. | 9 | 86 |
One function computes every run. The runtime decides only which thread it runs on, never which code runs.
| Decision | Why | What it costs |
|---|---|---|
| The run row is written at the request; its status, replay and summary are repeated in columns of their own | A run can no longer vanish, the run list reads no result and filters replays in SQL, and rows already stored are not rewritten at deploy | Three columns and an index to keep in step with the stored record; an old row is filled in the first time its trader's runs are listed |
| One function computes a run of either kind, and the runtime only decides which thread it runs on | No second mechanism for futures, and the code tested under robodev dev is the code production runs | Under robodev dev and hosted Robodev a run still holds the job's thread while it computes |
The run thread's entry lives in apps/server, which builds the thread's clients | The SDK gives the backend no storage constructor; only the server owns that configuration | bun dev, the API tests' backend and Playwright never exercise the thread; one server test and a boot do |
| A thread per run, not a pool | A run past its limit is stopped outright and its memory goes with the thread | Each run pays the thread's start: loading the runtime and the backend build |
| The assistant waits by reading the run row every 500 ms | Works whichever container claimed the job, holds no thread, and leaves the tool's contract and the audit chain as they were | Up to half a second of added latency per run, and one small query per poll |
| A refusal fails the run at once; any other error is retried, and the third execution fails it | An orphaned or flaky run recovers by itself, and no run is left pending by a dead job | A thread that crashes deterministically is started three times before the run reads as failed |
| Every write over a pending run names the status and attempt it expects | A late or duplicate execution cannot write over a settled or newer run | An execution finds out it lost its run only when its write does not land |
| A heartbeat on the run and a sweep every minute, not one transaction for the run and its job | The queue's enqueue takes no transaction of the caller's and hosted Robodev's queue is elsewhere; the sweep also catches a dead container | A run whose request died before enqueueing waits up to 2 minutes; a run that lost its container about 2; where runs compute in the job's thread a lost running run is noticed only after 16 minutes |
| Cancelled is a status of its own, not a failed run with a reason | Nothing went wrong, and lists and counts of failed runs stay honest | One more status every reader handles; where runs compute in the job's thread a cancelled run computes to its end before its outcome is dropped |
| A second identical request returns the pending run | Double clicks and an assistant asking again do not queue a second year of work | A trader cannot run the same thing twice at once on purpose |
| The run thread imports a function from the backend build instead of invoking a job | Nothing can enqueue or claim it | The server names a compiled module path of the backend |
The server opens its pools itself, with drizzle-orm, pg and zod at the SDK's versions | The SDK's createDb fixes the pool at 5 and offers no size | Three dependencies to keep at the SDK's versions, or the two would stop sharing one copy of Drizzle |
ADR-0014 in the pull request holds these with the alternatives that were turned down.
| Claim | Checked against | Result |
|---|---|---|
| A run computed on the thread is the run computed in the caller's thread, byte for byte, for futures and for options | apps/server/tests/runThread.test.ts on a real Postgres: both as returned and as read back from the run row | Pass, both kinds (7 cases in the file) |
| A refusal, a crash and the time limit each end with a failed run and its reason | The same test: dates outside the dataset, a thread whose configuration is broken, a 300 ms limit | Pass; the crash is retried twice first |
| The lifecycle holds: queued before anything is computed, guarded writes, heartbeat and sweep, cancel, one pending run per request | packages/record/src/runLifecycle.test.ts, 18 cases on the in-memory record | Pass |
| DuckDB works inside a run thread | apps/server/tests/runThreadData.test.ts: an imported futures run and two recorded options runs on real-format Parquet fixtures, each against the run computed in the test's thread | Pass, byte for byte |
| Cancel stops a computing thread | runThread.test.ts through the real heartbeat, and the booted server: cancelled at day 1 of 259, still cancelled 8 seconds later, the job ended | Pass |
| Cancel and the pending-run rule through the API | apps/fe/tests/api/backtester.e2e.test.ts on a throwaway Robodev | Pass |
| The whole repo still checks | bun check on top of current develop | 31 of 31 tasks |
| The real server computes on the thread | apps/server booted on a throwaway Postgres and driven through the API | Queued, running, succeeded; a second identical request got the same run; the log names the thread |
| Nothing in the browser flows regressed | Playwright on the first two commits and on a clean develop checkout | 27 passed, 10 failed on both: the same 10. Not run again after the review changes |
| The thread's memory is returned | Process memory around a year of the synthetic options chain | About 85 to 170 MB before, 120 to 260 MB peak, back to where it started |
Not evidenced: The sweep against a container that really died: the record tests and the store cover its logic, no test kills a process. Memory for a year of real options data. The Run bar's and the chat step's live progress in a browser. Hosted Robodev. The full Playwright suite after the review changes; the Cancel button and the cancelled state were looked at in a browser at 375 and 1440 px with the API answers held. The 10 Playwright failures are failures on develop too, so those flows have no browser check on either side.
runs/requeue-stale, every minute.RUN_THREADS=0 on the server computes runs in the job's thread; RUN_THREAD_DB_POOL_MAX (default 2) bounds a thread's connections.Ordered by how much a mistake would cost. Tick them off as you go; the ticks stay in this browser.