Repository navigation
fix(assistant): recover from skill directory symlinks - #1261
Merged
Merged
Conversation
newexploreor
left a comment
Collaborator
There was a problem hiding this comment.
Code Review
整体 LGTM,可以合。注意它和 #1260 修的是同一个问题(技能安装在会话技能目录里留下符号链接,下一轮被拦截),两个 PR 在 assistant.go、assistant_native_session.go、assistant_subagents.go、conversation_assets.go、conversation_process.go 上互相冲突,只能合其中一个。对比下来我更倾向合这个:它覆盖了所有引擎的技能目录,错误归因也拆得更清楚。
已确认的点
- 安全边界没有放松:
- 只有
conversationSkillTrees及其子路径上的链接会被收集并删除。凭证、生成的配置、home/.agents这类祖先目录如果是链接,仍然直接报错,而且是在删除任何东西之前就报错(TestConversationSkillPreparationKeepsProtectedPathChecks和 runner 的current-mcp.json用例都覆盖了)。 - 删除用的是
os.OpenRoot的Lstat+Remove,作用范围限定在会话根目录内,只删链接本身,不会读取或修改链接目标(测试里还专门覆盖了指向外部目录和悬空链接的情况)。
- 只有
- 加锁顺序正确:
openAssistantNativeSession在加锁前只做只读的ConversationSkillLinks,真正删除放在writeConversationAssets里,这时已经持有共享会话锁。TestSharedNativeSessionFencesAStaleWriter新增的断言也验证了抢锁失败的一方不会动锁内的链接。runner 侧只在prepare时删除,resetAssets、sync、start仍然做全量校验。 - 所有引擎一起处理:所有引擎的技能目录都会被清理,不依赖当前选的模型,所以中途切换引擎后也能恢复。
- 错误归因更准确:
- 抢锁冲突归为
SHARED_SESSION_BUSY(返回 409),文件系统错误归为CONVERSATION_STATE_ERROR(返回 500,消息里带操作名和相对路径)。之前两者都显示成“共享会话缓存不可用或正在使用”,排障很困难。 NewConversationStateError只取PathError/LinkError的底层错误,所以消息里不会出现宿主机上的绝对路径,测试里也断言了这一点。
- 抢锁冲突归为
- 状态码映射等价:
assistantGenerationFailure从判断ctx.Err()改成按错误码判断。由于classifyAssistantFailure会先把取消和超时归类,两种写法在语义上等价。前端也没有依赖聊天接口的 409。 - 本地验证:
- PR 分支上
go vet无告警,internal/httpapi和internal/runner整包通过,新增的 runtime、httpapi、runner 用例都通过。 internal/runtime整包有 7 个 Docker 相关用例失败(TestDockerSandboxRunsOnDemandClaudeCodeFromMountedDirectory等),但在 base 提交37e0dad上也一模一样地失败,和本 PR 无关。
- PR 分支上
建议(不阻塞)
- 安装到 CLI home 的技能下一轮就不可见了。 这个修法会把安装器建在
home/.agents/skills/<name>的链接删掉,用户全局安装的技能下一轮就从 CLI home 里消失了,虽然 activity 里会提示“已移除链接”。如果对应引擎会扫描ws/下项目级的技能目录,那就没问题;否则建议在 PR 描述或提示文案里说明“全局安装的技能不会保留,请装到工作区里”,避免用户以为装了没生效。 - 新平台连旧 Runner 时,错误信息仍会带绝对路径。 这种组合下
prepare仍会失败,返回的是旧版的纯文本错误(里面有绝对路径),会被归到GENERATION_FAILED。PR 描述里已经说明需要升级 Runner;可以考虑在平台侧识别旧版的“会话状态包含符号链接”文案,提示用户升级 Runner。 - 非流式请求现在也会记录
thought事件。sess.Notify在没有emit时也会把thought写进 activity,和流式路径的现有写法一致。不过 Docker 构建工具产生的事件也会因此进入非流式请求的 activity,确认一下这是预期行为。
Nit
reportRemovedConversationSkillLinks已经对每条路径做了 250 字符截断,最多显示 5 条;外层的sanitizeAssistantDiagnostic(..., 2048)里的长度上限其实不会触发,留着也没问题。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
A skill installation can leave a symbolic link in a conversation's managed skill directory. The next turn used to fail before the CLI started and showed the same error as a busy shared session.
Scope
Compatibility
Existing conversations can recover on their next turn after the update. Remote conversations need the updated platform and Runner to recover links on their respective hosts. The Runner response adds an optional field and uses the existing database schema.
Validation
mainafter a registration timeout in the broader run.bash scripts/build-chatbot.shpassed with 484 tests.python3 scripts/check-public.pypassed.mainand passed in Linux Docker.Safety
Recovery is confined to the link entries under managed skill directories and uses conversation-root-scoped filesystem operations.