UAT: Session export/import does not preserve cost_budget — data loss on round-trip #1355

Open
opened 2026-04-02 16:57:44 +00:00 by freemo · 0 comments
Owner

Bug Report

Feature Area: Session export/import — data completeness / round-trip fidelity

What Was Tested

The Session.as_export_dict() method and PersistentSessionService.import_session() were tested for round-trip fidelity of all session fields, specifically the cost_budget field.

Expected Behavior

A session exported and then re-imported should preserve all session data without loss. The cost_budget field (SessionCostBudget) is a first-class field on the Session domain model and should survive a round-trip.

Actual Behavior

The cost_budget field is not included in the export dict produced by Session.as_export_dict() and is not restored during import. After a round-trip, the imported session always has cost_budget = None, regardless of the original value.

Steps to Reproduce

from cleveragents.domain.models.core.session import Session
from cleveragents.domain.models.core.cost_budget import SessionCostBudget
from cleveragents.application.services.session_service import PersistentSessionService
from unittest.mock import MagicMock
from ulid import ULID

# Create session with cost budget
session = Session(
    session_id=str(ULID()),
    cost_budget=SessionCostBudget(max_cost_usd=10.0, total_cost=2.5)
)

# Export
export_data = session.as_export_dict()
print('cost_budget in export:', 'cost_budget' in export_data)  # False

# Import
mock_session_repo = MagicMock()
mock_message_repo = MagicMock()
service = PersistentSessionService(mock_session_repo, mock_message_repo)
imported = service.import_session(export_data)

print('cost_budget after import:', imported.cost_budget)  # None
print('Original max_cost_usd:', session.cost_budget.max_cost_usd)  # 10.0

Code Location

  • src/cleveragents/domain/models/core/session.py lines 369–410 (as_export_dict method) — cost_budget not included in export dict
  • src/cleveragents/application/services/session_service.py lines 257–290 (import_session method) — cost_budget not restored from import data

Severity

Medium — Any user who has configured a per-session cost budget will lose that configuration when exporting and re-importing their session. This is silent data loss with no warning to the user.

## Bug Report **Feature Area:** Session export/import — data completeness / round-trip fidelity ### What Was Tested The `Session.as_export_dict()` method and `PersistentSessionService.import_session()` were tested for round-trip fidelity of all session fields, specifically the `cost_budget` field. ### Expected Behavior A session exported and then re-imported should preserve all session data without loss. The `cost_budget` field (`SessionCostBudget`) is a first-class field on the `Session` domain model and should survive a round-trip. ### Actual Behavior The `cost_budget` field is **not included** in the export dict produced by `Session.as_export_dict()` and is **not restored** during import. After a round-trip, the imported session always has `cost_budget = None`, regardless of the original value. ### Steps to Reproduce ```python from cleveragents.domain.models.core.session import Session from cleveragents.domain.models.core.cost_budget import SessionCostBudget from cleveragents.application.services.session_service import PersistentSessionService from unittest.mock import MagicMock from ulid import ULID # Create session with cost budget session = Session( session_id=str(ULID()), cost_budget=SessionCostBudget(max_cost_usd=10.0, total_cost=2.5) ) # Export export_data = session.as_export_dict() print('cost_budget in export:', 'cost_budget' in export_data) # False # Import mock_session_repo = MagicMock() mock_message_repo = MagicMock() service = PersistentSessionService(mock_session_repo, mock_message_repo) imported = service.import_session(export_data) print('cost_budget after import:', imported.cost_budget) # None print('Original max_cost_usd:', session.cost_budget.max_cost_usd) # 10.0 ``` ### Code Location - `src/cleveragents/domain/models/core/session.py` lines 369–410 (`as_export_dict` method) — `cost_budget` not included in export dict - `src/cleveragents/application/services/session_service.py` lines 257–290 (`import_session` method) — `cost_budget` not restored from import data ### Severity **Medium** — Any user who has configured a per-session cost budget will lose that configuration when exporting and re-importing their session. This is silent data loss with no warning to the user.
freemo self-assigned this 2026-04-02 18:45:19 +00:00
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#1355
No description provided.