Enum Known-Values via INSERT-Grep
✅ PROMOTED — TDD Cycle 1 strong pass. RED subagent reacted heuristically correct ("grep first") but without concrete verification at a real repo (7 self-critique points). GREEN subagent executed 18 Bash tool uses in a real production domain repo and delivered substantial findings that would not have been reached without the skill: (1) current _KNOWN_SOURCES is already different from what the scenario assumed (recent hotfix), (2) missing productive value 'real' from ml/real_trade_bridge.py:142 — would silently trigger unknown source: real-warnings for weeks, (3) cross-table false positives explicitly rejected ('optimizer', 'manual'@strategy_params, 'av_earnings'), (4) _MODE_TO_SOURCES-Mapping + DB constraint implications identified. R1-Refactor applied: Step 4b "DB constraint verification" added as own sub-section — if a CHECK-Constraint / PG-ENUM limits the value-range, a constants-edit alone is ineffective.
Overview
A Python constants list that covers DB-values must be derived from the DB-values, not from memory.
When you write _KNOWN_X = {...}, VALID_<DIMENSION>, pydantic.Field(regex="^(a|b|c)$"), or a status-enum validator, that is a contract with the database. If the list deviates from the real value-space:
- False-positive: typo values slip through ("shadow" gets accepted even though nobody inserts that)
- False-negative: real values get warned / rejected ("manual" triggers
unknown source warning even though it's legitimate)
- cross-table drift: columns of the same name exist in multiple tables with different value-spaces — Python side mixes them accidentally
Skill = discipline: grep -rn "INSERT INTO <table>" + all <column> = setters BEFORE the constant is written.
This maxim is the definition-side variant of the maxim "avoid schema-drift": not only must the columns exist, but the value-ranges must also align with the code side.
When to use
Trigger phrases (you would say right now):
- "maintain / extend the _KNOWN_X list"
- "define valid_phase_set / valid_states"
- "build pydantic validator for "
- "filter-allowlist for UI / API"
- "new constants for DIMENSION X"
- "enum-class for "
- "allowed-values for "
Symptom-Trigger (you are investigating an existing skill):
- "Value X is silently accepted even though nobody inserts X" → grep INSERTs
- "Value Y triggers
unknown source-warning but is in code as a setter" → grep INSERTs + setters
- "Cohort A vs B from DB" → check whether both cohorts use the same value-vocabulary
High-risk markers:
- The column has the same name in multiple tables (e.g.
mode in system_phase AND virtual_trades AND signals_log)
- The column is type
text instead of enum — PG does not help
- Values are written in Python code at multiple locations (multiple services, multiple workers)
- Code has a
_KNOWN_X set OR a pydantic validator OR a UI dropdown on the same column
- Replay-mock setter differs from live setter
When NOT to use
- Greenfield table: no INSERT exists, you are defining the values right now. Then Constants → Migration → Setter, in that order
- Typed PostgreSQL ENUM (
CREATE TYPE foo AS ENUM ('a', 'b', 'c')): \d <table> shows the list completely + DB already rejects unknown values
- Purely internal Python constants without DB context (UI-theme-names, in-memory cache keys)
- Single-writer pattern with code lock (only one class may insert + it uses the constants list — validators are co-located)
The 4-Step Insert-Grep Flow
Step 1 — Identify table + column explicitly
Before the grep, write down:
- Table: e.g.
virtual_trades
- Column: e.g.
source
- Suspected value list: e.g.
{"live", "training", "shadow"}
- Assumption about disambiguation: are there same-named columns in other tables? (risk check)
Step 2 — Three grep passes for INSERTs + Setters + UPDATEs
# Pass 1: INSERT statements (all INSERTs touching virtual_trades)
grep -rn "INSERT INTO virtual_trades" --include="*.py" | head -50
# Pass 2: Setter lines (column = value or dict-style)
grep -rn "\.source\s*=\s*['\"]" --include="*.py" \
| grep -E "(virtual_trade|vt|trade)" \
| head -50
# Pass 3: UPDATE statements
grep -rn "UPDATE virtual_trades SET" --include="*.py" | grep "source"
# Pass 4 (cross-table check): same column-name in other tables
grep -rn "['\"]source['\"]" --include="*.sql" | head -20
grep -rn "\.source\s*=" --include="*.py" | head -20 # without table filter
Step 3 — Distill value-set from hits
Sort each hit:
| Value |
Source |
Really used? |
Similar-but-different? |
'live' |
services/live_dispatcher.py:42 |
✅ yes |
— |
'training' |
services/training_runner.py:104 |
✅ yes |
— |
'manual' |
cli/manual_trade.py:67 |
✅ yes |
— |
'replay' |
scripts/replay_session.py:88 |
✅ yes |
— |
'shadow' |
services/system_phase.py:21 (sets system_phase.mode!) |
❌ wrong table |
belongs to system_phase.mode, not virtual_trades.source |
Step 4 — Define constants correctly with cross-table disambiguation
# WRONG (mixes two tables):
_KNOWN_SOURCES = {"live", "training", "shadow"} # 'shadow' does not belong here
# RIGHT (one per table/column, documented):
# virtual_trades.source — values from INSERT-grep
_KNOWN_TRADE_SOURCES = {"live", "training", "manual", "replay"}
# system_phase.mode — separate set
_KNOWN_PHASE_MODES = {"live", "training", "shadow"}
In the validator or logger-warning:
- Use
_KNOWN_TRADE_SOURCES for virtual_trades.source
- Use
_KNOWN_PHASE_MODES for system_phase.mode
- Never mix
Step 4b — DB constraint verification (R1-Refactor)
If the column in the DB is constrained by a CHECK constraint, a PG ENUM type definition, or a foreign-key lookup table, the constants-edit alone is ineffective — new values will be rejected by the DB engine with CheckViolation or InvalidTextRepresentation.
# CHECK constraint on the column?
psql -c "\d+ virtual_trades" | grep -A1 "Check constraints"
# If ENUM type:
psql -c "\dT+ source_type" # shows the enum values
# If FK lookup:
psql -c "SELECT * FROM source_lookup;"
With a limiting DB constraint: requires additional migration BEFORE the Python constants edit:
-- Example: extend CHECK constraint
ALTER TABLE virtual_trades DROP CONSTRAINT IF EXISTS virtual_trades_source_check;
ALTER TABLE virtual_trades ADD CONSTRAINT virtual_trades_source_check
CHECK (source IN ('live', 'training', 'manual', 'replay', 'real', 'paper'));
-- Example: extend PG ENUM (PG13+)
ALTER TYPE source_type ADD VALUE 'paper';
Order: DB-Migration → Python-Constants-Update → Setter-Code → Test. Reversed, it crashes on the first real INSERT.
Quick Reference
| Constants type |
Grep pattern (example) |
_KNOWN_X = {...} |
grep -rn "INSERT INTO <table>" + grep -rn "\.<col>\s*=" |
| `pydantic regex='^(a |
b)$'` |
class XEnum(str, Enum) |
same plus grep "class.*Enum" for existing Enums |
| UI dropdown options |
same plus grep "options=\[" --include="*.ts,*.py" |
Anti-Patterns
| Anti-Pattern |
Lesson |
Copying _KNOWN_X from spec/docs without grep |
Spec drifts, code does not — Single Source of Truth is INSERT |
| "I know the 3 values from memory" |
Real case: 3 of 5 values were wrong (typo shadow + missing manual/replay) |
| Column name as disambiguation sufficient |
mode exists in system_phase AND signals_log AND virtual_trades — same-name ≠ same value-space |
| Validators without table suffix |
_KNOWN_SOURCES is ambiguous; _KNOWN_TRADE_SOURCES + _KNOWN_PHASE_MODES are explicit |
| Value list in a single file instead of central |
Each new source lands with only one maintainer → drift guaranteed. One validators module per DB column |
Cost of Skipping (real)
Real-world Phase-5-Re-Review (Schema-Drift-Sweep):
_KNOWN_SOURCES = {"live", "training", "shadow"} from memory
- Reality (clarified by INSERT-grep):
virtual_trades.source actually had {"live", "training", "manual", "replay"} (no shadow)
shadow was a system_phase.mode value — different table
- Consequence before fix:
manual + replay triggered silent unknown source warnings (filling logs), shadow typo would have been wrongly accepted
- Fix: two separate constants-sets per table
Pattern: same-named columns in different tables with different value-ranges are one of the most common drift sources. Python side not from memory — from the INSERT.
Red Flags — STOP and grep
- You are writing
_KNOWN_<DIMENSION> or a pydantic validator
- Your value list comes from memory / from spec / from old docs
- The column might exist in multiple tables
- You have not established a validators convention per table/column
All mean: 3 grep passes (INSERT, Setter, UPDATE) + cross-table check, then constants per table/column named explicitly.
Cross-References
- COMPLEMENT (read side):
enum-value-discovery-before-sql-where — same pain from SQL WHERE perspective
- COMPLEMENT:
schema-verify-via-information-schema — verifies that the column even exists
- COMPLEMENT:
silent-except-hides-schema-drift — the except Exception: x = [] pattern hides these drift bugs
- maxim: "Single Source of Truth — hardcoded defaults are ticking bombs"
Background: TDD progress (Bulletproofing Log)
Cycle 1 — strong pass with R1 refactor
RED subagent (without skill, scenario "Extend _KNOWN_SOURCES with 'paper' for paper-trading mode"): Reacted heuristically correct from prior pattern ("grep first"), but without repo access — gave commands instead of executing them. Self-critique listed 7 points (no concrete verification, ignored migration history, did not mention test fixtures, overlooked logging downstream, did not check naming convention, did not search user-specific notes, did not directly answer "is that enough?").
GREEN subagent (with skill): Executed 18 Bash tool uses in the real production repo your-app/ and delivered 4 substantial findings:
- Code-state drift:
_KNOWN_SOURCES is currently {"training", "live", "backtest", "manual", "replay"} — NOT the list claimed in the scenario. A recent Phase-5-Re-Review hotfix had already happened.
- Outstanding tech-debt discovered:
ml/real_trade_bridge.py:142 writes source='real' into virtual_trades, but it is missing from _KNOWN_SOURCES → silent unknown source: real warnings.
- cross-table false positives correctly rejected:
'optimizer', 'av_earnings', 'combo_optimizer' → other tables (strategy_params.source, etc.), do NOT belong in virtual_trades.source set.
_MODE_TO_SOURCES-Mapping + DB constraint implication: When system_phase.mode='paper' triggers, additionally _MODE_TO_SOURCES AND possibly PG-ENUM/CHECK-Constraint must be extended — otherwise the first SET mode='paper' attempt crashes.
R1 Refactor applied: Step 4b "DB constraint verification" added as own sub-section with code examples for CHECK constraint update, PG ENUM extension, FK lookup insert. Order documented explicitly: DB-Migration → Python-Constants → Setter → Test.
Avoided Anti-Pattern: GREEN explicitly noted that the obvious answer "Yes, just add 'paper'" would have produced 4 bugs: (a) misses the recent hotfix, (b) leaves 'real' missing, (c) cements 'shadow' cross-table error, (d) lets DB constraint crash.
Cycle-2 Backlog (Polish, non-blocking)
- Test pattern for completeness check: Test that compares
_KNOWN_X against _MODE_TO_X mapping (every mode value must be in sources set). GREEN suggested this.
- CWD-mismatch hint for subagents: make repo path explicit when CWD is not the production repo.
- DB live verification as optional Step 4c:
SELECT source, COUNT(*) FROM <table> GROUP BY source for existing-values audit. Complementary to Step 2 INSERT-grep.
- Cross-Reference:
schema-use-case-mismatch-detection as complement when DB-side value-range is limited.
1---2name: enum-known-values-via-insert-grep3description: Use BEFORE writing or editing a Python-side constants/enum/validator-set that should match a DB-column's real value-space — `_KNOWN_X = {...}`, `VALID_<DIMENSION> = frozenset(...)`, `class XStatus(str, Enum)`, `pydantic.Field(..., regex='^(a|b|c)$')`, in-app filter-allowlists. STOP and grep ALL `INSERT INTO <table>` + ALL `<table>.<column> = ...` setter-lines + ALL UPDATE-statements that touch the column BEFORE deciding the value-set in Python. Trigger when phrases like "maintain the _KNOWN_SOURCES list", "define valid_phase_set", "build pydantic validator for column", "filter-allowlist for UI", "value X is silently accepted", "value Y is wrongly rejected" appear. Method: grep INSERT/setter/UPDATE → verify actual values → disambiguate table/column/mode-field. Do NOT load for greenfield-tables (no INSERTs exist yet), typed-Postgres-ENUMs (`\d` shows the list), or purely internal Python constants without DB context.4---56# Enum Known-Values via INSERT-Grep78> ✅ **PROMOTED** — TDD Cycle 1 **strong pass**. RED subagent reacted heuristically correct ("grep first") but without concrete verification at a real repo (7 self-critique points). GREEN subagent executed **18 Bash tool uses** in a real production domain repo and delivered substantial findings that would not have been reached without the skill: (1) current `_KNOWN_SOURCES` is already different from what the scenario assumed (recent hotfix), (2) missing productive value `'real'` from `ml/real_trade_bridge.py:142` — would silently trigger `unknown source: real`-warnings for weeks, (3) cross-table false positives explicitly rejected (`'optimizer'`, `'manual'@strategy_params`, `'av_earnings'`), (4) `_MODE_TO_SOURCES`-Mapping + DB constraint implications identified. **R1-Refactor applied**: Step 4b "DB constraint verification" added as own sub-section — if a CHECK-Constraint / PG-ENUM limits the value-range, a constants-edit alone is ineffective.910## Overview1112**A Python constants list that covers DB-values must be derived from the DB-values, not from memory.**1314When you write `_KNOWN_X = {...}`, `VALID_<DIMENSION>`, `pydantic.Field(regex="^(a|b|c)$")`, or a status-enum validator, that is a **contract with the database**. If the list deviates from the real value-space:1516- **False-positive**: typo values slip through ("shadow" gets accepted even though nobody inserts that)17- **False-negative**: real values get warned / rejected ("manual" triggers `unknown source` warning even though it's legitimate)18- **cross-table drift**: columns of the same name exist in multiple tables with different value-spaces — Python side mixes them accidentally1920Skill = discipline: **`grep -rn "INSERT INTO <table>"` + all `<column> =` setters BEFORE the constant is written.**2122This maxim is the definition-side variant of the maxim "avoid schema-drift": not only must the columns exist, but the value-ranges must also align with the code side.2324## When to use2526**Trigger phrases (you would say right now)**:27- "maintain / extend the _KNOWN_X list"28- "define valid_phase_set / valid_states"29- "build pydantic validator for <column>"30- "filter-allowlist for UI / API"31- "new constants for DIMENSION X"32- "enum-class for <column>"33- "allowed-values for <field>"3435**Symptom-Trigger** (you are investigating an existing skill):36- "Value X is silently accepted even though nobody inserts X" → grep INSERTs37- "Value Y triggers `unknown source`-warning but is in code as a setter" → grep INSERTs + setters38- "Cohort A vs B from DB" → check whether both cohorts use the same value-vocabulary3940**High-risk markers**:41- The column has the **same name in multiple tables** (e.g. `mode` in `system_phase` AND `virtual_trades` AND `signals_log`)42- The column is **type `text`** instead of `enum` — PG does not help43- Values are written in Python code at **multiple locations** (multiple services, multiple workers)44- Code has a `_KNOWN_X` set OR a pydantic validator OR a UI dropdown on the same column45- Replay-mock setter differs from live setter4647## When NOT to use4849- **Greenfield table**: no INSERT exists, you are **defining** the values right now. Then Constants → Migration → Setter, in that order50- **Typed PostgreSQL ENUM** (`CREATE TYPE foo AS ENUM ('a', 'b', 'c')`): `\d <table>` shows the list completely + DB already rejects unknown values51- **Purely internal Python constants** without DB context (UI-theme-names, in-memory cache keys)52- **Single-writer pattern** with code lock (only one class may insert + it uses the constants list — validators are co-located)5354## The 4-Step Insert-Grep Flow5556### Step 1 — Identify table + column explicitly5758Before the grep, write down:59- **Table**: e.g. `virtual_trades`60- **Column**: e.g. `source`61- **Suspected value list**: e.g. `{"live", "training", "shadow"}`62- **Assumption about disambiguation**: are there **same-named columns in other tables**? (risk check)6364### Step 2 — Three grep passes for INSERTs + Setters + UPDATEs6566```bash67# Pass 1: INSERT statements (all INSERTs touching virtual_trades)68grep -rn "INSERT INTO virtual_trades" --include="*.py" | head -506970# Pass 2: Setter lines (column = value or dict-style)71grep -rn "\.source\s*=\s*['\"]" --include="*.py" \72 | grep -E "(virtual_trade|vt|trade)" \73 | head -507475# Pass 3: UPDATE statements76grep -rn "UPDATE virtual_trades SET" --include="*.py" | grep "source"7778# Pass 4 (cross-table check): same column-name in other tables79grep -rn "['\"]source['\"]" --include="*.sql" | head -2080grep -rn "\.source\s*=" --include="*.py" | head -20 # without table filter81```8283### Step 3 — Distill value-set from hits8485Sort each hit:8687| Value | Source | Really used? | Similar-but-different? |88|---|---|---|---|89| `'live'` | `services/live_dispatcher.py:42` | ✅ yes | — |90| `'training'` | `services/training_runner.py:104` | ✅ yes | — |91| `'manual'` | `cli/manual_trade.py:67` | ✅ yes | — |92| `'replay'` | `scripts/replay_session.py:88` | ✅ yes | — |93| `'shadow'` | `services/system_phase.py:21` (sets `system_phase.mode`!) | ❌ wrong table | belongs to `system_phase.mode`, not `virtual_trades.source` |9495### Step 4 — Define constants correctly with cross-table disambiguation9697```python98# WRONG (mixes two tables):99_KNOWN_SOURCES = {"live", "training", "shadow"} # 'shadow' does not belong here100101# RIGHT (one per table/column, documented):102# virtual_trades.source — values from INSERT-grep103_KNOWN_TRADE_SOURCES = {"live", "training", "manual", "replay"}104105# system_phase.mode — separate set106_KNOWN_PHASE_MODES = {"live", "training", "shadow"}107```108109In the validator or logger-warning:110- Use `_KNOWN_TRADE_SOURCES` for `virtual_trades.source`111- Use `_KNOWN_PHASE_MODES` for `system_phase.mode`112- Never mix113114### Step 4b — DB constraint verification (R1-Refactor)115116**If the column in the DB is constrained by a `CHECK` constraint, a PG `ENUM` type definition, or a foreign-key lookup table, the constants-edit alone is ineffective** — new values will be rejected by the DB engine with `CheckViolation` or `InvalidTextRepresentation`.117118```bash119# CHECK constraint on the column?120psql -c "\d+ virtual_trades" | grep -A1 "Check constraints"121122# If ENUM type:123psql -c "\dT+ source_type" # shows the enum values124125# If FK lookup:126psql -c "SELECT * FROM source_lookup;"127```128129**With a limiting DB constraint**: requires additional migration **BEFORE** the Python constants edit:130131```sql132-- Example: extend CHECK constraint133ALTER TABLE virtual_trades DROP CONSTRAINT IF EXISTS virtual_trades_source_check;134ALTER TABLE virtual_trades ADD CONSTRAINT virtual_trades_source_check135 CHECK (source IN ('live', 'training', 'manual', 'replay', 'real', 'paper'));136137-- Example: extend PG ENUM (PG13+)138ALTER TYPE source_type ADD VALUE 'paper';139```140141Order: **DB-Migration → Python-Constants-Update → Setter-Code → Test**. Reversed, it crashes on the first real INSERT.142143## Quick Reference144145| Constants type | Grep pattern (example) |146|---|---|147| `_KNOWN_X = {...}` | `grep -rn "INSERT INTO <table>" + grep -rn "\.<col>\s*="` |148| `pydantic regex='^(a|b)$'` | same plus `grep "<col>:.*=" --include="*.py"` |149| `class XEnum(str, Enum)` | same plus `grep "class.*Enum"` for existing Enums |150| UI dropdown options | same plus `grep "options=\[" --include="*.ts,*.py"` |151152## Anti-Patterns153154| Anti-Pattern | Lesson |155|---|---|156| Copying `_KNOWN_X` from spec/docs without grep | Spec drifts, code does not — Single Source of Truth is INSERT |157| "I know the 3 values from memory" | Real case: 3 of 5 values were wrong (typo `shadow` + missing `manual`/`replay`) |158| Column name as disambiguation sufficient | `mode` exists in `system_phase` AND `signals_log` AND `virtual_trades` — same-name ≠ same value-space |159| Validators without table suffix | `_KNOWN_SOURCES` is ambiguous; `_KNOWN_TRADE_SOURCES` + `_KNOWN_PHASE_MODES` are explicit |160| Value list in a single file instead of central | Each new source lands with only one maintainer → drift guaranteed. **One** validators module per DB column |161162## Cost of Skipping (real)163164**Real-world Phase-5-Re-Review** (Schema-Drift-Sweep):165- `_KNOWN_SOURCES = {"live", "training", "shadow"}` from memory166- Reality (clarified by INSERT-grep): `virtual_trades.source` actually had `{"live", "training", "manual", "replay"}` (no `shadow`)167- `shadow` was a `system_phase.mode` value — different table168- Consequence before fix: `manual` + `replay` triggered silent `unknown source` warnings (filling logs), `shadow` typo would have been wrongly accepted169- Fix: two separate constants-sets per table170171**Pattern**: same-named columns in different tables with different value-ranges are one of the most common drift sources. Python side not from memory — from the INSERT.172173## Red Flags — STOP and grep174175- You are writing `_KNOWN_<DIMENSION>` or a pydantic validator176- Your value list comes from memory / from spec / from old docs177- The column might exist in multiple tables178- You have not established a validators convention per table/column179180**All mean: 3 grep passes (INSERT, Setter, UPDATE) + cross-table check, then constants per table/column named explicitly.**181182## Cross-References183184- **COMPLEMENT (read side)**: `enum-value-discovery-before-sql-where` — same pain from SQL WHERE perspective185- **COMPLEMENT**: `schema-verify-via-information-schema` — verifies that the column even exists186- **COMPLEMENT**: `silent-except-hides-schema-drift` — the `except Exception: x = []` pattern hides these drift bugs187- maxim: "Single Source of Truth — hardcoded defaults are ticking bombs"188189## Background: TDD progress (Bulletproofing Log)190191### Cycle 1 — strong pass with R1 refactor192193- **RED subagent** (without skill, scenario "Extend _KNOWN_SOURCES with 'paper' for paper-trading mode"): Reacted heuristically correct from prior pattern ("grep first"), but **without repo access** — gave commands instead of executing them. Self-critique listed 7 points (no concrete verification, ignored migration history, did not mention test fixtures, overlooked logging downstream, did not check naming convention, did not search user-specific notes, did not directly answer "is that enough?").194195- **GREEN subagent** (with skill): **Executed 18 Bash tool uses** in the real production repo `your-app/` and delivered 4 substantial findings:196 1. **Code-state drift**: `_KNOWN_SOURCES` is currently `{"training", "live", "backtest", "manual", "replay"}` — NOT the list claimed in the scenario. A recent Phase-5-Re-Review hotfix had already happened.197 2. **Outstanding tech-debt discovered**: `ml/real_trade_bridge.py:142` writes `source='real'` into `virtual_trades`, but it is missing from `_KNOWN_SOURCES` → silent `unknown source: real` warnings.198 3. **cross-table false positives correctly rejected**: `'optimizer'`, `'av_earnings'`, `'combo_optimizer'` → other tables (`strategy_params.source`, etc.), do NOT belong in `virtual_trades.source` set.199 4. **`_MODE_TO_SOURCES`-Mapping + DB constraint implication**: When `system_phase.mode='paper'` triggers, additionally `_MODE_TO_SOURCES` AND possibly PG-ENUM/CHECK-Constraint must be extended — otherwise the first `SET mode='paper'` attempt crashes.200201- **R1 Refactor applied**: Step 4b "DB constraint verification" added as own sub-section with code examples for CHECK constraint update, PG ENUM extension, FK lookup insert. Order documented explicitly: DB-Migration → Python-Constants → Setter → Test.202203- **Avoided Anti-Pattern**: GREEN explicitly noted that the obvious answer "Yes, just add 'paper'" would have produced 4 bugs: (a) misses the recent hotfix, (b) leaves `'real'` missing, (c) cements `'shadow'` cross-table error, (d) lets DB constraint crash.204205### Cycle-2 Backlog (Polish, non-blocking)2062071. **Test pattern for completeness check**: Test that compares `_KNOWN_X` against `_MODE_TO_X` mapping (every mode value must be in sources set). GREEN suggested this.2082. **CWD-mismatch hint** for subagents: make repo path explicit when CWD is not the production repo.2093. **DB live verification as optional Step 4c**: `SELECT source, COUNT(*) FROM <table> GROUP BY source` for existing-values audit. Complementary to Step 2 INSERT-grep.2104. **Cross-Reference**: `schema-use-case-mismatch-detection` as complement when DB-side value-range is limited.