|
| 1 | +"""Internal release-gate matrix for selected Rust-backed provider paths.""" |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +from dataclasses import dataclass |
| 6 | +from typing import Final |
| 7 | + |
| 8 | +RUST_KERNEL_MODE_ROLLBACK: Final = "RUST_KERNEL_MODE=off" |
| 9 | + |
| 10 | +HARD_FAIL_IMPORT_FAILURE: Final = "import_failure" |
| 11 | +HARD_FAIL_CALL_FAILURE: Final = "call_failure" |
| 12 | +HARD_FAIL_INVALID_PAYLOAD: Final = "invalid_payload" |
| 13 | +HARD_FAIL_INVALID_RESPONSE: Final = "invalid_response" |
| 14 | +HARD_FAIL_PARITY_MISMATCH: Final = "parity_mismatch" |
| 15 | + |
| 16 | +REQUIRED_HARD_FAIL_MODES: Final = frozenset( |
| 17 | + { |
| 18 | + HARD_FAIL_IMPORT_FAILURE, |
| 19 | + HARD_FAIL_CALL_FAILURE, |
| 20 | + HARD_FAIL_INVALID_PAYLOAD, |
| 21 | + HARD_FAIL_INVALID_RESPONSE, |
| 22 | + HARD_FAIL_PARITY_MISMATCH, |
| 23 | + } |
| 24 | +) |
| 25 | + |
| 26 | +REQUIRED_CI_GATES: Final = frozenset( |
| 27 | + { |
| 28 | + "python_unit_security_tests", |
| 29 | + "kernel_bridge_smoke_tests", |
| 30 | + "rust_fmt", |
| 31 | + "rust_clippy", |
| 32 | + "rust_tests", |
| 33 | + "rust_wheel_smoke", |
| 34 | + "docker_packaging_smoke", |
| 35 | + "public_release_scan", |
| 36 | + } |
| 37 | +) |
| 38 | + |
| 39 | + |
| 40 | +@dataclass(frozen=True, slots=True) |
| 41 | +class RustKernelReleaseGate: |
| 42 | + """Audit contract for one selected Rust-backed implementation path. |
| 43 | +
|
| 44 | + The runtime switch stays intentionally small: Python owns orchestration and |
| 45 | + public API shape; Rust owns only selected pure kernels/helpers. This matrix |
| 46 | + makes the selected paths and their rollback/fail-closed evidence explicit. |
| 47 | + """ |
| 48 | + |
| 49 | + name: str |
| 50 | + bridge_function: str |
| 51 | + python_owner: str |
| 52 | + rust_owner: str |
| 53 | + rollback: str |
| 54 | + regression_matrix: tuple[str, ...] |
| 55 | + hard_fail_modes: frozenset[str] |
| 56 | + ci_gates: frozenset[str] |
| 57 | + performance_baseline: str |
| 58 | + public_api_change: bool = False |
| 59 | + |
| 60 | + |
| 61 | +SELECTED_RUST_KERNEL_GATES: Final = ( |
| 62 | + RustKernelReleaseGate( |
| 63 | + name="voiceprint_scoring", |
| 64 | + bridge_function="voiceprint_score", |
| 65 | + python_owner="voiceprints.scoring.score_voiceprint_candidates", |
| 66 | + rust_owner="voscript_core::voiceprint::score_voiceprint_candidates", |
| 67 | + rollback=RUST_KERNEL_MODE_ROLLBACK, |
| 68 | + regression_matrix=( |
| 69 | + "raw_cosine_adaptive_threshold", |
| 70 | + "asnorm_active_with_margin_guard", |
| 71 | + "small_cohort_raw_fallback", |
| 72 | + "non_finite_embedding_rejection", |
| 73 | + "db_required_mode_payload_export", |
| 74 | + "db_off_mode_python_scoring", |
| 75 | + ), |
| 76 | + hard_fail_modes=REQUIRED_HARD_FAIL_MODES, |
| 77 | + ci_gates=REQUIRED_CI_GATES, |
| 78 | + performance_baseline="internal_scoring_only_synthetic", |
| 79 | + ), |
| 80 | + RustKernelReleaseGate( |
| 81 | + name="postprocess_segments", |
| 82 | + bridge_function="postprocess_segments", |
| 83 | + python_owner="postprocess.segments.build_result_segments", |
| 84 | + rust_owner="voscript_core::postprocess::build_result_segments", |
| 85 | + rollback=RUST_KERNEL_MODE_ROLLBACK, |
| 86 | + regression_matrix=( |
| 87 | + "word_normalization", |
| 88 | + "adjacent_text_segment_merge", |
| 89 | + "word_payload_merge_block", |
| 90 | + "duplicate_display_name_disambiguation", |
| 91 | + "stable_speaker_label_preservation", |
| 92 | + ), |
| 93 | + hard_fail_modes=REQUIRED_HARD_FAIL_MODES, |
| 94 | + ci_gates=REQUIRED_CI_GATES, |
| 95 | + performance_baseline="internal_postprocess_only_synthetic", |
| 96 | + ), |
| 97 | + RustKernelReleaseGate( |
| 98 | + name="artifact_manifest_contract", |
| 99 | + bridge_function="artifact_manifest_contract", |
| 100 | + python_owner="pipeline.contracts.artifacts.build_artifact_manifest", |
| 101 | + rust_owner="voscript_core::contracts::artifact_manifest_contract", |
| 102 | + rollback=RUST_KERNEL_MODE_ROLLBACK, |
| 103 | + regression_matrix=( |
| 104 | + "public_safe_manifest_build", |
| 105 | + "path_and_url_rejection", |
| 106 | + "legacy_unknown_entry_tolerance", |
| 107 | + "stable_optional_experimental_categories", |
| 108 | + ), |
| 109 | + hard_fail_modes=REQUIRED_HARD_FAIL_MODES, |
| 110 | + ci_gates=REQUIRED_CI_GATES, |
| 111 | + performance_baseline="internal_helper_only_synthetic", |
| 112 | + ), |
| 113 | + RustKernelReleaseGate( |
| 114 | + name="status_payload_contract", |
| 115 | + bridge_function="status_payload_contract", |
| 116 | + python_owner="pipeline.contracts.status.build_status_payload", |
| 117 | + rust_owner="voscript_core::contracts::status_payload_contract", |
| 118 | + rollback=RUST_KERNEL_MODE_ROLLBACK, |
| 119 | + regression_matrix=( |
| 120 | + "known_status_normalization", |
| 121 | + "unknown_legacy_status_to_failed", |
| 122 | + "basename_only_filename", |
| 123 | + "legacy_status_payload_compatibility", |
| 124 | + ), |
| 125 | + hard_fail_modes=REQUIRED_HARD_FAIL_MODES, |
| 126 | + ci_gates=REQUIRED_CI_GATES, |
| 127 | + performance_baseline="internal_helper_only_synthetic", |
| 128 | + ), |
| 129 | +) |
| 130 | + |
| 131 | + |
| 132 | +def release_gate_matrix() -> tuple[RustKernelReleaseGate, ...]: |
| 133 | + """Return the selected Rust-backed release gates as an immutable tuple.""" |
| 134 | + |
| 135 | + return SELECTED_RUST_KERNEL_GATES |
| 136 | + |
| 137 | + |
| 138 | +def validate_release_gate_matrix( |
| 139 | + gates: tuple[RustKernelReleaseGate, ...] = SELECTED_RUST_KERNEL_GATES, |
| 140 | +) -> tuple[str, ...]: |
| 141 | + """Return policy gaps that would block a 0.8.x Rust-backed release.""" |
| 142 | + |
| 143 | + gaps: list[str] = [] |
| 144 | + names: set[str] = set() |
| 145 | + bridge_functions: set[str] = set() |
| 146 | + for gate in gates: |
| 147 | + if gate.name in names: |
| 148 | + gaps.append(f"{gate.name}: duplicate gate name") |
| 149 | + names.add(gate.name) |
| 150 | + if gate.bridge_function in bridge_functions: |
| 151 | + gaps.append(f"{gate.name}: duplicate bridge function") |
| 152 | + bridge_functions.add(gate.bridge_function) |
| 153 | + if not gate.regression_matrix: |
| 154 | + gaps.append(f"{gate.name}: missing regression matrix") |
| 155 | + missing_hard_fail = REQUIRED_HARD_FAIL_MODES.difference(gate.hard_fail_modes) |
| 156 | + if missing_hard_fail: |
| 157 | + gaps.append( |
| 158 | + f"{gate.name}: missing hard-fail modes {sorted(missing_hard_fail)}" |
| 159 | + ) |
| 160 | + missing_ci = REQUIRED_CI_GATES.difference(gate.ci_gates) |
| 161 | + if missing_ci: |
| 162 | + gaps.append(f"{gate.name}: missing CI gates {sorted(missing_ci)}") |
| 163 | + if gate.rollback != RUST_KERNEL_MODE_ROLLBACK: |
| 164 | + gaps.append(f"{gate.name}: rollback must be {RUST_KERNEL_MODE_ROLLBACK}") |
| 165 | + if gate.public_api_change: |
| 166 | + gaps.append(f"{gate.name}: public API change is not allowed in 0.8.4") |
| 167 | + return tuple(gaps) |
| 168 | + |
| 169 | + |
| 170 | +__all__ = [ |
| 171 | + "HARD_FAIL_CALL_FAILURE", |
| 172 | + "HARD_FAIL_IMPORT_FAILURE", |
| 173 | + "HARD_FAIL_INVALID_PAYLOAD", |
| 174 | + "HARD_FAIL_INVALID_RESPONSE", |
| 175 | + "HARD_FAIL_PARITY_MISMATCH", |
| 176 | + "REQUIRED_CI_GATES", |
| 177 | + "REQUIRED_HARD_FAIL_MODES", |
| 178 | + "RUST_KERNEL_MODE_ROLLBACK", |
| 179 | + "RustKernelReleaseGate", |
| 180 | + "SELECTED_RUST_KERNEL_GATES", |
| 181 | + "release_gate_matrix", |
| 182 | + "validate_release_gate_matrix", |
| 183 | +] |
0 commit comments