Skip to content

feat(research): add episode density-contrast gate - #123

Merged
stacknil merged 3 commits into
mainfrom
stacknil/v07-density-contrast-diagnostic
Aug 28, 2026
Merged

feat(research): add episode density-contrast gate#123
stacknil merged 3 commits into
mainfrom
stacknil/v07-density-contrast-diagnostic

Conversation

@stacknil

Copy link
Copy Markdown
Owner

Summary

  • add a pure research diagnostic that requires every adjacent selected-window bridge mean gap to be at least 2x the larger internal mean gap
  • use exact integer-microsecond Fraction arithmetic, binary-search bridge counts, and fail-closed candidate validation
  • lock dense-peak, uniform-background, single-selection, invalid-ratio, and permutation controls; record the evidence boundary in the ADR

Why

Candidate v1 can split a uniform threshold-rate stream into two episodes, so episode multiplication alone does not prove two dense peaks.

Hypothesis: a 2x mean-gap contrast separates the existing continuous two-peak fixture from the known uniform-background false split.

Decision rule:

  • accept this diagnostic as a candidate-v2 research prerequisite only if the dense fixture passes, the uniform control fails, and the single-selection case remains valid
  • stop after those positive, negative, single, and invalid-input controls; do not sweep cadence values

Observed bounded evidence:

  • continuous two peaks: 30 s internal means, 540 s bridge mean, 18x contrast
  • uniform background: 150 s internal means, 150 s bridge mean, 1x contrast

Design decision

Keep candidate selection unchanged and evaluate its selected windows through a separate research-only diagnostic. Pair comparison is:

bridge_mean_gap >= 2 * max(left_internal_mean_gap, right_internal_mean_gap)

This is not wired into Detector::analyze(), the CLI, or loglens.report.v3.

How to validate

python -m unittest tests.test_episode_candidate_core
python -m unittest discover -s tests -p 'test_episode*.py'
python -m ruff check scripts tests
cmake --build build --config Debug --target ALL_BUILD -- /m:4 /nr:false /v:q /nologo
ctest --test-dir build -C Debug --output-on-failure
git diff --check origin/main...HEAD
gitleaks detect --source . --no-banner --redact --verbose

Local results:

  • focused core: 9/9 passed
  • episode research suite: 31/31 passed
  • CTest: 7/7 passed
  • Ruff and diff checks: clean
  • Gitleaks: no leaks found
  • mutation control: bypassing the contrast comparison made the uniform-background regression fail

Risk / rollout notes

  • Main risk: 2x is an intentionally uncalibrated research threshold and could over- or under-separate unseen traffic shapes.
  • Compatibility impact: none for stable v0.6 behavior; only research Python, tests, and the ADR change.
  • Complexity: ordered validation and binary-search bridge counts add O(E log E + S log E) diagnostic work.
  • Rollback path: revert the three commits in this PR; no migration or report-schema rollback is required.
  • Non-claim: this does not estimate a real false-positive rate or authorize production adoption.

@stacknil

Copy link
Copy Markdown
Owner Author

Post-CI final diff review completed.

  • Design decision: keep candidate-v1 selection unchanged and expose one pure research-only gap-contrast diagnostic.
  • Main risk: the 2x ratio is not calibrated for production traffic and must not be treated as a production threshold.
  • Compatibility impact: none; Detector::analyze(), CLI behavior, and loglens.report.v3 are unchanged.
  • Rollback path: revert the three semantic commits; no data or schema migration is involved.
  • Evidence: 11/11 remote checks passed; local core 9/9, research 31/31, CTest 7/7, Ruff/diff/Gitleaks clean; mutation bypass was caught by the uniform-background regression.
  • Final review: no blocking review findings, privacy issues, or unrelated production-path changes.

@stacknil
stacknil merged commit ae359e6 into main Aug 28, 2026
11 checks passed
@stacknil
stacknil deleted the stacknil/v07-density-contrast-diagnostic branch August 28, 2026 10:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant