feat(live): show every replica's traffic in the live log view
Draft
SA
2d ago+2232+2232+0123456789012345678901234567890123456789-175-175-012345678901234567890123456789
Description
- The dashboard's live log view now shows traffic from every replica, not only the one the browser is connected to. Before, it showed roughly 1/N of the traffic.
- It adds no database writes of its own. Each audit and usage batch the loggers already write is stamped with the process's writer id and write time. That is two new nullable columns (
writer_id,written_at) onaudit_logsandusage, or two fields on MongoDB, and a partial index onwritten_at. PostgreSQL builds the indexCONCURRENTLYin the background. - While at least one dashboard stream is connected, each replica's live broker reads, every 2 seconds, the rows other writers stamped in the last 10 seconds. It publishes the ones it hasn't published yet. With no subscriber it runs no query. The window is measured on the reader's own clock, and published ids are remembered for that window. That makes every remote entry appear exactly once, even across overlapping polls and batches that become visible late.
- Delay: a remote request appears after its replica flushes it (
LOGGING_FLUSH_INTERVAL/USAGE_FLUSH_INTERVAL, 5s by default, or sooner at 100 buffered entries) plus up to one 2s poll. That is about 7s at most. - Remote events are
audit.flushedandusage.flushed, the persisted, completed entry with status, duration, model, provider, attempts, usage and cost. There are no in-flight,audit.started/updatedor per-chunk stream events. Bodies are left out of the event and load from the database when the entry is expanded. At most 200 audit and 200 usage entries are streamed per poll, newest first. - Local events are unchanged and stay instant. Rows this process wrote are excluded by writer id, so they are never duplicated.
- Dashboard: a live entry that is new to a list is now placed by request timestamp instead of always on top. Late remote rows land below newer local ones, and a late request that is older than its thread head joins the thread's children.
- The single-instance hot path is unchanged. The stamp is one pointer per entry, set once per batch at flush. The perf guard numbers match
main.
Tests: new store tests for RecentWrites / EntriesByID / LogEntriesByID, the schema migration and the stamping, run on SQLite, PostgreSQL and MongoDB. Feed tests cover polling only while subscribed, exactly-once publishing, late-visible batches, the start window, idle and restart, retry, and the per-poll cap. A two-replica test on one store runs on all three backends. Dashboard ordering tests were added. make test-race passed with PostgreSQL and MongoDB, and the perf guard, lint and npm test / npm run check passed.