Skip to content

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
aheden/tldr-ban-active-orgs-ratiofrom
aheden/fix-leadership-weekly-contract-activity-scope-on-tldr-ban
Open

Re-apply Block J contract-activity scope fix on top of PR #60#61
Assaf Hay Eden (AssafHayEden) wants to merge 1 commit into
aheden/tldr-ban-active-orgs-ratiofrom
aheden/fix-leadership-weekly-contract-activity-scope-on-tldr-ban

Conversation

@AssafHayEden
Copy link
Copy Markdown
Collaborator

Summary

PR #60 (leads regroup + Enterprise Dashboard link) merged to aheden/tldr-ban-active-orgs-ratio without 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.sql Block J, contracts_consumed_this_week and enterprise_token_usage filter activity with e.ent_type = 'Enterprise Contract', which restricts to users whose individual current_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:

metric buggy fixed
ent_users with ent_type='Enterprise Contract' 0 0
ent_users total at Meta 49 49
tokens this week 0 → reported inactive 967,036 → active
active users this week 0 11

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:

before after
enterprise.active_orgs_count 15 16
enterprise.inactive_org_names [Bosch, Indegene, Meta] [Bosch, Indegene]
enterprise.ent_tokens_this_week under-counted 8,932,698
enterprise.ent_tokens_last_week under-counted 7,895,752
enterprise.ent_ltx_tokens_this_week under-counted 1,308,472

(Prophet, Miroma were also partially under-counted by the same bug — small drops fixed in the same change.)

Fix

Two CTEs in Block J. In each:

  • Remove where e.ent_type = 'Enterprise Contract'
  • Add inner join active_enterprise_contracts as aec on aec.org = e.org

Pilot section is unchanged.

Validation

Why a separate PR (and not just rebase #59)

#59 targets main. This branch targets aheden/tldr-ban-active-orgs-ratio, which is currently ahead of main and 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 to main independently.

Test plan

  • Run the n8n flow against this branch on the next Monday window.
  • Confirm J_studio_summary.enterprise.active_orgs_count = 16 and inactive_org_names = ["Bosch", "Indegene"] for the Apr 27 → May 3 window (or current expected values for the latest week).
  • Sanity-check ent_tokens_this_week against an independent token total at the org level for any one contract org (e.g. Meta, McCann_Paris).
  • Confirm pilots block (active_pilots, new_pilot_names, ending_names) is unchanged vs. previous run.

Made with Cursor

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>
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