Title: Event store: one table for every statistic, from any source · Issue #1850 · developing-today/code · GitHub
Open Graph Title: Event store: one table for every statistic, from any source · Issue #1850 · developing-today/code
X Title: Event store: one table for every statistic, from any source · Issue #1850 · developing-today/code
Description: Relocated from dezren39/darwin-nix#6 on 2026-10-28 (placement audit): mcpx's single source lives in developing-today/code (pkgs/mcpx); re-home tracked at #309. Original body below; issue references inside it are historical (dezren39/nix ...
Open Graph Description: Relocated from dezren39/darwin-nix#6 on 2026-10-28 (placement audit): mcpx's single source lives in developing-today/code (pkgs/mcpx); re-home tracked at #309. Original body below; issue references...
X Description: Relocated from dezren39/darwin-nix#6 on 2026-10-28 (placement audit): mcpx's single source lives in developing-today/code (pkgs/mcpx); re-home tracked at #309. Original body below; issue refere...
Opengraph URL: https://github.com/developing-today/code/issues/1850
X: @github
Domain: github.com
IPv4 address: 140.82.112.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Event store: one table for every statistic, from any source","articleBody":"Relocated from dezren39/nix#6 on 2026-10-28 (placement audit): mcpx's single source lives in developing-today/code (pkgs/mcpx); re-home tracked at #309. Original body below; issue references inside it are historical (dezren39/nix numbering).\n\nParent: #181\n\n## Idea\n\nRecord everything mcpx and its harness learn as events in one table, so that\nany statistic is a query rather than a new code path.\n\nToday `mcpx stats` has seven dimensions and `mcpx stats --opencode` has six,\neach a hand-written query against a differently-shaped source. Adding a source\n— a REST API, a hosted mcpx, a second harness — means writing that set again.\n\n## Shape\n\n```sql\nCREATE TABLE event (\n id INTEGER PRIMARY KEY,\n ts_unix_ms INTEGER NOT NULL,\n kind_id INTEGER NOT NULL REFERENCES kind(id),\n idset_id INTEGER REFERENCES idset(id), -- who/what this concerns\n source TEXT NOT NULL, -- mcpx, opencode, rest, tui\n value REAL, -- the number, when there is one\n data TEXT -- the rest, as JSON\n);\n```\n\n### Identifier sets\n\nThe repeated shape is \"this event concerns session X, whose parent is Y, in\nworktree Z\". Those combinations recur constantly, so interning them is both a\nlarge space saving and what makes `GROUP BY idset_id` mean something.\n\n```sql\nCREATE TABLE idset (id INTEGER PRIMARY KEY, fingerprint TEXT UNIQUE);\nCREATE TABLE idset_member (idset_id INTEGER, key TEXT, value TEXT,\n PRIMARY KEY (idset_id, key, value));\n```\n\n`MCPX_TRACE_IDS` already carries exactly this, as pairs, with variadic entries\nfor aliases. The set is the natural landing place for it.\n\n### Kinds\n\nA kind is a declared event type, so a writer cannot invent a field shape and a\nreader cannot guess one.\n\n```sql\nCREATE TABLE kind (\n id INTEGER PRIMARY KEY,\n name TEXT UNIQUE, -- mcp.call, harness.tool, session.start\n unit TEXT, -- ms, tokens, usd, count\n schema TEXT -- JSON Schema for `data`\n);\n```\n\n## Open questions\n\n- **Is the schema table worth it?** The variadic/required/optional machinery\n sketched in the original note is a type system. It may be more than this\n needs; JSON Schema on `data` gets most of the value for none of the design.\n- **Retention.** Events are smaller than log lines but there are more of them.\n Probably the same age-and-count rotation, but per kind.\n- **Does it replace `records`, or sit beside it?** Beside, initially. The log\n index answers \"what happened\"; the event store answers \"how much, over\n time\". Merging them means one of the two questions gets a worse answer.\n\n## Gap semantics (owns #181 collision 13)\n\n**Owns #181 collision 13:** what a consumer of a bounded event history is told when it misses events. The\nlive bus (`internal/events`) has this problem today and the store will inherit it; #81's hooks consume\nwhatever is decided here rather than inventing their own.\n\nWhat exists at 05c78b2:\n\n| way to miss events | what happens | where |\n| --- | --- | --- |\n| reconnect with a `since` older than the retained history | `gap=true`; `/v1/events` sends `event: gap` with `{since, latest}` in-band | `internal/events/events.go:185-187`, `internal/daemon/server.go:838-842` |\n| a live subscriber that is not reading | its 256-slot channel fills, the event is dropped and `Dropped` is incremented -- **nothing outside `internal/events` reads `Dropped`**, so the gap is silent | `events.go:177`, `:224-231`, `:144-147` |\n| a replay longer than the channel | `SubscribeFrom` replays under the bus lock into the same 256-slot channel before anyone drains it, so `?since=0` (or a `Last-Event-ID` more than 256 matching events back) keeps the oldest 256, **silently drops the rest**, then continues live | `events.go:176-199`; history is `events.history`, default 1024 (`internal/defaults/defaults.json:52`, declared at `internal/settings/wire.go:225`, wired at `server.go:165`) |\n\nThe third row is a defect in shipped code, not only a design question: `docs/story.md:2203-2214`\n(\"Lossless reconnection\": \"`?since=0` replays everything retained\") and the `New` comment\n(`events.go:124-129`, \"lets a reconnecting subscriber miss nothing\") promise a reconnecting subscriber\nmisses nothing or is told so, and past 256 matching events it is neither. Found in the 2026-09-30 issues pass, not reproduced by running it.\n\n**A -- raise the limits.** Bigger history, bigger channel. Cheap, and it moves the cliff rather than\nremoving it; memory grows with every subscriber and a hook pool that saturates still loses events silently.\n\n**B -- back-pressure.** Let a hook subscriber block the publisher. Nothing is lost, and one slow hook stalls\nevery tool call, which is exactly what `Publish`'s \"never blocks\" rule (`events.go:203-206`) exists to\nprevent. Not for a bus that sits on the call path.\n\n**C -- recommended: one gap contract, three triggers.** Every consumer has a `seq` watermark. Whenever\ndelivery skips -- reconnect past history, live overflow, replay truncation -- the consumer receives the same\nexplicit marker the SSE path already sends for the first case (`gap {since, latest}`), and `Dropped` is\nreported (in the marker and per subscription in `/v1/status`). A consumer that sees a gap resynchronises\nfrom state instead of trusting the stream. Replay should drain history in order without the fixed-size\nchannel (or mark the truncation). For #81, a hook whose worker queue overflows is a consumer with a gap and\nis told so the same way; \"replay hooks over history\" then works from the watermark. Recommended because it\nis the only option where a consumer can always tell a complete stream from an incomplete one, and it reuses\na marker that already ships.\n\n## Why it is filed rather than built\n\nThe value is entirely in having several sources to query uniformly, and there\nare currently two. Building the general mechanism now means designing against\nimagined sources, which is how a schema acquires fields nothing fills. Worth\ndoing when the third source exists and its shape is known.\n\nThe gap contract above is the exception: it is small, #81 depends on it, and one of its three cases is a\nlive defect, so it should not wait for the third source.\n\n## Ease · Impact · Related\n\n**Ease** S for the gap contract (collision 13); M-L for the store. **Impact** med-high for the gap contract\n(every `/v1/events` consumer and every #81 hook depends on it); med for the store until a third source exists.\n\nRelated: #193 (the live bus already loses replayed events past 256 without a gap marker -- the first consumer of the gap contract), #81 (hooks consume the gap contract; the store is their history), #87 (expiry events belong here),\n#86 (a browser `EventSource` is a reconnecting subscriber), #85 (a remote TUI lives on `/v1/events`).\n\nSecurity/auth deferred; see tracker.\n\n","author":{"url":"https://github.com/dezren39","@type":"Person","name":"dezren39"},"datePublished":"2026-10-28T22:03:03Z","url":"https://github.com/developing-today/code/issues/1850"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:0f92f997-471c-4c99-78bd-ecf9223ad7cd |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EA00:B0F20:6EA7E4:94678F:6B062D98 |
| html-safe-nonce | 0e3889656b661205a9e7d9a697f4c45b5fd42dee418811cd90d7a2065aa4e2cd |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQTAwOkIwRjIwOjZFQTdFNDo5NDY3OEY6NkIwNjJEOTgiLCJ2aXNpdG9yX2lkIjoiNTIzMzk1MzMwNzQwNzgyMjIzMiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | a867bbc4306450d06aa6152713f7e3d83bd4005096b0f8a3c6eae0510a51a7d0 |
| hovercard-subject-tag | issue:6088309999 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/developing-today/code/1850/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d44af2b2e5de1b4d9d1c58f1863ab5e482293c6a61e80379d7e1e4f5cd76c155/developing-today/code/issues/1850 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d44af2b2e5de1b4d9d1c58f1863ab5e482293c6a61e80379d7e1e4f5cd76c155/developing-today/code/issues/1850 |
| og:image:alt | Relocated from dezren39/darwin-nix#6 on 2026-10-28 (placement audit): mcpx's single source lives in developing-today/code (pkgs/mcpx); re-home tracked at #309. Original body below; issue references... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dezren39 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7f961de5dd5c5d4aca24d33f8b3ffb3fb8b2ef53d0a4f32f01f0a790e512f6d3 |
| turbo-cache-control | no-preview |
| go-import | github.com/developing-today/code git https://github.com/developing-today/code.git |
| octolytics-dimension-user_id | 26439447 |
| octolytics-dimension-user_login | developing-today |
| octolytics-dimension-repository_id | 627308783 |
| octolytics-dimension-repository_nwo | developing-today/code |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 627308783 |
| octolytics-dimension-repository_network_root_nwo | developing-today/code |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 494ea0bb1e0feef734a83e2628697647755e8864 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width