Skip to content

fix(agent): 使用短 UUID 替代名称生成 Agent ID#2065

Open
gongzhi-netease wants to merge 1 commit into
netease-youdao:mainfrom
gongzhi-netease:fix/agent-id-short-uuid
Open

fix(agent): 使用短 UUID 替代名称生成 Agent ID#2065
gongzhi-netease wants to merge 1 commit into
netease-youdao:mainfrom
gongzhi-netease:fix/agent-id-short-uuid

Conversation

@gongzhi-netease

@gongzhi-netease gongzhi-netease commented May 28, 2026

Copy link
Copy Markdown

问题背景

当前 Agent ID 基于名称生成(如 "My Assistant" → "my-assistant"),存在以下问题:
数据复活问题:删除 Agent 后,本地文件(workspace、sessions)未清理,重新创建同名 Agent 时会复用相同 ID,导致旧数据意外复活。

删除 Agent 时的遗漏问题(待后续修复)

当前删除 Agent 时存在以下数据未清理的问题:

数据 当前状态 影响
cowork_sessions(关联的会话) ❌ 未清理 孤儿会话无法在 UI 显示
cowork_messages(关联的消息) ❌ 未清理 数据库空间浪费
im_session_mappings(IM 映射) ❌ 未清理 孤儿映射记录
定时任务(agentId 匹配的任务) ❌ 未处理 任务继续执行但结果无处显示
OpenClaw workspace 目录 ❌ 未清理 磁盘空间浪费、数据复活风险
OpenClaw sessions 目录 ❌ 未清理 磁盘空间浪费

本次 PR 通过使用随机 ID 解决数据复活的核心问题,上述清理逻辑作为后续优化项。

解决方案

使用 UUID v4 前 8 位作为 Agent ID(如 550e8400):

  • 每次创建 Agent 生成唯一随机 ID
  • 碰撞时自动重试(实际碰撞概率极低:43 亿种可能)
  • 保持向后兼容:如果调用方显式传入 request.id,仍使用传入值

改动内容

  • src/main/coworkStore.ts:修改 createAgent 方法的 ID 生成逻辑
image

Replace name-based slug generation with UUID v4 first 8 characters.

This prevents data resurrection when recreating agents with the same name

after deletion, as each new agent now gets a unique random ID.

- Generate 8-char hex ID from UUID v4 (e.g. '550e8400')

- Retry if ID already exists (collision probability is negligible)

- Preserve backward compatibility when request.id is provided
@github-actions

Copy link
Copy Markdown

This pull request has been inactive for 30 days. It will be automatically closed in 14 days unless there is new activity.

If you're still working on this, please leave a comment or push new commits to keep it open. Thank you!

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant