Add count-aware confidence and database-owned classifier tunables (D-0050) #127

Merged
hannah-vernon merged 1 commit from feature/classifier-count-aware-confidence into dev 2026-09-22 12:33:20 -05:00
Owner

What does this PR do?

Adds count-aware confidence to the deterministic incident classifier and makes the six classifier control values database-owned, Admin-UI editable, and API-exposed (D-0050).

Count-aware confidence. DeterministicIncidentClassifier adds a bounded repeat-volume term to confidence: min(RepeatConfidenceBonusCap, RepeatConfidenceCoefficient * log2(eventCount)), applied only once the incident's event count reaches RepeatConfidenceMinEvents (defaults 4 / 0.08 / 0.30). A high-volume incident can gain confidence without its severity moving; severity stays decoupled.

Database-owned tunables. The six controls (ScoreForFullConfidence, SeverityPerScorePoint, BlockRecommendationScore, RepeatConfidenceMinEvents, RepeatConfidenceCoefficient, RepeatConfidenceBonusCap) live in a single-row classifier_settings store, seeded create-only from ClassifierOptions, edited on /configuration (step-up gated, audited), and hot-refreshed over the Postgres viegard_config_classifier_settings NOTIFY channel. They are exposed read-only at /api/v1/classifier/settings (with a seeded flag that falls back to code options until seeded). The already database-owned policy thresholds are now also exposed at /api/v1/policy/thresholds.

No related issue.

How was this tested?

  • dotnet build - 0 errors, 0 warnings (Viegard.slnx)
  • dotnet test - all pass (Application 536/536, AdminApi 201/201, Postgres integration 82/82)
  • Manually tested on a local, disposable in-memory instance

End-to-end render check against a disposable in-memory instance (no real installation or database touched):

  • App started with no startup exception (the two new GET endpoints route without a 500).
  • GET /api/v1/classifier/settings returned seeded=false with the code-option fallback values, then seeded=true with the submitted values after editing and saving on /configuration.
  • GET /api/v1/policy/thresholds returned the threshold values.
  • The /configuration classifier section rendered all six inputs; the edit round-trip persisted and audited.
  • No exceptions in the server log during rendering.

Postgres integration tests were also run against a disposable Postgres 17 container (the per-test truncate list now includes classifier_settings to keep test isolation).

Checklist

  • I have read the Contributing Guide
  • Changes are focused - one logical change per PR
  • Documentation updated (DECISIONS.md D-0050, AGENT-README.md, ARCHITECTURE.md, TODO.md, docs/read-only-api.md)
  • New dependencies are MIT/Apache-2.0/BSD, security-vetted, and recorded in THIRD-PARTY-NOTICES.md (no new dependencies)
  • No secrets, credentials, or real infrastructure identifiers in the diff
  • No commented-out code or debug leftovers
## What does this PR do? Adds count-aware confidence to the deterministic incident classifier and makes the six classifier control values database-owned, Admin-UI editable, and API-exposed (D-0050). **Count-aware confidence.** `DeterministicIncidentClassifier` adds a bounded repeat-volume term to confidence: `min(RepeatConfidenceBonusCap, RepeatConfidenceCoefficient * log2(eventCount))`, applied only once the incident's event count reaches `RepeatConfidenceMinEvents` (defaults 4 / 0.08 / 0.30). A high-volume incident can gain confidence without its severity moving; severity stays decoupled. **Database-owned tunables.** The six controls (`ScoreForFullConfidence`, `SeverityPerScorePoint`, `BlockRecommendationScore`, `RepeatConfidenceMinEvents`, `RepeatConfidenceCoefficient`, `RepeatConfidenceBonusCap`) live in a single-row `classifier_settings` store, seeded create-only from `ClassifierOptions`, edited on `/configuration` (step-up gated, audited), and hot-refreshed over the Postgres `viegard_config_classifier_settings` NOTIFY channel. They are exposed read-only at `/api/v1/classifier/settings` (with a `seeded` flag that falls back to code options until seeded). The already database-owned policy thresholds are now also exposed at `/api/v1/policy/thresholds`. No related issue. ## How was this tested? - [x] `dotnet build` - 0 errors, 0 warnings (`Viegard.slnx`) - [x] `dotnet test` - all pass (Application 536/536, AdminApi 201/201, Postgres integration 82/82) - [x] Manually tested on a local, disposable in-memory instance End-to-end render check against a disposable in-memory instance (no real installation or database touched): - App started with no startup exception (the two new GET endpoints route without a 500). - `GET /api/v1/classifier/settings` returned `seeded=false` with the code-option fallback values, then `seeded=true` with the submitted values after editing and saving on `/configuration`. - `GET /api/v1/policy/thresholds` returned the threshold values. - The `/configuration` classifier section rendered all six inputs; the edit round-trip persisted and audited. - No exceptions in the server log during rendering. Postgres integration tests were also run against a disposable Postgres 17 container (the per-test truncate list now includes `classifier_settings` to keep test isolation). ## Checklist - [x] I have read the [Contributing Guide](../CONTRIBUTING.md) - [x] Changes are focused - one logical change per PR - [x] Documentation updated (DECISIONS.md D-0050, AGENT-README.md, ARCHITECTURE.md, TODO.md, docs/read-only-api.md) - [x] New dependencies are MIT/Apache-2.0/BSD, security-vetted, and recorded in THIRD-PARTY-NOTICES.md (no new dependencies) - [x] No secrets, credentials, or real infrastructure identifiers in the diff - [x] No commented-out code or debug leftovers
Add a bounded repeat-volume term to the deterministic classifier's
confidence so a high-volume incident (for example a repeated login
brute force whose events collapse to one evidence item) can reach the
action-confidence gate without its severity moving.  The bonus is
min(RepeatConfidenceBonusCap, RepeatConfidenceCoefficient * log2(count))
applied only at or above RepeatConfidenceMinEvents (defaults 4/0.08/0.30);
severity is unchanged and stays decoupled from the repeat term.

Move the six classifier control values (ScoreForFullConfidence,
SeverityPerScorePoint, BlockRecommendationScore, RepeatConfidenceMinEvents,
RepeatConfidenceCoefficient, RepeatConfidenceBonusCap) into a single-row
classifier_settings table: settings record + validator, IClassifierSettingsStore
with in-memory and Postgres stores (NOTIFY channel
viegard_config_classifier_settings), ClassifierSettingsSource snapshot with
code-options fallback until seeded, seed + refresh workers, EF migration,
step-up-gated audited write on /configuration, and a read-only
GET /api/v1/classifier/settings endpoint.  Expose the already database-owned
policy thresholds at GET /api/v1/policy/thresholds.

Tests: admin endpoint persist/audit/invalid/conflict, read-only API seeded
and unseeded-fallback shapes for both endpoints, and a Postgres integration
test for the classifier store (create/update/conflict/notify + seed-once).
Docs: DECISIONS.md D-0050, AGENT-README.md, ARCHITECTURE.md, TODO.md.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
hannah-vernon/viegard-sentinel!127
No description provided.