@@ -10,7 +10,7 @@ import { cachedOrgModeFor, NO_OVERRIDE } from "~/v3/snapshotStoreMode.server";
1010export type SnapshotStoreOrgCensusClient = {
1111 organization : {
1212 findMany ( args : {
13- where : { featureFlags : { path : string [ ] ; not : typeof Prisma . DbNull } } ;
13+ where : { OR : Array < { featureFlags : { path : string [ ] ; not : typeof Prisma . DbNull } } > } ;
1414 select : { id : true ; featureFlags : true } ;
1515 } ) : Promise < Array < { id : string ; featureFlags : unknown } > > ;
1616 } ;
@@ -24,12 +24,16 @@ type OrgCensusSnapshot = {
2424 redisOnly : boolean ;
2525 /** Orgs with any non-off override. */
2626 cohort : Set < string > ;
27+ /** Orgs with the one-way per-org residency latch set true (may be off now, or latch-only). */
28+ everEnabled : Set < string > ;
2729} ;
2830
2931export type SnapshotStoreOrgCensus = {
3032 anyOrgReadEnabled ( ) : boolean ;
3133 anyOrgRedisOnly ( ) : boolean ;
3234 isCohortMember ( organizationId : string ) : boolean ;
35+ /** DEFINITE never-enabled: census loaded AND the org is not in the ever-enabled set. */
36+ orgDefinitelyNeverEnabled ( organizationId : string ) : boolean ;
3337 /** Force one load and await it. For tests and boot; the interval drives it in production. */
3438 refresh ( ) : Promise < void > ;
3539 stop ( ) : void ;
@@ -38,17 +42,20 @@ export type SnapshotStoreOrgCensus = {
3842/** Classifies each org's blob exactly as the per-org resolver does (via cachedOrgModeFor). */
3943function classify ( rows : Array < { id : string ; featureFlags : unknown } > ) : OrgCensusSnapshot {
4044 const cohort = new Set < string > ( ) ;
45+ const everEnabled = new Set < string > ( ) ;
4146 let readEnabled = false ;
4247 let redisOnly = false ;
4348 for ( const row of rows ) {
4449 const flags = row . featureFlags as Record < string , unknown > | null | undefined ;
50+ // Strict: only an explicit true latches, matching stampSnapshotStoreOrgEverEnabled.
51+ if ( flags ?. [ FEATURE_FLAG . snapshotStoreOrgEverEnabled ] === true ) everEnabled . add ( row . id ) ;
4552 const mode = cachedOrgModeFor ( flags ?. [ FEATURE_FLAG . snapshotStoreOrgMode ] ) ;
4653 if ( mode === NO_OVERRIDE || mode === "off" ) continue ;
4754 cohort . add ( row . id ) ;
4855 if ( mode === "redis-read" || mode === "redis-only" ) readEnabled = true ;
4956 if ( mode === "redis-only" ) redisOnly = true ;
5057 }
51- return { readEnabled, redisOnly, cohort } ;
58+ return { readEnabled, redisOnly, cohort, everEnabled } ;
5259}
5360
5461export function createSnapshotStoreOrgCensus (
@@ -61,12 +68,20 @@ export function createSnapshotStoreOrgCensus(
6168 intervalMs : opts ?. intervalMs ?? env . GLOBAL_FLAGS_RELOAD_INTERVAL_MS ,
6269 autoStart : opts ?. autoStart ?? process . env . NODE_ENV !== "test" ,
6370 load : async ( ) =>
64- // WHERE bounds transfer to orgs that HAVE the key; cachedOrgModeFor still filters off /
65- // NO_OVERRIDE out of the cohort in code, so classification stays identical to the resolver.
71+ // WHERE returns orgs with EITHER key, so an ever-enabled org that is now off (or holds only
72+ // the latch after a clear) still returns. Classification stays in code, identical to the resolver.
6673 classify (
6774 await client . organization . findMany ( {
6875 where : {
69- featureFlags : { path : [ FEATURE_FLAG . snapshotStoreOrgMode ] , not : Prisma . DbNull } ,
76+ OR : [
77+ { featureFlags : { path : [ FEATURE_FLAG . snapshotStoreOrgMode ] , not : Prisma . DbNull } } ,
78+ {
79+ featureFlags : {
80+ path : [ FEATURE_FLAG . snapshotStoreOrgEverEnabled ] ,
81+ not : Prisma . DbNull ,
82+ } ,
83+ } ,
84+ ] ,
7085 } ,
7186 select : { id : true , featureFlags : true } ,
7287 } )
@@ -85,6 +100,12 @@ export function createSnapshotStoreOrgCensus(
85100 anyOrgReadEnabled : ( ) => registry . current ( ) ?. readEnabled ?? true ,
86101 anyOrgRedisOnly : ( ) => registry . current ( ) ?. redisOnly ?? false ,
87102 isCohortMember : ( organizationId ) => registry . current ( ) ?. cohort . has ( organizationId ) ?? false ,
103+ // FALSE cold/never-loaded: not-definite means the caller (10c) must NOT skip. Only a loaded
104+ // census whose ever-enabled set excludes the org yields a definite "never enabled".
105+ orgDefinitelyNeverEnabled : ( organizationId ) => {
106+ const snapshot = registry . current ( ) ;
107+ return snapshot ? ! snapshot . everEnabled . has ( organizationId ) : false ;
108+ } ,
88109 refresh : async ( ) => {
89110 // A failed reload keeps the last-good snapshot; swallow so accessors stay safe.
90111 try {
0 commit comments