Skip to content

Fix/sqlite cascade delete issue#50

Open
Gui-Yue wants to merge 2 commits intoshareAI-lab:mainfrom
Gui-Yue:fix/sqlite-cascade-delete-issue-49
Open

Fix/sqlite cascade delete issue#50
Gui-Yue wants to merge 2 commits intoshareAI-lab:mainfrom
Gui-Yue:fix/sqlite-cascade-delete-issue-49

Conversation

@Gui-Yue
Copy link
Copy Markdown
Contributor

@Gui-Yue Gui-Yue commented Apr 15, 2026

Summary

修复 SQLite 存储中 INSERT OR REPLACE 导致的外键级联删除问题:更新 Agent
元数据时,messagestool_callssnapshots 子表数据被意外清空。

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

  • Bug fix
  • Feature
  • Refactor
  • Docs
  • Test
  • Chore / Build

Scope / Modules

  • core (agent / events / pool / room / scheduler)
  • infra (db / provider / sandbox / store)
  • tools (fs / bash / mcp / skills / task)
  • skills
  • examples
  • docs (en / zh-CN)
  • tests
  • other: ___

Public API

  • Exports changed in src/index.ts
  • No public API change

Breaking Changes

  • Yes , and attach report(include necessity) and transition plan
  • No

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() 方法的级联删除)正确生效。
  • 新增回归测试验证更新 agent 后子表数据完整性。

Checklist

  • Docs updated if needed
  • Examples updated if needed
  • New feature includes related tests and docs
  • Tests follow tests/README.md structure
  • Docs follow docs/en + docs/zh-CN format rules
  • No secrets or tokens committed
  • No dist/ changes (unless release)
  • Only one lockfile updated for the package manager used

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When using sqlite for store, the messages, tool_calls cannot be persisted, only agents data can be saved

1 participant