tickets
All repositories: gitoria
4.5 KB
# Tickets wake bridgeThis service listens on **127.0.0.1 only**. It holds HyperConductor tokens; tickets holds only the shared signing secret and this service's `/wake` URL. It accepts exactly `{subscription, at, delivery}` and verifies `X-WorldAPI-Signature-256: sha256=<HMAC-SHA256 of raw UTF-8 body>` with constant-time comparison. It calls HC `/api/wake` or the configured chat's `/messages`, returning 204 only after success. Successful delivery IDs and body hashes are retained in SQLite across restarts. Unknown subscriptions fail closed. Redirects are refused. No request, secret or token is logged.Python 3 stdlib is used: the Hybriel docs provide HTTP, fetch and HMAC primitives but no documented constant-time comparison for general signatures. Password verification is not a signature comparator. No extra dependencies are needed.Example `/etc/tickets-waker/config.json` (subscription IDs come from tickets):```json{"instances": {"loreana": {"url": "http://127.0.0.1:45010", "tokenFile": "/etc/tickets-waker/loreana.token"}},"subscriptions": {"SUBSCRIPTION_ID": {"instance": "loreana", "wakeProject": "jukebox", "agent": "Jukebox"},"APOLLO_SUBSCRIPTION_ID": {"instance": "loreana", "chat": "CHAT_ID", "agent": "Apollo"}}}```Each mapping needs exactly one of `wakeProject` or `chat`. Instance URLs are private operator configuration. To reach another host, use an operator-managed private route or SSH tunnel. Restart after config changes. Removed subscription mappings must be removed here too.## Install (Apollo on byrodin; not performed by this build)1. Install Python 3 and copy `waker.py` to `/opt/tickets-waker/waker.py`. Create `/etc/tickets-waker` mode 0700 and `/var/lib/tickets-waker` mode 0700, owned by root. Create the config above mode 0600.2. Apollo writes HC tokens himself to the configured token files, owned by root, mode 0600. Never put them in tickets, tickets `.env`, git, logs or wake bodies.3. Create `/etc/tickets-waker/env` mode 0600 containing `TICKETS_WAKER_SECRET=<a random secret shared with tickets>`. The systemd EnvironmentFile supplies this variable; the script does not parse dotenv files.4. Install `/etc/systemd/system/tickets-waker.service`:```ini[Unit]Description=Tickets private wake bridgeAfter=network.target[Service]Type=simpleUser=rootEnvironmentFile=/etc/tickets-waker/envExecStart=/usr/bin/python3 /opt/tickets-waker/waker.py --port 8750 --config /etc/tickets-waker/config.json --state /var/lib/tickets-waker/deliveries.dbRestart=on-failureUMask=0077NoNewPrivileges=trueProtectSystem=strictProtectHome=trueReadWritePaths=/var/lib/tickets-waker[Install]WantedBy=multi-user.target```5. `systemctl daemon-reload` and `systemctl enable --now tickets-waker`. Put `TICKETS_WAKER_URL=http://127.0.0.1:8750/wake` and the same secret in tickets' live `.env` only after conductor review. Tickets' host networking reaches loopback. Port 8750 is an example; reserve the actual production port first.6. Create subscriptions, install mappings, and perform the mission's live proof in push-test. Retire Apollo's old polling/SSE subscriber only after successful live proof. Never deploy this worker's local test configuration.## Delivery and standby semanticsTickets main is the sole dispatcher. `docker-compose.yml` sets `TICKETS_WAKES_DISABLED=1` on standby. Standby still writes stream rows; main reconciles them every second or at startup after takeover. Do not run two enabled main dispatchers against the same store. Retries and restart resend the identical delivery/body, and this service serializes incoming requests and durably suppresses successful repeats. An accepted HC call followed by a waker crash before the SQLite commit can repeat the HC message: HC exposes no idempotency key, so exactly-once delivery across that crash is not promised. Main/standby startup alone does not create a second delivery ID for a pending episode.Tickets uses a 10-second timeout, with retries after 1, 5, 30 and 120 minutes, then `wakeStatus: failed` in GET subscriptions. A later tickets restart retries pending undelivered changes. Fetching the delta clears pending; peek does not. HTTP success means HC accepted the message, not that a model read the delta. Delivery IDs remain in SQLite; back it up with the config. Purging the table permits old signed delivery replays.## Test`python3 tools/waker/test_waker.py` uses fake HC on 127.0.0.1:8751 and the bridge on 8750. It checks missing/wrong signatures, wake and direct-chat shapes, repeated delivery suppression, restart persistence and HC failure retries. It holds no real tokens.
Branches
Latest commits
- 8d8e2053Document subscription contract and exercise delta deliverymre
- fd23726aAdd subscription delta API and signed wake bridgemre
- c5d28fb5Tickets conductor: S51 startedmre
- fd6ca1e6Tickets conductor: brief 027 waker design, push-test projectmre
- e448e656Tickets conductor: STATUS #51mre
- 1c10857bTickets conductor: P51 eval, brief 027mre
- e725969dTickets conductor: #51 directionmre
- 1b5c63ddTickets conductor: P51 startedmre
- 9f13fbdaTickets conductor: brief 026 prioritymre
- acc477d9Tickets conductor: brief 026 + Vinzenz recommendationsmre
- 9233a734Tickets conductor: brief 026 completemre
- 5da589fdTickets conductor: brief 026 + Gitoria's answermre
- a3cd5329Tickets conductor: tickets#51 opened, brief 026 draftmre
- 6f6e5797Tickets conductor: STATUS wordingmre
- 957de51fTickets conductor: T36 live, #36 review, #50 donemre
- bc2fde32Merge branch 'main' into t36-stylemre
- b7ca093atests: wait for the new row and normalize editor marker spacesmre
- 41da3525Tickets conductor: flake cause, T36 deploy stepmre
- 64c477e6Tickets conductor: deploy waits for Arachnemre
- 467d7286Tickets conductor: T36 done, deploy questionmre