@@ -916,22 +916,38 @@ async function siblingConsistencyLane(ctxs: ModelContext[], runner: ReviewRunner
916916 * only NEW PII (a column whose name appears in the added diff), so it never nags
917917 * about pre-existing PII columns the PR didn't touch.
918918 */
919- async function piiClassifyLane ( ctx : ModelContext , runner : ReviewRunner , dialect : string ) : Promise < Finding [ ] > {
920- if ( ! runner . classifyPii ) return [ ]
919+ async function piiClassifyLane (
920+ ctx : ModelContext ,
921+ runner : ReviewRunner ,
922+ dialect : string ,
923+ ) : Promise < { findings : Finding [ ] ; introducedColumns : Set < string > ; completed : boolean } > {
924+ const empty = { findings : [ ] , introducedColumns : new Set < string > ( ) , completed : false }
925+ if ( ! runner . classifyPii ) return empty
921926 const { file, engineNewSql } = ctx
922- if ( ! engineNewSql || file . status === "deleted" ) return [ ]
927+ if ( ! engineNewSql || file . status === "deleted" ) return empty
923928 const model = modelNameFromPath ( file . path )
924- if ( ! runner . columnLineage ) return [ ]
929+ if ( ! runner . columnLineage ) return empty
925930 // Output columns the change INTRODUCED = head targets − base targets (precise;
926931 // a pre-existing column merely mentioned in the diff is NOT counted).
927- const headCols = [ ...new Set ( ( await runner . columnLineage ( engineNewSql , dialect ) ) . map ( ( e ) => e . target ) . filter ( Boolean ) ) ]
928- if ( ! headCols . length ) return [ ]
929- const baseCols = ctx . engineOldSql
930- ? new Set ( ( await runner . columnLineage ( ctx . engineOldSql , dialect ) ) . map ( ( e ) => e . target . toLowerCase ( ) ) )
931- : undefined
932- const newCols = baseCols ? headCols . filter ( ( c ) => ! baseCols . has ( c . toLowerCase ( ) ) ) : headCols
933- if ( ! newCols . length ) return [ ]
934- const pii = await runner . classifyPii ( newCols )
932+ let newCols : string [ ]
933+ try {
934+ const headCols = [ ...new Set ( ( await runner . columnLineage ( engineNewSql , dialect ) ) . map ( ( e ) => e . target ) . filter ( Boolean ) ) ]
935+ if ( ! headCols . length ) return { ...empty , completed : true }
936+ const baseCols = ctx . engineOldSql
937+ ? new Set ( ( await runner . columnLineage ( ctx . engineOldSql , dialect ) ) . map ( ( e ) => e . target . toLowerCase ( ) ) )
938+ : undefined
939+ newCols = baseCols ? headCols . filter ( ( c ) => ! baseCols . has ( c . toLowerCase ( ) ) ) : headCols
940+ } catch {
941+ return empty
942+ }
943+ const introducedColumns = new Set ( newCols . map ( ( c ) => c . toLowerCase ( ) ) )
944+ if ( ! newCols . length ) return { findings : [ ] , introducedColumns, completed : true }
945+ let pii
946+ try {
947+ pii = await runner . classifyPii ( newCols )
948+ } catch {
949+ return empty
950+ }
935951 const out : Finding [ ] = [ ]
936952 const highExposureLayer = / ( ^ | \/ ) ( m a r t s | r e p o r t i n g ) \/ / . test ( file . path )
937953 for ( const p of pii ) {
@@ -959,16 +975,7 @@ async function piiClassifyLane(ctx: ModelContext, runner: ReviewRunner, dialect:
959975 } ) ,
960976 )
961977 }
962- return out
963- }
964-
965- async function introducedOutputColumns ( ctx : ModelContext , runner : ReviewRunner , dialect : string ) : Promise < Set < string > | undefined > {
966- if ( ! runner . columnLineage || ! ctx . engineNewSql || ctx . file . status === "deleted" ) return undefined
967- const headCols = [ ...new Set ( ( await runner . columnLineage ( ctx . engineNewSql , dialect ) ) . map ( ( e ) => e . target ) . filter ( Boolean ) ) ]
968- if ( ! headCols . length ) return new Set ( )
969- if ( ! ctx . engineOldSql ) return new Set ( headCols . map ( ( c ) => c . toLowerCase ( ) ) )
970- const baseCols = new Set ( ( await runner . columnLineage ( ctx . engineOldSql , dialect ) ) . map ( ( e ) => e . target . toLowerCase ( ) ) )
971- return new Set ( headCols . filter ( ( c ) => ! baseCols . has ( c . toLowerCase ( ) ) ) . map ( ( c ) => c . toLowerCase ( ) ) )
978+ return { findings : out , introducedColumns, completed : true }
972979}
973980
974981function piiLane ( file : ChangedFile & { kind : string } , columns : string [ ] ) : Finding [ ] {
@@ -1061,6 +1068,7 @@ export async function runReview(input: OrchestrateInput): Promise<VerdictEnvelop
10611068 const lanes = new Set ( input . config . reviewers . length ? input . config . reviewers : TIER_LANES [ tier ] )
10621069
10631070 const all : Finding [ ] [ ] = [ ]
1071+ const diffScopedPiiFiles = new Set < string > ( )
10641072 for ( const ctx of ctxByPath . values ( ) ) {
10651073 const tasks : Promise < Finding [ ] > [ ] = [ ]
10661074 // Engine lanes consume COMPILED SQL (rendered by dbt) when available.
@@ -1086,20 +1094,19 @@ export async function runReview(input: OrchestrateInput): Promise<VerdictEnvelop
10861094 tasks . push ( columnBreakageLane ( ctx , input . runner , getCompiled , dialect ) )
10871095 }
10881096 if ( lanes . has ( "test_coverage" ) ) tasks . push ( missingGrainTestLane ( ctx , input . runner ) )
1089- const diffScopedPiiCols =
1090- input . runner . classifyPii && input . runner . columnLineage
1091- ? await introducedOutputColumns ( ctx , input . runner , dialect )
1092- : undefined
1097+ // PII classification always runs (cheap name-pattern check, diff-scoped to
1098+ // newly-introduced columns) — exposing PII is a hard-floor concern that
1099+ // shouldn't depend on the cost tier enabling the pii_exposure lane. If core
1100+ // lineage/classification fails, keep the broad deterministic fallback.
1101+ const diffScopedPii = await piiClassifyLane ( ctx , input . runner , dialect )
1102+ if ( diffScopedPii . completed ) diffScopedPiiFiles . add ( ctx . file . path )
10931103 if ( lanes . has ( "pii_exposure" ) ) {
1094- const fallbackPii = diffScopedPiiCols
1095- ? ctx . pii . filter ( ( col ) => ! diffScopedPiiCols . has ( col . toLowerCase ( ) ) )
1104+ const fallbackPii = diffScopedPii . completed
1105+ ? ctx . pii . filter ( ( col ) => ! diffScopedPii . introducedColumns . has ( col . toLowerCase ( ) ) )
10961106 : ctx . pii
10971107 all . push ( piiLane ( ctx . file , fallbackPii ) )
10981108 }
1099- // PII classification always runs (cheap name-pattern check, diff-scoped to
1100- // newly-introduced columns) — exposing PII is a hard-floor concern that
1101- // shouldn't depend on the cost tier enabling the pii_exposure lane.
1102- tasks . push ( piiClassifyLane ( ctx , input . runner , dialect ) )
1109+ all . push ( diffScopedPii . findings )
11031110 // Deterministic dbt anti-pattern detectors run on RAW SQL + diff (need Jinja).
11041111 if ( lanes . has ( "dbt_patterns" ) ) {
11051112 all . push ( detectModelPatterns ( ctx . file , ctx . newSql , input . rubric ) )
@@ -1163,12 +1170,9 @@ export async function runReview(input: OrchestrateInput): Promise<VerdictEnvelop
11631170 // regex still covers functions core didn't flag (dialect-suppressed / not in
11641171 // core's set) plus reserved words / types / operators that L033 doesn't do.
11651172 const flat = all . flat ( )
1166- const diffScopedPiiFiles = new Set < string > ( )
1167- if ( input . runner . classifyPii && input . runner . columnLineage ) {
1168- for ( const ctx of ctxByPath . values ( ) ) {
1169- if ( ctx . engineNewSql && ctx . file . status !== "deleted" ) diffScopedPiiFiles . add ( ctx . file . path )
1170- }
1171- }
1173+ const schemaPiiFiles = new Set (
1174+ flat . filter ( ( f ) => f . category === "pii_exposure" && f . evidence ?. tool === "schema.detect_pii" ) . map ( ( f ) => f . file ) ,
1175+ )
11721176 // Per file, the concatenated rule names core's AST lint actually emitted —
11731177 // so we suppress a regex twin only when core genuinely covered that concern.
11741178 const coreRulesByFile = new Map < string , string > ( )
@@ -1195,7 +1199,7 @@ export async function runReview(input: OrchestrateInput): Promise<VerdictEnvelop
11951199 const fallbackRule = String ( ( f . evidence ?. result as any ) ?. rule ?? "" ) . replace ( / _ / g, "-" )
11961200 if (
11971201 ( tool === "dbt-patterns" || tool === "rule-catalog" ) &&
1198- diffScopedPiiFiles . has ( f . file ) &&
1202+ ( diffScopedPiiFiles . has ( f . file ) || schemaPiiFiles . has ( f . file ) ) &&
11991203 f . category === "pii_exposure" &&
12001204 ( fallbackRule === "pii-into-mart" || fallbackRule === "select-pii-columns" )
12011205 ) {
0 commit comments