File size: 11,496 Bytes
d36c7f0
 
152e0c1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d36c7f0
 
 
152e0c1
d36c7f0
152e0c1
 
d36c7f0
 
 
152e0c1
d36c7f0
 
 
152e0c1
 
 
 
 
 
d36c7f0
152e0c1
d36c7f0
 
 
 
 
 
 
 
 
152e0c1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d36c7f0
152e0c1
d36c7f0
152e0c1
 
 
 
d36c7f0
152e0c1
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# Remote browser runner

Astra runs on a Hugging Face Space, and Oracle's edge (Akamai) answers "Access Denied" to the Space's network on
Oracle demo pods. So the browsers that test or read an Oracle Fusion pod run on another host: the remote runner.
Everything else stays on the Space: approvals, AI agents, triage, reports and evidence.

- **Server side:** `coworker/adapters/remote_runner.py`, used by `coworker/graph/nodes/execute.py` (`run_planned`) and
  `coworker/adapters/screens.py` (`explore`, `capture`); pre-flight in `coworker/platform/preflight.py`.
- **Runner side:** `automation/remote_runner/server.py` (Python standard library only), behind Caddy for HTTPS.
- **Switched on by** `FPT_REMOTE_RUNNER_URL=https://<runner>` and the token in the vault as `remote_runner.token`
  (`FPT_SECRET_REMOTE_RUNNER_TOKEN`). Remove the URL to run browsers on the server itself again.

## What runs on the runner

| Job | Sent as | When |
|---|---|---|
| Test attempts on a Fusion pod (`playwright.fusion.config.ts`) | `POST /v1/attempts` | The executor step; one attempt per test user when areas sign in as different users (`FPT_FUSION_AREA_USERS`) |
| Screen reading: the explorer (`explore`, with the explorer's plan) and one screen (`capture`, a task such as "Payables > Invoices > Create Invoice") | `POST /v1/screens` | In a run, before the AI designs scenarios; in the background after discovery; Read screens on the pod's card |

The practice pod and quick simulations stay on the server.

The AI dry run (`FPT_FUSION_AI_DRY_RUN=1`, off by default) does **not** use the runner: `graph/nodes/ai_scenarios.py`
`dry_run` starts the browser on the Astra server itself. On a Space whose network Oracle's edge refuses, that dry run
fails. Keep it off while Fusion browsers need the runner.

## One job at a time

The runner holds one lock for every job: attempts and screen reads share it. A second job while one is running gets
**HTTP 409** ("another attempt is running on this runner"). Astra does not wait or queue on a 409:

- a test run fails with "the remote browser runner refused the attempt (HTTP 409 ...)"; resume it when the runner is free;
- a screen read fails with the same reason on the pod's card; read the screens again.

The usual cause is a background screen read (after discovery, or a release change) overlapping a run. Check
`/healthz` (`busy`) before starting work by hand.

Within one job, `FPT_FUSION_WORKERS` (set on the Astra server, sent with each attempt; 1 to 4, default 3) is how many
browsers run at once.

## Long runs, restarts and a busy runner

- **Each pass has a time budget for its size.** An attempt runs in passes of at most `FPT_FUSION_CHUNK_SCENARIOS`
  scenarios (default 24). Each pass gets `FPT_FUSION_SCENARIO_MINUTES` (default 12) per scenario a worker runs, plus 10
  minutes of start-up, kept between `FPT_FUSION_ATTEMPT_MIN_MINUTES` (30) and `FPT_FUSION_ATTEMPT_MAX_MINUTES` (240).
  A pass that runs out of time is first asked to stop, so Playwright still writes its report; one that writes none
  loses only its own scenarios, which are recorded as timed out and run again in the retry.
- **A restart of the Astra server does not lose the pass.** The runner job's id is kept in the run folder
  (`remote-job.json`) while it runs. Resume the run: it follows the same job and collects its results. Finished passes
  are kept. Cancelling the run instead stops the job and keeps the ledger of test records it made, for the clean-up.
- **A restart of the runner fails the pass in seconds.** The runner keeps each job's state in its folder (`job.json`). A
  job that was running when it restarted is reported `lost`, and an older runner answers 404. Astra stops waiting at
  once and says so.
- **A busy runner is waited for.** The runner takes one job at a time. A run or screen read that finds it busy waits up
  to `FPT_REMOTE_RUNNER_BUSY_WAIT_MINUTES` (default 15) and notes it in the run's activity. Pre-flight reports a busy
  runner as information, not as a failure.
- **Pre-flight compares versions.** When this server knows its commit (`FPT_COMMIT`, or a `VERSION` file at the repo
  root), a runner on another commit fails pre-flight: run `deploy/runner/sync.sh` on the deployed commit.

## How an attempt works

1. **Sent.** Astra posts it through the egress gate (https, the runner's host only) to `POST /v1/attempts`. The body
   holds the case ids and the Playwright config; the pod environment (address, test user and password, test data);
   AI-written draft specs, approved library specs and their step files; locator overrides from self-heal. The audit
   log records the ids and the config, never the password.
2. **Polled.** Astra asks `GET /v1/attempts/{id}` every few seconds (every 2 s with the Live panel, which also pulls
   `/v1/attempts/{id}/live` frames). The emergency stop cancels the job on the runner (`POST .../cancel`).
3. **Collected.** `GET /v1/attempts/{id}/bundle` returns one zip: the Playwright JSON report (attachment paths
   relative to the run directory), the run directory (screenshots, videos, traces, without the Fusion session file),
   the pod values tried, the ledger of created test records, and the log. Astra unpacks it where a local attempt
   leaves its files, so evidence, triage, clean-up and reports work unchanged.

A screen read works the same way through `POST /v1/screens`. Its poll takes `?since=<line>` and returns the newest log
lines for the pod card's progress. The bundle holds the log and the `out/` files: the inventories (`<slug>.json`,
Oracle's labels only) and the list choices (`<slug>.values`). Astra checks them with the same privacy rule as a local
read.

## Jobs live in memory

The runner keeps its job table in memory. After a runner restart it no longer knows the jobs it was running: their
polls get 404, and Astra waits until the job's deadline (an attempt: its timeout plus 5 minutes) before failing the
run. Do not restart the runner while `/healthz` shows `"busy": true`; `sync.sh` refuses to.

## Data on the runner

Each job has a folder, `RUNNER_HOME/job_<id>`, with the specs, the log, the report, screenshots, videos and traces.
These files are **not encrypted** on the runner. They are deleted `RUNNER_KEEP_HOURS` (default 24) after the job
started, by a sweep every 10 minutes. Folders left from before a runner restart are swept by their age on disk.

The Fusion sign-in session file is written in the run directory and removed by Playwright's teardown; it is never
put in the bundle. A job that was killed may leave it in its folder until the sweep.

## Safeguards

- One job at a time (see above).
- Every call except `/healthz` needs `Authorization: Bearer <RUNNER_TOKEN>`, compared in constant time. The service
  refuses to start without a token of at least 24 characters.
- Only known environment keys, the two Astra Playwright configs, plain case ids and plain spec names are accepted;
  bodies are limited to 20 MB.
- The service listens on `127.0.0.1` only; Caddy serves HTTPS in front.
- The Fusion password is passed in the Playwright process's environment, not written to disk by the runner.
- The runner's token is never passed to the Playwright process.

## `/healthz`

`GET /healthz` needs no token and returns:

| Field | Meaning |
|---|---|
| `ok` | The service has a token. |
| `busy` | A job holds the lock. |
| `automation` | `AUTOMATION_DIR` exists. |
| `cases` | The scenario files the step specs read (`tests/cases`, next to `automation/`) are there. |
| `version` | The commit `sync.sh` installed (the `VERSION` file), or `unknown`. |

Pre-flight reads it before every Fusion browser run: a runner that does not answer, has no token or no test code, or
has no scenario files stops the run before any browser starts.

## Set up a runner (Ubuntu 22.04)

**1. Tools.** Install Node 22, Python 3, and Caddy.

**2. Token and settings.** The token needs at least 24 random characters. Keep it in a root-only environment file,
for example `/etc/astra/runner.env`:

```

RUNNER_TOKEN=<random>

AUTOMATION_DIR=/home/ubuntu/astra/automation

RUNNER_HOME=/home/ubuntu/runner-data

```

Optional: `RUNNER_PORT` (default 8899), `RUNNER_KEEP_HOURS` (default 24).

**3. Service.** A systemd unit named `astra-runner` (the name `sync.sh` restarts; another name goes in
`RUNNER_SERVICE`), with `User=ubuntu`, `EnvironmentFile=/etc/astra/runner.env`,
`ExecStart=/usr/bin/python3 -I /home/ubuntu/astra/automation/remote_runner/server.py` and `Restart=always`. The
`ubuntu` user needs `sudo systemctl restart astra-runner` without a password, for `sync.sh`.

**4. HTTPS.** Caddy can serve a real certificate for an IP through `<ip-with-dashes>.sslip.io`:

```

129-225-117-95.sslip.io {

	reverse_proxy 127.0.0.1:8899

}

```

Open ports 80 and 443 in the cloud firewall. On Oracle's Ubuntu images, also open them in iptables.

**5. Install the code** with `sync.sh` from the repository (next section). The first time, also install the
browser's system libraries once: `cd ~/astra/automation && sudo npx playwright install-deps chromium`.

**6. Point Astra at the runner.** On the Space: `FPT_REMOTE_RUNNER_URL=https://<host>` (variable) and
`FPT_SECRET_REMOTE_RUNNER_TOKEN=<the token>` (secret). Restart (save first: RUNBOOK).

## Update the runner: `deploy/runner/sync.sh`

Run it after **every** Astra deploy, from the repository, on the commit that was deployed:

```bash

deploy/runner/sync.sh ubuntu@<runner> ~/.ssh/<runner key> https://<runner>

```

What it does:

1. Refuses when `automation/` or `tests/` has uncommitted changes, and when the runner's `/healthz` shows
   `"busy": true` (exit 2).
2. Packs the committed `automation/` and `tests/` (`git archive HEAD`) and unpacks them in `~/astra.new` on the
   runner, with the commit in `VERSION`.
3. Reuses `node_modules` when `package-lock.json` did not change, else runs `npm ci`; then installs Chromium.
4. Checks `/healthz` again: a job that started during the install means nothing is switched (exit 2).
5. Moves `~/astra` to `~/astra.prev`, puts the new copy in place, restarts the service.
6. Verifies that `/healthz` reports the new commit as `version` and `"cases": true` (exit 3 otherwise: check the
   service's `AUTOMATION_DIR`), and prints `/healthz` from outside when the URL is given.

To roll back, run it on the previous commit.

## A PC as the runner

`deploy/pc-runner/start-pc-runner.ps1` runs the runner on a Windows PC (port 8898) and opens an SSH tunnel to the
runner VM, so the VM's port 8898 leads to the PC. The VM's Caddy must be set to send to port 8898 first while it
answers and to fall back to its own runner on 8899; that Caddy configuration is not in the repository. The PC runs
the repository's own `automation/`, so it is not updated by `sync.sh` and its `version` is `unknown`.

## Sizing

| Host | Fits |
|---|---|
| 4 vCPU, 16 GB RAM | 3 to 4 browsers at once (`FPT_FUSION_WORKERS=3` or `4`): regression runs and screen reading of several areas. |
| 1 GB RAM (plus swap), for example an OCI Always Free AMD Micro | One browser for a short run, at best (`FPT_FUSION_WORKERS=1` on the Astra server). **Not enough for regression runs.** |

`FPT_FUSION_WORKERS` is a setting of the Astra server and applies to every Fusion run; lower it there when the runner
is small.