interplane.Get Omega
Read in your language

aienos.com

Source of www.aienos.com, served from my own hardware

Brought by drakestapleton

branch main Branches Tags History

aienos.com / scripts / allen / README.md

559 lines · 36348 bytes Raw Blame History Source

allen-chat: the public Allen gateway

https://www.aienos.com/allen/ lets anyone talk to Allen, my AI, run small programs in their own browser, find what I have built, propose an issue or a project, and introduce themselves with consent. No model answers there right now: the Qwen3.6-35B-A3B FP8 this gateway was written for (on :18091) was retired on 2026-11-06, and my own model, the Omega LLM, is not deployed yet. MODEL in allen_chat.py is empty, so the gateway names no model; fill it with the served id when a model is deployed. This directory is the server half: one Python process on the Spark (allen_chat.py plus allen_spool.py), its systemd unit, the hub nginx route and the tests. The page half is om/allen-page/ (Omega-generated markup and JS).

browser --TLS--> hub :443 SNI router --PROXY protocol--> hub nginx www.aienos.com (127.0.0.1:4446)
        /allen/api/... --tailnet--> 100.64.0.2:18110 allen-chat (system unit, User=drakestapleton)
        chat      --> 127.0.0.1:18091 (shared model server, streamed, keep-alive)
        omega     --> bwrap { pinned omc (native check, then IR) -> pinned irwasm } -> .wasm to the browser
        submit    --> spool/in/<id>.json          (omega-projects-pusher files it; see below)
        projects/save|publish --> spool/in/<id>.json (the build loop; see "Build loop")
        introduce --> contacts-drop/<hex>.json    (allen-contacts-ingest stores it; see below)

What public Allen cannot do

Public Allen cannot deploy anything: not to this site, not to any repository, not to the hub and not to the Spark. This is enforced by structure, not by the prompt, and each point is tested with a negative control (results in the PR):

  1. Compute only, never deployment. Native function calls are admitted only for math_compute, omega_compile, web_app, paper, research, and plot, with strict schemas, bounded arguments and at most three tool rounds. The gateway forwards them only to a separate allen-science process on loopback. Its inherited listener is its only network access: the science process has an empty network namespace, no credentials, a read-only install, private temporary storage, and bounded compiler/math subprocess sandboxes. Neither process has shell, git, gh, ssh, deployment or arbitrary URL tools. Unknown tool names and malformed calls are refused, never executed as text. Math comes from the pinned pure-Omega aien-math engine, not model arithmetic; unsupported expressions remain unsupported. Engine output is experimental, not proof of correctness. Panes retain its exact expression, result and pin. Research has no live web search. Papers and research are unverified drafts; plots show input data. Browser apps and WASM require explicit visitor Run. Projects stay in browser IndexedDB; optional memory sync sends only a short summary after a separate visitor action, never an anonymous server write. There is no Wolfram integration, account, key or public-use dependency. pane-contract.om versions the SSE pane contract; science_protocol.py validates it on the host. These Python HTTP/JSON adapters are recorded migration dependencies, not represented as Omega implementation.
  2. Sandboxed process. allen-chat.service is a system unit running as drakestapleton (the user manager on this Spark silently skips mount namespacing, so a --user unit would not enforce these): NoNewPrivileges, empty CapabilityBoundingSet, PrivateUsers, ProtectProc=invisible, ProtectSystem=strict, ProtectHome=tmpfs with read-only binds of only its code dir and the pusher's status dir and read-write binds of only the two drop directories, PrivateTmp, PrivateDevices, `RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX AF_NETLINK` (netlink only so bwrap can bring up the sandbox's own loopback), IPAddressDeny=any with `IPAddressAllow=127.0.0.1 100.64.0.1 100.64.0.2 100.64.0.3 100.64.0.4(.1 and .4 are my devices, for the console),LockPersonality, MemoryDenyWriteExecute`, SystemCallFilter=@system-service @mount unshare setns. Measured: it cannot read ~/.ssh, ~/.config/gh, ~/.omp, the vault, the contact store or the gb10 lock (also not through /proc/<pid>/root), cannot sudo, and cannot connect to github.com, the internet or the LAN. The Spark firewall admits port 18110 only from the hub's tailnet address.
  3. Compiling is not running. The Omega path runs only the pinned compiler and translator, inside bwrap with no network, a read-only root containing only the tool, an 8 MiB tmpfs, no /proc, cleared environment, no capabilities, its own pid namespace, RLIMIT_CPU 4 s, RLIMIT_AS 512 MiB, RLIMIT_FSIZE 4 MiB and a 5 s wall clock. Nothing the compiler produces is ever executed on the server; the .wasm runs only in the visitor's browser, without imports. If bwrap is missing or cannot build a sandbox the gateway refuses to start (no bare omc). Nothing is persisted.
  4. Web apps run only in the visitor's <iframe sandbox="allow-scripts"> with a default-src 'none' CSP: opaque origin, no cookies, no storage, no network, no top navigation.
  5. Proposals, not publication. Allen can draft an issue or a project. Only after the visitor confirms the exact text does the gateway drop it into a spool it can write but not act on. A separate unit, omega-projects-pusher (path-activated, the only holder of GitHub write access, scoped in code to aien-dev/omega-projects), re-validates it, removes emails and phone numbers, and files exactly one issue (labels from-allen, area:<repo>), commits a visitor's save to their own branch u/<handle>, or commits a publish to p/<handle>/<project> and opens one pull request to main. It never pushes to main and never merges; the repository's ruleset requires my approval with no bypass. Only my merge publishes anything.
  6. Introductions are private and consented. Nothing is stored unless the visitor (or agent) sends consent: true after the notice. The gateway drops the record for allen-contacts-ingest, which appends it to a store that is not in the gateway's mount namespace, so the gateway, and therefore a prompt-injected Allen, can never read one visitor's details back to another. Deletion: the delete link (#forget=<id>.<token>, the token is only ever stored as a hash) or by email; I read the store with allen-contacts.
  7. Upstream auth ready. The gateway reads ALLEN_UPSTREAM_TOKEN from ~/.config/allen-chat/env of the unit's user (empty today) and sends it as a bearer to 18091, for the sovereign-core #771 cutover.

What protects the shared model

GuardWhereDefault
Public requests in flight upstreamgateway --cap2 of the server's 8 batch slots
Waiting queue, position streamed to the visitorgateway --queue, --queue-wait6 deep, 90 s
Back-off while the server is busygateway --busy-at (reads /health in_flight)no new public start at >= 6
Per-address ratenginx limit_req (chat 6/min burst 4, omega 12/min burst 6, submit/introduce 6/min burst 3) and gateway token buckets (chat burst 4 then one per 20 s; omega burst 6 then one per 10 s; submit and introduce 3 per hour)both
Global submissionsgateway (40 per UTC day) and pusher (40 issues, 20 PRs per day)both
Turn sizegateway24 messages, 4000 chars each, 16000 total, 1024 output tokens
Timeoutsgateway60 s to first token, 20 s between tokens, 150 s per answer
Connections per addressnginx limit_conn4

The system prompt is sent byte-identically on every request so the server's prefix stays the same between turns. The hub keys limits on the PROXY protocol address only inside /allen/api/; $remote_addr stays the loopback for the rest of the site, so the site's own access log is unchanged, and /allen/api/ is not logged at all.

Temporary workaround: the native pre-check

The gateway compiles every Omega unit twice: first in omc's native function mode (output discarded), then in IR mode. This is a workaround for check gaps in the IR mode of the pinned omc 734f0a39 (extra words at the end of a line, names over 8 characters, shadowing are accepted in IR mode, and one unknown-word case lowers a different program). OmegaNext has routed the repros to OmegaMemory; remove the pre-check once that fix merges into omega-mv and the site's omc pin moves past it (link the PR here when it exists). When the pin changes, also recheck the system prompt's "names at most 8 characters" line: omega-mv main has different name-length rules.

Speed test (infer, infer-info, infer-verify; allen_infer.py)

On /aien/ the speed test opens as a glass pane (Speed control, or a #r= link). A run is a plain chat completion: no Aien persona, temperature 0, and a first system line Speed test run <8 hex>. so the engine can never continue a cached row (its log shows reuse 0 tok (cold) for every test request): prefill is always measured from scratch. Modes: single (preset or own prompt, up to 4096 output tokens), parallel (2 to 4 streams, aggregate tokens/s) and a context sweep (separate requests at 512, 1k, 2k, ... up to 4k/8k/16k/32k prompt tokens, 8 output tokens each). The gateway times every chunk as it arrives (TTFT, prefill tok/s = prompt tokens / TTFT, decode tok/s = (tokens - 1) / first-to-last chunk) and stamps each result with host load1 and the server's in_flight. Results carry an HMAC (key derived from ALLEN_VISITOR_SECRET), so a shared #r= link can be checked with infer-verify without storing anything.

Protection, because a prefill on this engine slows every generating row 6-9x (handoffs/AienPage/LATENCY.md): tests together hold at most 4 of the 8 rows and start only while /health in_flight + rows <= 6; heavy tests (parallel, any sweep, prompts over ~4k tokens) run one at a time, start only while no chat turn runs or waits here, and yield the moment one arrives (parallel: streams closed; sweep: stops before the next step; the page shows "yielded to a live chat" with the partial result). Per visitor: one run at a time, 6 runs a minute, 3 heavy runs in 10 minutes. FIFO line of 8 with visible position, 180 s maximum wait; prompts up to 48 KiB (about 32k tokens); hub zone allen_infer 12 r/m. Tests: ALLEN_TEST_ONLY=infer in test_gateway.py.

The same benchmark on any OpenAI-compatible server (same presets, same measure()):

git clone https://github.com/aien-dev/aienos.com && cd aienos.com
python3 scripts/allen/allen_infer.py bench http://127.0.0.1:8000 --model <your-model> [--streams 4] [--sweep 8192]

Math panes (math; allen_math.py)

POST /aien/api/math with {"expression": "Integrate[x^2,{x,0,1}]", "title": "Area"} sends the expression, as the math_compute tool, to the math-only allen-science instance (127.0.0.1:18114, allen-science-math-fg: the same service started with --tools math_compute, which answers 403 to every other tool), which runs the pure-Omega aien-math engine in its sandbox. allen-chat's egress filter admits 18114, not the full-service port 18113. The reply is at most three v1 pane events plus a one-line result; the page renders them with AllenPanes, which checks them again against the pane contract. No model call, nothing stored. Limits: expression 4096 characters, 12 a minute per visitor, hub zone allen_omega. A missing or malformed service answer is a 503. Tests: python3 scripts/allen/test_math.py.

Speed: one warm prefix, cards per turn, answers from a cache

What reaches the model, in order (allen_speed.py): the system text (system prompt + catalog.txt, byte-stable until the catalog changes), the fixed opening for the greeting the visitor saw, the visitor's recalled notes (frozen per conversation), then the visitor's turns. Each user turn carries its own cards (repo detail lines from catalog-detail.jsonl via the catalog's retrieve.py, and lesson cards from --learn-dir), produced by the same pure function of that turn's text on every request, so turn N+1's prompt starts with exactly turn N's prompt and reply and the server reuses that row's history.

The server (qwen36_batch.rs admit()) reuses a row only when the new prompt starts with that row's history or with its snapshot at the last <|im_start|>. The warm thread keeps one snapshot of [system, open line] per greeting variant (at start, after every catalog change, and after each first turn takes it); a first turn on it prefills only the opening and the question. meta says warm when the warm thread last left that snapshot in place and cold when a first turn arrives before the re-warm finished (the server log's join: line is the ground truth; speed/ in the handoff compares the two).

Without the model at all:

Cached and static answers stream in token-sized pieces at --cache-tps and end with the usual done event. Every chat response names its source in the X-Allen-Source header and an event: meta {"source": "static"|"cache"|"warm"|"cold"} before the first token; done repeats it.

Privacy

No prompt, reply, source, address or path is written anywhere: the handler's access log is disabled, nginx has access_log off on these routes, and the rate-limit keys are salted BLAKE2 hashes held in memory. The journal gets one aggregate counter line every ten minutes. Introductions are the only personal data kept, only with consent, as described above.

Every public POST passes a cross-site gate first: a request with an Origin header must come from https://www.aienos.com or https://aienos.com (more with --allow-origin), or it is refused 403; one without Origin but with Sec-Fetch-Site is a browser and refused 403 too; one with neither is a server-side client (the X bot, tests, curl) and is allowed. Then the body must be Content-Type: application/json (415 otherwise), except transcribe, which checks its own audio type. A cross-site "simple" request (text/plain or a form) therefore never runs on a visitor's IP allowance. The hub snippet applies the same rules before proxying.

Reaching me (relay, live takeover, console)

Push-to-talk (POST transcribe)

The page posts one raw clip (no JSON, no base64) with Content-Type audio/webm or audio/ogg (Opus) or audio/wav (16-bit PCM, mono or stereo, 8-48 kHz). Limits: 1 MiB, 15 s of audio (longer clips are refused with 413, never cut), 0.3 s minimum, the chat route's per-address bucket (own bucket; hub zone allen_voice, 6/min burst 4), one transcription at a time (503 busy, Retry-After: 2). Reply: 200 {"text","ms","seconds","model"}; refusals {"error","message"}: 411 length, 413 too_long, 400 empty, 415 format (wrong type, or bytes that do not match it), 422 audio (undecodable, not Opus, not 16-bit PCM, too short), 429 rate, 503 busy.

The body is read into one buffer in memory. WebM/Ogg goes through ffmpeg (forced demuxer, native Opus decoder, pipe: only) in a bwrap sandbox that sees read-only /usr and the loader files and nothing else; the PCM then goes over a pipe to the pinned static whisper-cli in a second sandbox that sees only itself and the pinned model. Both run with RLIMIT_FSIZE 0, so neither can write a file; no audio file exists at any point (test_transcribe.py traces every open with strace and fails on any write outside bwrap's own namespace setup; a mutant that writes the clip to disk is caught). The gateway zeroes its buffers after use; the immutable copy that subprocess returns for ffmpeg's output is dropped by reference. The transcript is returned, never logged. Without --whisper-cli the route is 404; with it, the gateway refuses to start unless whisper-cli and the model match their pins and both sandboxes run. The page detects the route without recording anything: GET presence carries "transcribe": true only when the gateway was started with --whisper-cli (and therefore passed its pin and sandbox checks). Visitors say the name "Aien" like "Ian": unambiguous spellings (Ayen, Een, Aian, ...) become "Aien" anywhere, and "Ian" only when it addresses him (start of the clip, after a greeting, or "..., Ian." at the end). "My friend Ian" is left alone.

Dependencies and the Omega path

Omega has no HTTP, TLS or socket words yet, so this gateway is host code, like crates/hive-feed and hive-receive. Recorded per the AIEN dependency rule:

DependencyVersion on the SparkWhat it does hereOmega replacement
CPython standard library (http.server, http.client, subprocess)3.12.3HTTP/1.1 server, upstream client, SSE relay, sandbox launcherAn Omega gateway once host words for sockets, HTTP and process spawn land; the open host-primitive proposal is aien-dev/omega-mv#788 (bounded TLS HTTP/JSON host primitives). This hop is plain HTTP over the tailnet, so no TLS is needed in Omega for it.
bubblewrap0.9.0Namespace sandbox for omc and irwasmKept as an isolation tool around the compiler; the compiler and translator themselves are seeded Omega.
nginx (hub)1.28.3TLS, PROXY protocol, rate limits, routingExisting edge; unchanged dependency.

The compiler (omc, sha256 734f0a39...6b61) and the IR-to-WebAssembly translator (irwasm, sha256 2d235a70...82e6) are seeded Omega binaries (om/hive-page/); the gateway refuses to start on any other bytes.

Catalog (allen-catalog)

catalog.py writes three files into /var/lib/allen-catalog/:

Sources, all unauthenticated, so a private repository cannot appear:

Output is ASCII and LF, sorted, with no clock time. The Sources: line records the aienos.com head and a digest of every input (full head shas, README digests, seo.rs digest), so the file changes only when an input changes. Text containing we, our or us is cut before that clause. A failed fetch exits 1 and the old files stay. Files are written through temporaries and renamed. Unchanged output is not rewritten, so the gateway's mtime stays put and the opening snapshot stays warm.

Units (system units; allen-catalog is a system user with no home and no credential):

Install:

sudo install -d -o root -g root -m 0755 /opt/allen-catalog
sudo install -o root -g root -m 0644 catalog.py retrieve.py /opt/allen-catalog/
sudo install -d -o allen-catalog -g allen-catalog -m 0755 /var/lib/allen-catalog
sudo install -m 0644 allen-catalog.service allen-catalog.timer /etc/systemd/system/
sudo systemctl daemon-reload && sudo systemctl enable --now allen-catalog.timer
sudo systemctl start allen-catalog.service

The gateway reads `--catalog /var/lib/allen-catalog/catalog.txt --areas-file /var/lib/allen-catalog/areas.txt` through a read-only bind.

Deploy (Spark)

D=$HOME/.local/lib/aienos-allen-chat
S=$HOME/.local/state/allen-chat
install -d -m 700 "$D" "$S/spool/in" "$S/spool/status" "$S/contacts-drop" ~/.config/allen-chat
install -m 644 scripts/allen/allen_chat.py scripts/allen/allen_spool.py scripts/allen/system-prompt.txt "$D"/
install -m 755 om/hive-page/omc om/hive-page/irwasm "$D"/
printf 'ALLEN_UPSTREAM_TOKEN=\n' > ~/.config/allen-chat/env && chmod 600 ~/.config/allen-chat/env
sudo install -m 644 scripts/allen/allen-chat.service /etc/systemd/system/
sudo systemctl daemon-reload && sudo systemctl enable --now allen-chat.service
# firewall: admit the hub only (persisted in /etc/nftables.conf)
sudo nft add rule inet atlas_ingress input iifname '"tailscale0"' ip saddr 100.64.0.3 tcp dport 18110 accept

Rollback: sudo systemctl disable --now allen-chat.service, delete the 18110 rule (sudo nft -a list chain inet atlas_ingress input, then delete rule ... handle N) and restore /etc/nftables.conf from its .bak-allenchat-* copy. Nothing else on the Spark changes.

Deploy (hub nginx)

Files: nginx-allen-zones.conf -> /etc/nginx/conf.d/aienos-allen.conf, nginx-allen-location.conf -> /etc/nginx/snippets/aienos-allen.conf (included in the www.aienos.com server), a second listener listen 127.0.0.1:4446 ssl proxy_protocol; in that server, and in /etc/nginx/stream.d/sni-router.conf: proxy_protocol on; on the :443 server, aienos_web -> 4446, and two strip shims (`listen 127.0.0.1:4453 proxy_protocol; proxy_protocol off; proxy_pass 127.0.0.1:4443;` and the same 4454 -> 4444) so headscale and interplane still receive plain TLS from 127.0.0.1. Applied in two reloads (listeners first, then the switch). Backup and rollback: /root/allenchat-backup-<UTC> holds stream.d, sites-*, snippets and conf.d as they were; copy them back, nginx -t, reload.

Deploy the A2A introduction endpoint

POST /aien/api/a2a is A2A protocol 1.0 JSON-RPC. Nginx rewrites it to /allen/api/a2a. The only method is SendMessage. The older name message/send is the same call. The gateway passes that message to the introduce door. Consent and storage are that door's: consent must be the JSON boolean true, the response is Cache-Control: no-store, and the JSON-RPC envelope is not written. A consented introduction is the only record, in the same write-only drop as POST /aien/api/introduce.

These methods are not supported. Each one is a JSON-RPC error and stores nothing:

Older slash names of those same methods return the same codes. scripts/allen/a2a.py lists them.

A missing or empty A2A-Version is version 0.3. Spec section 3.6.2 says an empty value is 0.3, and section 3.6.1 assumes 0.3 for an empty header. This door implements 1.0 only, so that request returns -32009 and stores nothing. Send A2A-Version: 1.0. When the header is absent, the query parameter A2A-Version is read instead.

Rate-limit and daily-cap refusals stay JSON-RPC -32603. Spec section 3.3.2 lists "rate limit exceeded" as an example of that code. The A2A table from -32001 to -32009 has no rate-limit code.

The location is location = /allen/api/a2a in nginx-allen-location.conf. $allen_notjson allows only application/json, so this location uses $allen_a2a_notjson, which also allows application/a2a+json. On the hub, after that file is installed as /etc/nginx/snippets/aienos-allen.conf:

sudo nginx -t

Then reload:

sudo systemctl reload nginx

Then check the response. This asks for GetTask, which is not supported, and it does not send consent:

curl -sS -D - -o /tmp/a2a-check.json -X POST https://www.aienos.com/aien/api/a2a \
  -H 'Content-Type: application/json' \
  -H 'A2A-Version: 1.0' \
  --data '{"jsonrpc":"2.0","id":"deploy-check","method":"GetTask","params":{}}'

Expect HTTP 200, a Cache-Control: no-store header, and a JSON body whose error code is -32004. Nothing is stored. Do not send a consented SendMessage as the deploy check.

The same call with Content-Type: application/a2a+json must not be 415. $allen_notjson would refuse that media type. This location does not use it:

curl -sS -D - -o /tmp/a2a-ctype.json -X POST https://www.aienos.com/aien/api/a2a \
  -H 'Content-Type: application/a2a+json' \
  -H 'A2A-Version: 1.0' \
  --data '{"jsonrpc":"2.0","id":"ctype-check","method":"GetTask","params":{}}'

Expect HTTP 200, not 415, Cache-Control: no-store, and error code -32004.

The same call with no A2A-Version header is version 0.3 and returns -32009:

curl -sS -D - -o /tmp/a2a-version.json -X POST https://www.aienos.com/aien/api/a2a \
  -H 'Content-Type: application/json' \
  --data '{"jsonrpc":"2.0","id":"version-check","method":"GetTask","params":{}}'

Rollback: restore the previous snippet, run nginx -t, then reload.

After the greeting Allen asks what the visitor would like to build for humanity and builds it with them; the result can be downloaded freely, saved to their home or published. Rules live in allen_build.py (shared with the pusher), routes in allen_projects.py:

Tests

python3 scripts/allen/test_sandbox.py              # compile sandbox escape tests, each with a control
python3 scripts/allen/test_a2a.py                 # A2A SendMessage: consent, errors, nothing stored
python3 scripts/allen/test_gateway.py --omc om/hive-page/omc --irwasm om/hive-page/irwasm \
    --system-prompt scripts/allen/system-prompt.txt [--skip-model --upstream 127.0.0.1:<closed port>]
    # cookie/edge suites: console cookie flags, nginx copies' guards; NGINX=/path/to/nginx adds nginx -t
PROBE_HOME=$HOME python3 scripts/allen/probe.py   # outside; inside the unit's properties: systemd-run ... -E PROBE_HOME=$HOME
python3 scripts/allen/relay/test_relay_mailer.py      # relay mailer against a loopback SMTP stub, each with a control
python3 scripts/allen/test_reaching_drake_prod.py  # production: console reachability, one real TEST relay email, live takeover
python3 scripts/allen/test_transcribe.py --omc om/hive-page/omc --irwasm om/hive-page/irwasm \
    --system-prompt scripts/allen/system-prompt.txt --whisper-cli /opt/allen-chat/whisper-cli \
    --whisper-model /opt/allen-chat/ggml-base.en.bin --sample jfk.wav  # push-to-talk: formats, caps, 429/503, no file, latency
python3 scripts/allen/test_build_loop.py --omc om/hive-page/omc --irwasm om/hive-page/irwasm \
    --system-prompt scripts/allen/system-prompt.txt --pusher-dir scripts/allen/pusher  # homes, ownership, saves, publish, console, gallery (GitHub stub)
python3 scripts/allen/pusher/test_pusher.py        # pusher against the stub; LIVE=1 adds live repository settings
python3 scripts/allen/e2e_calculator.py ... --calc calc.om --out DIR  # real omega-projects, test-labelled (needs the vault token)

test_gateway.py starts throwaway loopback gateways (never the production unit): input caps, Omega refusals (including the native pre-check), per-address 429 with a control address, first-token and mid-stream timeouts against a stalling stub, health back-off, submit validation (project items refused, binary and secret-shaped text; valid control; dedupe; status URL filtering), the introduce consent gate and drop format, the output cap, and a 10-client load test that records the peak of concurrent streams, queue positions and the shared server's /health throughout. dev_proxy.py serves a built site and forwards /allen/api/ to a local gateway for browser tests; it is never deployed.