perf(agent-sessions): project the span read down to the keys the mapper reads - #739
Open
JeremyFunk wants to merge 2 commits into
Open
perf(agent-sessions): project the span read down to the keys the mapper reads#739JeremyFunk wants to merge 2 commits into
JeremyFunk wants to merge 2 commits into
Conversation
…er reads The session spans read selected `SpanAttributes` and `ResourceAttributes` whole, then `mapAiSpan` read a fixed list of keys off the first and nothing off the second. Measured on the largest production sessions, the resource map was ~60% of the raw bytes and one unrelated key (`db.query.text`) was half of what remained — none of it reached the wire. `spanProjection` now filters the span map to `aiSpanAttributeKeys` — every source key of every integration plus what the refine hooks read, declared next to the hook as `refineKeys` — and the prompt-variable prefix, and drops the resource map. The byte cap on the read now measures what actually ships. `mapFilterKeys` is the builder primitive: `mapFilter((k, v) -> …)` with the key predicate written in the DSL's own conditions.
This was referenced Sep 2, 2026
…ean-span-projection # Conflicts: # packages/query-engine-integrations/src/ai/ai-sessions.ts
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.
Why
The Agent Sessions spans read selected the whole
SpanAttributesandResourceAttributesmaps per span and then mapped a fixed set of keys server-side. On the largest sessions in the warehouse the resource map alone was ~60% of the raw response and a single unrelated key (db.query.text) was half of the rest. The mapper never read either, so the byte ceiling on the read was measuring bytes that never reached the client.What
spanProjectionprojectsSpanAttributesthroughmapFiltertoaiSpanAttributeKeys— the union of every integration's source keys, themaple_ai.*envelope, and the keys refine hooks read (now declared on the integration asrefineKeys) — plus thegen_ai.prompt.variable.*family.ResourceAttributesis no longer selected.mapFilterKeysadded to@maple-dev/clickhouse-builder:mapFilter((k, v) -> <predicate>, map)with the key predicate written in DSL conditions.Verification
clickhouse-builder,query-engine-integrations(AI + catalog/baseline) andapps/apiroute tests green.CLICKHOUSE_E2E=1SQL catalog sweep against a local ClickHouse: 253 shapes pass.🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.