UAT: agents project context set replaces entire view on each call — previously set fields silently lost (data loss) #6062

Open
opened 2026-04-09 14:19:11 +00:00 by HAL9000 · 0 comments
Owner

Summary

agents project context set creates a brand-new ContextView on every invocation using only the flags provided in that call. Any fields not explicitly passed are reset to their defaults (None / empty list). This means a user who sets --max-file-size 1024 in one call and then sets --include-resource "db-*" in a second call will silently lose the max_file_size setting.

Expected Behavior

context set should merge the provided flags into the existing view for the target phase, preserving all previously configured fields that are not explicitly overridden in the current call.

Actual Behavior

# src/cleveragents/cli/commands/project_context.py  lines 610-618
new_view = ContextView(
    include_resources=include_resource or [],
    exclude_resources=exclude_resource or [],
    include_paths=include_path or [],
    exclude_paths=exclude_path or [],
    max_file_size=max_file_size,      # None if not passed
    max_total_size=max_total_size,    # None if not passed
)
policy = policy.model_copy(update={f"{view}_view": new_view})

Every call constructs a fresh ContextView from scratch. Fields not provided in the current CLI invocation are set to None / [], overwriting any previously persisted values.

Steps to Reproduce

# Step 1: Set max_file_size
agents project context set myproject --view default --max-file-size 1024

# Step 2: Verify it was saved
agents project context show myproject --view default --format json
# → resolved_view.max_file_size == 1024  ✓

# Step 3: Add an include-resource (without repeating max-file-size)
agents project context set myproject --view default --include-resource "db-*"

# Step 4: Verify — max_file_size is now gone
agents project context show myproject --view default --format json
# → resolved_view.max_file_size == null  ✗ (was 1024)
# → resolved_view.include_resources == ["db-*"]  ✓

Code Location

  • src/cleveragents/cli/commands/project_context.py lines 609–618

Fix

Read the existing view for the target phase and merge only the explicitly-provided flags:

# Read existing view for the target phase
existing_view = policy.resolve_view(view) if view != "default" else policy.default_view

# Build update dict from only the flags that were explicitly provided
updates: dict[str, Any] = {}
if include_resource is not None:
    updates["include_resources"] = include_resource
if exclude_resource is not None:
    updates["exclude_resources"] = exclude_resource
if include_path is not None:
    updates["include_paths"] = include_path
if exclude_path is not None:
    updates["exclude_paths"] = exclude_path
if max_file_size is not None:
    updates["max_file_size"] = max_file_size
if max_total_size is not None:
    updates["max_total_size"] = max_total_size

new_view = existing_view.model_copy(update=updates)
policy = policy.model_copy(update={f"{view}_view": new_view})

Note: The --clear flag already correctly resets the view to defaults, so that path does not need to change.

Impact

  • Users cannot incrementally configure a context view — every context set call must repeat all previously set flags or they are lost
  • Particularly problematic for max_file_size/max_total_size budget constraints which are easily forgotten when adding resource/path filters
  • No error or warning is shown when settings are overwritten

Automated by CleverAgents Bot
Supervisor: UAT Testing | Agent: uat-tester

## Summary `agents project context set` creates a brand-new `ContextView` on every invocation using only the flags provided in that call. Any fields not explicitly passed are reset to their defaults (`None` / empty list). This means a user who sets `--max-file-size 1024` in one call and then sets `--include-resource "db-*"` in a second call will silently lose the `max_file_size` setting. ## Expected Behavior `context set` should **merge** the provided flags into the existing view for the target phase, preserving all previously configured fields that are not explicitly overridden in the current call. ## Actual Behavior ```python # src/cleveragents/cli/commands/project_context.py lines 610-618 new_view = ContextView( include_resources=include_resource or [], exclude_resources=exclude_resource or [], include_paths=include_path or [], exclude_paths=exclude_path or [], max_file_size=max_file_size, # None if not passed max_total_size=max_total_size, # None if not passed ) policy = policy.model_copy(update={f"{view}_view": new_view}) ``` Every call constructs a fresh `ContextView` from scratch. Fields not provided in the current CLI invocation are set to `None` / `[]`, overwriting any previously persisted values. ## Steps to Reproduce ```bash # Step 1: Set max_file_size agents project context set myproject --view default --max-file-size 1024 # Step 2: Verify it was saved agents project context show myproject --view default --format json # → resolved_view.max_file_size == 1024 ✓ # Step 3: Add an include-resource (without repeating max-file-size) agents project context set myproject --view default --include-resource "db-*" # Step 4: Verify — max_file_size is now gone agents project context show myproject --view default --format json # → resolved_view.max_file_size == null ✗ (was 1024) # → resolved_view.include_resources == ["db-*"] ✓ ``` ## Code Location - `src/cleveragents/cli/commands/project_context.py` lines 609–618 ## Fix Read the existing view for the target phase and merge only the explicitly-provided flags: ```python # Read existing view for the target phase existing_view = policy.resolve_view(view) if view != "default" else policy.default_view # Build update dict from only the flags that were explicitly provided updates: dict[str, Any] = {} if include_resource is not None: updates["include_resources"] = include_resource if exclude_resource is not None: updates["exclude_resources"] = exclude_resource if include_path is not None: updates["include_paths"] = include_path if exclude_path is not None: updates["exclude_paths"] = exclude_path if max_file_size is not None: updates["max_file_size"] = max_file_size if max_total_size is not None: updates["max_total_size"] = max_total_size new_view = existing_view.model_copy(update=updates) policy = policy.model_copy(update={f"{view}_view": new_view}) ``` Note: The `--clear` flag already correctly resets the view to defaults, so that path does not need to change. ## Impact - Users cannot incrementally configure a context view — every `context set` call must repeat all previously set flags or they are lost - Particularly problematic for `max_file_size`/`max_total_size` budget constraints which are easily forgotten when adding resource/path filters - No error or warning is shown when settings are overwritten --- **Automated by CleverAgents Bot** Supervisor: UAT Testing | Agent: uat-tester
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#6062
No description provided.