chadtmiller.com/group-host
atmosphere group host
The host keeps its logs and counts its use, for its operators
MergedThis pull keeps the host's stdout JSON lines in logs.sqlite and counts requests and MCP tools by day in stats.sqlite. It gives each request a trace and an x-trace-id header, and adds the operator-only getLogs and getStats with the admin logs and admin stats commands. The design is sound and the docs and tests cover it well. I found two defects that review alone would catch. I did not run the code or check the runner, only read the diff.
- The request method is stored as received, so the stats table can grow without bound. Anyone can send arbitrary extension methods, and each new one makes a new
(day, route, method, class)key. Those keys are held in memory and written tostats.sqlitefor 400 days, which breaks the claim that routes are bounded by pattern. Fold any method outside the standard set into one value such asOTHER. reportcan panic. The request and tool queries selectday >= firstwith no upper bound, butby_dayholds only days up to today. If the clock has ever been set back, or a count from a future day is on disk,get_mut(&day).expect("a day asked for")panics inside the handler. The spaces and accounts loop already clamps with.min(now). Bound those queries by the last day, or skip days not inby_day.
Minor: a caller can send any valid traceparent, so a client can reuse another request's trace id and mix its lines into that trace when an operator reads it. That may be acceptable, but the docs could say so.
crates/group-host/src/observe.rsline 50Outdated
These lines can no longer be read.
req.method() goes into the stats key as sent. Arbitrary extension methods each add a distinct key that is kept 400 days. Map anything but the standard methods to one bucket.
crates/group-host/src/stats.rsline 193Outdated
These lines can no longer be read.
This expect panics for a row whose day is after today (clock set back). The query has day >= ?1 but no upper bound, and the same applies to the tool query at line 205. Bound the queries or skip days not in by_day.
I read stats.rs and observe.rs at the new head. Neither defect from my first round is fixed. The rest of the design still looks sound. I did not run the code.
- The method is still stored as received.
observe.rs:50takesreq.method().to_string()and passes it tostats.served. A client can send arbitrary extension methods, and each one adds a(day, route, method, class)key. Those keys are kept in memory and instats.sqlitefor 400 days. Fold any method outside the standard set (GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS) into one value such asOTHER. reportcan still panic. The request and tool queries selectday >= firstwith no upper bound, butby_daystops at today. A future-dated row makesget_mut(&day).expect("a day asked for")panic in the handler. That can happen if the clock was ever set back, and the spaces and accounts loop already guards against it with.min(now). AddAND day <= ?2with the last day to both queries, or skip days not inby_day. A test with a future-dated row would cover it.
The minor point about traceparent is also not addressed: a client can reuse another request's trace id, which mixes lines into that trace. This is acceptable, but say so in the docs.
crates/group-host/src/observe.rsline 50Outdated
These lines can no longer be read.
The method is stored as received, so unbounded extension methods become unbounded stats keys. Fold non-standard methods into OTHER.
crates/group-host/src/stats.rsline 194Outdated
These lines can no longer be read.
This expect panics for a row dated after today, since the query has no upper bound. Bound the query or skip days missing from by_day. The tool loop at line 206 has the same problem.
I read stats.rs and observe.rs at the new head. Neither defect from my last two rounds is fixed. I did not run the code.
- The request method is still stored as received.
observe.rs:50is stillreq.method().to_string(). A client can send arbitrary extension methods, and each one adds a(day, route, method, class)key. Those keys are kept in memory and instats.sqlitefor 400 days. Fold any method outside GET, POST, PUT, DELETE, PATCH, HEAD and OPTIONS into one value such asOTHER. reportcan still panic. The request and tool queries instats.rs(around lines 183–208) still selectday >= ?1with no upper bound.by_dayends at today, so a future-dated row makesget_mut(&day).expect("a day asked for")panic in the handler. A clock that was ever set back can leave such a row. The accounts and spaces loop already guards against this with.min(now). AddAND day <= ?2with the last day to both queries, or skip days not inby_day. A test with a future-dated row would cover it.
The traceparent point is minor and still open: a client can reuse another request's trace id and mix its lines into that trace. Say so in the docs.
crates/group-host/src/observe.rsline 50Outdated
These lines can no longer be read.
Fold methods outside the standard set into OTHER. As written, unbounded client-chosen values become stats keys.
crates/group-host/src/stats.rsline 195Outdated
These lines can no longer be read.
No upper bound on day, and the expect below panics for a day past today. Bound the query by the last day, or skip days not in by_day. The tool query has the same problem.
Both defects from my earlier rounds are fixed at this head. I read observe.rs and stats.rs. I did not run the code or check the runner.
- Method folding.
method_ofinobserve.rskeeps GET, POST, PUT, DELETE, PATCH, HEAD and OPTIONS and counts every other method asOTHER. The stats key space is now bounded. reportpanic. The request and tool queries now haveday <= ?2withlast = day_of(now). The accounts and spaces loop clamps with.min(now). A future-dated row can no longer hitexpect("a day asked for").traceparent. Theobserve.rsmodule doc now says a caller can name another caller's trace and have its lines read with them.
I'm approving the pull. I did not check whether a test covers a future-dated row.
The only change since my approval at 6ffb067 is in tests/admin.rs. The BREW/WHEN requests now go to getGroup instead of the health route. The test now asserts the OTHER bucket is on that route and that the health route is not counted. This fixes a test that was muddled by health checks being uncounted, and no production code changed. My earlier approval stands: method folding, the bounded report queries and the traceparent note are all in place. I read only this diff and did not run the code.
What changes
The host keeps what it logs, for its operators. Every JSON line it writes to stdout is also kept in
logs.sqlitein its data directory, written a second at a time off the requests' way: the lastLOGS_KEEP(500,000) at info and below, warnings and errors all, and nothing past 30 days. A line is kept even when nothing reads stdout any more.Each request has a trace and a line. A request is answered in a trace of its own, or the one a W3C
traceparentnames, and its answer carries it asx-trace-id; every line logged while answering it carries it too. When answered, it logsrequestwith its method, route, path (never its query), status andduration_ms. The health checks are logged at debug and not counted. An MCP tool call logsmcp toolwith its name and whether it worked.The host counts how it is used. In
stats.sqlite, by the day (UTC): requests by route pattern, method and status class, how long they took and how many were slow (a second or more, the firehose's stream never); MCP tools by name and whether they worked. Nothing counted names who asked. Kept 400 days.Its operators read both.
HOST_ADMINSnames them, by DID.fyi.opensocial.getLogsanswers the lines by trace, message, level, duration and limit;fyi.opensocial.getStatsthe lastdays(7 by default), with what the host holds (groups, those switched off, spaces, bytes of files) and the groups and spaces made each day. Anyone else is refusedForbidden. The commands areopensocial admin logsandopensocial admin stats.No MCP tool for them. An MCP client acts in one group, and these read the whole host, every group's requests in it, so they join the commands with no tool (AGENTS.md, the CLI and MCP references).
A group moved here is made at a time in seconds.
account.created_atwas kept in milliseconds for an account moved or imported here and in seconds otherwise; a migration brings the first to seconds, so each counts on the day it was made.Why
To see what a running host is doing, and how it is used, without a shell on its machine: an operator reads one request's lines by the trace its answer gave them, or the warnings of the last hour, or a month of counts, from anywhere, signed in as themselves. The logs and counts are kept in files of their own beside the database, so their writes never wait on the groups' own.
How it was checked
logs.rsandstats.rsunit tests: keeping, reading by each filter, letting go past keeping, a failed write held for the next, the tee to the sink, counting by day, route and tool, old days dropped, the migration's moved group counted on its day.tests/admin.rs: only operators read either (401 without auth, 403 for anyone else); one request's lines by trace; the lexicon refusing a limit past 500; a request counted by its route, an unmatched one as(unmatched), the health checks not;traceparenthonoured; the groups and spaces held and made; the writing loop flushing and pruning.tests/serve.rs: the built binary, logging at info, keeps therequestline in the trace its answer named,servingandstopped, and its counts, as it stops on SIGTERM.tests/mcp.rs: tool calls counted, failed whether refused in planning or by the host.opensocialtests/commands.rs:admin logsandadmin statsas an operator, refused for anyone else, an unknown flag and a stray word.just lex,just docslocally; the coverage gate is the runner's.Shortcomings
admin statsprints lines, not JSON; the method answers JSON for a script.🤖 Generated with Claude Code