Files
cleveragents-core/benchmarks/plan_preflight_guardrails_bench.py
T
freemo a44082ab70
CI / benchmark-publish (pull_request) Has been skipped
CI / lint (pull_request) Successful in 15s
CI / build (pull_request) Successful in 17s
CI / quality (pull_request) Successful in 20s
CI / security (pull_request) Successful in 34s
CI / typecheck (pull_request) Successful in 36s
CI / unit_tests (pull_request) Successful in 2m8s
CI / docker (pull_request) Successful in 38s
CI / integration_tests (pull_request) Successful in 3m8s
CI / coverage (pull_request) Successful in 4m43s
CI / quality (push) Successful in 17s
CI / lint (push) Successful in 21s
CI / build (push) Successful in 24s
CI / security (push) Successful in 54s
CI / typecheck (push) Successful in 1m13s
CI / benchmark-regression (push) Has been skipped
CI / unit_tests (push) Successful in 2m25s
CI / docker (push) Successful in 39s
CI / integration_tests (push) Successful in 3m38s
CI / coverage (push) Successful in 4m32s
CI / benchmark-publish (push) Successful in 16m58s
CI / benchmark-regression (pull_request) Successful in 29m51s
feat(guardrails): implement Plan Generation Pre-flight Guardrails (7 checks before execution)
Implement spec-mandated pre-flight guardrail checks that validate plan
readiness before entering the Strategize phase:

1. Action schema validation — verifies action exists and is well-formed.
2. Actor availability — confirms all 4 actor roles registered.
3. Skill/tool existence — transitively resolves all tools/skills.
4. Automation policy — verifies profile permits execution.
5. Rollback feasibility — ensures all tools checkpointable if required.
6. Resource accessibility — shallow connectivity check on linked resources.
7. Validation attachment resolution — pre-resolves all applicable validations.

PlanPreflightGuardrail service runs all 7 checks via run_all_checks().
On first failure, raises PreflightRejection with check name and message.
Wired into plan_lifecycle_service before Strategize phase.

Behave BDD: 18 scenarios covering all 7 checks (positive + negative).
Robot Framework: 3 integration smoke tests.
ASV benchmarks: pre-flight check execution time.

ISSUES CLOSED: #582
2026-03-08 22:31:40 +00:00

135 lines
4.6 KiB
Python

"""ASV benchmarks for plan pre-flight guardrail execution time.
Measures the performance of:
- Individual pre-flight checks
- Full ``run_all_checks`` pass
- ``PreflightReport`` construction
"""
from __future__ import annotations
import sys
from pathlib import Path
try:
from cleveragents.application.services.plan_preflight_guardrail import (
PlanPreflightGuardrail,
PreflightCheckName,
PreflightCheckResult,
PreflightReport,
)
except ModuleNotFoundError:
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
from cleveragents.application.services.plan_preflight_guardrail import (
PlanPreflightGuardrail,
PreflightCheckName,
PreflightCheckResult,
PreflightReport,
)
class PreflightCheckSuite:
"""Benchmark individual pre-flight check methods."""
def setup(self) -> None:
"""Set up shared guardrail instance."""
self.guardrail = PlanPreflightGuardrail()
self.action_registry: dict[str, object] = {
"test-action": {"name": "test-action"}
}
self.actor_registry: dict[str, object] = {
"strategy": "s",
"execution": "e",
"estimation": "est",
"invariant_reconciliation": "ir",
}
self.tool_registry: dict[str, object] = {
"tool-a": {},
"tool-b": {},
}
def time_check_action_schema(self) -> None:
"""Benchmark action schema validation check."""
self.guardrail.check_action_schema("test-action", self.action_registry)
def time_check_actor_availability(self) -> None:
"""Benchmark actor availability check."""
self.guardrail.check_actor_availability(self.actor_registry)
def time_check_skill_tool_existence(self) -> None:
"""Benchmark skill/tool existence check."""
self.guardrail.check_skill_tool_existence(
("tool-a", "tool-b"), self.tool_registry, (), {}
)
def time_check_automation_policy(self) -> None:
"""Benchmark automation policy check."""
self.guardrail.check_automation_policy({"name": "auto"})
def time_check_rollback_feasibility_skip(self) -> None:
"""Benchmark rollback feasibility when checkpoints not required."""
self.guardrail.check_rollback_feasibility(False, {})
def time_check_rollback_feasibility_pass(self) -> None:
"""Benchmark rollback feasibility when all tools checkpointable."""
self.guardrail.check_rollback_feasibility(
True, {"tool-a": True, "tool-b": True}
)
def time_check_resource_accessibility_empty(self) -> None:
"""Benchmark resource accessibility with no paths."""
self.guardrail.check_resource_accessibility(())
def time_check_validation_resolution_empty(self) -> None:
"""Benchmark validation resolution with no validations."""
self.guardrail.check_validation_resolution((), {})
class PreflightRunAllSuite:
"""Benchmark the full ``run_all_checks`` method."""
def setup(self) -> None:
"""Set up shared guardrail with fully populated registries."""
self.guardrail = PlanPreflightGuardrail()
def time_run_all_checks_pass(self) -> None:
"""Benchmark run_all_checks with all checks passing."""
self.guardrail.run_all_checks(
action_name="test-action",
action_registry={"test-action": {}},
actor_registry={
"strategy": "s",
"execution": "e",
"estimation": "est",
"invariant_reconciliation": "ir",
},
tool_names=("tool-a",),
tool_registry={"tool-a": {}},
automation_profile={"name": "auto"},
require_checkpoints=False,
)
class PreflightReportSuite:
"""Benchmark PreflightReport construction and queries."""
def time_report_construction(self) -> None:
"""Benchmark creating a report with 7 results."""
report = PreflightReport()
for check in PreflightCheckName:
report.add(PreflightCheckResult(check, True, "ok"))
def time_report_all_passed(self) -> None:
"""Benchmark all_passed property."""
report = PreflightReport()
for check in PreflightCheckName:
report.add(PreflightCheckResult(check, True, "ok"))
_ = report.all_passed
def time_report_format(self) -> None:
"""Benchmark format_report rendering."""
report = PreflightReport()
for check in PreflightCheckName:
report.add(PreflightCheckResult(check, True, "ok"))
report.format_report()