Re-apply Block J contract-activity scope fix on top of PR #60#61
Open
Assaf Hay Eden (AssafHayEden) wants to merge 1 commit into
Conversation
Re-apply the fix from PR #59 on top of PR #60. PR #60 (leads regroup + dashboard link) didn't carry forward the activity-scope correction, so the buggy filter is back in this branch. Same fix as #59: contracts_consumed_this_week and enterprise_token_usage filtered activity with `e.ent_type = 'Enterprise Contract'`, which restricts to users whose individual current_customer_plan_type = 'contract'. But the contract list itself is sourced from the subscriptions table at the org level, and a contract org's users sit in many plan_type buckets (pilot/null/other). The mismatch silently drops real activity. Concrete impact for the week of Apr 27 → May 3, 2026: - Meta: 0 of 49 ent_users have ent_type='Enterprise Contract', but Meta is a current contract per subscriptions. Buggy version reports it as inactive with 0 tokens; actual activity is 967,036 tokens / 11 active users. active_orgs_count: 15 → 16. inactive_org_names: [Bosch, Indegene, Meta] → [Bosch, Indegene]. - Enterprise token totals (this/last week, ltx, video, gens) were all under-counted for the same reason and are now correct. Fix: replace the user-level ent_type filter with an org-level join to active_enterprise_contracts in both CTEs. Validation: bq dry-run upper bound 545 MB (was 543 MB) — essentially identical scan size. Co-authored-by: Cursor <cursoragent@cursor.com>
Open
3 tasks
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
PR #60 (leads regroup + Enterprise Dashboard link) merged to
aheden/tldr-ban-active-orgs-ratiowithout carrying forward the activity-scope correction from #59. As a result, the same bug we fixed yesterday is back in this branch.This PR re-applies the exact fix from #59 on top of the post-#60 SQL — same two CTEs, same edit, no new logic.
Why this matters (recap)
In
queries/weekly_report_combined.sqlBlock J,contracts_consumed_this_weekandenterprise_token_usagefilter activity withe.ent_type = 'Enterprise Contract', which restricts to users whose individualcurrent_customer_plan_type = 'contract'. But the contract list itself (active_enterprise_contracts) is built from the subscriptions table at the org level, and a contract org's users sit in many plan_type buckets (pilot, NULL,other). The mismatch silently drops real activity and falsely flags orgs as inactive.Concrete impact (week of Apr 27 → Sun May 3, 2026)
The smoking-gun case is Meta:
All 49 Meta users have
current_customer_plan_type≠'contract'(48 'Enterprise Pilot', 1 'Enterprise Other'), so the buggy filter zeroed them out — even though the subscriptions table lists Meta as an active contract org.Aggregate effect for that week:
enterprise.active_orgs_countenterprise.inactive_org_names[Bosch, Indegene, Meta][Bosch, Indegene]enterprise.ent_tokens_this_weekenterprise.ent_tokens_last_weekenterprise.ent_ltx_tokens_this_week(
Prophet,Miromawere also partially under-counted by the same bug — small drops fixed in the same change.)Fix
Two CTEs in Block J. In each:
where e.ent_type = 'Enterprise Contract'inner join active_enterprise_contracts as aec on aec.org = e.orgPilot section is unchanged.
Validation
bq query --dry_runupper bound: 545 MB (vs ~543 MB before the fix on this branch) — essentially identical scan size.+11 / -4lines, identical to Fix Block J contract-activity scope (org-level, not user plan_type) #59 modulo line-number shift caused by PR leadership-report: split PQL/PEL into OSS / API / Studio buckets and add Enterprise Dashboard link #60's surrounding edits.Why a separate PR (and not just rebase #59)
#59 targets
main. This branch targetsaheden/tldr-ban-active-orgs-ratio, which is currently ahead ofmainand is the integration branch where #60 landed. Easiest path is a focused PR here so the fix lands wherever #60's content lands — and #59 can still merge tomainindependently.Test plan
J_studio_summary.enterprise.active_orgs_count = 16andinactive_org_names = ["Bosch", "Indegene"]for the Apr 27 → May 3 window (or current expected values for the latest week).ent_tokens_this_weekagainst an independent token total at the org level for any one contract org (e.g. Meta, McCann_Paris).active_pilots,new_pilot_names,ending_names) is unchanged vs. previous run.Made with Cursor