Skip to content

Feature/95 Isolate file read cache by session / 按会话隔离文件读取缓存#106

Merged
SunYanbox merged 4 commits intodevelopfrom
feature/95-isolate-file-read-cache-by-session
May 3, 2026
Merged

Feature/95 Isolate file read cache by session / 按会话隔离文件读取缓存#106
SunYanbox merged 4 commits intodevelopfrom
feature/95-isolate-file-read-cache-by-session

Conversation

@SunYanbox
Copy link
Copy Markdown
Owner

fix #95

SunYanbox added 4 commits May 3, 2026 08:42
- 新增功能: 为文件读取记录表添加会话关联支持
  * 在 `file_read_records` 表中新增 `session_id` 字段并建立外键约束引用 `sessions(id)`
  * 将唯一索引从单列 `file_path` 变更为复合索引 `(session_id, file_path)`
  * 更新 `record_file_read` API 签名,强制传入 `session_id` 参数以区分不同会话的数据
  * 更新 `get_file_read_record` API 签名,增加 `session_id` 查询条件
  * 在 `delete_session` 方法中增加级联删除逻辑,清理对应会话的 `file_read_records` 数据
- 破坏性变更: 数据库架构与API接口变更
  * `file_read_records` 表结构已重组,旧版本依赖全局 `file_path` 唯一性的逻辑失效,所有调用方必须传递 `session_id`
  * `record_file_read` 和 `get_file_read_record` 方法签名发生变更,调用处需补充 `session_id` 参数
  * 迁移脚本 `_migrate_file_read_records_add_session` 会重建该表,导致历史无会话ID的记录丢失
- 重构优化: 更新工具层与审计提交器以适配新的数据库模型
  * `src/workspace/tools/base_tool.py`: 在 `_track_file_read` 和 `check_file_modified` 方法中获取当前会话ID (`_current_session_id`),并作为必需参数传递给 `db.record_file_read` 和 `db.get_file_read_record`
  * `src/core/audit_committer.py`: 修改 `commit_snapshot` 逻辑,使用 `_session_id` 调用数据库接口,并将 `record` 元组中的 `mtime` 索引从 `2` 修正为 `3` (因新增 `session_id` 字段导致列偏移)
  * 确保所有文件读取记录均绑定到特定会话,防止跨会话数据污染
- 破坏性变更: 依赖项API签名变更
  * `workspace.db.record_file_read` 和 `get_file_read_record` 方法签名已强制增加 `session_id` 参数,所有直接调用这些方法的代码必须更新以传入有效的会话ID
  * `FileTracker` 相关逻辑不再支持无会话上下文的全局查询,若 `session_id` 为 `None` 将直接返回 `None`
- 修复问题: 修正数据库接口调用及元组索引偏移错误
  * `tests/core/test_database_manager.py`: 在 `TestFileReadRecords` 类中引入 `create_session` 获取 `session_id`,并更新 `record_file_read` 和 `get_file_read_record` 调用参数
  * `tests/core/test_database_manager.py`: 调整断言中的元组索引,将 `mtime`, `size`, `checksum` 的索引从 `2/3/4` 修正为 `3/4/5`,将 `read_count` 索引从 `6` 修正为 `7`
  * `tests/workspace/tools/test_read_tool.py`, `test_write_tool.py`, `test_edit_tool.py`, `test_audit_committer.py`: 在 `workspace` fixture 中初始化 `_current_session_id`,确保所有测试场景均绑定有效会话
  * `tests/workspace/tools/test_read_tool.py`: 同步更新文件读取记录查询逻辑,增加 `session_id` 参数并修正索引引用
  * `tests/core/test_audit_committer.py`: 修改 `commit_snapshot` 相关测试,显式传递 `session_id` 参数给 `record_file_read` 和快照创建函数
- 破坏性变更: 测试代码依赖变更
  * 所有涉及 `file_read_records` 的测试必须传入 `session_id`,移除无会话上下文的测试用例
  * 测试数据验证逻辑需根据新表结构调整字段索引顺序
- 重构优化: 分离迁移脚本与初始化阶段的索引构建
  * 移除 `create_tables` 方法中硬编码的 `idx_file_read_records_session_path` 定义,避免在旧版本表结构上重复执行或冲突
  * 新增独立代码块,在数据库初始化流程末尾显式调用 `CREATE INDEX IF NOT EXISTS idx_file_read_records_session_path ON file_read_records(session_id, file_path)`
  * 确保新索引仅在 `session_id` 列存在后(即完成 Phase 4 迁移或新建库时)才被创建,提升初始化逻辑的健壮性
  * 修正 `_migrate_file_read_records_add_session` 迁移脚本中的索引名称,将 `idx_file_read_records_path` 统一更新为 `idx_file_read_records_session_path`
@SunYanbox SunYanbox added bug Something isn't working enhancement New feature or request labels May 3, 2026
@SunYanbox SunYanbox changed the base branch from main to develop May 3, 2026 01:05
@SunYanbox SunYanbox merged commit 1ffc619 into develop May 3, 2026
3 checks passed
@SunYanbox SunYanbox deleted the feature/95-isolate-file-read-cache-by-session branch May 3, 2026 01:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Isolate file read cache by session / 按会话隔离文件读取缓存

1 participant