automation protocols and drivers · lesson 5 of 7 · sources checked 2026-11-20
launcher backends and adapter contracts
This lesson shows how an orchestrator selects a launcher backend for a tool, and how an adapter contract reports four statuses.
status of this lesson: documented in my test systempurpose
A system that runs many automation tools must start each tool correctly, and read each result in one form. A wrong start gives a result that looks correct but describes a different tool. Also, a tool that did not start is not a tool that failed.
objectives
- Explain why the selection of a launcher backend is a pure function of three inputs.
- Describe the two subprocess contracts: an endpoint line on stdout and a JSON out-file.
- Design an adapter contract that reports "unavailable" separately from "error".
- Identify the status of a tool run from its output, its exit, and its deadline.
new terms
- launcher backend
- The part of an orchestrator that starts or connects to a browser for one tool.
- adapter contract
- The fixed input and output rules between an orchestrator and one tool process.
- engine
- The part of a browser that parses, lays out, and renders a page and runs its scripts.
- attach mode
- The way a tool gets control of a browser: launch, connect, attach, WebDriver, BiDi, or none.
- ambiguous
- A verdict that says the oracle cannot tell; it is not a failure and it stays out of the denominator.
- availability fact
- A record that a tool did not start or a gateway refused, kept apart from the outcome.
- benchmark
- A repeatable measurement of many tools or configurations on a fixed set of targets.
how it works
An orchestrator runs many tools against the same test pages. Each tool gets control of a browser in its own way. Thus the orchestrator has two jobs for each tool: it must start the tool correctly, and it must read the result in one fixed form.
The benchmark platform, my test system, gives each job to a separate part:
| part | job |
|---|---|
| launcher backend | Starts the browser for one tool, or connects to the browser of the tool |
| adapter contract | Fixes the input and the output between the orchestrator and one tool process |
dispatch is a pure function
The benchmark platform has four launcher backends. Each tool has one catalog entry, its record in the tool list of the platform. A pure function selects one backend from three inputs of the entry: the engine, the attach mode, and an exec command.
The exec command is the own start command of the tool. The function reads no clock, no file, and no network. Thus the same catalog entry always gives the same backend, and a test can check each entry with no browser.
the dispatch of the code example
In my model, a dispatch function selects one of these four backends. They are not the four backends of the benchmark platform:
- Run the tool with its own command, and read an endpoint line that it prints.
- Run the tool with its own command, and read a JSON file that it writes.
- Launch the engine through an automation library.
- Open a WebDriver session for the engine.
example A catalog entry gives the engine chromium, the attach mode connect, and an exec command. The function of the code example selects backend 1. The same entry with no exec command gets a refusal, not a different backend.
run the actual tool
The benchmark platform follows one rule for each tool: "Run the actual tool; error if you cannot." A substitute that looks correct can give a wrong result. For example, an unchanged library that runs in place of a tool with its own CDP client measures the library, not the tool. The result can then be ambiguous.
The same rule applies to a part of a tool. A mapped API can look correct and still capture wrong data. Then an honest absence is better: the record says "no capture", and the reader knows that the value is not there.
two subprocess contracts
The benchmark platform runs a tool as a subprocess under one of two contracts:
- Endpoint line on stdout. The tool prints one line with the address of its debug endpoint. The orchestrator then connects to that endpoint. For example, the synthetic line
ENDPOINT port=9222of the code example gives the port of the endpoint. - JSON out-file. The tool writes its result to a JSON file and exits. The orchestrator reads the file after the exit.
The first contract suits a tool that keeps a browser open for the orchestrator. The second contract suits a tool that does its full task alone and returns only a result.
four statuses
In my model, an adapter contract gives each tool run one of four statuses: ok, error, unavailable, and timeout.
ok: the contract output came, and it is valid.error: the tool started and failed, for example with an exit code and no endpoint line.unavailable: the tool did not start, for a closed reason. An example is an engine that the host does not have.timeout: the deadline came first.
The benchmark platform records an unavailable run as an availability fact. It goes to a separate table, apart from pass, fail, and ambiguous. Thus a missing tool does not lower the pass rate of a page.
For example, a tool that cannot get through its proxy is unavailable. The orchestrator never sends it on a direct connection in place of the proxy.
The deadline kills first, and then it reports. A tool that prints a warning and goes silent cannot hold a worker, the process that runs the jobs.
A browser can also start under the tool, two levels below the orchestrator. Thus, on a POSIX host, the orchestrator starts the adapter, the process that runs the tool, as the leader of a process group. It stops the full group with one call. More detail is in The driver life cycle (not yet published).
the two sides
| automation side | detection side |
|---|---|
A substitute that looks correct can give a wrong result. An honest absence, or a status unavailable, is better. A pure dispatch function makes the selection of each backend testable. | No direct view. These parts are the design of the automation system. The page sees only the protocol residue of the attach mode that the backend uses. More detail is in Attach modes and what each leaves (not yet published). |
design decisions
| option | gain | cost | when it is correct |
|---|---|---|---|
| A pure dispatch function | Each catalog entry has one testable backend. | The catalog must hold the engine, the attach mode, and the exec command. | Each system with more than one tool |
| An endpoint line on stdout | The orchestrator can control the browser of the tool. | The orchestrator must wait for the line under a deadline. | A tool that keeps a browser open |
| A JSON out-file | The contract is simple, and the tool does its task alone. | The orchestrator sees nothing before the exit. | A tool that returns only a result |
A separate status unavailable | A missing tool does not change the pass rate. | Each reason must be in a closed list. | Each benchmark that compares tools |
| A substitute library for a missing tool | The run gives a result. | The result measures a different tool. | Never in a benchmark. Report an error. |
diagram
launcher backend dispatch: three inputs select one of four backends, or a refusal
A matrix of the four statuses ok, error, unavailable, and timeout against the two contracts, the endpoint line on stdout and the JSON out-file. Each cell gives the evidence for that status under that contract.
| status | endpoint line on stdout | json out-file |
|---|---|---|
| ok | Line comes before the deadline | Valid file after the exit |
| error | Exit with no endpoint line | Exit with no file or a bad file |
| unavailable | Tool reports a closed reason | File holds a closed reason |
| timeout | No line at the deadline | No exit at the deadline |
code example
The first example selects a backend for five synthetic catalog entries. The second example runs four synthetic tool processes under a deadline and gives one status for each.
The tools, the commands, and the port number are synthetic. No part describes a real product.
Select a launcher backend with a pure function of the engine, the attach mode, and the exec command, and refuse an entry with no backend.
// Pure dispatch of a launcher backend from synthetic catalog metadata.
// The function reads three inputs and returns one backend or a refusal.
type Engine = "chromium" | "firefox" | "webkit";
type AttachMode = "launch" | "connect" | "webdriver" | "none";
interface ToolEntry {
name: string;
engine: Engine;
attachMode: AttachMode;
execCommand?: string[]; // the command of the tool itself, if it has one
}
type Backend =
| { kind: "exec-endpoint"; command: string[] }
| { kind: "exec-outfile"; command: string[] }
| { kind: "library-launch"; engine: Engine }
| { kind: "webdriver-session"; engine: Engine }
| { kind: "refused"; reason: string };
function selectBackend(t: ToolEntry): Backend {
if (t.execCommand && t.attachMode === "connect") {
return { kind: "exec-endpoint", command: t.execCommand };
}
if (t.execCommand && t.attachMode === "none") {
return { kind: "exec-outfile", command: t.execCommand };
}
if (t.attachMode === "webdriver") {
return { kind: "webdriver-session", engine: t.engine };
}
if (t.attachMode === "launch" && !t.execCommand) {
return { kind: "library-launch", engine: t.engine };
}
// No silent substitute: a tool that needs its own command and has none is refused.
return { kind: "refused", reason: `no backend for ${t.attachMode} with this entry` };
}
const catalog: ToolEntry[] = [
{ name: "tool-a", engine: "chromium", attachMode: "connect", execCommand: ["tool-a", "--print-endpoint"] },
{ name: "tool-b", engine: "chromium", attachMode: "none", execCommand: ["tool-b", "--out", "result.json"] },
{ name: "tool-c", engine: "firefox", attachMode: "launch" },
{ name: "tool-d", engine: "webkit", attachMode: "webdriver" },
{ name: "tool-e", engine: "chromium", attachMode: "connect" },
];
for (const entry of catalog) {
const b = selectBackend(entry);
const detail = "command" in b ? b.command[0] : "engine" in b ? b.engine : b.reason;
console.log(`${entry.name}: ${b.kind} (${detail})`);
}
// The same input gives the same output: run the dispatch two times and compare.
const same = catalog.every((e) => JSON.stringify(selectBackend(e)) === JSON.stringify(selectBackend(e)));
console.log(`pure: ${same}`);output
One backend or one refusal for each synthetic entry, and a check that the function is pure.
tool-a: exec-endpoint (tool-a)
tool-b: exec-outfile (tool-b)
tool-c: library-launch (firefox)
tool-d: webdriver-session (webkit)
tool-e: refused (no backend for connect with this entry)
pure: trueI ran the first example with the Node runtime and the flag --experimental-strip-types. The entry tool-e must have its own command to connect, and it has none. Thus it gets a refusal, not a library launch.
Run a synthetic tool process under a deadline, and parse one of four statuses from its endpoint line, its exit, or the deadline.
// Run a synthetic tool process with a deadline, and parse one of four statuses.
// Each child is a small Node script. No network, no browser.
import { spawn } from "node:child_process";
const DEADLINE_MS = Number(process.argv[2] ?? 1500);
const tools = {
"prints-endpoint": 'console.log("log: start"); console.log("ENDPOINT port=9222")',
"reports-unavailable": 'console.log("UNAVAILABLE reason=engine-not-installed"); process.exit(3)',
"crashes": 'console.error("synthetic fault"); process.exit(1)',
"goes-silent": 'console.log("warning: retry later"); setInterval(() => {}, 1000)',
};
function runAdapter(name, script) {
return new Promise((resolve) => {
const child = spawn(process.execPath, ["-e", script], { stdio: ["ignore", "pipe", "pipe"] });
let out = "";
let done = false;
const finish = (status, detail) => {
if (done) return;
done = true;
clearTimeout(timer);
resolve({ name, status, detail });
};
// The deadline kills first, then reports. A silent tool cannot hold the worker.
const timer = setTimeout(() => {
child.kill("SIGKILL");
finish("timeout", `no endpoint line after ${DEADLINE_MS} ms`);
}, DEADLINE_MS);
child.stdout.on("data", (chunk) => {
out += chunk;
const line = out.split("\n").find((l) => l.startsWith("ENDPOINT "));
if (line) {
finish("ok", line.trim());
child.kill("SIGKILL");
}
});
child.on("exit", (code) => {
const unavailable = out.split("\n").find((l) => l.startsWith("UNAVAILABLE "));
if (unavailable) finish("unavailable", unavailable.trim());
else finish("error", `exit code ${code} and no endpoint line`);
});
});
}
for (const [name, script] of Object.entries(tools)) {
const r = await runAdapter(name, script);
console.log(`${r.name}: ${r.status} (${r.detail})`);
}output
One status line for each of four synthetic tools.
prints-endpoint: ok (ENDPOINT port=9222)
reports-unavailable: unavailable (UNAVAILABLE reason=engine-not-installed)
crashes: error (exit code 1 and no endpoint line)
goes-silent: timeout (no endpoint line after 1500 ms)I ran the second example with the Node runtime and the argument 1500, the deadline in milliseconds. The silent tool prints a warning and then nothing. The deadline kills it and reports timeout.
failure modes
| problem | cause | correction |
|---|---|---|
| A benchmark of a tool with its own CDP client gives an ambiguous result. | A library ran in place of the tool. | Run the actual tool, or report an error. |
| A worker stops and holds its job until a person starts it again. | The tool printed a warning and went silent, and the adapter had no deadline. | Add the deadline as a fourth exit. The deadline kills first. |
| The memory of the host goes up after each run. | The stop reached the adapter but not the browser below it. | Start the adapter as the leader of a process group, and stop the full group with one call. |
| A capture holds wrong script bodies. | A mapped API looked correct but did not capture the true data. | Remove the mapping, and record "no capture". |
| The pass rate of a page goes down when a tool is missing. | The run counted a tool that did not start as a fail. | Report the run as unavailable, with a closed reason, in a separate table. |
| A tool sends traffic with no proxy. | The orchestrator used a direct connection after a proxy fault. | Mark the tool unavailable. Never fall back to a direct connection. |
check questions
Explain why the selection of a launcher backend is a pure function, and name its three inputs.
sample answer
The function reads only the engine, the attach mode, and the exec command of the tool. It reads no clock, no file, and no network. Thus the same catalog entry always gives the same backend, and a test can check each entry with no browser.
Describe the two subprocess contracts, and give the kind of tool that each one suits.
sample answer
Under the first contract, the tool prints one line on stdout with the address of its debug endpoint, and the orchestrator connects to it. This suits a tool that keeps a browser open. Under the second contract, the tool writes its result to a JSON file and exits, and the orchestrator reads the file. This suits a tool that does its full task alone.
A tool cannot start, because the host does not have its engine. Which record is correct?
- A fail of the page, in the pass rate
- An error of the tool, with the exit code
- The status unavailable, with a closed reason, in a separate table
answer
c. The status unavailable, with a closed reason, in a separate table
The tool did not start, thus the page did not cause the result. An availability fact stays apart from pass, fail, and ambiguous.
A tool with its own CDP client is missing from the host. What must the orchestrator do?
- Report an error or the status unavailable
- Run an unchanged library in place of the tool
- Run the tool on a different engine
answer
a. Report an error or the status unavailable
The rule is to run the actual tool, or to report an error. A substitute measures a different tool.
A tool prints a warning and then prints nothing. It does not exit. Which status does the adapter report?
- ok
- timeout
- unavailable
answer
b. timeout
No endpoint line and no exit came before the deadline. The deadline kills the process first, and then it reports timeout.
exercise
exercise Do this task in your own lab, with synthetic data only. Do not start a browser, and do not send a request to a site.
- Save the second code example in an empty folder of your lab.
- Run it with Node and the argument
1500. - Record the status of each synthetic tool.
- In the script of
prints-endpoint, remove the statement that prints the endpoint line. - Run the code again with the same argument.
- Write the new status of
prints-endpoint, and the reason for it. - Write which status of the four goes to a separate table, and why.
sample answer
This sample answer uses the synthetic tools of the code example.
The first run gives ok, unavailable, error, and timeout, in that order. Without its endpoint line, prints-endpoint exits with code 0 and no endpoint line. Thus its new status is error. The status unavailable goes to a separate table, because the tool did not start. A count of it as a fail would lower the pass rate for a reason that the page did not cause.
sources
- Benchmark platform, design (my test system): the four launcher backends, their three dispatch inputs, the two subprocess contracts, and the table of availability facts, 2026-11 (not public).
- Benchmark platform, design (my test system): the rule "Run the actual tool; error if you cannot", 2026-11 (not public).
- My model of the names of the backends and the statuses, and of the failure modes of an adapter, 2026-11 (not public).