UAT: ResourceModel has read_only and auto_discovered columns with no corresponding fields in the Resource domain model — data is silently lost on round-trip #2410

Open
opened 2026-04-03 17:37:41 +00:00 by freemo · 1 comment
Owner

Metadata

  • Branch: fix/resource-model-read-only-auto-discovered-domain-fields
  • Commit Message: fix(data-models): add read_only and auto_discovered fields to Resource domain model to prevent silent data loss on round-trip
  • Milestone: v3.6.0
  • Parent Epic: #398

Bug Report

What Was Tested

The ResourceModel database model (src/cleveragents/infrastructure/database/models.py, lines 1532–1613) and its round-trip through the Resource domain model (src/cleveragents/domain/models/core/resource.py, lines 108–283).

Expected Behavior (from spec)

The Resource domain model should faithfully represent all data stored in the resources table. When a resource is loaded from the database and saved back, no data should be lost.

Actual Behavior

ResourceModel defines two columns that have no corresponding fields in the Resource domain model:

  1. read_only = Column(Boolean, nullable=False, default=False) (line 1568)
  2. auto_discovered = Column(Boolean, nullable=False, default=False) (line 1569)

This causes the following data loss:

  1. When a ResourceModel is converted to a Resource domain object, the read_only and auto_discovered values are silently discarded.
  2. When a Resource domain object is converted back to a ResourceModel, these fields default to False regardless of their original values.
  3. This is a data loss bug on every round-trip through the domain layer.

Note: The Resource domain model does have capabilities.writable (related to read_only), but this is a capability flag derived from the resource type — not the per-resource read_only override stored in the database. These are semantically different and must both be preserved.

Impact

  • Resources marked as read_only=True in the database will lose that flag after any domain-layer round-trip.
  • Auto-discovered resources (children discovered by resource handlers) lose their auto_discovered=True flag after round-trip.
  • Any service logic that checks resource.read_only or resource.auto_discovered will not work correctly.

Code Locations

  • src/cleveragents/infrastructure/database/models.py:1568-1569read_only and auto_discovered columns in ResourceModel
  • src/cleveragents/domain/models/core/resource.py:108-283Resource domain model (missing these fields)

Subtasks

  • Add read_only: bool field to the Resource domain model (src/cleveragents/domain/models/core/resource.py)
  • Add auto_discovered: bool field to the Resource domain model (src/cleveragents/domain/models/core/resource.py)
  • Update ResourceModel.to_domain() to map read_only and auto_discovered to the new domain fields
  • Update ResourceModel.from_domain() (or equivalent) to serialize read_only and auto_discovered from the domain object back to the DB model
  • Write Behave unit tests (in features/) covering round-trip serialization of read_only=True and auto_discovered=True
  • Verify nox -e typecheck passes with no errors after changes
  • Verify nox -e unit_tests passes with coverage ≥ 97%

Definition of Done

  • Resource domain model has read_only: bool and auto_discovered: bool fields
  • ResourceModel.to_domain() correctly maps both fields to the domain object
  • ResourceModel.from_domain() correctly serializes both fields back to the DB model
  • No data is lost on a ResourceModel → Resource → ResourceModel round-trip for either field
  • Behave unit tests cover the round-trip for both read_only and auto_discovered
  • All nox stages pass
  • Coverage >= 97%

Automated by CleverAgents Bot
Supervisor: UAT Testing | Agent: ca-new-issue-creator

## Metadata - **Branch**: `fix/resource-model-read-only-auto-discovered-domain-fields` - **Commit Message**: `fix(data-models): add read_only and auto_discovered fields to Resource domain model to prevent silent data loss on round-trip` - **Milestone**: v3.6.0 - **Parent Epic**: #398 ## Bug Report ### What Was Tested The `ResourceModel` database model (`src/cleveragents/infrastructure/database/models.py`, lines 1532–1613) and its round-trip through the `Resource` domain model (`src/cleveragents/domain/models/core/resource.py`, lines 108–283). ### Expected Behavior (from spec) The `Resource` domain model should faithfully represent all data stored in the `resources` table. When a resource is loaded from the database and saved back, no data should be lost. ### Actual Behavior `ResourceModel` defines two columns that have no corresponding fields in the `Resource` domain model: 1. `read_only = Column(Boolean, nullable=False, default=False)` (line 1568) 2. `auto_discovered = Column(Boolean, nullable=False, default=False)` (line 1569) This causes the following data loss: 1. When a `ResourceModel` is converted to a `Resource` domain object, the `read_only` and `auto_discovered` values are **silently discarded**. 2. When a `Resource` domain object is converted back to a `ResourceModel`, these fields **default to `False`** regardless of their original values. 3. This is a **data loss bug on every round-trip** through the domain layer. **Note:** The `Resource` domain model does have `capabilities.writable` (related to `read_only`), but this is a capability flag derived from the resource type — not the per-resource `read_only` override stored in the database. These are semantically different and must both be preserved. ### Impact - Resources marked as `read_only=True` in the database will lose that flag after any domain-layer round-trip. - Auto-discovered resources (children discovered by resource handlers) lose their `auto_discovered=True` flag after round-trip. - Any service logic that checks `resource.read_only` or `resource.auto_discovered` will not work correctly. ### Code Locations - `src/cleveragents/infrastructure/database/models.py:1568-1569` — `read_only` and `auto_discovered` columns in `ResourceModel` - `src/cleveragents/domain/models/core/resource.py:108-283` — `Resource` domain model (missing these fields) ## Subtasks - [ ] Add `read_only: bool` field to the `Resource` domain model (`src/cleveragents/domain/models/core/resource.py`) - [ ] Add `auto_discovered: bool` field to the `Resource` domain model (`src/cleveragents/domain/models/core/resource.py`) - [ ] Update `ResourceModel.to_domain()` to map `read_only` and `auto_discovered` to the new domain fields - [ ] Update `ResourceModel.from_domain()` (or equivalent) to serialize `read_only` and `auto_discovered` from the domain object back to the DB model - [ ] Write Behave unit tests (in `features/`) covering round-trip serialization of `read_only=True` and `auto_discovered=True` - [ ] Verify `nox -e typecheck` passes with no errors after changes - [ ] Verify `nox -e unit_tests` passes with coverage ≥ 97% ## Definition of Done - [ ] `Resource` domain model has `read_only: bool` and `auto_discovered: bool` fields - [ ] `ResourceModel.to_domain()` correctly maps both fields to the domain object - [ ] `ResourceModel.from_domain()` correctly serializes both fields back to the DB model - [ ] No data is lost on a `ResourceModel → Resource → ResourceModel` round-trip for either field - [ ] Behave unit tests cover the round-trip for both `read_only` and `auto_discovered` - [ ] All nox stages pass - [ ] Coverage >= 97% --- **Automated by CleverAgents Bot** Supervisor: UAT Testing | Agent: ca-new-issue-creator
freemo added this to the v3.6.0 milestone 2026-04-03 17:37:56 +00:00
Author
Owner

Issue triaged by project owner:

  • State: Verified
  • Priority: Medium — read_only and auto_discovered columns exist in the DB but are lost on domain model round-trip. Silent data loss.
  • Milestone: v3.6.0
  • MoSCoW: Should Have — These fields are important for resource management semantics but the core resource CRUD operations work without them.
  • Parent Epic: #398 (Post-MVP Resources)

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

Issue triaged by project owner: - **State**: Verified - **Priority**: Medium — `read_only` and `auto_discovered` columns exist in the DB but are lost on domain model round-trip. Silent data loss. - **Milestone**: v3.6.0 - **MoSCoW**: Should Have — These fields are important for resource management semantics but the core resource CRUD operations work without them. - **Parent Epic**: #398 (Post-MVP Resources) --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: ca-project-owner
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.

Blocks
#398 Epic: Post-MVP Resources
cleveragents/cleveragents-core
Reference
cleveragents/cleveragents-core#2410
No description provided.