thermograph/backend/daemon
Emi Griffith ce4350c64e
All checks were successful
PR build (required check) / build-frontend (pull_request) Has been skipped
PR build (required check) / validate-observability (pull_request) Has been skipped
secrets-guard / encrypted (pull_request) Successful in 6s
PR build (required check) / changes (pull_request) Successful in 9s
shell-lint / shellcheck (pull_request) Successful in 6s
PR build (required check) / build-backend (pull_request) Successful in 1m10s
PR build (required check) / gate (pull_request) Successful in 2s
daemon: let the conversational agent own @mentions in server channels
THERMOGRAPH_DISCORD_BOT_MENTIONS=0 makes the gateway bot silent on guild
mentions. Default on, and unset counts as on, so every env file that predates
the knob behaves exactly as before.

The reason is a second responder. The operator's desktop now runs a
conversational agent that replies as this same bot account (discord-voice-bot,
AGENTS.md) and grades through the same API we do, so with both live a single
"@Thermograph Phoenix" gets answered twice — once as a card, once as a reply.
Only one of us can own that surface, and the agent is the one that can also hold
a conversation.

Scoped to guild mentions on purpose. DMs stay here: the agent polls guild
channels only, so staying silent in a DM would just drop the message. And
/grade is a signed HTTP interaction that never touched this path, so it keeps
answering from prod while the desktop is asleep — which is what stops this from
trading an always-on surface for a sometimes-on one.

Claude-Session: https://claude.ai/code/session_015Z1ebLbhUxeZ9ozpNrVTCP
2026-07-24 13:24:21 -07:00
..
internal daemon: let the conversational agent own @mentions in server channels 2026-07-24 13:24:21 -07:00
go.mod daemon: move the Discord gateway and scheduler out of the web process into Go (#21) 2026-07-23 22:49:54 +00:00
go.sum daemon: move the Discord gateway and scheduler out of the web process into Go (#21) 2026-07-23 22:49:54 +00:00
main.go daemon: move the Discord gateway and scheduler out of the web process into Go (#21) 2026-07-23 22:49:54 +00:00
README.md daemon: move the Discord gateway and scheduler out of the web process into Go (#21) 2026-07-23 22:49:54 +00:00

thermograph-daemon

Single Go binary that owns the backend's long-lived stateful I/O: the Discord gateway connection (IDENTIFY/RESUME/heartbeat/reconnect backoff) and the recurring-job timers (warm-cities, IndexNow). It replaces the two in-process background jobs web/app.py used to run under leader election — one daemon replica makes the single-connection invariant a deployment fact instead of a runtime election.

The Go/Python split

Go here owns no climate or grading logic. Grading depends on polars and the parquet cache, and the slash-command path deliberately shares one grade builder with the API so bot grades and API grades never drift. So anything data-shaped is a POST back into the Python app's internal-only routes:

Route Purpose
POST /internal/discord/grade {"query": "phoenix"} → gateway-ready Discord message JSON, relayed to Discord verbatim
POST /internal/jobs/warm-cities trigger the warm-cities job
POST /internal/jobs/indexnow trigger the IndexNow check-and-submit

Every request carries X-Thermograph-Internal-Token. Caddy never routes /internal/* to the backend, so the token is defence in depth, not the only control. If THERMOGRAPH_INTERNAL_TOKEN is unset, the Python side disables the routes and this daemon refuses to start (fail closed on both ends).

Configuration (env)

Var Required Meaning
THERMOGRAPH_INTERNAL_TOKEN yes shared secret for the internal routes
THERMOGRAPH_API_BASE_INTERNAL yes backend base URL, e.g. http://web:8137
THERMOGRAPH_DISCORD_BOT no 1/true/yes/on enables the gateway
THERMOGRAPH_DISCORD_BOT_TOKEN no bot token (gateway stays off without it)
THERMOGRAPH_WARM_CITIES_INTERVAL_HOURS no default 24; malformed → default
THERMOGRAPH_INDEXNOW_INTERVAL_HOURS no default 6; malformed → default

Run locally

cd backend/daemon
go build ./... && go vet ./... && go test ./...

THERMOGRAPH_INTERNAL_TOKEN=dev-token \
THERMOGRAPH_API_BASE_INTERNAL=http://localhost:8137 \
go run .

Deployed as /usr/local/bin/thermograph-daemon in the backend image.