Step 551: refine review-gate escalation policy

This commit is contained in:
Bill
2026-02-17 10:21:04 -07:00
parent 08e978d055
commit e8c90df871
4 changed files with 247 additions and 0 deletions

View File

@@ -3838,4 +3838,13 @@ target_link_libraries(step550_test PRIVATE
tree_sitter_javascript tree_sitter_typescript
tree_sitter_java tree_sitter_rust tree_sitter_go)
add_executable(step551_test tests/step551_test.cpp)
target_include_directories(step551_test PRIVATE src)
target_link_libraries(step551_test PRIVATE
nlohmann_json::nlohmann_json
unofficial::tree-sitter::tree-sitter
tree_sitter_python tree_sitter_cpp tree_sitter_elisp
tree_sitter_javascript tree_sitter_typescript
tree_sitter_java tree_sitter_rust tree_sitter_go)
# Step 12: Dear ImGui shell scaffolding created (main.cpp exists but not built due to dependencies)

View File

@@ -0,0 +1,70 @@
#pragma once
// Step 551: Review-Gate Policy Refinement
#include <string>
#include <vector>
struct ReviewGateInput {
bool safetyCritical = false;
bool securitySensitive = false;
bool policyViolationDetected = false;
int confidenceScore = 0; // 0..100
int postApplyFailureStreak = 0;
bool deterministicTemplatePath = false;
bool highCostOverage = false;
};
struct ReviewGateResult {
bool requiresHumanReview = false;
std::string decision; // auto_approve/auto_approve_with_audit/escalate_review/block
std::vector<std::string> reasons;
};
class ReviewGatePolicyRefinement {
public:
static ReviewGateResult evaluate(const ReviewGateInput& input) {
ReviewGateResult out;
if (input.policyViolationDetected) {
out.requiresHumanReview = true;
out.decision = "block";
out.reasons.push_back("policy_violation_detected");
return out;
}
if (input.safetyCritical || input.securitySensitive) {
out.requiresHumanReview = true;
out.decision = "escalate_review";
if (input.safetyCritical) out.reasons.push_back("safety_critical_change");
if (input.securitySensitive) out.reasons.push_back("security_sensitive_change");
return out;
}
if (input.postApplyFailureStreak >= 3) {
out.requiresHumanReview = true;
out.decision = "escalate_review";
out.reasons.push_back("repeated_post_apply_failures");
return out;
}
if (input.confidenceScore >= 85 && input.deterministicTemplatePath && !input.highCostOverage) {
out.requiresHumanReview = false;
out.decision = "auto_approve";
out.reasons.push_back("high_confidence_deterministic_path");
return out;
}
if (input.confidenceScore >= 70 && !input.highCostOverage) {
out.requiresHumanReview = false;
out.decision = "auto_approve_with_audit";
out.reasons.push_back("moderate_confidence_low_risk");
return out;
}
out.requiresHumanReview = true;
out.decision = "escalate_review";
if (input.highCostOverage) out.reasons.push_back("high_cost_overage");
if (input.confidenceScore < 70) out.reasons.push_back("low_confidence");
return out;
}
};

View File

@@ -0,0 +1,132 @@
// Step 551: Review-Gate Policy Refinement (12 tests)
#include "ReviewGatePolicyRefinement.h"
#include <iostream>
static int passed = 0, failed = 0;
#define TEST(name) { std::cout << " " << #name << "... "; }
#define PASS() { std::cout << "PASS\n"; ++passed; }
#define FAIL(msg) { std::cout << "FAIL: " << msg << "\n"; ++failed; }
#define CHECK(cond, msg) if (!(cond)) { FAIL(msg); return; } else {}
static bool hasReason(const ReviewGateResult& r, const std::string& reason) {
for (const auto& x : r.reasons) if (x == reason) return true;
return false;
}
void test_policy_violation_blocks_immediately() {
TEST(policy_violation_blocks_immediately);
auto r = ReviewGatePolicyRefinement::evaluate({false, false, true, 95, 0, true, false});
CHECK(r.requiresHumanReview, "block should still require human review state");
CHECK(r.decision == "block", "policy violation should block");
CHECK(hasReason(r, "policy_violation_detected"), "reason expected");
PASS();
}
void test_safety_critical_requires_review() {
TEST(safety_critical_requires_review);
auto r = ReviewGatePolicyRefinement::evaluate({true, false, false, 95, 0, true, false});
CHECK(r.decision == "escalate_review", "safety-critical should escalate");
CHECK(hasReason(r, "safety_critical_change"), "safety reason expected");
PASS();
}
void test_security_sensitive_requires_review() {
TEST(security_sensitive_requires_review);
auto r = ReviewGatePolicyRefinement::evaluate({false, true, false, 95, 0, true, false});
CHECK(r.decision == "escalate_review", "security-sensitive should escalate");
CHECK(hasReason(r, "security_sensitive_change"), "security reason expected");
PASS();
}
void test_repeated_failures_require_review() {
TEST(repeated_failures_require_review);
auto r = ReviewGatePolicyRefinement::evaluate({false, false, false, 95, 3, true, false});
CHECK(r.decision == "escalate_review", "failure streak should escalate");
CHECK(hasReason(r, "repeated_post_apply_failures"), "failure streak reason expected");
PASS();
}
void test_high_confidence_deterministic_auto_approves() {
TEST(high_confidence_deterministic_auto_approves);
auto r = ReviewGatePolicyRefinement::evaluate({false, false, false, 90, 0, true, false});
CHECK(!r.requiresHumanReview, "should auto approve");
CHECK(r.decision == "auto_approve", "decision mismatch");
PASS();
}
void test_moderate_confidence_auto_approve_with_audit() {
TEST(moderate_confidence_auto_approve_with_audit);
auto r = ReviewGatePolicyRefinement::evaluate({false, false, false, 75, 0, false, false});
CHECK(!r.requiresHumanReview, "should not require human review");
CHECK(r.decision == "auto_approve_with_audit", "decision mismatch");
PASS();
}
void test_low_confidence_escalates_review() {
TEST(low_confidence_escalates_review);
auto r = ReviewGatePolicyRefinement::evaluate({false, false, false, 60, 0, false, false});
CHECK(r.requiresHumanReview, "low confidence should require review");
CHECK(r.decision == "escalate_review", "decision mismatch");
CHECK(hasReason(r, "low_confidence"), "low confidence reason expected");
PASS();
}
void test_high_cost_overage_escalates_review() {
TEST(high_cost_overage_escalates_review);
auto r = ReviewGatePolicyRefinement::evaluate({false, false, false, 90, 0, true, true});
CHECK(r.requiresHumanReview, "high overage should escalate");
CHECK(r.decision == "escalate_review", "decision mismatch");
CHECK(hasReason(r, "high_cost_overage"), "overage reason expected");
PASS();
}
void test_safety_overrides_high_confidence_auto_approve() {
TEST(safety_overrides_high_confidence_auto_approve);
auto r = ReviewGatePolicyRefinement::evaluate({true, false, false, 95, 0, true, false});
CHECK(r.decision == "escalate_review", "safety should override auto approval");
PASS();
}
void test_policy_violation_overrides_all_other_conditions() {
TEST(policy_violation_overrides_all_other_conditions);
auto r = ReviewGatePolicyRefinement::evaluate({true, true, true, 99, 10, true, true});
CHECK(r.decision == "block", "policy violation should dominate");
CHECK(hasReason(r, "policy_violation_detected"), "policy reason expected");
PASS();
}
void test_failure_streak_threshold_is_inclusive() {
TEST(failure_streak_threshold_is_inclusive);
auto r = ReviewGatePolicyRefinement::evaluate({false, false, false, 90, 3, true, false});
CHECK(r.decision == "escalate_review", "streak==3 should escalate");
PASS();
}
void test_deterministic_path_without_high_confidence_uses_audit_path() {
TEST(deterministic_path_without_high_confidence_uses_audit_path);
auto r = ReviewGatePolicyRefinement::evaluate({false, false, false, 80, 0, true, false});
CHECK(r.decision == "auto_approve_with_audit", "80 confidence should use audit path");
PASS();
}
int main() {
std::cout << "Step 551: Review-Gate Policy Refinement\n";
test_policy_violation_blocks_immediately(); // 1
test_safety_critical_requires_review(); // 2
test_security_sensitive_requires_review(); // 3
test_repeated_failures_require_review(); // 4
test_high_confidence_deterministic_auto_approves(); // 5
test_moderate_confidence_auto_approve_with_audit(); // 6
test_low_confidence_escalates_review(); // 7
test_high_cost_overage_escalates_review(); // 8
test_safety_overrides_high_confidence_auto_approve(); // 9
test_policy_violation_overrides_all_other_conditions(); // 10
test_failure_streak_threshold_is_inclusive(); // 11
test_deterministic_path_without_high_confidence_uses_audit_path(); // 12
std::cout << "\nResults: " << passed << "/" << (passed + failed) << " passed\n";
return failed == 0 ? 0 : 1;
}

View File

@@ -9621,3 +9621,39 @@ cost, rejection, and latency metrics by worker and task class.
- `editor/src/WorkerEfficiencyDashboardModel.h` within header-size limit (`71` <= `600`)
- `editor/tests/step550_test.cpp` within test-file size guidance (`170` lines)
- Header-only architecture and naming conventions remain aligned with `ARCHITECTURE.md`
### Step 551: Review-Gate Policy Refinement
**Status:** PASS (12/12 tests)
Implements refined review-gate policy logic to reduce unnecessary human
escalations while preserving hard safety/security/policy protections.
**Files added:**
- `editor/src/ReviewGatePolicyRefinement.h` - review-gate policy module:
- policy-violation hard block precedence
- safety/security escalation precedence
- repeated post-apply failure escalation trigger
- high-confidence deterministic auto-approval path
- moderate-confidence auto-approve-with-audit path
- low-confidence/high-cost escalation behavior
- `editor/tests/step551_test.cpp` - 12 tests covering:
- policy/safety/security precedence behavior
- failure-streak escalation behavior
- auto-approve and audit-path behavior
- low-confidence/high-cost escalation behavior
- precedence override behavior across mixed conditions
- threshold boundary behavior
**Files modified:**
- `editor/CMakeLists.txt` - `step551_test` target
**Verification run:**
- `cmake -S editor -B editor/build-native` - PASS
- `cmake --build editor/build-native --target step551_test step550_test` - PASS
- `./editor/build-native/step551_test` - PASS (12/12)
- `./editor/build-native/step550_test` - PASS (12/12) regression coverage
**Architecture gate check:**
- `editor/src/ReviewGatePolicyRefinement.h` within header-size limit (`70` <= `600`)
- `editor/tests/step551_test.cpp` within test-file size guidance (`132` lines)
- Header-only architecture and naming conventions remain aligned with `ARCHITECTURE.md`