Skip to content

fix(model-comparison): harden casewise numeric trust boundary - #990

Closed
seonghobae wants to merge 6 commits into
mainfrom
fix/model-comparison-casewise-trust-boundary
Closed

seonghobae wants to merge 6 commits into
mainfrom
fix/model-comparison-casewise-trust-boundary

Conversation

@seonghobae

@seonghobae seonghobae commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Advances #608.

Defect

The public compare_nonnested_models() boundary bounded the casewise log-likelihood vectors but still called arbitrary float(item) on each non-boolean element. A caller-controlled __float__ provider or numeric subclass could therefore execute code during Python validation/marshalling before the Rust Vuong kernel.

Test-first lineage

  • 22130c2be0a2300d3fd31a588fcf67705596eb52 — RED public regressions for hostile float providers/subclasses on both loglik_a and loglik_b, plus accepted NumPy scalar compatibility.
  • b0aaeb25a0b89a06aaf131984bc82bfe97f16663 — GREEN: route casewise scalar admission through the existing exact trusted Python/NumPy real-scalar boundary before conversion.
  • 92f2fcacc212cb236b558e88c1c83b37eea20507 — remove an unused test import before hosted validation.
  • 89d1bf01c3cfc7ecb2510a6439934482b9d763a2 — initial changelog trace.
  • Hosted CI at 89d1bf01… exposed two branch-owned integration defects: the new changelog fragment did not use the governed fragment schema, and an older resource-exhaustion test still expected an arbitrary __float__ object to be an accepted conversion path.
  • eab1f43312fec35f677e5cc9087ec0a22ee921b9 — format the fragment with the required level-one title and Fixed section.
  • f59c74f79cd5a37e8c1bd74e1f83a1924a11b508 — preserve explicit MemoryError only for still-accepted iterator creation/iteration callbacks; arbitrary numeric protocols now remain fail-closed without dispatch.

Preserved scientific ownership

Python still only validates, marshals, and orchestrates. The casewise log-likelihood-ratio mean, omega, BIC correction, Vuong z statistic, and two-sided p value remain owned by the compiled Rust path. Formal distinguishability remains a separate fail-closed requirement and this change does not manufacture a model preference.

Exact built-in int/float and the package-supported concrete NumPy integer/float scalar classes remain admitted. Booleans, caller subclasses, and arbitrary conversion providers fail closed without invoking conversion callbacks.

Current integration state

Exact source head f59c74f79cd5a37e8c1bd74e1f83a1924a11b508 is Ready after terminal-success repository CI, Security Scan, CodeQL, and Semgrep on that same SHA, with no formal reviews or unresolved review threads at the Ready transition. Central protected-head review/coverage workflows must evaluate this unchanged head before merge; predecessor-head evidence does not transfer.

Summary by CodeRabbit

  • Bug Fixes
    • Strengthened validation for model-comparison casewise numeric values.
    • Untrusted numeric objects and custom numeric subclasses are now rejected safely without executing conversion callbacks.
    • Non-finite values continue to be rejected.
    • Genuine Python and supported NumPy numeric scalars remain compatible.
    • Vuong statistics and valid numeric results are preserved.

@coderabbitai

coderabbitai Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 3fb36f83-79ca-4e13-99bc-d64e69e2af24

📥 Commits

Reviewing files that changed from the base of the PR and between 04d0bc2 and f59c74f.

📒 Files selected for processing (4)
  • docs/changelog.d/608-model-comparison-casewise-trust-boundary.md
  • python/fast_mlsirm/model_comparison.py
  • tests/test_model_comparison_input_error_boundary.py
  • tests/test_model_comparison_numeric_callback_safety.py

Included review availability: Your plan includes up to 1 review per rolling hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The change hardens casewise model-comparison input validation. Trusted built-in and NumPy real scalars remain supported. Arbitrary float-protocol objects and caller-defined numeric subclasses are rejected without invoking conversion callbacks. Regression tests cover rejection and compatibility behavior.

Changes

Casewise numeric admission

Layer / File(s) Summary
Trusted scalar validation
python/fast_mlsirm/model_comparison.py, docs/changelog.d/608-model-comparison-casewise-trust-boundary.md
_casewise_values validates trusted finite real scalars without generic float() coercion. The changelog records the stricter admission boundary.
Callback safety and compatibility tests
tests/test_model_comparison_numeric_callback_safety.py, tests/test_model_comparison_input_error_boundary.py
Tests verify rejection without executing caller-defined callbacks, genuine NumPy scalar compatibility, forwarded Vuong arguments, and preserved MemoryError behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to f59c7

The change is localized to numeric input validation and its associated tests and changelog; no actionable merge-blocking risk remains after normal checks and review.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: hardening the casewise numeric trust boundary in model comparison.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/model-comparison-casewise-trust-boundary

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@seonghobae
seonghobae marked this pull request as ready for review August 18, 2026 16:22
@seonghobae
seonghobae enabled auto-merge (squash) August 18, 2026 16:23

@opencode-agent opencode-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

OpenCode cannot approve yet because required coverage evidence did not pass.

Review outcome

1. HIGH .github/workflows/opencode-review.yml:1 - Coverage evidence did not prove required test/docstring evidence

  • Problem: The required coverage-evidence job result was failure, so OpenCode cannot establish approval sufficiency for this head.

  • Root cause: Automated approval is only valid when the same-head coverage-evidence job proves supported repository test suites passed and configured docstring gates passed or were advisory, or reports not applicable because no supported source files or package manifests exist. Missing, failed, skipped, unavailable, or unsupported-tooling test evidence is a blocker.

  • Fix: Install or configure the repository test/docstring evidence tooling when source files or package manifests exist, rerun the current-head coverage-evidence job, and approve only after it reports success with required evidence or explicit no-source not-applicable evidence.

  • Regression test: Keep the approval branch checking needs.coverage-evidence.result == success before posting APPROVE, and publish REQUEST_CHANGES when coverage-evidence blocker states such as cancelled, skipped, failed, unsupported-tooling, or below-100 evidence are present.

  • Result: REQUEST_CHANGES

  • Reason: coverage-evidence result was failure, so required test/docstring evidence was not proven for current head f59c74f79cd5a37e8c1bd74e1f83a1924a11b508.

  • Head SHA: f59c74f79cd5a37e8c1bd74e1f83a1924a11b508

  • Workflow run: 32167081903

  • Workflow attempt: 1

Coverage evidence

Coverage evidence job did not run or did not publish coverage evidence.

Changed-File Evidence Map

flowchart LR
  PR["PR changed files"] --> Evidence["OpenCode bounded evidence"]
  Evidence --> S1["Docs: 608-model-comparison-casewise-trust-boundary.md"]
  S1 --> I1["operator or user guidance"]
  I1 --> R1["Review risk: Docs: 608-model-comparison-casewise-trust-boundary.md"]
  R1 --> V1["docs review"]
  Evidence --> S2["Changed file: model_comparison.py"]
  S2 --> I2["repository behavior"]
  I2 --> R2["Review risk: Changed file: model_comparison.py"]
  R2 --> V2["required checks"]
  Evidence --> S3["Test (2 files)"]
  S3 --> I3["regression suite"]
  I3 --> R3["Review risk: Test (2 files)"]
  R3 --> V3["targeted test run"]
Loading

@opencode-agent

Copy link
Copy Markdown
Contributor

OpenCode Review Overview

  • Head SHA: f59c74f79cd5a37e8c1bd74e1f83a1924a11b508
  • Workflow run: 32167081903
  • Workflow attempt: 1
  • Gate result: REQUEST_CHANGES (approval step)

Pull request overview

OpenCode cannot approve yet because required coverage evidence did not pass.

Review outcome

1. HIGH .github/workflows/opencode-review.yml:1 - Coverage evidence did not prove required test/docstring evidence

  • Problem: The required coverage-evidence job result was failure, so OpenCode cannot establish approval sufficiency for this head.

  • Root cause: Automated approval is only valid when the same-head coverage-evidence job proves supported repository test suites passed and configured docstring gates passed or were advisory, or reports not applicable because no supported source files or package manifests exist. Missing, failed, skipped, unavailable, or unsupported-tooling test evidence is a blocker.

  • Fix: Install or configure the repository test/docstring evidence tooling when source files or package manifests exist, rerun the current-head coverage-evidence job, and approve only after it reports success with required evidence or explicit no-source not-applicable evidence.

  • Regression test: Keep the approval branch checking needs.coverage-evidence.result == success before posting APPROVE, and publish REQUEST_CHANGES when coverage-evidence blocker states such as cancelled, skipped, failed, unsupported-tooling, or below-100 evidence are present.

  • Result: REQUEST_CHANGES

  • Reason: coverage-evidence result was failure, so required test/docstring evidence was not proven for current head f59c74f79cd5a37e8c1bd74e1f83a1924a11b508.

  • Head SHA: f59c74f79cd5a37e8c1bd74e1f83a1924a11b508

  • Workflow run: 32167081903

  • Workflow attempt: 1

Coverage evidence

Coverage evidence job did not run or did not publish coverage evidence.

Changed-File Evidence Map

flowchart LR
  PR["PR changed files"] --> Evidence["OpenCode bounded evidence"]
  Evidence --> S1["Docs: 608-model-comparison-casewise-trust-boundary.md"]
  S1 --> I1["operator or user guidance"]
  I1 --> R1["Review risk: Docs: 608-model-comparison-casewise-trust-boundary.md"]
  R1 --> V1["docs review"]
  Evidence --> S2["Changed file: model_comparison.py"]
  S2 --> I2["repository behavior"]
  I2 --> R2["Review risk: Changed file: model_comparison.py"]
  R2 --> V2["required checks"]
  Evidence --> S3["Test (2 files)"]
  S3 --> I3["regression suite"]
  I3 --> R3["Review risk: Test (2 files)"]
  R3 --> V3["targeted test run"]
Loading

@opencode-agent
opencode-agent Bot disabled auto-merge August 18, 2026 19:02

Copy link
Copy Markdown
Contributor Author

@opencode-agent Please re-review the unchanged current exact head f59c74f79cd5a37e8c1bd74e1f83a1924a11b508. The current CHANGES_REQUESTED is the central coverage-evidence failure from run 32167081903; the owning ContextualWisdomLab/.github main has since advanced with the flat-lock/relative-include coverage-tooling repair. Re-evaluate this exact head only, preserve Rust ownership of Vuong/model-comparison arithmetic, and do not transfer the prior failed central evidence.

Copy link
Copy Markdown
Contributor Author

@opencode-agent Please re-review unchanged exact head f59c74f79cd5a37e8c1bd74e1f83a1924a11b508 against the current central coverage implementation. Repository CI, Security Scan, CodeQL, and Semgrep are terminal-success on this SHA, and CodeRabbit reports no actionable current-head findings. The existing formal CHANGES_REQUESTED maps to central run 32167081903, which predates .github main b71a02a310e77f70c1e59f4719f6857cb33ca886 and its trusted-uv/flat-lock correction. Please generate fresh same-head formal evidence rather than carrying forward the superseded central tooling failure.

Copy link
Copy Markdown
Contributor Author

@opencode-agent Please re-review unchanged exact head f59c74f79cd5a37e8c1bd74e1f83a1924a11b508 with the current central workflow. Repository CI, Security Scan, CodeQL, and Semgrep are terminal-success; the only formal REQUEST_CHANGES is prior coverage-evidence infrastructure failure. Reassess the casewise numeric trust boundary and current same-head coverage evidence without carrying that superseded tooling verdict.

Copy link
Copy Markdown
Contributor Author

Superseded by #1009 at identical source SHA f59c74f79cd5a37e8c1bd74e1f83a1924a11b508. Repository CI/Security/CodeQL/Semgrep are terminal-success and no unresolved review threads remain. The formal REQUEST_CHANGES is solely central coverage-evidence run 32167081903; #1009 supplies a fresh current-workflow event without source churn, review dismissal, gate weakening, or force-push. Closing this predecessor unmerged avoids duplicate landing vehicles.

@seonghobae seonghobae closed this Aug 19, 2026
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