Skip to content

fix(chat): resume conversations after skill installation - #1260

Open
Robert0622 wants to merge 2 commits into
mainfrom
codex/fix-shared-skill-symlinks
Open

Robert0622 wants to merge 2 commits into
mainfrom
codex/fix-shared-skill-symlinks

Conversation

@Robert0622

@Robert0622 Robert0622 commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Validate the directories scheduled for replacement before opening the native conversation, so stale links inside generated Skills, role definitions, or attachment copies do not block the next turn.
  • Apply the same rule to Runner prepare, asset reset, and transient cleanup. Sync and CLI startup validate the files they use, and validation covers asset roots and protected session paths.

Verification

  • Reproduced the original shared-cache error in a disposable project chat with CodeBuddy and DeepSeek V4.1 Flash. The failure occurred before the second CLI attempt.
  • With the full patch, personal and project chats each completed two real Flash turns. Before the second turn, the three generated trees held stale links. Both chats resumed the same native session, preserved the workspace link target, and rebuilt the registered attachment.
  • Replayed prepare, reset, sync, and transient discard through a local Runner against real files.
  • Passed the complete HTTP API, runtime, and Runner Go test packages, including the new regressions for generated assets and protected paths.

@newexploreor newexploreor left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

整体 LGTM。定位准确,改动收敛,安全边界没有放松。下面有两条建议和一个小 nit,都不阻塞合入。

已确认的点

  • 技能目录根和祖先路径仍然做全量校验:WalkDir 先判断 ModeSymlink 再走 SkipDir,所以 home/.agents/skills 本身是链接、或者 home/.agents 是链接时,仍然会被拒绝。TestConversationAssetResetHandlesInstalledSkillLink 的后半段覆盖了这种情况。
  • 跳过技能目录内部校验后,没有任何路径会穿过链接读写:
    • 控制面在 chat 和 openAssistantNativeSession 里跳过当前引擎的技能目录,紧接着 writeConversationAssets 会用 RemoveAll 把整棵树重建。RemoveAll 不跟随链接,所以不会伤到 ws/ 里的目标文件。
    • runner 侧的 prepare 不读技能文件;resetAssets 是在 lockAssets 加锁、并确认进程未运行之后才 RemoveAll,不存在 TOCTOU。
    • sync 和 start 仍然做全量校验;conversationInputFiles 本来也会跳过链接。
  • 本地验证:在 PR 分支上,internal/runtime(Conversation*)和 internal/httpapi(SharedNativeSession|ConversationAsset|Subagent|SharedDirectChat)都能通过,internal/httpapi 整包也通过。把实现回退到 main、只保留新增测试后,两条新用例都会失败:一条报 prepare failed ... home/.agents/skills/installed,另一条报 409,说明它们确实能复现原问题。
    • internal/runtime 整包跑时,TestAgentStateMountsAndDockerManagerReclaim 失败过一次。这个用例在 PR 分支上单独跑三次都能通过,看起来是 fake docker 在并发跑时的偶发失败,和本 PR 无关。

建议

  1. 控制面只放过当前引擎的技能目录,切换引擎后可能还会 409。
    assistant.go 和 openAssistantNativeSession 只把 assistantConversationSkillTree(req.Model) 传给了 ValidateConversationRoot。设想这样一个场景:共享会话先用 CodeBuddy,CLI 在 home/.codebuddy/skills/ 下装了一个链接;之后同一会话切到 Codex。openAssistantNativeSession 的 contextHash 里包含 engine,所以这种切换是支持的。但这时 .codebuddy/skills 不在放行列表里,也不会被 writeConversationAssets 重建,于是每一轮都会报“共享会话缓存不可用”,而且没法自愈。
    可选的修法:控制面也放行全部 conversationSkillTrees,并在 writeConversationAssets 里顺手 RemoveAll 掉非当前引擎的技能目录(runner 的 resetAssets 已经是这样做的,两边规则也就一致了)。如果确认“一个会话固定一个 CLI”,至少补一句注释说明这个前提。
  2. 安装的技能会在下一轮从 CLI home 里消失,需要确认这是预期行为。
    新测试断言 home/.../skills/installed 这个别名会被删掉。也就是说,用户在工作区里用 npx skills add -g 之类的方式装到全局的技能,下一轮就从 CLI home 里看不到了,只剩 ws/.agents/skills/installed。如果对应 CLI 会扫描项目级的 ws/.agents/skills,那就没问题;否则用户会觉得“装了的技能又没了”。建议在 PR 描述里写明这个行为,或者确认几个引擎都能从 ws 目录发现技能。

Nit

  • conversation_assets.go:refreshingSkills 对每个遍历到的条目都要算两次 slices.Contains。可以把它挪到 entry.IsDir() 分支里再算,读起来也更直观:
if entry.IsDir() && (rel == "ws" || slices.Contains(refreshedSkillTrees, rel) && slices.Contains(conversationSkillTrees, rel)) {
	return filepath.SkipDir
}

@crispinhu27 crispinhu27 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review — APPROVE

审查范围(head 5252fe03,base 52560f49,初审)

本 PR 对 ValidateConversationRoot 增加了 replacedAssetTrees ...string 可变参数,允许控制面在写入生成资产之前跳过对即将被 RemoveAll 覆盖的树内容的符号链接检查,解决了安装技能后下一轮产生 409 的问题。


验证结果

本地 Go 验证(head 5252fe03,SQLite)

  • go build ./... && go vet ./internal/runtime ./internal/httpapi — 通过
  • go test ./internal/runtime -run TestConversationAsset.*|TestConversationPlatformPathsRejectLinks|TestConversationNativeCacheLinks — 全部 PASS
  • go test ./internal/httpapi -run TestNativeSessionResumesAfterAssetRefresh — PASS(personal + shared 两个子用例)

对照验证(base 52560f49)

在 base 上运行同样的测试用例(包含相同逻辑的等价场景):409 被正确触发。在 head 上,第二轮正确返回 200 并重建了 skill tree;外部链接目标文件内容未被修改;skill tree 根本身是链接时仍拒绝(409)。

CI(5252fe03)

  • core、e2e-required、platform-required(非 browser)等 required checks 均为 success
  • browser 失败原因:ui/03-workbench-settings.spec.mjs:103 desktop settings navigation reopens on the current page,该测试在 feat/native-sandbox-repo-cache(与本 PR 无关的分支)上也持续失败,当前 main(52560f49)pass;属于 CI 环境级偶发失败,与本 PR 改动无因果关系

安全性

  • 仅调用方同时传入 replacedAssetTrees 时才跳过树内容检查;树目录本身及其祖先路径仍然做符号链接校验,ws/ 保持原有豁免
  • writeConversationAssets → WriteInertSkillTree/writeConversationAttachments/agents 三处写入均使用 RemoveAll 后重建,不跟随符号链接
  • runner 侧(resetAssets、discard)的行为不变

建议(非阻塞,沿用前置审查意见)

见 newexploreor 的评论,以及 PR 描述中已说明的两条设计取舍(单引擎技能目录与已安装技能的 ws 目录行为),均不阻塞合入。


不存在待解决的已确认缺陷,审查和验证均已完成。

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.

3 participants