a4a6b061a6
CI / benchmark-publish (pull_request) Has been skipped
CI / build (pull_request) Successful in 18s
CI / lint (pull_request) Successful in 20s
CI / helm (pull_request) Successful in 22s
CI / typecheck (pull_request) Successful in 51s
CI / quality (pull_request) Successful in 3m45s
CI / integration_tests (pull_request) Successful in 3m59s
CI / security (pull_request) Successful in 4m8s
CI / unit_tests (pull_request) Successful in 5m44s
CI / docker (pull_request) Successful in 1m32s
CI / coverage (pull_request) Successful in 11m50s
CI / e2e_tests (pull_request) Successful in 20m28s
CI / status-check (pull_request) Successful in 1s
CI / lint (push) Successful in 17s
CI / build (push) Successful in 18s
CI / helm (push) Successful in 22s
CI / quality (push) Successful in 31s
CI / typecheck (push) Successful in 1m1s
CI / benchmark-regression (push) Has been skipped
CI / unit_tests (push) Successful in 3m57s
CI / security (push) Successful in 4m3s
CI / docker (push) Successful in 1m21s
CI / integration_tests (push) Successful in 7m11s
CI / coverage (push) Successful in 11m56s
CI / e2e_tests (push) Successful in 20m56s
CI / status-check (push) Successful in 1s
CI / benchmark-publish (push) Successful in 28m22s
CI / benchmark-regression (pull_request) Successful in 55m20s
Aligned v3_plans table with specification DDL:
1. Added effective_profile_snapshot column (TEXT NOT NULL) for
storing frozen JSON snapshot of automation profile at plan
creation time. Added Pydantic field_validator ensuring the
value is well-formed JSON. Validator catches RecursionError
for deeply nested JSON, consistent with automation_profile
deserialization hardening. Validator error message uses
length-only to avoid potential information disclosure.
Documented that the default "{}" exists for backward
compatibility; new plans should explicitly set the snapshot.
2. Made root_plan_id NOT NULL — root plans self-reference their
own plan_id, child plans reference the root ancestor. Added
explicit ondelete="RESTRICT" FK policy for consistency with
other FKs in the model. Documented known FK policy drift
between ORM model (RESTRICT) and migrated databases (retained
SET NULL) in the migration; data integrity is preserved by
the NOT NULL constraint regardless. Moved root_plan_id
self-reference resolution into a PlanIdentity model_validator
so the domain model is consistent with the DB NOT NULL
constraint before and after persistence (previously the
resolution only happened in from_domain(), creating an
asymmetry where root_plan_id was None in-memory but non-null
after round-tripping through the database).
3. Made automation_profile NOT NULL with default "balanced".
4. Documented intentional deviation: phase default is "action"
(code) vs "strategize" (spec) because the Action phase was
added as a pre-Strategize setup step.
5. Created Alembic migration with backfill logic for existing
rows. Root-ancestor backfill uses level-by-level propagation
with a parent-readiness guard to correctly resolve plans at
arbitrary hierarchy depth (3+ levels). Added safety bound
(max 100 iterations) with logged error on exhaustion to guard
against cycles in parent_plan_id. Merged batch_alter_table
operations to avoid redundant full-table copies in SQLite
batch mode. Migration backfill also handles empty-string
automation_profile values. Documented downgrade limitation
(backfill is not reversible). Orphan-row fallback now logs
affected row count at WARNING level. Migration cycle-detection
now logs affected plan_id values before the orphan fallback
overwrites them. All migration SQL uses sa.text() for
consistency with SQLAlchemy best practices.
6. Hardened automation_profile deserialization in to_domain() to
catch ValueError (invalid StrEnum provenance), Pydantic
ValidationError, and RecursionError (deeply nested JSON) in
addition to JSONDecodeError and KeyError, preventing
unreadable plans from corrupted DB rows. Applied the same
defensive deserialization pattern to effective_profile_snapshot
in to_domain(): corrupted JSON falls back to '{}' with a
WARNING log instead of crashing the read path. Added TypeError
to the effective_profile_snapshot exception list in to_domain()
for consistency with the Pydantic validator. Logging of
unparseable values uses length only to avoid potential
information disclosure.
7. Used explicit None check (is not None) instead of truthiness
for root_plan_id resolution in from_domain(), for
effective_profile_snapshot in to_domain(), and in
_serialize_automation_profile() for consistency.
8. Documented intentional column naming conventions vs spec DDL
(e.g. automation_profile vs automation_profile_name, *_actor
vs *_actor_name, processing_state vs state, v3_plans vs
plans). Documented the semantic difference: automation_profile
stores either a bare name or structured JSON with provenance,
whereas the spec automation_profile_name stores a plain name.
9. Fixed benchmark plan constructors
(plan_phase_migration_bench.py) that were missing the now-
required root_plan_id and effective_profile_snapshot fields.
10. Replaced defensive getattr() with direct attribute access for
effective_profile_snapshot in from_domain() and update(),
since the field is now defined on the Plan domain model.
11. Fixed Any type annotation in test helper _make_plan() to use
AutomationProfileRef | None for proper type safety.
12. Added BDD scenarios for PlanIdentity self-reference
resolution, NULL effective_profile_snapshot constraint
enforcement, valid-JSON-missing-profile_name-key
deserialization, invalid-JSON and empty-string snapshot
rejection by Pydantic validator, and corrupted
effective_profile_snapshot DB fallback in to_domain().
13. Extracted default automation profile name to a module-level
constant (DEFAULT_AUTOMATION_PROFILE) to reduce sentinel
duplication across models.py and repositories.py.
14. Centralised automation-profile serialisation into
LifecyclePlanModel._serialize_automation_profile() to
eliminate duplication between from_domain() and
LifecyclePlanRepository.update().
15. Fixed to_domain() root_plan_id type cast from str | None
to str, reflecting the NOT NULL column constraint.
16. Added PlanIdentity model_validator that resolves None
root_plan_id to plan_id at domain construction time, ensuring
the domain model honours the spec DDL NOT NULL constraint
regardless of persistence state. Simplified from_domain()
root resolution accordingly.
ISSUES CLOSED: #921
182 lines
5.7 KiB
Python
182 lines
5.7 KiB
Python
"""ASV benchmarks for plan phase rebaseline migration (a5_005).
|
|
|
|
Measures:
|
|
- Schema creation time with rebaselined constraints
|
|
- Plan insert throughput with Action phase
|
|
- Plan insert throughput with Apply terminal states
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import threading
|
|
from datetime import UTC, datetime
|
|
|
|
from sqlalchemy import create_engine
|
|
from sqlalchemy.orm import sessionmaker
|
|
|
|
from cleveragents.infrastructure.database.models import (
|
|
Base,
|
|
LifecycleActionModel,
|
|
LifecyclePlanModel,
|
|
)
|
|
|
|
# Thread-safe counter so repeated ASV iterations never collide on IDs.
|
|
_iter_lock = threading.Lock()
|
|
_iter_counter = 0
|
|
|
|
|
|
def _next_iter() -> int:
|
|
"""Return a monotonically increasing iteration number."""
|
|
global _iter_counter
|
|
with _iter_lock:
|
|
_iter_counter += 1
|
|
return _iter_counter
|
|
|
|
|
|
def _now_iso() -> str:
|
|
return datetime.now(tz=UTC).isoformat()
|
|
|
|
|
|
def _make_ulid(n: int) -> str:
|
|
return str(n).zfill(26)
|
|
|
|
|
|
class SchemaCreationWithRebaseline:
|
|
"""Benchmark schema creation including rebaselined v3_plans constraints."""
|
|
|
|
def time_create_all_tables(self) -> None:
|
|
engine = create_engine("sqlite:///:memory:")
|
|
Base.metadata.create_all(engine)
|
|
engine.dispose()
|
|
|
|
|
|
class PlanInsertActionPhase:
|
|
"""Benchmark inserting plans with phase='action' (new phase)."""
|
|
|
|
def setup(self) -> None:
|
|
self.engine = create_engine("sqlite:///:memory:")
|
|
Base.metadata.create_all(self.engine)
|
|
self.session_factory = sessionmaker(bind=self.engine)
|
|
|
|
# Create parent action
|
|
session = self.session_factory()
|
|
action = LifecycleActionModel()
|
|
action.namespaced_name = "bench/phase-action"
|
|
action.namespace = "bench"
|
|
action.name = "phase-action"
|
|
action.description = "Benchmark action"
|
|
action.definition_of_done = "Done"
|
|
action.strategy_actor = "bench/s"
|
|
action.execution_actor = "bench/e"
|
|
action.state = "available"
|
|
action.tags_json = "[]"
|
|
action.created_at = _now_iso()
|
|
action.updated_at = _now_iso()
|
|
session.add(action)
|
|
session.commit()
|
|
session.close()
|
|
|
|
def teardown(self) -> None:
|
|
self.engine.dispose()
|
|
|
|
def time_insert_100_action_phase_plans(self) -> None:
|
|
it = _next_iter()
|
|
base = it * 10000
|
|
session = self.session_factory()
|
|
now = _now_iso()
|
|
for i in range(100):
|
|
plan = LifecyclePlanModel()
|
|
pid = _make_ulid(base + i)
|
|
plan.plan_id = pid
|
|
plan.root_plan_id = pid
|
|
plan.action_name = "bench/phase-action"
|
|
plan.namespaced_name = f"bench/plan-{it}-{i}"
|
|
plan.namespace = "bench"
|
|
plan.phase = "action"
|
|
plan.processing_state = "queued"
|
|
plan.description = f"Benchmark plan {it}-{i}"
|
|
plan.tags_json = "[]"
|
|
plan.effective_profile_snapshot = "{}"
|
|
plan.created_at = now
|
|
plan.updated_at = now
|
|
session.add(plan)
|
|
session.commit()
|
|
session.close()
|
|
|
|
|
|
class PlanInsertApplyTerminalStates:
|
|
"""Benchmark inserting plans with Apply terminal states."""
|
|
|
|
def setup(self) -> None:
|
|
self.engine = create_engine("sqlite:///:memory:")
|
|
Base.metadata.create_all(self.engine)
|
|
self.session_factory = sessionmaker(bind=self.engine)
|
|
|
|
session = self.session_factory()
|
|
action = LifecycleActionModel()
|
|
action.namespaced_name = "bench/terminal-action"
|
|
action.namespace = "bench"
|
|
action.name = "terminal-action"
|
|
action.description = "Benchmark terminal action"
|
|
action.definition_of_done = "Done"
|
|
action.strategy_actor = "bench/s"
|
|
action.execution_actor = "bench/e"
|
|
action.state = "available"
|
|
action.tags_json = "[]"
|
|
action.created_at = _now_iso()
|
|
action.updated_at = _now_iso()
|
|
session.add(action)
|
|
session.commit()
|
|
session.close()
|
|
|
|
def teardown(self) -> None:
|
|
self.engine.dispose()
|
|
|
|
def time_insert_50_applied_plans(self) -> None:
|
|
it = _next_iter()
|
|
base = it * 10000
|
|
session = self.session_factory()
|
|
now = _now_iso()
|
|
for i in range(50):
|
|
plan = LifecyclePlanModel()
|
|
pid = _make_ulid(base + i)
|
|
plan.plan_id = pid
|
|
plan.root_plan_id = pid
|
|
plan.action_name = "bench/terminal-action"
|
|
plan.namespaced_name = f"bench/applied-{it}-{i}"
|
|
plan.namespace = "bench"
|
|
plan.phase = "apply"
|
|
plan.processing_state = "applied"
|
|
plan.description = f"Applied plan {it}-{i}"
|
|
plan.tags_json = "[]"
|
|
plan.effective_profile_snapshot = "{}"
|
|
plan.created_at = now
|
|
plan.updated_at = now
|
|
session.add(plan)
|
|
session.commit()
|
|
session.close()
|
|
|
|
def time_insert_50_constrained_plans(self) -> None:
|
|
it = _next_iter()
|
|
base = it * 10000
|
|
session = self.session_factory()
|
|
now = _now_iso()
|
|
for i in range(50):
|
|
plan = LifecyclePlanModel()
|
|
pid = _make_ulid(base + i)
|
|
plan.plan_id = pid
|
|
plan.root_plan_id = pid
|
|
plan.action_name = "bench/terminal-action"
|
|
plan.namespaced_name = f"bench/constrained-{it}-{i}"
|
|
plan.namespace = "bench"
|
|
plan.phase = "apply"
|
|
plan.processing_state = "constrained"
|
|
plan.description = f"Constrained plan {it}-{i}"
|
|
plan.tags_json = "[]"
|
|
plan.effective_profile_snapshot = "{}"
|
|
plan.created_at = now
|
|
plan.updated_at = now
|
|
session.add(plan)
|
|
session.commit()
|
|
session.close()
|