feat(ingest): classify AI spans on the write path and store the columns - #434
Closed
JeremyFunk wants to merge 1 commit into
Closed
feat(ingest): classify AI spans on the write path and store the columns#434JeremyFunk wants to merge 1 commit into
JeremyFunk wants to merge 1 commit into
Conversation
JeremyFunk
force-pushed
the
ai/05-ingest-classification-write-path
branch
from
August 12, 2026 20:04
a27070c to
3fa90ce
Compare
Adds five defaulted trailing columns to `traces` (`AiVendor`, `AiSessionKeyState`, `AiSessionKeyHash`, `AiRulesVersion`, `AiRollupHour`) plus two skip indexes, as ClickHouse migration 0015 and local-store migration v4 -> v5, and wires the classifier from level 3 into the Rust gateway's row writer, the local-mode OTLP encoder and the ingest metrics. The columns are all DEFAULT-valued so the ALTER is metadata-only — no mutation on a table whose 30-day TTL retires unindexed parts on its own — and rows written before the classifier shipped stay readable, with `AiRulesVersion = 0` meaning "never examined" as distinct from "examined, not AI". `AiRollupHour` is receive-time-clamped and written unconditionally so a skewed client cannot open a partition in 2038. **Operational note:** 0015 is `requiredForIngest: true`, so `clickHouseSchemaVersion` moves from 13 to 15. The gateway's INSERT now names all five AI columns, and a BYO cluster without them would reject every direct insert — so BYO-ClickHouse orgs resolve `clickhouse_ready = false` and route to the managed pipeline until their schema syncs 0015. That fallback is the designed behaviour, not a regression, but it is the reason this level should not ship without the schema rollout. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
JeremyFunk
force-pushed
the
ai/05-ingest-classification-write-path
branch
from
August 12, 2026 21:05
3fa90ce to
19aa5a1
Compare
Collaborator
Author
🍁 Maple PR previewNote Preview resources were removed when this pull request closed. Final commit |
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.
What this layer contains
The schema change and the wiring that makes classification actually happen — the largest layer in the stack.
traces(AiVendor,AiSessionKeyState,AiSessionKeyHash,AiRulesVersion,AiRollupHour) plus theidx_ai_vendorandidx_scope_nameskip indexes, as ClickHouse migration0015and local-store migration v4 → v5 (local schema version 5, frozenlocal-schema-v5.sql, history entry, manifest check).apps/ingest's row writer (telemetry.rs), metrics and OTLP spans, and into the local-mode encoder inapps/cli.clickhouse-schema.ts,tinybird-project-manifest.ts,local-schema.sql,local-inserts.jsonandclickhouse_insert_mappings.rs— all produced bybun run clickhouse:schema+bun run tinybird:manifest, never hand-edited.WarehouseQueryService.clickhouse.e2e.test.ts, and the datasource contract test.Why it is shaped this way
Every new column is
DEFAULT-valued, which makes theALTERmetadata-only: noMATERIALIZE, noOPTIMIZE, no whole-table mutation ontraces, whose 30-day TTL retires unindexed parts on its own. That also keeps rows written before the classifier shipped readable, withAiRulesVersion = 0meaning "never examined" as distinct from "examined and found not to be AI".AiRollupHouris receive-time-clamped and written unconditionally for every span, classification on or off, so a skewed client cannot open a partition in 2038.0015isrequiredForIngest: true, soclickHouseSchemaVersionmoves from13to15. The gateway's INSERT now names all five AI columns, and a BYO cluster without them would reject every direct insert. Orgs stamped below 15 therefore resolveclickhouse_ready = falseand route to the managed pipeline until their schema syncs 0015. That fallback is the designed behaviour rather than a regression, but it is the reason this PR should not merge ahead of the schema rollout.Gates run at this level
bun typecheck— 37/37 tasks pass.bun run clickhouse:schema:check— all five generators up to date, lint OK (37 tables, 39 MVs), local manifest up to date at schema v5.packages/domainvitest — 533 passed.apps/clivitest — 430 passed.cargo test --locked(+TRACE_CAPTURE_DIR) — 134 lib + 75 bin, 0 failures.bun run ch:testagainst a real ClickHouse — 3 files, 182 passed.Dependencies
Requires #432 (the classifier) and #433 (the registry TS layer).
Partition note:
CURRENT_SCHEMA_PROJECT_REVISIONis pinned to the recorded v5 identity (09513d18…) so it matches the append-only history tip, whichcheck-local-schema-manifest.tsenforces. The generated artifacts at this level carry062342f1…: the recorded v5 revision was cut when the AI columns had no jsonPaths, and jsonPaths move the Tinybird-wide project revision without changing any DDL. Confirmed by reproducing09513d18…exactly with the jsonPaths removed. The two converge again at the top of the stack.🤖 Generated with Claude Code
Stack created with GitHub Stacks CLI • Give Feedback 💬
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.