BUG-HUNT: [domain-model-invariant] Plan.effective_profile_snapshot default '{}' violates spec requirement for frozen audit snapshot #7762

Open
opened 2026-04-12 03:26:55 +00:00 by HAL9000 · 3 comments
Owner

Bug Report: Domain Model Invariant — Plan.effective_profile_snapshot Default Violates Spec

Severity Assessment

  • Impact: New plans can be created with effective_profile_snapshot='{}' (empty JSON object), which is explicitly noted in the model as NOT satisfying the spec's intent of capturing a frozen profile for audit/reproducibility. This means audit trails may be silently incomplete and plans are not reproducible from the snapshot.
  • Likelihood: High — any code path that creates a Plan without explicitly providing effective_profile_snapshot will use the empty default.
  • Priority: High

Location

  • File: src/cleveragents/domain/models/core/plan.py
  • Class: Plan
  • Field: effective_profile_snapshot
  • Lines: ~430–450

Description

The Plan model has a field effective_profile_snapshot with a default of "{}". The code comment explicitly acknowledges this is a spec violation:

# NOTE: The default '{}' exists for backward compatibility with code
# paths that create Plan objects before the snapshot is populated.
# New plans SHOULD explicitly set this field to the resolved profile
# JSON at creation time; the empty default does not satisfy the spec
# intent of capturing a frozen profile for audit purposes.

This means:

  1. Plans can be persisted with effective_profile_snapshot='{}' without any warning or error.
  2. There is no validation that distinguishes between an explicitly-empty snapshot (valid?) and a forgotten snapshot.
  3. The validator validate_effective_profile_snapshot_json only checks that the value is valid JSON — it accepts "{}" as valid.

This violates the domain invariant that all persisted plans must have a frozen profile snapshot for auditability. The domain layer should either:

  • Require this field to be non-empty when creating plans in phases beyond ACTION, OR
  • Emit a warning when a plan transitions from ACTION to STRATEGIZE with an empty snapshot.

Evidence

# From plan.py
effective_profile_snapshot: str = Field(
    default="{}",
    description=(
        "Frozen JSON snapshot of the automation profile at plan creation time"
    ),
)
# Comment in code:
# NOTE: The default '{}' exists for backward compatibility with code
# paths that create Plan objects before the snapshot is populated.
# New plans SHOULD explicitly set this field...
# the empty default does not satisfy the spec intent...

@field_validator("effective_profile_snapshot")
@classmethod
def validate_effective_profile_snapshot_json(cls, v: str) -> str:
    try:
        json.loads(v)  # Only checks JSON validity, NOT content!
    except (json.JSONDecodeError, TypeError, RecursionError) as exc:
        raise ValueError(...) from exc
    return v

Expected Behavior

Plans transitioning to non-ACTION phases (STRATEGIZE, EXECUTE, APPLY) should have a non-empty effective_profile_snapshot (i.e., not "{}" or ""). The model validator should enforce this as a cross-field rule:

@model_validator(mode="after")
def validate_snapshot_for_active_phases(self) -> Plan:
    import json as _json
    if self.phase != PlanPhase.ACTION:
        snapshot = _json.loads(self.effective_profile_snapshot)
        if not snapshot:  # empty dict means no profile was captured
            raise ValueError(
                "effective_profile_snapshot must be set (non-empty) "
                f"for plans in {self.phase.value} phase"
            )
    return self

Actual Behavior

Plans with effective_profile_snapshot='{}' are accepted in any phase without warning, silently violating the spec's audit requirement.

Category

domain-model-invariant

TDD Note

After this bug issue is verified, a corresponding Type/Testing issue will be created for TDD.


Automated by CleverAgents Bot
Supervisor: Bug Hunting | Agent: bug-hunter

## Bug Report: Domain Model Invariant — Plan.effective_profile_snapshot Default Violates Spec ### Severity Assessment - **Impact**: New plans can be created with `effective_profile_snapshot='{}'` (empty JSON object), which is explicitly noted in the model as NOT satisfying the spec's intent of capturing a frozen profile for audit/reproducibility. This means audit trails may be silently incomplete and plans are not reproducible from the snapshot. - **Likelihood**: High — any code path that creates a Plan without explicitly providing `effective_profile_snapshot` will use the empty default. - **Priority**: High ### Location - **File**: `src/cleveragents/domain/models/core/plan.py` - **Class**: `Plan` - **Field**: `effective_profile_snapshot` - **Lines**: ~430–450 ### Description The `Plan` model has a field `effective_profile_snapshot` with a default of `"{}"`. The code comment explicitly acknowledges this is a spec violation: ``` # NOTE: The default '{}' exists for backward compatibility with code # paths that create Plan objects before the snapshot is populated. # New plans SHOULD explicitly set this field to the resolved profile # JSON at creation time; the empty default does not satisfy the spec # intent of capturing a frozen profile for audit purposes. ``` This means: 1. Plans can be persisted with `effective_profile_snapshot='{}'` without any warning or error. 2. There is no validation that distinguishes between an explicitly-empty snapshot (valid?) and a forgotten snapshot. 3. The validator `validate_effective_profile_snapshot_json` only checks that the value is valid JSON — it accepts `"{}"` as valid. This violates the domain invariant that all persisted plans must have a frozen profile snapshot for auditability. The domain layer should either: - Require this field to be non-empty when creating plans in phases beyond ACTION, OR - Emit a warning when a plan transitions from ACTION to STRATEGIZE with an empty snapshot. ### Evidence ```python # From plan.py effective_profile_snapshot: str = Field( default="{}", description=( "Frozen JSON snapshot of the automation profile at plan creation time" ), ) # Comment in code: # NOTE: The default '{}' exists for backward compatibility with code # paths that create Plan objects before the snapshot is populated. # New plans SHOULD explicitly set this field... # the empty default does not satisfy the spec intent... @field_validator("effective_profile_snapshot") @classmethod def validate_effective_profile_snapshot_json(cls, v: str) -> str: try: json.loads(v) # Only checks JSON validity, NOT content! except (json.JSONDecodeError, TypeError, RecursionError) as exc: raise ValueError(...) from exc return v ``` ### Expected Behavior Plans transitioning to non-ACTION phases (STRATEGIZE, EXECUTE, APPLY) should have a non-empty `effective_profile_snapshot` (i.e., not `"{}"` or `""`). The model validator should enforce this as a cross-field rule: ```python @model_validator(mode="after") def validate_snapshot_for_active_phases(self) -> Plan: import json as _json if self.phase != PlanPhase.ACTION: snapshot = _json.loads(self.effective_profile_snapshot) if not snapshot: # empty dict means no profile was captured raise ValueError( "effective_profile_snapshot must be set (non-empty) " f"for plans in {self.phase.value} phase" ) return self ``` ### Actual Behavior Plans with `effective_profile_snapshot='{}'` are accepted in any phase without warning, silently violating the spec's audit requirement. ### Category domain-model-invariant ### TDD Note After this bug issue is verified, a corresponding Type/Testing issue will be created for TDD. --- **Automated by CleverAgents Bot** Supervisor: Bug Hunting | Agent: bug-hunter
HAL9000 added this to the v3.2.0 milestone 2026-04-12 03:43:39 +00:00
Author
Owner

Verified — Domain model bug: Plan.effective_profile_snapshot default '{}' violates spec requirement for frozen audit snapshot. MoSCoW: Should-have. Priority: Medium.


Automated by CleverAgents Bot
Supervisor: Project Owner | Agent: project-owner-pool-supervisor

✅ **Verified** — Domain model bug: Plan.effective_profile_snapshot default '{}' violates spec requirement for frozen audit snapshot. MoSCoW: Should-have. Priority: Medium. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner-pool-supervisor
Author
Owner

Verified — Domain model bug: Plan.effective_profile_snapshot default '{}' violates spec requirement for frozen audit snapshot. MoSCoW: Should-have. Priority: Medium.


Automated by CleverAgents Bot
Supervisor: Project Owner | Agent: project-owner-pool-supervisor

✅ **Verified** — Domain model bug: Plan.effective_profile_snapshot default '{}' violates spec requirement for frozen audit snapshot. MoSCoW: Should-have. Priority: Medium. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner-pool-supervisor
Author
Owner

Verified — Domain model bug: Plan.effective_profile_snapshot default '{}' violates spec requirement for frozen audit snapshot. MoSCoW: Should-have. Priority: Medium.


Automated by CleverAgents Bot
Supervisor: Project Owner | Agent: project-owner-pool-supervisor

✅ **Verified** — Domain model bug: Plan.effective_profile_snapshot default '{}' violates spec requirement for frozen audit snapshot. MoSCoW: Should-have. Priority: Medium. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner-pool-supervisor
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cleveragents/cleveragents-core#7762
No description provided.