Files
cleveragents-core/benchmarks/plan_diff_bench.py
T
brent.edwards eb46f0ff54
CI / push-validation (push) Successful in 40s
CI / helm (push) Successful in 44s
CI / build (push) Successful in 1m14s
CI / lint (push) Successful in 1m18s
CI / quality (push) Successful in 1m36s
CI / e2e_tests (push) Successful in 1m19s
CI / typecheck (push) Successful in 2m22s
CI / security (push) Successful in 2m23s
CI / benchmark-regression (push) Failing after 41s
CI / integration_tests (push) Successful in 4m46s
CI / unit_tests (push) Failing after 20m13s
CI / benchmark-publish (push) Failing after 28m28s
CI / coverage (push) Has been cancelled
CI / docker (push) Has been cancelled
CI / status-check (push) Has been cancelled
fix(plan): add tier hydration and improve architecture review output (#10938)
## Summary

This PR fixes issue #10878 where architecture reviews were truncated because the regex pattern for parsing file output would stop at the first ``` encountered in the Markdown report.

## Changes

- Change file delimiters from ``` to >>>>>>>/<<<<<<< to avoid Markdown conflicts
- Add tier hydration before strategize phase in plan_executor.py
- Increase max_tokens to 16384 in llm_actors.py for longer outputs
- Increase context_max_tokens_hot from 16000 to 32000 in settings.py
- Fix get_hot_view → get_hot_fragments in strategy_actor.py and plan_executor.py
- Add opencode to skip directories in context_tier_hydrator.py
- Change sandbox output location to plan-output/ directory in plan.py
- Add get_context_summary stub method to acms_service.py

## Testing

Run architecture review action and verify the output report is complete with all sections.

Reviewed-on: #10938
2026-05-19 12:43:34 +00:00

162 lines
4.9 KiB
Python

"""ASV benchmarks for plan diff rendering overhead.
Measures the performance of:
- Diff rendering in rich format
- Diff rendering in plain format
- Diff rendering in JSON format
- Artifacts summary building
- Empty changeset guard check
"""
from __future__ import annotations
import importlib
import sys
from pathlib import Path
# Ensure the local *source* tree is importable even when ASV has an
# older build of the package installed.
_SRC = str(Path(__file__).resolve().parents[1] / "src")
if _SRC not in sys.path:
sys.path.insert(0, _SRC)
import cleveragents # noqa: E402
importlib.reload(cleveragents)
from cleveragents.application.services.plan_apply_service import ( # noqa: E402
PlanApplyService,
_render_diff_json,
_render_diff_plain,
_render_diff_rich,
)
from cleveragents.application.services.plan_lifecycle_service import ( # noqa: E402
PlanLifecycleService,
)
from cleveragents.config.settings import Settings # noqa: E402
from cleveragents.domain.models.core.change import ( # noqa: E402
ChangeEntry,
ChangeOperation,
InMemoryChangeSetStore,
SpecChangeSet,
)
from cleveragents.domain.models.core.plan import PlanPhase # noqa: E402
def _build_changeset(plan_id: str, n_entries: int = 10) -> SpecChangeSet:
"""Build a SpecChangeSet with *n_entries* for benchmarking."""
entries = []
ops = [ChangeOperation.CREATE, ChangeOperation.MODIFY, ChangeOperation.DELETE]
for i in range(n_entries):
entries.append(
ChangeEntry(
plan_id=plan_id,
resource_id=f"res-{i:04d}",
tool_name="file-write",
operation=ops[i % len(ops)],
path=f"src/module_{i:04d}.py",
before_hash=f"before{i:08x}" if i % 3 != 0 else None,
after_hash=f"after{i:08x}" if i % 3 != 2 else None,
)
)
return SpecChangeSet(
changeset_id="bench-cs-001",
plan_id=plan_id,
entries=entries,
)
def _create_plan_and_service() -> tuple[str, PlanApplyService, InMemoryChangeSetStore]:
"""Create a lifecycle service, plan, and apply service."""
settings = Settings()
lifecycle = PlanLifecycleService(settings=settings)
store = InMemoryChangeSetStore()
apply_svc = PlanApplyService(lifecycle_service=lifecycle, changeset_store=store)
lifecycle.create_action(
name="local/bench-diff",
description="Benchmark diff",
definition_of_done="Benchmarks pass",
strategy_actor="local/planner",
execution_actor="local/executor",
)
plan = lifecycle.use_action(action_name="local/bench-diff")
plan_id = plan.identity.plan_id
lifecycle.start_strategize(plan_id)
lifecycle.complete_strategize(plan_id)
plan = lifecycle.get_plan(plan_id)
if plan.phase == PlanPhase.STRATEGIZE:
lifecycle.execute_plan(plan_id)
plan = lifecycle.get_plan(plan_id)
if plan.phase == PlanPhase.EXECUTE:
lifecycle.start_execute(plan_id)
lifecycle.complete_execute(plan_id)
cs = _build_changeset(plan_id, 20)
store._store[cs.changeset_id] = cs
plan = lifecycle.get_plan(plan_id)
plan.changeset_id = cs.changeset_id
plan.sandbox_refs = ["sandbox-bench-001"]
lifecycle.commit_plan(plan)
return plan_id, apply_svc, store
class DiffRenderingSuite:
"""Benchmark suite for diff rendering in various formats."""
def setup(self) -> None:
self.plan_id, self.apply_svc, self.store = _create_plan_and_service()
def time_diff_rich(self) -> None:
self.apply_svc.diff(self.plan_id, fmt="rich")
def time_diff_plain(self) -> None:
self.apply_svc.diff(self.plan_id, fmt="plain")
def time_diff_json(self) -> None:
self.apply_svc.diff(self.plan_id, fmt="json")
def time_diff_yaml(self) -> None:
self.apply_svc.diff(self.plan_id, fmt="yaml")
class ArtifactsSuite:
"""Benchmark suite for artifacts rendering."""
def setup(self) -> None:
self.plan_id, self.apply_svc, self.store = _create_plan_and_service()
def time_artifacts_json(self) -> None:
self.apply_svc.artifacts(self.plan_id, fmt="json")
def time_artifacts_plain(self) -> None:
self.apply_svc.artifacts(self.plan_id, fmt="plain")
class GuardSuite:
"""Benchmark suite for empty changeset guard."""
def setup(self) -> None:
self.plan_id, self.apply_svc, self.store = _create_plan_and_service()
def time_guard_non_empty(self) -> None:
self.apply_svc.guard_empty_changeset(self.plan_id)
class HelperFunctionsSuite:
"""Benchmark suite for low-level rendering helpers."""
def setup(self) -> None:
self.changeset = _build_changeset("bench-plan-001", 50)
def time_render_diff_plain(self) -> None:
_render_diff_plain(self.changeset)
def time_render_diff_rich(self) -> None:
_render_diff_rich(self.changeset)
def time_render_diff_json(self) -> None:
_render_diff_json(self.changeset)