feat(etl): Wave 2B — 5 mart builders (daily, session, project, provider_day, model_day)#74
Merged
Conversation
…er_day, model_day) Wave 2B of the three-layer ETL pipeline (see docs/specs/etl-architecture.md). Five MartBuilder subclasses under stackunderflow/etl/marts/, each watermarked and idempotent. Additive marts (daily, provider_day, model_day) refresh via INSERT ... ON CONFLICT DO UPDATE so re-runs after partial failure self-heal. Their COUNT(DISTINCT session_id) columns are recomputed for affected keys after the additive upsert — DISTINCT counts don't sum across refresh windows without double-counting sessions that span the boundary. Per-entity marts (session, project) use INSERT OR REPLACE over a re-aggregated subquery so a new event for an existing session/project invalidates the prior aggregate and recomputes from all events. rebuild_from_scratch() drops + repopulates each mart from scratch for the --rebuild path. Same final state as a clean incremental run. Foundation pieces (Normalizer/MartBuilder ABCs, marts/normalize registries, watermark helpers, v006_etl_layer.sql migration) are scaffolded here so the marts can be exercised end-to-end before Wave 1 lands. They mirror the spec contract exactly; Wave 1's PR will reconcile any textual overlap when it merges. 33 new tests in tests/stackunderflow/etl/marts/ (8 daily, 4 provider_day, 4 model_day, 7 session, 5 project, 5 integration). Total suite: 1341 → 1374 passing. No version bump (still v0.6.1).
0bserver07
added a commit
that referenced
this pull request
May 6, 2026
Bumps to 0.7.0. Consolidates the [Unreleased] CHANGELOG entries from the 11 ETL PRs (#72, #73, #74, #75, #76, #79, #81, #80, #78, #77, #82) into a single [0.7.0] section. New: docs/HANDOFF.md — state-of-the-codebase walkthrough for incoming agents. Architecture map, recent history, key gotchas, what's left, files-to-read-first. End-state on the maintainer's real store: 150,337 usage_events Marts populated and watermarks in sync Dashboard cold-load 2.5s → <50ms warm Watcher 155ms end-to-end source-file-write → dashboard-data-fresh 1598 backend tests passing, 2 skipped, 11 deselected (slow suite). Frontend typecheck + build clean. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
0bserver07
added a commit
that referenced
this pull request
May 20, 2026
…er_day, model_day) (#74) Wave 2B of the three-layer ETL pipeline (see docs/specs/etl-architecture.md). Five MartBuilder subclasses under stackunderflow/etl/marts/, each watermarked and idempotent. Additive marts (daily, provider_day, model_day) refresh via INSERT ... ON CONFLICT DO UPDATE so re-runs after partial failure self-heal. Their COUNT(DISTINCT session_id) columns are recomputed for affected keys after the additive upsert — DISTINCT counts don't sum across refresh windows without double-counting sessions that span the boundary. Per-entity marts (session, project) use INSERT OR REPLACE over a re-aggregated subquery so a new event for an existing session/project invalidates the prior aggregate and recomputes from all events. rebuild_from_scratch() drops + repopulates each mart from scratch for the --rebuild path. Same final state as a clean incremental run. Foundation pieces (Normalizer/MartBuilder ABCs, marts/normalize registries, watermark helpers, v006_etl_layer.sql migration) are scaffolded here so the marts can be exercised end-to-end before Wave 1 lands. They mirror the spec contract exactly; Wave 1's PR will reconcile any textual overlap when it merges. 33 new tests in tests/stackunderflow/etl/marts/ (8 daily, 4 provider_day, 4 model_day, 7 session, 5 project, 5 integration). Total suite: 1341 → 1374 passing. No version bump (still v0.6.1).
0bserver07
added a commit
that referenced
this pull request
May 20, 2026
Bumps to 0.7.0. Consolidates the [Unreleased] CHANGELOG entries from the 11 ETL PRs (#72, #73, #74, #75, #76, #79, #81, #80, #78, #77, #82) into a single [0.7.0] section. New: docs/HANDOFF.md — state-of-the-codebase walkthrough for incoming agents. Architecture map, recent history, key gotchas, what's left, files-to-read-first. End-state on the maintainer's real store: 150,337 usage_events Marts populated and watermarks in sync Dashboard cold-load 2.5s → <50ms warm Watcher 155ms end-to-end source-file-write → dashboard-data-fresh 1598 backend tests passing, 2 skipped, 11 deselected (slow suite). Frontend typecheck + build clean. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Wave 2B of the three-layer ETL refactor (see
docs/specs/etl-architecture.md). Ships fiveMartBuildersubclasses understackunderflow/etl/marts/— indexed read-side rollups derived fromusage_events:DailyMartBuilder—(day, project_id, provider, model, speed)rollupSessionMartBuilder— one row per session with lifetime aggregates +is_one_shotflag +primary_modelProjectMartBuilder— one row per project with lifetime totalsProviderDayMartBuilder—(day, provider)rollup for the by-provider chartModelDayMartBuilder—(day, model, speed)rollup for compare-across-agentsEach builder is watermarked (
mart_watermark.last_event_idper mart, independently tracked) and idempotent. Two refresh patterns:INSERT ... ON CONFLICT DO UPDATEadds incremental events into existing rows. After the additive upsert,COUNT(DISTINCT session_id)columns are recomputed for affected keys via a follow-upUPDATE— DISTINCT counts don't sum across refresh windows without double-counting sessions that span the boundary.INSERT OR REPLACEover a subquery that re-aggregates from scratch for affectedsession_id/project_idvalues. New events invalidate prior per-entity aggregates, so the row gets rewritten in full.rebuild_from_scratch()doesDELETE FROM <mart>; refresh(conn, since_event_id=0)— drops + full backfill, same final state as incremental.The Wave 1 foundation pieces (Normalizer/MartBuilder ABCs, marts/normalize registries, watermark helpers,
v006_etl_layer.sqlschema migration) are scaffolded in this branch so the marts can be exercised end-to-end before Wave 1 lands. They mirror the spec contract; Wave 1's PR will reconcile any textual overlap when it merges first.Notes
v006_etl_layer.sql(notv004_*as the spec text says): two migrations (v004 synthetic-models cleanup, v005 cursor-workspace redistribute) shipped between the spec being written and this PR.usage_eventstable contents — no provider-specific logic, no import fromstackunderflow.etl.normalize.Test plan
tests/stackunderflow/etl/marts/test_<mart>.py(8 daily, 4 provider_day, 4 model_day, 7 session, 5 project)pytest tests/ -qclean: 1374 passed, 2 skippedruff check stackunderflow/etl/cleanruff format stackunderflow/etl/ --checkclean