Skip to content

feat: add versioned state-store migrations#380

Merged
liujuanjuan1984 merged 2 commits intomainfrom
chore/372-state-store-migration-review
Apr 2, 2026
Merged

feat: add versioned state-store migrations#380
liujuanjuan1984 merged 2 commits intomainfrom
chore/372-state-store-migration-review

Conversation

@liujuanjuan1984
Copy link
Copy Markdown
Collaborator

@liujuanjuan1984 liujuanjuan1984 commented Apr 2, 2026

背景

当前自维护 state store 已经出现显式 schema 演进需求,但升级路径仍停留在 create_all + 隐式补列。本 PR 将其收敛为内建、自动执行的轻量 migration 机制,优先覆盖 opencode-a2a 自维护的 state tables。

State Store Migrations

  • 新增 src/opencode_a2a/server/migrations.py
  • 引入 a2a_schema_version 记录表,当前 scope 为 state_store
  • 增加顺序 migration runner,并定义首个 migration:补齐历史 a2a_interrupt_requests.details_json 字段
  • 保持 SQLite 优先支持,不引入 Alembic;首个补列 migration 通过当前 SQLAlchemy dialect 生成 DDL,避免把自动升级路径错误限制在 SQLite

Initialization Path

  • src/opencode_a2a/server/state_store.py 改为统一走显式 migration 初始化路径
  • 删除旧的 _add_missing_sqlite_column() / _ensure_state_store_schema() 隐式补丁逻辑
  • 保持 DatabaseSessionStateRepositoryDatabaseInterruptRequestRepository 的外部行为不变
  • 明确本次 migration 仅接管自维护 state tables,不接管 A2A SDK DatabaseTaskStoretasks 表 schema 生命周期

Tests And Docs

  • tests/server/test_state_store.py 新增/扩展以下回归:
    • 旧 schema 自动升级
    • 当前 schema 但缺少 version 记录时自动补记版本
    • 多 repository / 重复初始化幂等性
    • 非 SQLite dialect 的补列 DDL 生成
  • docs/guide.md 增加 migration scope 与 ownership 边界说明
  • 验证:./scripts/doctor.sh

Issue 关联

@liujuanjuan1984 liujuanjuan1984 changed the title feat: add lightweight state-store schema migrations feat: add versioned state-store migrations Apr 2, 2026
@liujuanjuan1984
Copy link
Copy Markdown
Collaborator Author

本次 PR 自审结论如下。

  • 未发现阻塞性问题。
  • 实现方向与 #372 的目标一致:把 state store 从 create_all + 隐式补列 收敛为内建、顺序执行的轻量 migration runner,比在当前项目形态下直接引入 Alembic 更贴合实际。
  • scope 控制是合理的:本 PR 只接管 opencode-a2a 自维护 state tables 的 schema 生命周期,没有把 A2A SDK DatabaseTaskStoretasks 表强行纳入本仓库 migration ownership,避免了混合 ownership。
  • 测试覆盖与需求也对齐:旧 schema 自动升级、当前 schema 补记版本、重复初始化幂等性都已补齐回归,./scripts/doctor.sh 已通过,结果为 480 passed,总覆盖率 91.40%

风险与边界说明:

  • 当前 migration runner 的自动升级 DDL 明确只覆盖 SQLite,这一点与文档说明和当前默认 durable 部署路径一致,因此不是缺陷;但如果未来要正式支持非 SQLite 的 state schema 演进,需要补对应 migration,而不是默认复用当前实现。
  • PR 中 src/opencode_a2a/py.typed 的 diff 只是工具链规范化空文件的结果,不影响运行时行为。

Issue 关系检查:

  • Closes #372 准确。
  • Related #367 准确。
  • 当前不需要修正为其它 closes / related 关系。

@liujuanjuan1984
Copy link
Copy Markdown
Collaborator Author

补充说明:已追加兼容性修复。

  • 原先 migration helper 对自动升级 DDL 做了 SQLite 限定;对于旧的非 SQLite durable state store,如果缺少 details_json 列,会在启动时直接报不支持。
  • 现在已改为按当前 SQLAlchemy dialect 生成通用 ALTER TABLE ... ADD COLUMN ... 语句,并补了方言级测试,避免把自动升级路径错误地限制在 SQLite。
  • 回归已重新通过:./scripts/doctor.sh => 481 passed,总覆盖率 91.40%

@liujuanjuan1984 liujuanjuan1984 merged commit 393efc1 into main Apr 2, 2026
3 checks passed
@liujuanjuan1984 liujuanjuan1984 deleted the chore/372-state-store-migration-review branch April 2, 2026 12:22
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.

[Priority: Med] [Reliability] 为 state store 引入 schema version 与 migration 机制

1 participant