Bug: Inconsistent path handling prevents retrieving context for files added with relative paths #8128

Open
opened 2026-04-13 03:39:27 +00:00 by HAL9000 · 1 comment
Owner

Metadata

  • Commit message: fix(context_service): normalize file paths to absolute before storing in context
  • Branch name: fix/context-service-path-normalization
  • Module: src/cleveragents/application/services/context_service.py
  • Lines: 242, 489
  • Analysis Pass: Code Consistency / Data Flow

Background and Context

The ContextService allows adding files to a plan's context and later retrieving their content. For this to work reliably, the path used to store a file's context must be handled in the same way as the path used to retrieve it.

There is a critical inconsistency in how file paths are handled:

  • When a file is added, _add_file_to_context stores the path as a simple string without normalization: path=str(file_path) (line 242). If a user provides a relative path (e.g., src/main.py), it is stored as a relative path.
  • When content is retrieved, get_context_content takes a path, resolves it to an absolute path (resolved_path = path.resolve(), line 489), and then compares this absolute path to the (potentially relative) path stored in the database.

This mismatch means that if a file is added using a relative path, the get_context_content method will never find it, because the resolved absolute path will not match the stored relative path. This breaks a core feature of the service.


Expected Behavior

All file paths should be normalized to a consistent format (i.e., absolute paths) before being stored in the database. When retrieving content, the lookup path should be normalized in the same way, ensuring that lookups are reliable regardless of how the path was initially provided.


Acceptance Criteria

  • Paths are resolved to absolute paths before being stored in the Context model.
  • get_context_content can successfully retrieve content for files that were added using either relative or absolute paths.
  • The path normalization is consistent across the service.

Subtasks

  • Modify the _add_file_to_context method to store the resolved, absolute path: path=str(file_path.resolve()).
  • Review other methods in ContextService to ensure consistent path handling.
  • Add a unit test that adds a file with a relative path and then successfully retrieves its content using get_context_content.

Definition of Done

  • All subtasks are complete.
  • Code is reviewed and merged.
  • Unit tests pass.

Automated by CleverAgents Bot
Supervisor: Bug Hunt Pool | Agent: bug-hunt-pool-supervisor


Automated by CleverAgents Bot
Agent: new-issue-creator

## Metadata - **Commit message:** `fix(context_service): normalize file paths to absolute before storing in context` - **Branch name:** `fix/context-service-path-normalization` - **Module:** `src/cleveragents/application/services/context_service.py` - **Lines:** 242, 489 - **Analysis Pass:** Code Consistency / Data Flow --- ## Background and Context The `ContextService` allows adding files to a plan's context and later retrieving their content. For this to work reliably, the path used to store a file's context must be handled in the same way as the path used to retrieve it. There is a critical inconsistency in how file paths are handled: - When a file is added, `_add_file_to_context` stores the path as a simple string without normalization: `path=str(file_path)` (line 242). If a user provides a relative path (e.g., `src/main.py`), it is stored as a relative path. - When content is retrieved, `get_context_content` takes a path, resolves it to an absolute path (`resolved_path = path.resolve()`, line 489), and then compares this absolute path to the (potentially relative) path stored in the database. This mismatch means that if a file is added using a relative path, the `get_context_content` method will never find it, because the resolved absolute path will not match the stored relative path. This breaks a core feature of the service. --- ## Expected Behavior All file paths should be normalized to a consistent format (i.e., absolute paths) before being stored in the database. When retrieving content, the lookup path should be normalized in the same way, ensuring that lookups are reliable regardless of how the path was initially provided. --- ## Acceptance Criteria - [ ] Paths are resolved to absolute paths before being stored in the `Context` model. - [ ] `get_context_content` can successfully retrieve content for files that were added using either relative or absolute paths. - [ ] The path normalization is consistent across the service. --- ## Subtasks - [ ] Modify the `_add_file_to_context` method to store the resolved, absolute path: `path=str(file_path.resolve())`. - [ ] Review other methods in `ContextService` to ensure consistent path handling. - [ ] Add a unit test that adds a file with a relative path and then successfully retrieves its content using `get_context_content`. --- ## Definition of Done - All subtasks are complete. - Code is reviewed and merged. - Unit tests pass. --- **Automated by CleverAgents Bot** Supervisor: Bug Hunt Pool | Agent: bug-hunt-pool-supervisor --- **Automated by CleverAgents Bot** Agent: new-issue-creator
HAL9000 added this to the v3.4.0 milestone 2026-04-13 03:39:32 +00:00
Author
Owner

Verified — Path handling inconsistency is a real bug but Backlog priority suggests it's an edge case. Could Have fix for v3.4.0. Verified.


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

✅ **Verified** — Path handling inconsistency is a real bug but Backlog priority suggests it's an edge case. **Could Have** fix for v3.4.0. Verified. --- **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#8128
No description provided.