MemberJunction / MemberJunction/MJ
CodeGen's new validator count is pre-dedup, so it roughly doubles on AI-enabled runs
- Dominant language
- TSQL
- Stars
- 29
- Forks
- 6
- Avg merge
- 2d 1h
- Merged PRs (30d)
- 323
Description
## What happens
#4372 added a validator count to CodeGen's load line, so a zero-load run is visible instead of indistinguishable from a healthy one ([`runCodeGen.ts:504`](https://github.com/MemberJunction/MJ/blob/next/packages/CodeGenLib/src/runCodeGen.ts#L504)):
```ts
const loadedValidators = ManageMetadataBase.generatedValidators.length;
succeedSpinner(`AI Generated Code loaded from Metadata (${loadedValidators} validator${loadedValidators === 1 ? '' : 's'})`);
```
`generatedValidators` is the raw backing array, and on an **AI-enabled** full run the same validator is pushed into it twice:
1. `manageMetadata`'s pass (`manage-metadata.ts:4375`, `skipDBUpdate = false` → `generateNewCode = true`). When the persisted `GeneratedCode` record's constraint text matches, `generateValidatorFunctionFromCheckConstraint` returns it early without calling the LLM — and pushes.
2. `loadGeneratedCode` (`runCodeGen.ts:493`) — pushes the same record again.
Deduplication happens later, in `GenerateValidateFunction`, keyed on `functionName` over a deterministic sort. The emitted output is correct; only the printed figure is inflated.
## Impact
Cosmetic, and confined to the AI path:
- On `--no-ai` the count is exact — CI just printed `(116 validators)`, matching the 116 → 56 figures in #4372's verification.
- On a full AI run the number will read roughly double for the same database.
The double-push predates #4372; that PR neither introduced nor worsened it. This is only worth fixing because the number is new and its entire purpose is diagnostic accuracy: someone comparing a local AI run against a CI run sees two different counts for one database and has no way to tell which is lying.
## Fix
Either count distinct function names:
```ts
const loadedValidators = new Set(ManageMetadataBase.generatedValidators.map(v => v.functionName)).size;
```
or leave the figure and say in the message that it is pre-dedup.
## Origin
Found reviewing #4372.
Contributor guide
Research direction
Start at packages/CodeGenLib/src/runCodeGen.ts:493-504 and trace the validator population through manage-metadata.ts:4375 and GenerateValidateFunction. Compare the displayed count with the deduplicated validator output on AI-enabled and --no-ai runs, then verify the diagnostic message reports the same logical validators in both paths.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 88/100