Fix/sqlite cascade delete issue#50
Open
Gui-Yue wants to merge 2 commits intoshareAI-lab:mainfrom
Open
Conversation
…n of child records
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
修复 SQLite 存储中
INSERT OR REPLACE导致的外键级联删除问题:更新 Agent元数据时,
messages、tool_calls、snapshots子表数据被意外清空。Motivation / Context
SqliteStore.saveInfo()使用INSERT OR REPLACE INTO agents,在 SQLite 中等价于 DELETE + INSERT。由于子表声明了FOREIGN KEY ... ON DELETE CASCADE,每次更新 agent 信息都会触发级联删除,导致关联的 messages、tool_calls、snapshots 全部丢失。修复方式:将
INSERT OR REPLACE改为INSERT ... ON CONFLICT DO UPDATE SET(UPSERT),避免触发DELETE;同时启用
PRAGMA foreign_keys = ON使外键约束生效。Type of Change
Scope / Modules
Public API
src/index.tsBreaking Changes
Testing
npm run test:unit(required)npm run test:integration(if needed)npm run test:e2e(if needed)Impact / Risk
风险较低。
本次改动:
saveInfo()和saveSnapshot()从INSERT OR REPLACE改为ON CONFLICT DO UPDATE,语义不变,仅避免触发 DELETE 行为。PRAGMA foreign_keys = ON,使外键约束(含delete()方法的级联删除)正确生效。Checklist
tests/README.mdstructuredocs/en+docs/zh-CNformat rulesdist/changes (unless release)