microsoft / microsoft/Huabu

引入 DB 之后需要进行的修改

Open
#60 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
146
Forks
20
Avg merge
2d 6h
Merged PRs (30d)
43

Description

背景

Long-horizon Tasks 的第一阶段暂时通过 Canvas 中的 Question Nodes 按 threadId 线性查找 Agent Node。这个实现足够简单,也避免在数据库落地前提前引入持久化抽象。

引入 DB 后,应将线程与 Huabu 应用实体之间的稳定关系正规化到应用层数据表中,而不是放进 Agenetes WorkloadSpec 的 application-specific bindingContext

需要修改

  1. 增加 Agent Thread 关系表,建议最小字段为:
    • thread_id:全局唯一主键
    • canvas_id:所属 Canvas,建立索引
    • node_id:对应的 Agent/Question Node,全局或 Canvas 内唯一约束
    • run_id:可空;Task 可通过 Run 关联
    • parent_thread_id:可空;记录递归委派关系
    • created_at
  2. 增加 Workspace 全局的 threadId -> canvasId 索引表或等价全局索引。即使 Agent Thread 业务数据和 Agenetes 历史按 Canvas 分区,调用方也必须能够仅凭全局唯一的 threadId 定位 canvasId,然后加载对应 Agent Node、Run 和内部 Namespace。
  3. 提供只接受 threadId 的全局定位 Repository/API;调用方不应为了查找线程而额外携带 Canvas 参数。
  4. resolveFixedAgentNodeByThreadId() 等 Canvas 线性扫描替换为全局索引 + Repository/DB 查询,调用层接口保持稳定。
  5. 在 Agent Node 创建、Run root 创建和 delegated Agent 创建时同步写入关系记录与全局索引。
  6. 明确 Node/Canvas/Run 删除后的引用和索引清理策略,避免 DB 关系、全局索引与 Canvas 拓扑静默漂移。
  7. 为现有 Canvas 中带 threadId 的 Question Nodes 提供一次性回填迁移,并检测重复 threadId、重复 nodeId 和失效引用。

设计约束

  • 应用关系以 DB 为准;WorkloadSpec 只描述运行与恢复,不复制 nodeIdtaskIdrunId 等 Huabu 业务关系。
  • threadId 保持全局唯一,是 Agent Thread 的公开地址和全局索引主键。
  • Canvas/Agenetes Namespace 仍可作为内部持久化位置,但不得重新暴露到新的 Agent-facing API。
  • 全局索引必须位于 Workspace 级别,不能要求先知道 Canvas 才能查询。
  • 在 DB 实现落地前,继续使用当前的 Canvas 扫描,不单独引入临时索引或第二套关系存储。

验收标准

  • 仅凭 threadId 可以通过 Workspace 全局索引定位 canvasId 和对应 Agent Node。
  • Agent Thread 调用、恢复和 RFS continuation 不再要求调用方提供 Canvas,也不再扫描 Canvas 节点列表。
  • 新建 root/delegated Agent Thread 会写入正确的全局索引、Run 和父线程关系。
  • Canvas/Node 删除会按定义更新或保留索引,不产生静默悬挂记录。
  • 旧数据迁移可重复执行,并对冲突或损坏数据显式失败。
  • 删除与恢复场景具有覆盖完整性约束的测试。

相关清理:#58(移除 Agenetes thread API 的 legacy Namespace 参数)。

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing resolveFixedAgentNodeByThreadId() and the current Canvas node scan, then review the related Agent Thread, Run, Node, and Canvas APIs. Define the database relationship and Workspace-level threadId-to-canvasId lookup around the listed constraints. Done means thread-only lookup, creation and deletion consistency, repeatable migration with explicit conflict failures, and coverage for deletion and recovery scenarios.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
backend-api-design, database
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.