Runtime contract
Normative. The contract binds a backend and a host; both sides are
tested by the executable cases in conformance/host/.
The machine-readable constants are rendered as
generated/contract.json.
Environment
The host MUST pass, the backend MUST read:
| Variable | Meaning |
|---|---|
PORT |
The port to bind; the host chose it and owns it |
HOST |
127.0.0.1 |
APP_TOKEN |
The one-time session token for the handshake |
APP_DATA_DIR |
The only directory the backend may write to |
APP_PARENT_PID |
The supervisor's pid, for backends that want a parent watch |
Behaviour
- The backend MUST bind
127.0.0.1onPORT; it MUST NOT be reachable on other interfaces (AA203) and MUST NOT open a browser (AA204). - It MUST answer 2xx on the declared health path before it is ready; the
host polls until then (
AA201,AA202). - The host fetches the frontend with
/?app_token=<APP_TOKEN>; the backend MUST respond by redirecting to/and setting theapp_tokencookie. A conformant backend MAY enforce the cookie on every request (AA401checks that enforcement is possible). - It MUST NOT send
Access-Control-Allow-Origin: *(AA402). - When the host closes stdin, the backend MUST stop its children and exit
(
AA205); no process MUST survive it (AA206). - It MUST treat stdout as a protocol channel: logs go to stderr, and any
stdout output MUST be utf-8 and small (
AA207). - It MUST write only inside
APP_DATA_DIR(AA301,AA302).
Stopping
The host stops the backend in order: close stdin; wait stop_timeout;
SIGTERM the process group; wait; SIGKILL the group. A backend that exits
on stdin EOF never sees a signal.
A backend reading the environment sees exactly this shape:
{
"PORT": "54321",
"HOST": "127.0.0.1",
"APP_TOKEN": "6f1c9a4e7b2d",
"APP_DATA_DIR": "/run/app-anything/acme.notes/data",
"APP_PARENT_PID": "4102"
}
Two hosts
The Python reference host and the Rust runner implement this contract independently and MUST both pass the same conformance cases; a behaviour change in one without the other is a CI failure, not an option.
Rendered from spec/contract.md on main.