Appearance
Docker backend example
This optional local server demonstrates submitting a run, preparing a stored dataset in an isolated Node process, and replaying it over HTTP. It uses the same public @grabm/abm package as a consumer. Docker is not required to use the library or run the normal package and documentation checks.
Start and test
From the repository root, with Docker Engine and Docker Compose running:
sh
npm ci
npm run up
npm run test:backend:docker
npm run downup builds the private package into a Node image and waits for a healthy backend at http://localhost:4180. The image runs as a non-root user without rendering peers. The smoke test submits the docs demo's eight-node, 24-hour scenario, polls the job, opens its dataset with createHttpReader, and verifies recorded positions at 10:00 and an agent's trip history. It prints a job ID and dataset reference.
down stops and removes the container and its network. Completed datasets and job records remain in the named volume, so another up can serve them again. Verify a saved job after restarting with its printed ID:
sh
JOB_ID=<saved-job-id> npm run test:backend:dockerTo intentionally discard all example jobs and datasets, use docker compose down --volumes. This is separate from the normal shutdown command.
For host-side integration tests without Docker, run npm run test:backend. They test HTTP replay against in-memory results, admission limits, cancellation, shutdown, restart recovery, validation, and resource access boundaries.
HTTP contract
| Request | Response |
|---|---|
GET /health | Health and active/max job counts |
POST /jobs | Accepts complete simulation input JSON; returns 202, job ID, and Location |
GET /jobs/:id | Running progress or final status; completed jobs include a dataset reference |
DELETE /jobs/:id | Cancels active work and waits for cleanup; finished jobs return 409 |
GET /datasets/:id/:key | Streams an immutable manifest or a resource listed in that manifest |
For your own simulation JSON:
sh
curl -i http://localhost:4180/jobs \
-H 'Content-Type: application/json' \
--data-binary @input.json
curl http://localhost:4180/jobs/<job-id>Only a completed job exposes dataset resources. Final states are completed, cancelled, failed, and interrupted. Progress describes engine execution; dataset preparation may still be running after engine progress reaches its endpoint. Wait for completed before opening the reference. Restart marks unfinished jobs as interrupted and removes their unpublished datasets; it does not retry them.
Read a completed job from a browser or Node consumer:
ts
import { createHttpReader, openRunDataset } from '@grabm/abm/datasets'
const backend = 'http://localhost:4180'
const job = await fetch(`${backend}/jobs/${jobId}`).then((response) => response.json())
if (job.status !== 'completed') throw new Error(`Job is ${job.status}`)
const source = await openRunDataset(
createHttpReader(new URL(job.dataset.basePath, backend).href),
job.dataset.reference,
)
try {
const frame = await source.window(600)
const detail = await source.agent(source.scene.agents[0].id)
// Feed source to ReplayLayer for buffered playback, or inspect frame and detail.
} finally {
source.dispose()
}The backend serves the compressed bytes verbatim, without Content-Encoding: gzip. The dataset reader owns checksum verification and decompression. It does not download an archive or a complete RunResult. See stored replay for caching, buffering, and renderer integration.
Limits and configuration
| Variable | Default | Meaning |
|---|---|---|
BACKEND_PORT | 4180 | Host port, bound to 127.0.0.1 |
MAX_JOBS | 1 | Concurrent simulations, from 1 to 4; excess submissions return 429 |
MAX_HEAP_MB | 512 | V8 old-space ceiling per simulation child; not total memory |
BACKEND_MEMORY | 1g | Docker memory ceiling for the entire service |
ALLOWED_ORIGIN | http://localhost:4175 | Exact permitted browser origin for the docs |
For example, BACKEND_PORT=4181 npm run up changes the port; use the same variable with the smoke test. BACKEND_URL can instead give the test a complete server URL. The input body limit is 4 MiB. Individual dataset resources retain the library's default limit. There is no unbounded request queue, and completed results are kept on disk rather than retained by the HTTP process.
The engine still holds a full run in child-process memory. Increasing concurrency requires sufficient aggregate memory. Container termination can interrupt jobs; startup recovery cleans their unpublished output. Completed data persists until you remove the volume; this example does not implement automatic retention or backups.
This is a single-host development example without authentication, a database, or multi-replica coordination. It binds to loopback deliberately. Applications adopting it must own authentication, admission policy, storage durability, and deployment. PreFORM remains unchanged.