Operations
Portal does not deploy itself. It publishes versions; each site decides when to take one.
Cut a release
cargo release patch # or minor / major
That bumps Cargo.toml, tags v<version> and pushes. CI
(.gitea/workflows/publish.yml) reacts to the tag, builds once for
each kind of machine (x86_64 on ergo’s runner, aarch64 on macbropro’s;
when macbropro is away its files arrive when it is back), and
attaches portal-v<version>.tar.gz (portal, bratac, iris,
learn, hash.txt, site/, examples/, and models/ when the repo
ships a model) and each binary bare (portal-x86_64-linux, -iris,
-bratac, -learn) to the Gitea release. Three binaries, one
version: portal is the site, bratac the trainer and the kit
worker, iris the lint on its own, which a content repo’s CI
downloads (portal lint is the same code, so a workflow that pins the
portal binary goes on working); the workflow checks each says the
tag’s version. The aarch64 files are named beside them:
portal-v<version>-aarch64.tar.gz and portal-aarch64-linux, -iris,
-bratac, -learn. A deploy asks for its file by name, never for the
first of the release: Gitea lists assets by name, and with two machines’
files the first is not x86_64’s. Plain pushes to main only run the tests: nothing reaches
production from this repo.
Before cutting, move the Unreleased lines in CHANGELOG.md under a
heading for the new version. That section becomes the release notes,
and the table at the end of the file records which version each site
runs. learn/ is a workspace of its own, so its lock follows by hand:
cargo update -p dhd --manifest-path learn/Cargo.toml in the same
commit.
Pkg files are content-hashed (hash-files = true, instances run with
LEPTOS_HASH_FILES=true), so a freshly served page can never pair a
stale cached bundle with new wasm.
Roll it out
In the content repo, one line of .gitea/workflows/deploy.yml:
env:
PORTAL_RELEASE: v1.0.0
Its CI downloads the pinned artifact, ships
/srv/app/<instance>/releases/<tag>, flips current, rewrites the
instance env from that repo’s own Actions variables and secrets,
restarts app@<instance> and refreshes the Caddy route. Every rollout
is a commit, so reverting a bad version is git revert and a push.
Sites upgrade independently and may pin different versions.
New content reaches a running site when the content repo’s CI asks for it, after its lint passes (New content, and reading the store), and at every start.
Moving a site to 1.0
1.0 keeps everything a site has in one file of its own, and the
programs beside it dial it. Nothing moves over from NATS: what a 0.x
site needs comes across with portal import.
- A place for the store. The unit needs a
StateDirectory=drop-in (The site’s store). - The programs. gdo, kron, learn and the kit’s worker each get
PORTAL_DHD=<site key>@<address>and say their own key as they start; the site names them inDHD_KEYS(Programs that dial the site):<gdo>=mail,note,ask:owners;<kron>=payments,ask:owners;<learn>=rank;<kit>=kit. The site’s key is in its log as it starts, so a program comes up on the second deploy. Sites sharing a host each get aDHD_BINDport of their own. - The automations. n8n takes the answers as a signed webhook
(
DHD_HOOKS=answers=https://…,DHD_HOOK_SECRET) and calls the site over HTTPS with a token (DHD_TOKENS). - The content’s CI posts
Loadwith a token namedload, and prints what the site answers:{"loaded": …}, or 422 with why the content did not pass (the last good content serves on). - Backups to garage, varde or both (Backups).
- The content passes 1.0’s lint, which refuses a key no page reads
(0.x let it pass): an old
route:orbind:, or a label a comma cut short in a flow mapping (label: "Inhabil, går ut"needs its quotes).iris check --path questionsat the new release says where.
The search box is off until site.yaml asks for one (search:,
Content reference). Before a site
adds it, its host needs Ollama serving bge-m3 at OLLAMA_HOST
(http://127.0.0.1:11434 unless set), and the release’s learn beside
portal, which the tarball brings; a learn serve --dhd beside the
site saves starting a process per search (The ranker).
Add a site
- A content repo with a copy of an existing
deploy.yml: changeINSTANCE, the port and the domains. - Its Actions variables:
PUBLIC_URL,SITE_NAME, and sign-in (OIDC_ISSUERorKANIDM_URL, withOAUTH2_CLIENT_ID). - Its secrets:
OAUTH2_CLIENT_SECRET,PORTAL_GITEA_API_TOKEN(Gitea reserves theGITEA_prefix for secret names) andLOAD_TOKEN, with which its CI hands the site new content. - A sign-in client at the provider (Bringing your people in).
- A place for the store: the unit’s
StateDirectory=drop-in (The site’s store). - DNS for its domains.
site.yaml handles all branding; no portal change is needed.
Environment
Runtime configuration is environment variables; src/main.rs is the
authority and each content repo’s deploy.yml holds the production
values.
LEPTOS_SITE_ADDR | the address the site listens on; 127.0.0.1:3010 unless set, and a unit sets each instance its own port |
PORTAL_STORE | the site’s own redb file (see The site’s store). Unset, site.redb in the unit’s STATE_DIRECTORY; with neither the site does not start |
PORTAL_COMMAND | what portal does when started with no arguments, in place of serving: import --path … <file>, for a unit that runs an import into its own store (Starting a site filled in). Unset: the site |
DHD_KEYS, DHD_BIND | the programs that dial the site, and where (see Programs that dial the site) |
CONTENT_REPO, CONTENT_BRANCH | the repo that is the site |
CONTENT_DIR | the site from a directory on this host instead (questions/, aggregates.yaml, site.yaml, and the files /site/ serves), read at start and on every Load: for trying a site out or writing one offline (Try it) |
KANIDM_URL, OAUTH2_CLIENT_ID, OAUTH2_CLIENT_SECRET | sign-in |
OIDC_ISSUER | sign in through another OpenID provider than Kanidm: its issuer, exactly as its discovery document gives it (Rauthy: https://id.example.no/auth/v1/). Wins over KANIDM_URL for sign-in; KANIDM_URL may stay for making accounts |
PEOPLE_BACKEND | kanidm, rauthy or memberships (see Memberships); unset, Kanidm when KANIDM_API_TOKEN is set, memberships otherwise |
KANIDM_API_TOKEN | invites and grants: through Kanidm |
RAUTHY_URL, RAUTHY_API_KEY, RAUTHY_LANGUAGE | with memberships and no Kanidm: accounts made in Rauthy (see Memberships). The key is <name>$<secret> with read and create on users; the language is the one Rauthy writes the account’s pages and mail in, nb for Norwegian, English unless set |
KANIDM_GROUP_PREFIX | for a Kanidm shared with other sites: the content’s kunder is the group <prefix>kunder there, and the OAuth2 client’s claim map gives it back to portal as kunder |
PHONE_COUNTRY | the calling code a bare phone number gets, +47 unless set |
OIDC_EXTRA_SCOPES | scopes to ask the provider for besides openid profile email: phoneNumber for Vipps. Not for Kanidm, which denies a sign-in that asks for a scope the person does not hold |
SEED_ADMIN_EMAIL or SEED_ADMIN_PHONE, SEED_ADMIN_NAME, SEED_GROUP | the first person in, invited once at start into the most privileged group (or SEED_GROUP) |
RESPONSIBLE_GROUP | the group every person a page names as responsible joins, at start and whenever the content changes, and leaves when no page names them any more; they get an account either way |
PUBLIC_URL, SITE_NAME | what the site calls itself in links, mail and the words its rooms hear. Unset, SITE_NAME is the host in PUBLIC_URL |
GITEA_API_TOKEN | authenticated resource pulls, and a private content repo: with it set, every content fetch (the tree, each page, site.yaml, aggregates.yaml, the /site/ and /.well-known/ assets) carries the token, to the content repo’s own host only. Read-only access to that repo is enough. An Actions secret cannot be named GITEA_…, so deploy workflows keep it as e.g. PORTAL_GITEA_API_TOKEN and write it into the env file as GITEA_API_TOKEN. |
AUTOMATION_READ_TOKEN | the automation KV read endpoint |
MAPBOX_TOKEN | map tiles, proxied; unset, maps are off |
MAPBOX_STYLE | the Mapbox style every map is drawn in, as <owner>/<style-id>: one of Mapbox’s or your own from Mapbox Studio. Default mapbox/streets-v12 |
ADDRESS_LOOKUP | off keeps every site on this host from asking an address register (site.yaml addresses:, Kartverket for a Norwegian site); a type: address field is then a plain line of text. Unset, each site’s own choice stands |
GARAGE_* (4) | attachments; see below. Unset, upload fields fail closed |
PORTAL_BACKUP_TO, GARAGE_BACKUPS_BUCKET, VARDE_SOCKET, VARDE_PUSH_TO | sealed backups of the store to garage, varde or both; PORTAL_BACKUP_EVERY, PORTAL_BACKUPS_KEPT and PORTAL_VARDE_DIR tune them (see Backups) |
PORTAL_RATE_BURST, PORTAL_RATE_PER_SECOND, PORTAL_TRUST_FORWARDED | the rate limit, and whose word on the caller’s address counts; see below |
PORTAL_SESSION_DAYS | how long a session lasts from its last use, default 90 |
PUBLIC_URL | where the site is reached; the base of /sitemap.xml’s URLs and the links in mail. Unset, the sitemap takes the host the request came to |
PORTAL_EXTRA_CA | a PEM file of certificate authorities trusted beside the public ones, for a Kanidm or Gitea behind a private CA (a preview, a test) |
EDIT_GITEA_TOKEN | a token that may push branches and open and merge PRs on the content repo: “Suggest a change to this page” becomes a conversation whose change is applied on the responsible person’s yes. Unset, it is the plain form. EDIT_TALK_MODEL, EDIT_MODEL, EDIT_LLM, EDIT_ENGINE, EDIT_NUM_CTX, EDIT_TIMEOUT, EDIT_MAX_ANSWERS, EDIT_MAX_CHARS, EDIT_DRAFT_ROUNDS, EDIT_CHECK_MINUTES, EDIT_MAINTAINER_GROUP, EDIT_COMMITTER_NAME/_EMAIL, EDIT_LINT_BIN and EDIT_WORK_DIR tune it (see Training) |
PORTAL_NOTICES_PER_MINUTE | how many notice mails the instance sends a minute over every bucket, 600 unless set; each bucket’s own per_minute (60) is within it |
PAY_URL | the money service (kron) is there: a state’s payment: may then leave by_hand: true out, and each request waits in the payments outbox for kron as its record is made. Portal never calls the address; kron dials the site (see Programs that dial the site). Unset, the lint requires by_hand: true on every payment:, and a content repo’s own lint needs it set the same way its deploy does |
CHAT_URL | where the site’s chat answers (e.g. https://chat.lindtun.no), without a trailing /. Set, a case on a desk with no conversation yet links to ${CHAT_URL}/room/<group>/case/<bucket>/<id> to start one; unset, a case shows only a conversation the chat has told of. Optional; see Rooms |
LEARN_BIN, LEARN_MODEL, LEARN_CACHE, OLLAMA_HOST | the ranker behind the search box; all optional, and none is read by a site whose site.yaml has no search: block (see The ranker) |
Mail is delivered by gdo, a
separate unit on the same host that dials the site and takes what
waits in its mail outbox.
Credentials never appear in the log. A URL that may carry a user and
password or a token (CONTENT_REPO, KANIDM_URL,
OLLAMA_HOST) is written as scheme://user:***@host wherever a log
line or an error names it, and the map proxy’s warning leaves the
Mapbox token out.
Groups that need a strong sign-in
site.yaml may name groups that count only when the person signed in
with more than a password:
mfa_groups: [board, treasurer, editors]
Portal reads the token’s amr (RFC 8176) at sign-in. With mfa, hwk
or swk in it the session has every group as before; without, the
groups listed are held back for that session: their pages answer
“You have a place here, but this page needs a sign-in with a passkey
…”, with a link to add a passkey (account_url, or Rauthy’s own
account page under OIDC_ISSUER) and one to sign in again
(/auth/login?fresh=1, which asks the provider to sign them in anew
rather than reuse its session). Membership is not touched: notices to
the group still reach them, and desks still list them.
A site with mfa_groups asks the same of whoever changes it: “Apply
this change” on a suggested change (Training)
is refused after a weak sign-in, whatever groups the person holds, and
the change waits for them to sign in again.
Rauthy sends mfa for anyone with a passkey. A provider that sends no
amr makes every sign-in weak, so the groups are held back from
everyone; set mfa_groups only where the provider says how someone
signed in.
The chat asks portal with strong in its question
(dhd::access::Principal::User), and portal holds the groups back from
an asker that does not say strong: true. A chat that predates it says
nothing, so release the chat that sends it before setting mfa_groups,
or the groups’ rooms close for everyone.
A name in mfa_groups that no page uses is refused at load, since it
would protect nothing.
The site’s store
A site keeps what is its own in one redb file: every record and its event log, the work waiting in its outboxes, its sessions, and what it keeps for a while (a change talked through, a web interview, a draft written together). Only its process opens it; a second process on the same file is refused at start.
The file is PORTAL_STORE, or site.redb in the directory systemd
gives the unit for its StateDirectory=. With DynamicUser=yes, as
app@.service has, that is the only place the site may write that
outlives its release, so a 1.0 site’s unit needs one, as a drop-in
beside the others:
# dropins/app@uhhm.service.d/state.conf
[Service]
StateDirectory=uhhm
The working directory is the release’s, so the site does not start with neither: a file there would go with the next deploy.
A sign-in returns before the disk has it. The site takes such writes down to the disk every minute, and as it stops: on SIGTERM it takes no new connection, gives the requests under way 10 seconds, and writes the file before it exits. A deploy signs nobody out. A crash loses the sign-ins of the last minute at most, and those people sign in again; a sign-out always waits for the disk. Sessions past their date are deleted once an hour.
Backups
The site’s store is one file, so a backup is one file too. Every six hours the site copies the whole store as it stands at one moment, while writes go on, seals the copy, and hands it to garage, to varde, or to both. It keeps the newest fourteen.
age-keygen -o backup-key.txt # on your own machine, never the server
# the instance's env file:
PORTAL_BACKUP_TO=age1… # the public key age-keygen printed
GARAGE_BACKUPS_BUCKET=uhhm-backups
VARDE_SOCKET=/run/varde/varde.sock
VARDE_PUSH_TO=<the peer's node id>
- Sealed on the site.
PORTAL_BACKUP_TOis an age public key. Every copy is encrypted to it before it leaves, so the bucket, the peer’s disk and anyone who reaches either see only noise. The private key stays off the server. To varde a backup goes sealed or not at all: the site will not start withVARDE_SOCKETand no key. Without a key, garage gets copies in the clear, and the site warns at every start. - garage:
GARAGE_BACKUPS_BUCKETnames a bucket the site’sGARAGE_*key may read and write. Each copy is<site>/<time>.redb.age, and the site removes copies older than the newestPORTAL_BACKUPS_KEPT. - varde: the site puts each copy into this host’s varde, pins it
closed (served to varde’s trusted peers alone), and pushes it to
every node
VARDE_PUSH_TOnames. varde answers once the peer has it whole. The two vardes must trust each other (varde-ctl peer trust <node id>on each). The site lets go of its own older pins. A peer keeps what it was given until its operator lets it go, so a site that is broken into cannot delete the copies away from it. A copy no peer took counts as a failed backup. A store bigger than 16 MiB sealed goes throughPORTAL_VARDE_DIR, a directory both can reach. - Do not export a ticket for a backup’s hash on a peer. In varde a ticket is a publication: whoever holds it may fetch the content without being trusted. Without one, a node that knows the hash and the peer’s address gets nothing. The copy is sealed either way.
PORTAL_BACKUP_EVERYis hours,6unless set.PORTAL_BACKUPS_KEPTis a count,14unless set. Backups are off unless a bucket or a varde socket is named.
To restore, stop the site, open the copy with the key and put it in place of the store:
age -d -i backup-key.txt 20261119T101500Z.redb.age > site.redb
From varde, have it write the copy out first, to a path varde may
write:
varde-ctl materialize <hash> /var/lib/varde-out/backup.redb.age.
Programs that dial the site (dhd/1)
The programs beside a site (gdo for mail, kron for money, learn for
search, kino for the chat, the kit’s worker for briefs) dial the site
over dhd/1, by its key. The site dials no one, and opens nothing
until the instance names a program:
| variable | what it does |
|---|---|
DHD_KEYS | each program’s key, then what it may do (below): <key>=mail,note;<key>=payments. A key is what the program prints as its own. Unset or empty: no program, and no port |
DHD_BIND | where programs dial: 127.0.0.1:4300 unless it says otherwise, so only this host |
DHD_TOKENS | what a caller over HTTPS may do, by the SHA-256 of its token: <sha256>=submit;<sha256>=note,payments;<sha256>=scanner. The site keeps no token, only its hash (printf %s "$TOKEN" | sha256sum). Unset or empty: no HTTPS calls |
DHD_HOOKS, DHD_HOOK_SECRET | outboxes posted as signed webhooks instead of waiting for a program to serve them: answers=https://n8n.example/webhook/x;mail=…, each row signed with the secret (see below) |
What a key may be named for:
- an outbox it takes:
mail,payments(and then it may move payments),answers,rooms,kit(and then it may queue a brief, say how its job ended, and settle a job it filed once an owner approves it, see Training); - a destination of a state’s
post:,posts.<name>(<key>=posts.scribe): it takes the steps handed to that name and answers each with aMoveon the step inportal_posts, its payload the answer (State machines);DHD_HOOKSmay name the same outbox for a webhook; submit, to send an answer as a visitor would, anywhere a visitor could; orsubmit:<bucket>, only through forms that record into that bucket, which is what to give a party outside the organisation;- a call it may make:
notefor replies,mayfor the access question,watchfor the groups,loadfor the deploy,readforportal db; ask:<group>orask:person: it may ask that group, or one person, a question (Questions a program asks); the answer comes down its call alone, secrets sealed to it, and only its key may say what came of it;- a name from
site.yaml’sprograms:(<key>=scanner): it may make the moves listed there, as a desk button does (content reference, “Programs that move records”).
The site’s own key is site.key beside its store, made the first time
and readable by the site alone; the log says it, with where it listens,
as the site starts. A program needs both: the key and the address.
A program serving an outbox holds its call open and is handed every row of it, oldest first; each row it acknowledges goes from the outbox. A row it has not acknowledged when it goes is handed to it again when it dials back, or to a webhook the instance names for that outbox. Nothing goes out twice at once, and nothing a move said is lost to a program that was away.
What is not Rust (n8n, a script) makes the same calls over HTTPS, with
a token as Authorization: Bearer <token>:
| post | body | answer |
|---|---|---|
/dhd/1/submit | {question_id, alternative, responses} | {chain_hash}: the answer, as a visitor would send it |
/dhd/1/move | {bucket, record, to, by, seen, payload} | {sequence}: a move a programs: name may make, or a payment as the money service moves one |
/dhd/1/note | {id, bucket, record, by, subject, text, at_ms} | {ok}: a reply read elsewhere, kept on its record |
/dhd/1/load | {at} | {loaded}: the content at commit at (the branch’s head where empty) fetched, checked and swapped in; the last good content serves until then, and stays if the new one fails |
/dhd/1/read | {bucket, key, log} | the record as JSON, its event log with log, or every record of the bucket without key |
A refusal’s status says why: 401, a token the site does not know; 403, not what the token may do; 422, a call that will never succeed (no such record, the wrong sender); 503, not now, so try again; 501, not taken yet.
And the other way: an outbox named in DHD_HOOKS is posted to its
address, a row at a time, oldest first, as the JSON it is, instead of
waiting for a program to serve it. n8n gets every answer
(answers=…) this way.
Each post carries Dhd-Outbox and Dhd-Row (the same every time it is
sent, so the receiver keeps it once) and Dhd-Signature,
sha256=<hex>, the HMAC-SHA256 of <outbox>.<row>.<body> under
DHD_HOOK_SECRET. A 2xx lets the row go; anything else, and it is
tried again after 5 seconds and then longer, up to 5 minutes, with the
rows behind it waiting so they arrive in order.
gdo does this where it is told the site (PORTAL_DHD=<site key>@<address>):
it prints its own key as it starts,
and the site names it <gdo's key>=mail,note (with ask:owners where gdo
asks for the site’s own mailbox), note for the replies it
reads, which the site keeps on the record they answer. kron does the
same for money (<kron's key>=payments): it takes the requests and
tells the site what the provider says as a move on the payment. With
ask:owners too, it asks the owners for its Vipps keys when it has
none, and keeps its ledger in a file of its own (KRON_STATE).
New content, and reading the store
A content repo’s CI tells the site to load what it just linted, with a
token the site names load:
curl -fsS -X POST https://<site>/dhd/1/load \
-H "Authorization: Bearer $LOAD_TOKEN" -H "Content-Type: application/json" \
-d "{\"at\": \"$GITHUB_SHA\"}"
The site fetches that commit, checks it whole and swaps it in; until then, and if anything fails, the last good content goes on serving. The answer says how many pages are in place, or why nothing changed.
The operator reads what a running site keeps with portal db, since
the site alone opens its store:
portal db --site <site key>@<address> hires # every hire, by key
portal db --site <site key>@<address> hires h-17 # one, as it is kept
portal db --site <site key>@<address> hires h-17 --log
portal db says its own key as it starts (kept in ~/.config/portal/db.key,
or PORTAL_DB_KEY); the site names it <key>=read. PORTAL_DHD may
stand for --site.
On a site being tried out, with no sign-in provider, portal session --as <name> --groups <group>[,<group>] [--email <address>] [--hours 24] writes a signed-in session into the store (PORTAL_STORE, with
the site stopped) and prints the cookie for a browser, so a desk can
be looked at (Try it). It refuses where OIDC_ISSUER
or KANIDM_URL is set.
Presence
Who is beside a site is whoever holds a Serve open to it over
dhd/1. Each program says, as it opens the call, its name (gdo,
kron, learn, the chat), its version and what it can do: providers
on a money service (vipps,stripe), calendar on the mail gate
(caldav). The site logs each as it comes and goes. A payment request
names the provider a kron here has; a mail’s event goes out knowing
whether a calendar will take it. Nothing is refused for want of a
program: with nobody there, the site does what it does alone, and the
outbox holds the work until the program comes.
Questions a program asks
A program beside the site can ask its people something: gdo how the
site’s mail should go out, a courier when to come. It sends a question
in the shape a page has, with the Ask call (or POST /dhd/1/ask with
a token):
{
"id": "mail-login",
"to": "group:owners",
"seal_to": "age1…",
"question": {
"name": "How should the site's mail go out?",
"alternatives": [
{ "name": "Through your mail server (SMTP)",
"features": [ { "name": "The server", "requirements": [
{ "name": "host", "label": "Server" },
{ "name": "password", "label": "Password", "secret": true } ] } ] },
{ "name": "Not now" }
]
}
}
- Who it is for:
group:<name>, everyone in that group, orperson:<address>, one person. The site says who a program may ask:ask:<group>orask:personbeside its key inDHD_KEYS(or a token’s inDHD_TOKENS). People read who asks by the name the program opened itsServewith, or over HTTPS byfrom("from": "n8n"). - Where it shows: in the header of whoever it is for, and on a page
the site draws from the question itself,
/asks/<id>. Nothing in the content has to place it. - What it may hold: words, alternatives, and fields of the kinds
text,textarea,email,tel,url,number,dateandselect. A field markedsecret: trueis sealed toseal_tobefore the site writes anything, and only someone signed in with more than a password may answer it. Nothing that reads the site’s records or takes a file. - The answer goes to the program alone: down its own
Servewhen it says it doesasks, or, for a caller over HTTPS, to theaskswebhook (DHD_HOOKS). It names the alternative picked and carries its fields, secrets sealed (dhd::ask::Answered). - What came of it: the program moves the record to
doneorrefusedwith its words, or towithdrawnwhile nobody has answered (dhd::ask::Word), and the page says so.
Each ask is a record in portal_asks, opened once per program and id,
so a program that asks again after a restart asks nothing new. A desk
can list it like any bucket.
What waits is not left for someone to find. A signed-in person’s name in the header is marked with how many things wait for them, and opens onto the list: each question asked of them or a group of theirs, and any change they suggested that waits for their yes, each with a link to where it is answered. A visitor, and someone with nothing waiting, see the header as it always was.
A program built before 1.0.0-rc.10 that asked for a login in its
Serve (waiting, ask, public_key) is not heard by a 1.0 site:
gdo and kron ask with a question; a 0.x site keeps the gdo and kron it
has.
Schedules, notices and boards
Three sweeps run beside the deadline and announcement sweeps, and each
looks at the content first: a site without recurs, notice or
board gets no work from them and no new buckets.
| sweep | every | does |
|---|---|---|
schedules (recurring.rs) | minute, and at start | opens the record a recurs series has fallen due |
what comes round (comes_round.rs) | minute, and at start | moves a comes_round record out before its date and back after, and asks for a date that follows no rule |
notices (notices.rs) | 10 s | mails notices in their sending state, as many as the rate allows, and moves each to its sent state once everyone has it |
boards (boards.rs) | minute | holds every board’s ledger and its place records to each other |
What they keep, in the site’s store beside its other buckets:
| bucket | holds | key |
|---|---|---|
portal_recurring | where each series has got to: the last record it opened and its due day | <bucket>.<series>.<hash of the subject> |
portal_comes_round | which date a record has been out for, and the last year a date was asked for | <bucket>.<hash of the record> |
portal_notice_log | who a notice has gone to, and when; written after the mail | <bucket>.<notice>.<hash of the address> |
portal_notice_optouts | each address’s token for a bucket’s notices, and whether they stopped them | <bucket>.<hash of the address> |
portal_places | each thing’s ledger: seats and the line, by a hash of who | <board>.<record> |
No key holds an address. Each person’s mail and the line saying it
went are written in one batch, so a stop halfway sends nobody the
notice twice. The log says how far a notice has got
(a notice went out to more people, with counts) and never who.
Routes: GET /ics/<board>.ics, GET /ics/<places>/<id>.ics?email=
(404 for anyone the policy does not let subscribe), and
/notices/unsubscribe?b=&r=&t=, which asks first on a GET and changes
something only on the POST its button sends, so a mail program that
opens links to look at them stops nobody’s notices.
Starting a site filled in
portal import brings in what a site already has: years of events, a
committee’s documents, a board’s minutes. Run it where the site’s
variables are set:
PORTAL_STORE=... portal import --path questions seed/committees.yaml --dry-run
PORTAL_STORE=... portal import --path questions seed/committees.yaml
# seed/committees.yaml
committees: # a bucket
- id: path # letters, digits, - and _; what makes it once
state: active # the bucket's first when left out
fields: { name: The footpath, purpose: "Keeps the path clear." }
announcements: # a bucket that belongs_to: committees
- id: workday-2024
state: archived
at: 2024-05-04T10:00:00+02:00 # or a day, 2024-05-04
source: https://old.example/news/24-05-04-workday
fields: { title: Workday on the path, text: "<p>Bring a rake.</p>" }
documents:
- { id: path-plan-2023, at: 2023-11-01, file: files/path-plan-2023.pdf, fields: { title: Path plan } }
board: # a bucket's `owner:`, holding what is its
documents:
- { id: agm-2019, at: 2019-03-14, fields: { title: AGM 2019 } }
A record nested under another carries its key, in the field its bucket’s
belongs_to names. One at the top of a bucket with an owner: is the
owner’s. file is relative to the file, and goes in the form’s one file
field; it needs the site’s GARAGE_*.
Checked first. The file is read whole, against the content, and held
to what a form is: fields the form has, the ones it asks for, its
choices, rich text cleaned, parents and references that resolve (in the
file or on the site), files that exist, ids once. Everything wrong is said
at once, and one thing wrong writes nothing. A dry run says what it would
do and writes nothing; with no PORTAL_STORE it checks against the content
alone. Once writing has started, a store that fails stops the run with
what came before it kept, and running again finishes it.
Dates. at is a field of the record’s own, which a list sorts by and
shows, so a 2019 record says 2019 and sorts there. The log’s time and
order are the import’s: a past date rewrites nothing.
Quiet. Each record’s one event says it was imported, from which file
and from where (source), and “History” on its row reads it. No mail,
no grants, nothing announced, no chain. No after: clock and no
leaves_after runs on it, and it is not taken in by comes_round, until
a person has moved it: it lands where it says and stays. One resting in a
comes_round bucket comes round in its time, as a date still to come is
live.
Once. Run again, nothing changes. A field that differs from the file is reported and left, since a desk may have changed it.
On a deployed site. The store opens in one process, and under
app@.service only the unit may open its StateDirectory. So the
unit runs the import itself: portal started with no arguments does
what PORTAL_COMMAND says. A deploy puts the files where the unit can
read them, adds one line to the instance’s env, restarts the unit,
waits for it to end, takes the line out and starts the site:
echo "PORTAL_COMMAND=import --path /srv/app/<instance>/seed/questions /srv/app/<instance>/seed/import/machines.yaml" >> /etc/app/<instance>.env
systemctl restart app@<instance> # the import, in place of the site
# wait until it is no longer running; `systemctl show -p Result` says success
Since a second run changes nothing, a deploy can do this every time.
Where the deploy runs as a service that may not set the setgid bit
(RestrictSUIDSGID=, as the bare runner has), copy the files in with
tar, as the release is unpacked: cp -r and chmod -R fail on
directories that hand their group down.
What it refuses. People: portal’s own buckets, portal_memberships
above all. A place in a group is an invitation someone accepts (and a
submit: press below is how one is made). Places on
a board, which are the ledger’s, and a notice in the state it is sent
from, which would go out. It warns of a field holding an address or a
phone number: such a file stays out of the repo.
Where. Into the site’s own store: PORTAL_STORE, or the unit’s
STATE_DIRECTORY, as the site has them. The store opens in one
process, so run the import while the site is stopped; while it runs,
the import says so and writes nothing. Each record and the event that
makes it are written together, so a run stopped halfway leaves every
record it wrote whole, and the next run takes up the rest. The mail
and answers the presses below make wait in the store’s outboxes,
as the site’s own do, for gdo and the automations when the site starts.
Onboarding: the desk’s own presses. People still come in the one way
they ever do, by an invite from a desk, but the presses can be replayed.
A submit: list in the same file is the board’s buttons, in order, each
sent through the same code as the desk sends it (submit_as), as someone
in one group: --as <group>, else SEED_GROUP, else the group that may
invite into the most groups (the board). So a site starts with everyone
it already knows invited, from the first person on, without anyone
pressing anything:
# onboarding.yaml - names and addresses: keep it out of the repo
submit:
- page: /board
alternative: Invite someone onto the board
fields: { name: Kari Nordmann, email: kari@example.no }
- page: /committee/traffic/board
alternative: Give the committee a lead
fields: { name: Ola Nordmann, email: ola@example.no }
PORTAL_STORE=... portal import --path questions onboarding.yaml --dry-run
PORTAL_STORE=... portal import --path questions onboarding.yaml
A press may be “Change” on a record instead of a new answer: record:
names the record, and fields: only what changes, through the same
code as the desk’s save (editing::edit_as), so the rest of the record
stays as it is and the change is an event in its log. The group must be
one a list with edit: lets change that bucket, and the record one that
list shows it:
submit:
- page: /committees/content
alternative: Add an event
record: 51cf1ee171ae9649fbf4ad2c6d0d1487d1477e74946de211f0e27ce715931792
fields: { places: "100" }
Each press is held to what the desk holds it to before anything is sent,
and one that would be refused refuses the file: the page and alternative
are there, the group may send that page, the alternative is open, the
form has what it asks for, an invite says who and the group may invite
into its group. A dry run lists what each would do (would submit #2 /committee/traffic/board «Give the committee a lead»: invites Ola Nordmann <ola@example.no> into committees_traffic_lead); with the site’s store it also
says which are made already. The real run is not quiet: each does what
the press does, the account, the mail and all. An invite to someone
already in the group, or with a place held there, is skipped, so a run
again sends nothing new; one into a record’s group whose record is not
open is refused. The records in the file go first, then the presses.
Invites need the site’s people settings (PEOPLE_BACKEND and Rauthy’s
or Kanidm’s), so run it where the site runs, with its environment.
portal comes-round --path questions makes one pass of what comes round,
by hand. --at <RFC 3339> makes it a test clock on a throwaway: it makes
real moves and sends real mail, so it needs PORTAL_TEST_CLOCK=1.
Rooms
A site’s groups are rooms in its chat, a program beside the site that
dials it like the others, and the site says in each what the group
needs to act on. The whole of it is in Rooms; for the
operator it is one key in DHD_KEYS, <chat's key>=rooms,watch,may:
| the chat | what it does |
|---|---|
Serve doing rooms | takes what the site says in each group’s room (landed, clock_soon, clock_ran, moved, opened), waiting in the rooms outbox while the chat is away |
Watch of groups | the site’s groups, one document per room, then every change as content loads |
Note with subject: thread | tells the site a case has a thread, on its first message and every tenth; the site keeps the newest per case (portal_threads) for the desk’s row |
May | the access question, which also answers for {kind: room, name: <group>} (see Access) |
CHAT_URL is the only setting, and it is optional.
The chat is kino, one per site,
from the [uhhm] registry like gdo:
pacman -S kino
cp /usr/share/doc/kino/env.example /etc/kino/<site>.env # PORTAL_DHD, sign-in, PUBLIC_URL
systemctl enable --now kino@<site> # says its key: name it in DHD_KEYS
The ranker
learn ships in the same tarball as portal, so every release dir
holds both binaries side by side:
/srv/app/<instance>/releases/<tag>/
portal bratac iris learn hash.txt site/
models/route.bpk models/route.json
Portal spawns learn rank with one JSON request on stdin and reads one
JSON reply back. Nothing has to be configured for that: each binary
looks beside itself first. The service starts portal through the
current/<instance> link, and the binary’s own path resolves through
it to the release dir, so a rollout or a rollback moves portal, learn
and the model together.
LEARN_BIN | the learn binary portal runs. Unset, learn beside portal’s own binary, then learn on PATH. A wrapper script that sets an environment should exec learn; either way, a call past its deadline is stopped with everything it started (its process group) |
LEARN_MODEL | the model learn rank uses: a packed <name>.bpk (with its <name>.json beside it) or a model directory from learn train. Unset, models/route.bpk beside the learn binary, which is the shipped one. A request may name its own model, and that wins |
LEARN_CACHE | the embedding cache, /srv/app/<instance>/learn-cache. Keep it outside releases/ so it survives a rollout, and make it writable by the instance’s service user |
OLLAMA_HOST | the encoder for texts the cache has not seen, and for every search’s words, http://127.0.0.1:11434 unless set. The shipped model’s encoder is bge-m3 |
If the cache dir cannot be written, learn keeps the cache in memory
for that one call. Ranking still works, but every call then embeds all
of its texts again. If a text is not cached and the encoder cannot be
reached, learn rank exits 3 and portal reads that as “no decision”
and carries on as it would without a model.
The shipped model is learn/models/route.{bpk,json} in this repo,
written only by
learn/scripts/ship-model.sh <model dir>
That script refuses (exit 1, nothing written) any model whose manifest
does not say site_classes == ["fictional"]: this repo and its
releases are public, and a model trained on a client’s rows would
carry what it learned from them into both. The release workflow checks
the sidecar again before packing, and checks that learn rank loads
the model from beside the binary. To try the release’s model on a host
without touching the instance:
printf '%s' '{"decision":"route","context":{"text":"…"},"candidates":[{"id":"a","text":"…"},{"id":"b","text":"…"}]}' \
| LEARN_CACHE=/srv/app/<instance>/learn-cache /srv/app/<instance>/current/learn rank
The search box
A site whose site.yaml has a search: block
(Content reference) shows a box
on the pages it lists, while this instance can rank. Portal checks
with a probe, one learn rank --ephemeral of a fixed sentence and two
fixed options: at start, every ten minutes, and within seconds of a
reload that changes the block. The box shows while the last probe got
a reply. A site without the block never asks learn.
When a search finds learn gone (Ollama unreachable, exit 3, or no answer in three seconds), the box goes at once and the probe runs every 30 seconds until learn replies, so an Ollama restart costs the box half a minute. A search that fails another way (no model, a reply that is not one) leaves the box where it is.
Each search:
- is one
learn rank --ephemeralin the visitor’s request, or one question to a learn serve, with three seconds in all; - takes one of four places, at most two per caller (by IP as the rate limit reads it, an IPv6 caller by its /64; two, because an office’s NAT puts many people behind one address), and waits up to a second for one before saying search is not available;
- uses
LEARN_BIN,LEARN_MODEL(or the block’smodel:, a name under themodels/besidelearn),LEARN_CACHEandOLLAMA_HOSTas above; - keeps the visitor’s words in memory only: they go to Ollama, never to the cache or the log. Only the options’ texts, the site’s own words, are cached, so Ollama must be up for search to work at all.
Keep bge-m3 resident. learn asks Ollama to keep it loaded for 30
minutes, and the probe calls every ten, so with nothing competing it
stays. A search that finds it evicted waits out the reload (5 s cold,
16 s beside a chat model) and is told search is not available. On a
host whose GPU also runs chat models, give search its own Ollama on
the CPU (ollama-embed.service on 127.0.0.1:11435, and
OLLAMA_HOST=http://127.0.0.1:11435 in the instance’s env), and keep
bulk embedding (learn embed) on the GPU’s. Measured on ergo
(2026-10-22): a warm search against six cached options takes about
70 ms on the CPU, no slower than on the GPU, and the vectors agree to
a cosine of 0.99991 or better on 2,000 texts; on the shared GPU, loading qwen3:8b
evicted bge-m3 and the next search took 21 s.
Whether search is ready shows in three places:
- the log, when a block is first probed, when a search takes the box
away, and whenever readiness changes:
search: learn answered the probe; the search box shows where site.yaml puts it,search: learn did not answer the probe, so no search box: <why>, orsearch: a search found learn gone (<why>), so no search box until it answers the probe; - the site’s own answer,
curl -s -X POST https://<site>/api/get_site, whose"search_ready"istrueorfalse; - the probe by hand, as the instance runs it:
printf '%s' '{"decision":"route","context":{"text":"Water is coming through the ceiling when it rains."},"candidates":[{"id":"a","text":"- A roof that leaks\n"},{"id":"b","text":"- Something else\n"}]}' \
| LEARN_CACHE=/srv/app/<instance>/learn-cache /srv/app/<instance>/current/learn rank --ephemeral
Each search that got an answer is one JSON line in the log (target
portal::search): the page, the top card’s framing id, the
confidence, whether the gate acted, the storyline, and which way learn
answered. Never the words.
/api/search_alternatives for a page with no box, or none at all, is
answered 404; arguments it cannot read, 400. Neither shows as a 500.
learn serve
learn serve is learn rank --ephemeral kept running beside the site,
so a search starts no process. The model loads once, at start, and the
Ollama client stays open. It dials the site and serves rank: each
search comes down the open call as a question, a free lane ranks it,
and the answer goes back up, the same request and reply as on learn’s
stdin.
learn serve --dhd <site key>@<address> [--max-in-flight 4] # built with --features serve, as the release is
- learn reads with a key of its own (
LEARN_KEY, elselearn.keyin itsSTATE_DIRECTORY), says it as it starts, and the site names it<learn's key>=rankinDHD_KEYS.PORTAL_DHDmay stand for--dhd. --max-in-flightis how many searches it ranks at once, four by default, the same as the site’s own cap.--model,LEARN_MODEL,LEARN_CACHEandOLLAMA_HOSTmean what they mean forlearn rank. A model that does not load stops it at start, before it answers anyone.- On SIGTERM, as systemd sends on a rollout, it answers what it has
taken and turns the rest away with 421, “this one is going”: the site
then starts
learn rankfor that search, keeps the search box, and does not say learn is gone.
The site asks a learn serving it first, for half of a search’s
deadline at most: a search has three seconds in all, so learn gets
1.5, and the probe five of its ten. With none serving, none in time,
or one going, the site starts learn rank --ephemeral with what is
left, never more, so a hung learn costs a search 1.5 seconds and the
search still ends within its three. An answer of 503 is no decision,
and 400 or 500 a failed search, as exit 2 or 1 is. The probe’s log
line says which way learn answered (over dhd/1 or as a process),
and so does each search’s count (via).
What it saves is the process and the model load per search. With the
shipped model and a stand-in for Ollama, a warm rank took 0.9 ms at
the median and a spawned one 7.2 ms; through a real bge-m3 both took
about 84 ms, nearly all of it Ollama embedding the words.
Rate limiting
Every request that makes portal do something passes a per-caller-IP limit before a session is loaded or a handler is entered: a burst of 100, refilled at ten a second. More than a hundred requests in ten seconds is a script; someone reloading a page again and again stays well inside it.
The files a page is made of, served from portal’s own disk, are not
counted: the stylesheet and scripts under /pkg, the fonts, the
favicons, the vendored libraries. Refusing one of those is what turns
a reloaded page into an unstyled mess, and serving one costs next to
nothing. Anything that makes portal ask someone else is counted: a
content picture under /site/ is fetched from Gitea, a map tile from
the map provider.
PORTAL_RATE_BURST | how many requests at once, default 100 |
PORTAL_RATE_PER_SECOND | requests refilled per second, default 10 |
Either set to 0 turns it off, for an instance behind something that
already does this. The caller is read from X-Forwarded-For or
X-Real-IP, falling back to the socket — all of these instances are
behind Caddy.
The caller is the address the proxy in front of portal saw, not the
one the request claims: X-Forwarded-For counts only when the
connection comes from a loopback or private address (Caddy on the same
host), and then its last entry is the caller, the one Caddy wrote;
Caddy appends to a header that arrives, so the first entry is whatever
the caller sent. From any other peer the connection’s own address is
the caller. PORTAL_TRUST_FORWARDED is private (that), always (a
proxy on another host, on a public address) or never (limit by
connection).
This is a fence, not an accounting system. What keeps uploads honest is the policy check on the route itself.
The ledger
A bucket whose states say ledger: (state machines, “ledger”) writes
each move’s postings on the move’s event, under postings, and keeps
a projection of them in the store’s bucket portal_ledger:
b.<unit>.<account> a balance, t.<unit>.<account>.<transfer> a
statement line under each of its two accounts, r.<bucket>.<record>. <transfer> the same line under its record, and a.<bucket>.<record>. <sequence> the mark that an event’s postings were taken, so an event
seen twice posts once. The log is the truth and the projection is
derived: portal ledger rebuild [--from-scratch], run while the site is
stopped (it opens the site’s store), reads every event of
every bucket with a ledger and applies what is not applied yet, which
is the repair for a projection that fell behind (a write that failed
is said in the log at error with those words). Nothing is deleted or
edited in it; a correction is a posting.
A program with a ledger engine of its own (tally over TigerBeetle, when
a site’s volume wants invariants the projection does not enforce) reads
the events and needs nothing else; the shapes are dhd::ledger.
What a jq filter may cost
A jq: on a resource runs in portal, on a thread of its own, within
a budget: two seconds, twenty thousand values, sixteen megabytes of
output. No honest filter meets any of them; repeat(.) or a range
into the billions does. A filter that yields more values or bytes
than its budget is cut there, and the page shows what it had, with a
warn in the log naming the filter and what it cost. A filter that
runs past its time is stopped between two values where it can be; one
that labours over a single value is given up on, the page gets an
error naming the budget, and the filter is set aside until the next
Load, so a page whose filter never finishes costs one
thread once and not one per visit. The thread it took ends when the
filter does; nothing in Rust stops it sooner.
PORTAL_JQ_BUDGET_MS | how long a filter may run, default 2000 |
PORTAL_JQ_MAX_OUTPUTS | how many values it may yield, default 20000 |
PORTAL_JQ_MAX_BYTES | how much output, default 16777216 |
Lists in memory
A list reads its bucket from memory, not from the store: the first visit reads the bucket once and keeps every record parsed, and from then on each commit that writes the bucket updates what is kept. A page always shows what the store says, and a desk over a few hundred records costs no more to open than one over ten. A bucket nobody looks at costs nothing.
Nothing is configured. A listing that falls behind the store’s
commits forgets what it kept and reads it again on the next visit. An
open page hears which of its lists a commit changed (/live, as
server-sent events) and draws just those again.
Compressed on the way
Nothing portal serves goes over the wire plain when the browser can take it compressed. Two layers:
- Files the release ships. The publish workflow runs
tools/precompress.sh target/siteafter the build, which writes a.br(brotli, quality 11) and a.gz(gzip, 9) beside every wasm, script, stylesheet, SVG and JSON file under the site root. Portal serves the sibling the browser accepts, withContent-EncodingandVary, and the plain file to a browser that accepts neither. The page’s wasm is 2.6 MB plain and 0.7 MB as brotli; nothing is compressed per request. Fonts are woff2 and already compressed. - Everything else, on the way: the HTML of a page, a server function’s answer, the sitemap, a file from a build that has no siblings, compressed as the browser accepts (brotli, zstd or gzip) at a fast level, level 4. A response already encoded, an image, and a body too small to gain are left alone.
Caddy in front of these instances has no encode directive, and needs
none: what it passes through is compressed already.
What a browser may load
Every page carries a Content-Security-Policy:
- Scripts are the site’s own, and inline ones only with the response’s nonce; WebAssembly runs, nothing else that evaluates.
- Styles may be inline, since components write
style=. - Pictures may come from any https host, for a wordmark kept elsewhere. Maps and feature icons come from the site itself.
- Connections go to the site, and to the relays a voice or gesture field names, over https and wss only.
- Nothing is embedded as an object, and no other site frames a page.
Every response also says X-Content-Type-Options: nosniff, a
Referrer-Policy that stops at the origin for other sites, a
Permissions-Policy keeping camera, microphone and position to the
site, and X-Frame-Options: SAMEORIGIN.
The policy as shipped (crates/portal/src/csp.rs):
default-src 'self'; script-src 'self' 'nonce-…' 'wasm-unsafe-eval';
style-src 'self' 'unsafe-inline'; img-src 'self' data: blob: https:;
font-src 'self' data:; connect-src 'self' https: wss:;
media-src 'self' blob: data:; worker-src 'self' blob:; frame-src 'self';
object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'self'
PORTAL_CSP replaces it whole, {nonce} in it filled per response,
for a site that embeds something from a named host or wants less. A
violation shows in the browser’s console as the policy’s words; nothing
is reported back to portal. Every script a page runs is served by the
site: the rich-text editor and its Loro extension are vendored under
/vendor/prosekit/ at pinned versions (tools/vendor-prosekit), as
swiper and maplibre are.
Attachments
A type: file field stores an object key in the record. The file
comes back out at:
GET /attachment/{bucket}/{record}/{field}
which reads the key out of that record rather than taking one from the
caller, so a file can only be fetched through a record somebody is
allowed to see, and a leaked key is a link to nothing. Reading it
needs the same policy permission as reading the bucket on a desk, through
a list that shows the record: its states, and its where. A list on a
[key] page shows every record with something in the field it asks about.
Uploads need a bucket and a key in the Garage on the host:
garage bucket create <site>-attachments
garage key create <site>-portal-uploads
garage bucket allow --read --write <site>-attachments --key <site>-portal-uploads
then GARAGE_S3_ENDPOINT, GARAGE_ACCESS_KEY, GARAGE_SECRET_KEY and
GARAGE_UPLOADS_BUCKET in that instance’s env. Unset, an upload field
fails closed rather than appearing to work and storing nowhere.
The report
GET /report is public and answers with counts only: per bucket, per
storyline, per state. It is what the trainer reads to
compare the storylines on what people did.
The docs site
These pages are portal.uhhm.no: docs/ built
with mdBook (book.toml, docs/SUMMARY.md) by .gitea/workflows/docs.yml
on every push to main that touches them, and put to git-pages the way
every static site on uhhm.no is (uhhm/infrastructure PAGES.md). The
changelog is the book’s last page. mdbook serve previews it locally.
Who deploys what
Both hosts deploy from CI now, and a rollout is the same commit either
way: bump PORTAL_RELEASE in the site’s own content repo.
| runner | how it is allowed to | |
|---|---|---|
| ergo | runs-on: bare | the runner is privileged and writes /srv/app and /etc/app itself |
| kasse | runs-on: fish | the runner is not privileged. It may run one root script, /usr/local/bin/deploy-portal-instance, which checks the instance against a fixed list and the tag against a release-tag shape before touching anything |
The kasse grant is a single sudoers line
(/etc/sudoers.d/30-portal-deploy). It exists so a workflow can pick
which of three known instances gets which published portal tag, and
nothing else.
Both paths health-check the instance afterwards without a forwarded header. A check that sends the header Caddy would send cannot tell you the site is broken for everything that is not Caddy.
A repo’s lint workflow downloads iris from its PORTAL_RELEASE and
runs iris check, so the lint and the site are one version by
construction.