Files
cleveragents-core/benchmarks/phase_reversion_bench.py
T
brent.edwards b88bc0ec1b
CI / build (push) Successful in 19s
CI / lint (push) Successful in 3m19s
CI / quality (push) Successful in 3m43s
CI / typecheck (push) Successful in 3m55s
CI / security (push) Successful in 4m2s
CI / unit_tests (push) Successful in 6m39s
CI / integration_tests (push) Successful in 6m48s
CI / docker (push) Successful in 1m7s
CI / e2e_tests (push) Successful in 9m7s
CI / benchmark-regression (push) Has been skipped
CI / coverage (push) Failing after 16m36s
CI / benchmark-publish (push) Successful in 25m51s
CI / status-check (push) Failing after 4s
feat(perf): large project scaling tests (#984)
## Summary

Add large project scaling benchmarks and tests at production scale (10K–100K files).

### New ASV Benchmarks

**IndexingScalingSuite** (`large_project_scaling_bench.py`):
- `time_walk_and_index` at 1K/10K/50K/100K files
- `time_incremental_refresh` (1% modified files)
- `track_indexed_file_count`, `track_tokens_per_second`

**ContextAssemblyScalingSuite** (`context_assembly_scaling_bench.py`):
- `time_full_pipeline` at 100/1K/5K/10K fragments
- `time_tiered_strategy`, `time_recency_strategy`
- `track_assembled_tokens`, `track_fragments_per_second`

**ExecutionThroughputSuite** (`execution_throughput_bench.py`):
- `time_sequential_plans` at 10/50/100 plans
- `time_executor_construction`, `time_decision_tree_scaling`

### Scale Fixture Updates

- Added `xlarge` (50K files) and `xxlarge` (100K files) profiles to `scale_metadata.json`
- Added 50K/100K thresholds to `baseline_thresholds.json`
- Added `context_assembly` and `execution_throughput` threshold sections

### Tests & Documentation

- 15 Behave scenarios validating profiles, thresholds, monotonicity, memory budgets
- 6 Robot integration tests including live 1K-file indexing throughput check
- `docs/reference/scaling_baselines.md` documenting all baseline metrics

### Quality Gates

| Session | Result |
|---|---|
| `nox -s lint` | PASS |
| `nox -s typecheck` | PASS (0 errors) |
| `nox -s unit_tests` | PASS (10,910 scenarios) |
| `nox -s integration_tests` | PASS (1,526 tests) |
| `nox -s coverage_report` | 97% (>= 97%) |

Closes #859

Reviewed-on: #984
Co-authored-by: Brent E. Edwards <brent.edwards@cleverthis.com>
Co-committed-by: Brent E. Edwards <brent.edwards@cleverthis.com>
2026-03-21 04:46:45 +00:00

150 lines
4.7 KiB
Python

"""ASV benchmarks for phase reversion state machine.
Measures the performance of:
- Plan.can_revert_to() validation
- PlanLifecycleService.revert_plan() overhead
- PlanLifecycleService.try_auto_revert_from_apply() overhead
- Decision recording during reversion
- Reversion loop guard check overhead
"""
from __future__ import annotations
import sys
from pathlib import Path
try:
from cleveragents.application.services.plan_lifecycle_service import (
PlanLifecycleService,
)
from cleveragents.config.settings import Settings
from cleveragents.domain.models.core.plan import (
AutomationProfileProvenance,
AutomationProfileRef,
PlanPhase,
ProcessingState,
)
except ModuleNotFoundError:
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
from cleveragents.application.services.plan_lifecycle_service import (
PlanLifecycleService,
)
from cleveragents.config.settings import Settings
from cleveragents.domain.models.core.plan import (
AutomationProfileProvenance,
AutomationProfileRef,
PlanPhase,
ProcessingState,
)
def _make_service() -> PlanLifecycleService:
return PlanLifecycleService(settings=Settings())
def _create_plan_in_execute(
service: PlanLifecycleService,
action_name: str = "local/bench-action",
profile: str = "manual",
) -> str:
service.create_action(
name=action_name,
description="Benchmark action",
definition_of_done="Tests pass",
strategy_actor="local/strategist",
execution_actor="local/executor",
)
plan = service.use_action(action_name)
plan.automation_profile = AutomationProfileRef(
profile_name=profile,
provenance=AutomationProfileProvenance.PLAN,
)
plan_id = plan.identity.plan_id
service.start_strategize(plan_id)
service.complete_strategize(plan_id)
service.execute_plan(plan_id)
return plan_id
class CanRevertToSuite:
"""Benchmark Plan.can_revert_to() validation."""
def setup(self) -> None:
service = _make_service()
plan_id = _create_plan_in_execute(service, "local/bench-can-revert")
self.plan = service.get_plan(plan_id)
def time_can_revert_to_valid(self) -> None:
self.plan.can_revert_to(PlanPhase.STRATEGIZE)
def time_can_revert_to_invalid(self) -> None:
self.plan.can_revert_to(PlanPhase.APPLY)
class RevertPlanSuite:
"""Benchmark PlanLifecycleService.revert_plan() overhead."""
def setup(self) -> None:
self.service = _make_service()
self.counter = 0
def time_revert_plan(self) -> None:
self.counter += 1
name = f"local/bench-revert-{self.counter}"
plan_id = _create_plan_in_execute(self.service, name)
self.service.revert_plan(plan_id, PlanPhase.STRATEGIZE, reason="benchmark")
class AutoRevertSuite:
"""Benchmark auto-reversion from constrained apply."""
def setup(self) -> None:
self.service = _make_service()
self.counter = 0
def time_auto_revert_from_apply(self) -> None:
self.counter += 1
name = f"local/bench-auto-{self.counter}"
self.service.create_action(
name=name,
description="Benchmark action",
definition_of_done="Tests pass",
strategy_actor="local/strategist",
execution_actor="local/executor",
)
plan = self.service.use_action(name)
plan.automation_profile = AutomationProfileRef(
profile_name="ci",
provenance=AutomationProfileProvenance.PLAN,
)
plan_id = plan.identity.plan_id
self.service.start_strategize(plan_id)
self.service.complete_strategize(plan_id)
plan = self.service.get_plan(plan_id)
if plan.phase != PlanPhase.EXECUTE:
self.service.execute_plan(plan_id)
self.service.start_execute(plan_id)
self.service.complete_execute(plan_id)
self.service.apply_plan(plan_id)
self.service.start_apply(plan_id)
plan = self.service.get_plan(plan_id)
plan.processing_state = ProcessingState.CONSTRAINED
self.service.try_auto_revert_from_apply(plan_id, "benchmark")
class LoopGuardSuite:
"""Benchmark loop guard check overhead."""
def setup(self) -> None:
self.service = _make_service()
plan_id = _create_plan_in_execute(self.service, "local/bench-guard")
self.plan = self.service.get_plan(plan_id)
def time_loop_guard_under_limit(self) -> None:
self.plan.reversion_count = 2
self.plan.can_revert_to(PlanPhase.STRATEGIZE)
def time_loop_guard_at_limit(self) -> None:
self.plan.reversion_count = 3
self.plan.can_revert_to(PlanPhase.STRATEGIZE)