Skip to content

refactor(events): pass event contexts instead of subscription - #6294

Open
tiagolupepic wants to merge 1 commit into
mainfrom
refactor/change-events-to-support-context
Open

refactor(events): pass event contexts instead of subscription#6294
tiagolupepic wants to merge 1 commit into
mainfrom
refactor/change-events-to-support-context

Conversation

@tiagolupepic

@tiagolupepic tiagolupepic commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Context

This change unblocks the initial BillingSegment refactor needed to support BillingPeriodFilterService. BillingSegment filtering queries raw events through contract data, while the existing event stores and billable metric aggregators assumed every event context was a Subscription.

Description

Introduce Events::Stores::EventContext as the explicit object passed into event stores and aggregators. The stores now ask the context for external ids, organization, customer, duration, subscription history, and date calculations instead of depending directly on a subscription.

Contract-backed contexts currently support the raw event lookup surface needed by BillingSegment, and intentionally raise NotImplementedError for subscription-specific methods that are not defined yet: invoice_subscriptions, previous_subscription, previous_subscription_id, previous_subscription_id?, next_subscription, upgraded?, downgraded?, id, and charges_duration_at. Those contract behaviours will be addressed in a separate PR.

This refactor is necessary to unblock products and plans (contract) #6296

@tiagolupepic
tiagolupepic force-pushed the refactor/change-events-to-support-context branch 2 times, most recently from d90faa1 to 1d5fd5f Compare September 4, 2026 15:08
This change unblocks the initial BillingSegment refactor needed to support BillingPeriodFilterService. BillingSegment filtering queries raw events through contract data, while the existing event stores and billable metric aggregators assumed every event context was a Subscription.

Introduce Events::Stores::EventContext as the explicit object passed into event stores and aggregators. The stores now ask the context for external ids, organization, customer, duration, subscription history, and date calculations instead of depending directly on a subscription.

Contract-backed contexts currently support the raw event lookup surface needed by BillingSegment, and intentionally raise NotImplementedError for subscription-specific methods that are not defined yet: invoice_subscriptions, previous_subscription, previous_subscription_id, previous_subscription_id?, next_subscription, upgraded?, downgraded?, id, and charges_duration_at. Those contract behaviours will be addressed in a separate PR.
@tiagolupepic
tiagolupepic force-pushed the refactor/change-events-to-support-context branch from 1d5fd5f to a8826df Compare September 4, 2026 15:21
@lago-claude-ai-agent

Copy link
Copy Markdown
Contributor

Automated pre-review (advisory, not a required check) — verdict: HOLD · CI green

HOLD: Contract-backed raw event lookup is broken for the enriched ClickHouse store.

  • ClickhouseEnrichedStore#needs_code_based_fallback? calls context.previous_subscription_id before its use_from_boundary fast exit. EventContext deliberately raises for that method on contracts, so an ordinary bounded events lookup crashes for organizations using enriched events. Avoid the unnecessary subscription-only probe and add a contract-backed store regression spec.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant