Integrations
Brain Town reader
The Brain Town feed is GAOS pushing its own changes out. This page is the other direction: GAOS pulling the town's pull-request events, so a card can open when a pull request appears and another when it merges. The reader is off by default and reads only what the operator declares it needs.
Why a reader and not the public stream
The public stream is masked on purpose: a hidden product appears under its alias and every title is removed. That is right for a public town and wrong for a platform that has to act on a pull request — GAOS needs the repository's real name and the pull request's title the moment the event arrives.
So GAOS reads a scoped path: a machine token that opens one stream, filtered by the owners, repositories, kinds and event types the operator registered in Brain Town. Brain Town keeps the payload it already stores; the reader gets the repository's real name and the pull request's title, and no diff, no pull-request body and no login, because Brain Town never stored them.
The six settings
| Setting | Default | Meaning |
|---|---|---|
BRAIN_TOWN_CONSUMER_ENABLED | off | true or 1 turns the reader on. Anything else: no listener, no goroutine, no request. |
BRAIN_TOWN_CONSUMER_URL | unset | The town's base address (for example https://town.example.org). https only; no path, userinfo, query or fragment; redirects are refused; an address or a loopback host is refused. |
BRAIN_TOWN_CONSUMER_TOKEN_FILE | unset | A file holding the reader's bearer token, mode 600. In production it is deploy/stacks/prod.bt-consumer-token. The token must start with bt_c_: a bt_live_ token (the town's input credential) and a gaos_ token are refused. A file others can read is refused, not warned about. |
BRAIN_TOWN_CONSUMER_CURSOR_FILE | unset | A file, mode 600, holding the last event the reader handed over. It is what makes a restart resume instead of replaying the whole retention. |
BRAIN_TOWN_CONSUMER_TYPES | pr.opened,pr.merged | The town event types the reader accepts. An empty list means these two. |
BRAIN_TOWN_CONSUMER_KINDS | github | The event kinds the reader accepts, a comma list. It is sent as the stream's kind parameter and filtered again on the client. Add gitlab for a GitLab product (GitLab). |
An unusable setting never stops GAOS: the reader stays off, the boot log says why
(brain town: consumer unusable (…)) and the back office's Integrations view shows the
reason.
The scope GAOS declares
The operator registers the scope in Brain Town's back office: the owners, the repositories, the kinds and the event types the reader may see. Brain Town filters by it.
GAOS filters again, by the repositories its own products declare
(owner/repo pairs). The match is owner-qualified: a repository of the same name under another
owner does not match, and a bare name never matches. So a scope that is broader than GAOS's products still
cannot make GAOS act on a repository it does not own — and the repository GAOS acts on is always the
product's, never the event's.
So a repository linked to a product in GAOS (Linked repositories) must also be inside this scope; otherwise Brain Town never sends its events.
One scope per GAOS instance. GAOS runs a second instance with its own database; two instances pointing at one scope would each open the same cards.
What the reader sees
The frame has the public frame's own shape — seq, id, type,
source, at, payload — with the payload unmasked,
plus productKey and orgLogin from the town's store:
id: 1975
event: pr.opened
data: {"seq":1975,"id":"gh-…","type":"pr.opened","source":"github","at":"…",
"productKey":"sample-service","orgLogin":"acme-org",
"payload":{"product":{"key":"sample-service","name":"sample-service","visibility":"hidden"},
"task":{"id":"4931","kind":"pr","title":"Fix export"},
"data":{"pr":4931,"draft":false}}}
The pull request's title is untrusted text: it is capped at 200 characters, stripped of control characters and screened for anything that looks like a credential before it reaches a card.
A GitLab frame (D-114) is read differently: GAOS takes the
repository only from payload.data.gitlab — host, pathWithNamespace and
projectId, which Brain Town takes from the integration’s own instance — never from
productKey or orgLogin. A frame without the three is skipped as
gitlab-frame-incomplete; one whose path no product lists is skipped as not-owned; the
project id must be the one the repository is pinned to.
Reading, losing and replaying
- One goroutine, one stream. Nothing here blocks a GAOS action: a slow or dead town slows nothing.
- The hand-over is a bounded channel of 256. A full channel does not drop the event: it ends the session, and the reconnect resumes after the saved cursor. An event that was never handed over is a state change that never happened, and it must not be lost.
- The cursor has one writer: the drain, after the flow has committed the event or skipped it on
purpose. A frame the reader filters out still moves the cursor, in order, as a marker. A transient
failure (the products could not be read, a GitHub network error, a 5xx or a 429) keeps the cursor,
ends the session and is tried again after 5, 10, 20, 40 and 80 s; after that the event is skipped, the
log says
brain town reader: gave up seq <n>and the Cursor row shows it (v0.60.1). A GitHub 403, 404 or 422 and a store error are skipped at once: the pull-request poller is the source of truth for a merge, and finishes the review card it left in Review. - The waits before the second, third and fourth attempt are 1 s, 5 s and 30 s; after the fourth
consecutive failure the reader holds at 30 s. A
401or a403stops the reader and says so — but the token file is re-read on the next attempt, so a rotated token is picked up without a restart. - There is no whole-request timeout on a stream; a 45 s watchdog (three heartbeats) notices a half-open connection and reconnects.
- One log line per skipped frame, and never a token, a path or a title.
Turn it on
- In the town's back office, open Consumers, create one for GAOS and give it the scope: the owners, the repositories, the kinds and the event types. Copy the token — it is shown once.
- Create the token file and the cursor directory, as the deploy user:
install -m 600 /dev/null deploy/stacks/prod.bt-consumer-tokenandmkdir -m 700 deploy/stacks/prod.bt-state, then put the token in the file. Both must exist beforeup; the deploy refuses a missing directory, one owned by someone else, or one that is not mode 700. The container runs as the deploy user and writescursorinside it. - Redeploy with the settings on the line, and repeat them on every redeploy:
BRAIN_TOWN_CONSUMER_ENABLED=true BRAIN_TOWN_CONSUMER_URL=https://town.example.org ./deploy/rebuild-restart.sh prod deploy --tag vX.Y.Z. - Open the back office's Integrations view: the Brain Town reader block says enabled, the host, and how many events were handed over.
The town must already serve the reader's path. A GAOS that ships the reader first leaves it off with the reason the stream answers 404, which is the expected state until the town ships it.