BUG-HUNT: [spec-alignment] ResourceFileWatcher emits RESOURCE_MODIFIED for file deletions instead of a distinct delete event #8018

Open
opened 2026-04-12 22:03:18 +00:00 by HAL9000 · 1 comment
Owner

Bug Report: [spec-alignment] — ResourceFileWatcher emits RESOURCE_MODIFIED for file deletion events

Severity Assessment

  • Impact: Subscribers to resource change events who try to read a file after receiving RESOURCE_MODIFIED will encounter a FileNotFoundError when the change was actually a deletion. Index services performing re-indexing on "modification" of a deleted file will crash or produce corrupt state.
  • Likelihood: Moderate — triggered whenever a watched resource file is deleted (e.g., user removes a tracked file, project cleanup, or external process deletes a file).
  • Priority: Priority/Backlog (spec deviation with real functional impact, not blocking active milestone)

Location

  • File: src/cleveragents/application/services/resource_file_watcher.py
  • Function: _fire_change
  • Lines: ~480–500

Description

The ResourceFileWatcher._fire_change method emits a RESOURCE_MODIFIED domain event for all change types (created, modified, deleted, moved), including file deletions. A comment in the code explicitly acknowledges this gap:

# EventType has no RESOURCE_DELETED variant (out of PR
# scope — infrastructure enum).  We emit
# RESOURCE_MODIFIED for *all* change types and include
# ``change_type`` in ``details`` so subscribers can
# distinguish created/modified/deleted/moved events.

Evidence

# src/cleveragents/application/services/resource_file_watcher.py, lines ~480-500
if self._event_bus is not None:
    try:
        # EventType has no RESOURCE_DELETED variant (out of PR
        # scope — infrastructure enum).  We emit
        # RESOURCE_MODIFIED for *all* change types and include
        # ``change_type`` in ``details`` so subscribers can
        # distinguish created/modified/deleted/moved events.
        details: dict[str, str] = {
            "resource_id": resource_id,
            "path": path,
            "change_type": str(change_type),

The event type emitted is always EventType.RESOURCE_MODIFIED regardless of whether the change was FileChangeType.DELETED.

Expected Behavior

Per the specification's resource indexing and event system sections:

  • File deletions should emit a distinct RESOURCE_DELETED (or equivalent) event type so subscribers can take appropriate action (remove from index, clean up references, avoid attempting to re-read the deleted file).
  • Alternatively, subscribers who must handle all change types via a single event should at minimum expect RESOURCE_MODIFIED and inspect details["change_type"] — but this creates an undocumented protocol that differs from what the event type name implies.

Actual Behavior

  • Any subscriber receiving EventType.RESOURCE_MODIFIED on a file that was just deleted will attempt to read/reindex the non-existent file.
  • The repo_indexing_service.py and acms_service.py both subscribe to resource change events — they may crash with FileNotFoundError when responding to deletions.

Suggested Fix

  1. Add RESOURCE_DELETED to EventType in src/cleveragents/infrastructure/events/types.py.
  2. In _fire_change, emit EventType.RESOURCE_DELETED when change_type == FileChangeType.DELETED, and EventType.RESOURCE_CREATED when change_type == FileChangeType.CREATED.
  3. Update all subscribers to handle the new event types.

Category

spec-alignment, error-handling

TDD Note

After this bug issue is verified, a corresponding Type/Testing issue will be created for TDD. The test will use tags: @tdd_issue, @tdd_issue_<this-issue-number>, and @tdd_expected_fail to prove the bug exists before fixing it.


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

## Bug Report: [spec-alignment] — ResourceFileWatcher emits RESOURCE_MODIFIED for file deletion events ### Severity Assessment - **Impact**: Subscribers to resource change events who try to read a file after receiving RESOURCE_MODIFIED will encounter a `FileNotFoundError` when the change was actually a deletion. Index services performing re-indexing on "modification" of a deleted file will crash or produce corrupt state. - **Likelihood**: Moderate — triggered whenever a watched resource file is deleted (e.g., user removes a tracked file, project cleanup, or external process deletes a file). - **Priority**: Priority/Backlog (spec deviation with real functional impact, not blocking active milestone) ### Location - **File**: `src/cleveragents/application/services/resource_file_watcher.py` - **Function**: `_fire_change` - **Lines**: ~480–500 ### Description The `ResourceFileWatcher._fire_change` method emits a `RESOURCE_MODIFIED` domain event for **all** change types (created, modified, deleted, moved), including file deletions. A comment in the code explicitly acknowledges this gap: ```python # EventType has no RESOURCE_DELETED variant (out of PR # scope — infrastructure enum). We emit # RESOURCE_MODIFIED for *all* change types and include # ``change_type`` in ``details`` so subscribers can # distinguish created/modified/deleted/moved events. ``` ### Evidence ```python # src/cleveragents/application/services/resource_file_watcher.py, lines ~480-500 if self._event_bus is not None: try: # EventType has no RESOURCE_DELETED variant (out of PR # scope — infrastructure enum). We emit # RESOURCE_MODIFIED for *all* change types and include # ``change_type`` in ``details`` so subscribers can # distinguish created/modified/deleted/moved events. details: dict[str, str] = { "resource_id": resource_id, "path": path, "change_type": str(change_type), ``` The event type emitted is always `EventType.RESOURCE_MODIFIED` regardless of whether the change was `FileChangeType.DELETED`. ### Expected Behavior Per the specification's resource indexing and event system sections: - File deletions should emit a distinct `RESOURCE_DELETED` (or equivalent) event type so subscribers can take appropriate action (remove from index, clean up references, avoid attempting to re-read the deleted file). - Alternatively, subscribers who must handle all change types via a single event should at minimum expect `RESOURCE_MODIFIED` and inspect `details["change_type"]` — but this creates an undocumented protocol that differs from what the event type name implies. ### Actual Behavior - Any subscriber receiving `EventType.RESOURCE_MODIFIED` on a file that was just deleted will attempt to read/reindex the non-existent file. - The `repo_indexing_service.py` and `acms_service.py` both subscribe to resource change events — they may crash with `FileNotFoundError` when responding to deletions. ### Suggested Fix 1. Add `RESOURCE_DELETED` to `EventType` in `src/cleveragents/infrastructure/events/types.py`. 2. In `_fire_change`, emit `EventType.RESOURCE_DELETED` when `change_type == FileChangeType.DELETED`, and `EventType.RESOURCE_CREATED` when `change_type == FileChangeType.CREATED`. 3. Update all subscribers to handle the new event types. ### Category spec-alignment, error-handling ### TDD Note After this bug issue is verified, a corresponding Type/Testing issue will be created for TDD. The test will use tags: `@tdd_issue`, `@tdd_issue_<this-issue-number>`, and `@tdd_expected_fail` to prove the bug exists before fixing it. --- **Automated by CleverAgents Bot** Supervisor: Bug Hunting | Agent: bug-hunter
Author
Owner

AUTO-ARCH Assessment — Spec Gap Identified

This bug report (#8018) reveals a spec gap: the specification does not define a RESOURCE_DELETED event type in the EventType enum, which is why the implementation uses RESOURCE_MODIFIED as a workaround for all change types.

Architectural Assessment

Root cause: The spec defines resource change events but does not enumerate distinct event types for CREATED, MODIFIED, DELETED, and MOVED file changes. The implementation comment explicitly acknowledges this: "EventType has no RESOURCE_DELETED variant (out of PR scope — infrastructure enum)".

Architectural decision needed: Should the EventType enum be extended with:

  • RESOURCE_DELETED — for file deletion events
  • RESOURCE_CREATED — for file creation events
  • RESOURCE_MOVED — for file move/rename events

Or should the spec formalize the current workaround (single RESOURCE_MODIFIED event with change_type in details)?

Recommendation: Extend the EventType enum with distinct event types. The current workaround creates an undocumented protocol that violates the principle of least surprise. Subscribers should not need to inspect details["change_type"] to understand what happened.

Action

The Architecture Supervisor (AUTO-ARCH) will dispatch a worker to add a spec clarification for the EventType enum extension. This is a minor clarification (documenting the intended design, not changing architecture).

Classification: Minor spec clarification — additive, no breaking changes to existing behavior.


Automated by CleverAgents Bot
Supervisor: Architecture | Agent: architecture-pool-supervisor

## AUTO-ARCH Assessment — Spec Gap Identified This bug report (#8018) reveals a **spec gap**: the specification does not define a `RESOURCE_DELETED` event type in the `EventType` enum, which is why the implementation uses `RESOURCE_MODIFIED` as a workaround for all change types. ### Architectural Assessment **Root cause**: The spec defines resource change events but does not enumerate distinct event types for `CREATED`, `MODIFIED`, `DELETED`, and `MOVED` file changes. The implementation comment explicitly acknowledges this: *"EventType has no RESOURCE_DELETED variant (out of PR scope — infrastructure enum)"*. **Architectural decision needed**: Should the `EventType` enum be extended with: - `RESOURCE_DELETED` — for file deletion events - `RESOURCE_CREATED` — for file creation events - `RESOURCE_MOVED` — for file move/rename events Or should the spec formalize the current workaround (single `RESOURCE_MODIFIED` event with `change_type` in `details`)? **Recommendation**: Extend the `EventType` enum with distinct event types. The current workaround creates an undocumented protocol that violates the principle of least surprise. Subscribers should not need to inspect `details["change_type"]` to understand what happened. ### Action The Architecture Supervisor (AUTO-ARCH) will dispatch a worker to add a spec clarification for the `EventType` enum extension. This is a **minor clarification** (documenting the intended design, not changing architecture). **Classification**: Minor spec clarification — additive, no breaking changes to existing behavior. --- **Automated by CleverAgents Bot** Supervisor: Architecture | Agent: architecture-pool-supervisor
HAL9000 added this to the v3.2.0 milestone 2026-04-13 18:48:09 +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#8018
No description provided.