Open-source AI coworkers that each get a computer of their own: a browser, files and tools, with every action decided before it happens and recorded after. Bring any AG-UI agent.
Refuse a port that answers but is not OpenBot, and stop compose blanking the tokens (#239)
anygivenfriday43ea5c11210c
diff --git a/.env.example b/.env.exampleindex e749f1eb..706b402a 100644--- a/.env.example+++ b/.env.example@@ -7,7 +7,17 @@ KEY_ENCRYPTION_KEY=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=# one to leave alone until somebody has decided otherwise: the trail is append-only and nothing else# can remove a row, so this is the only way it ever shrinks.# AUDIT_RETENTION_DAYS=365+# Two names for one number, and they have to agree.+#+# The server reads PORT (server/src/index.ts). scripts/start.sh reads SERVER_PORT, because it also+# has to know where the app should proxy and which port to report free -- and docs/configuration.md+# documents SERVER_PORT as the setting. Only PORT shipped here, so moving the server by editing this+# line left the script still looking at 3001: it found whatever else was there, accepted the first+# 200 as proof, and failed several stages later parsing that stranger's HTML as JSON.+#+# Change both, or neither.PORT=3001+SERVER_PORT=3001TENANT_PACKAGE_DIR=../examples/fintech# What this deployment calls itself, when more than one shares an Intelligence project. A copy of a# deployment made for development uses the same project key, and threads are listed per Bot withdiff --git a/CHANGELOG.md b/CHANGELOG.mdindex bf9f33e3..25d106f0 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -631,6 +631,44 @@ one they are, so those match too.No configuration changes and nothing is stored differently; a deployment that was already on thelight theme sees no difference at all.+### `start.sh` refuses a port that answers but is not OpenBot++The startup checks asked whether a port answered, and treated that as proof the port belonged to this+stack. Those are not the same claim. Any single-page app serves its index.html for every path it does+not recognise, so an unrelated dashboard on a default port answers `200` to `/api/capabilities` as+readily as this server does.++The cost was not a wrong answer, it was a wrong answer three stages later. `require_free_or_ours`+reported "already up", so the server was never started; `wait_for` then printed a green+"server ready"; and the run failed at stage 3 inside `json.loads`, parsing that stranger's HTML. The+error names `char 0`, which reads like an empty response rather than a `<`, so the visible symptom+pointed nowhere near the port.++Each surface is now asked for something only it can produce: a `licenseStatus` field for the server,+its own `<title>` for the app, `/health` for the compose services. When a check gives up it says+whether the process failed to start or the port belongs to something else.++The root cause was in `.env.example`, and is fixed there too. The server reads `PORT`, this script+reads `SERVER_PORT`, `docs/configuration.md` documents `SERVER_PORT` as the setting, and only `PORT`+shipped. Moving the server by editing that one line left the script still looking at 3001. Both names+are now present, next to each other, saying they have to agree.++**A run may now stop where it used to continue.** That is the point: it stops at the port that is+wrong, naming it, rather than several steps later on a parse error.++### `docker compose up -d` configures the same stack `scripts/start.sh` does++`SUPERVISOR_TOKEN` and `COMPUTER_TOKEN` defaulted to the empty string in `docker-compose.yml`, so+which stack you got depended on how you brought it up. `scripts/start.sh` resolves both to their+`openbot-dev-*` defaults and exports them before calling compose. A plain `docker compose up -d` —+which this project's own shutdown notes tell you to use — passed an empty string instead.++`agent-computer` refuses to start without one, so that half failed loudly. The supervisor half was+the quiet one: the server kept the token it started with while the supervisor held an empty string,+and every call between them was refused at the door.++Both now carry the same defaults `start.sh` applies, as `COMPUTER_IMAGE` already did two lines down.+A value set in `.env` still wins, and a deployment should set one.## 0.0.4diff --git a/docker-compose.yml b/docker-compose.ymlindex b420e933..e89f4f93 100644--- a/docker-compose.yml+++ b/docker-compose.yml@@ -72,7 +72,13 @@ services:required: falseenvironment:# The secret every caller must present. The container refuses to start without it.- COMPUTER_TOKEN: ${COMPUTER_TOKEN:-}+ #+ # The default matches the one scripts/start.sh applies when .env leaves this blank, which+ # .env.example does. Without it the two paths disagree: the script exports a value and brings+ # the stack up working, while a plain `docker compose up -d` -- which this project's own+ # shutdown notes tell you to use -- hands the container an empty string instead. Reaches only+ # a loopback-bound port; a deployment sets a real value in .env.+ COMPUTER_TOKEN: ${COMPUTER_TOKEN:-openbot-dev-computer-token}# How many Bots may hold a running browser at once, and how long an untouched one is kept.# A few hundred MB each, so on a deployment with many Bots these are the difference between# a container that holds steady and one that is killed for memory. Defaults are 8 and 30@@ -161,9 +167,11 @@ services:PORT: "4300"# Shared with the API server. The Bot-level verb set is the boundary; this token keeps other# services on the network from calling those verbs.- SUPERVISOR_TOKEN: ${SUPERVISOR_TOKEN:-}+ # Defaulted for the same reason as agent-computer's above: so `docker compose up -d` by hand+ # configures the same stack scripts/start.sh does, rather than a silently unauthenticated one.+ SUPERVISOR_TOKEN: ${SUPERVISOR_TOKEN:-openbot-dev-supervisor-token}# Handed to every computer this creates, so the server and the computers share one secret.- COMPUTER_TOKEN: ${COMPUTER_TOKEN:-}+ COMPUTER_TOKEN: ${COMPUTER_TOKEN:-openbot-dev-computer-token}COMPUTER_IMAGE: ${COMPUTER_IMAGE:-openbot-agent-computer:latest}# Which deployment the computers it creates belong to, so two stacks on one Docker host never# derive the same container and volume names for the same Bot.diff --git a/scripts/start.sh b/scripts/start.shindex 20536095..54831826 100755--- a/scripts/start.sh+++ b/scripts/start.sh@@ -111,21 +111,65 @@ holder() {lsof -nP -iTCP:"$1" -sTCP:LISTEN -Fcn 2>/dev/null | awk '/^c/{c=substr($0,2)} /^n/{print c" ("substr($0,2)")"; exit}' || true}+# Does whatever holds this port answer as OpenBot, rather than merely answer?+#+# `curl -f` proves something is listening and returned 2xx. That is not the same claim, and the gap+# between them is not academic: any single-page app serves its own index.html for every path it does+# not recognise, so an unrelated dashboard sitting on a default port answers 200 to+# `/api/capabilities` as readily as this server does.+#+# When that happened here the cost was not a wrong answer, it was a wrong answer three stages later.+# `require_free_or_ours` reported "already up", the server was therefore never started, `wait_for`+# printed a green "server ready", and the run died at stage 3 in `json.loads` on a mouthful of HTML —+# a JSON parse error standing in for "that port belongs to something else".+#+# So each surface is asked for something only it can produce.+identifies_as_openbot() {+ local port="$1" name="$2"+ case "$name" in+ # A field of this server's own payload. A stray 200 does not carry it.+ server)+ curl -fsS --max-time 3 "http://localhost:$port/api/copilotkit/info" 2>/dev/null \+ | grep -q '"licenseStatus"'+ ;;+ # The app is static HTML with nothing to interrogate, so its title is the identity available.+ app)+ curl -fsS --max-time 3 "http://localhost:$port/" 2>/dev/null \+ | grep -qi '<title>[^<]*OpenBot'+ ;;+ # Compose services on dedicated loopback ports, answering a route named for this stack.+ *)+ curl -fsS --max-time 3 "http://localhost:$port/health" >/dev/null 2>&1+ ;;+ esac+}+require_free_or_ours() {local port="$1" name="$2" whowho="$(holder "$port")"[ -z "$who" ] && return 0- if curl -fsS --max-time 3 "http://localhost:$port/health" >/dev/null 2>&1 \- || curl -fsS --max-time 3 "http://localhost:$port/api/capabilities" >/dev/null 2>&1 \- || curl -fsS --max-time 3 "http://localhost:$port/" >/dev/null 2>&1; then+ if identifies_as_openbot "$port" "$name"; theninfo " $name: already up on $port ($who)"return 0fi- red " $name: port $port is held by something else: $who"+ red " $name: port $port is held by something that is not OpenBot: $who"red " Re-run with ${name^^}_PORT=<free port>, or stop that process yourself."exit 1}+# As wait_for, but satisfied only by OpenBot answering, not by anything answering.+wait_for_openbot() {+ local port="$1" name="$2" tries="${3:-40}"+ for _ in $(seq 1 "$tries"); do+ identifies_as_openbot "$port" "$name" && { green " $name ready"; return 0; }+ sleep 1+ done+ red " $name never answered as OpenBot on port $port"+ red " Either it failed to start, or that port belongs to another process."+ red " Log: $LOGS/${name}.log"+ exit 1+}+wait_for() {local url="$1" name="$2" tries="${3:-40}"for _ in $(seq 1 "$tries"); do@@ -214,7 +258,7 @@ if [ "$SECRETS_ROTATED" = "true" ]; thenpkill -f "bun --env-file=../.env src/index.ts" >/dev/null 2>&1 || truesleep 1fi-if ! curl -fsS --max-time 3 "http://localhost:$SERVER_PORT/api/capabilities" >/dev/null 2>&1; then+if ! identifies_as_openbot "$SERVER_PORT" server; thenif [ "$ONE_COMPUTER_EACH" = "true" ]; then(cd server && PORT="$SERVER_PORT" \COMPUTER_SUPERVISOR_URL="http://localhost:$SUPERVISOR_PORT" \@@ -225,7 +269,7 @@ if ! curl -fsS --max-time 3 "http://localhost:$SERVER_PORT/api/capabilities" >/d(cd server && PORT="$SERVER_PORT" bun --env-file=../.env src/index.ts >"$LOGS/server.log" 2>&1 &)fifi-wait_for "http://localhost:$SERVER_PORT/api/capabilities" "server"+wait_for_openbot "$SERVER_PORT" serverinfo "3/4 Runtime health"INFO="$(curl -fsS --max-time 8 "http://localhost:$SERVER_PORT/api/copilotkit/info")"@@ -246,10 +290,10 @@ PYinfo "4/4 App"require_free_or_ours "$APP_PORT" app-if ! curl -fsS --max-time 3 "http://localhost:$APP_PORT/" >/dev/null 2>&1; then+if ! identifies_as_openbot "$APP_PORT" app; then(cd app && bun run dev --port "$APP_PORT" --strictPort >"$LOGS/app.log" 2>&1 &)fi-wait_for "http://localhost:$APP_PORT/" "app"+wait_for_openbot "$APP_PORT" appcat <<EOF