Skip to content

fix(assistant): recover from skill directory symlinks - #1261

Merged
crispinhu27 merged 1 commit into
mainfrom
fix/conversation-skill-links
Nov 23, 2026
Merged

crispinhu27 merged 1 commit into
mainfrom
fix/conversation-skill-links

Conversation

@crispinhu27

Copy link
Copy Markdown
Collaborator

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.

  • Remove unsupported skill links during asset preparation on both the platform and Runner. Record the relative path in the turn activity and continue the existing conversation.
  • Report lock contention separately from filesystem failures. File errors include the operation, relative path, and underlying cause.
  • Keep strict validation for credentials, generated configuration, and other protected paths.

Scope

  • Platform core / API / Runner

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

  • Focused Go tests for original-session resume, link recovery, protected paths, stale-writer isolation, and cache-read diagnostics passed on the rebased branch.
  • The connected-Runner workspace test passed in isolation on both this branch and main after a registration timeout in the broader run.
  • bash scripts/build-chatbot.sh passed with 484 tests. python3 scripts/check-public.py passed.
  • Linux Docker runtime regression tests and disposable Docker MySQL shared-session continuation and concurrency tests passed on the original base. The patch is identical after rebasing.
  • The earlier broader macOS run timed out in the HTTP API suite and reported Runner failures. Two runtime failures reproduced on unmodified main and passed in Linux Docker.

Safety

Recovery is confined to the link entries under managed skill directories and uses conversation-root-scoped filesystem operations.

@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,可以合。注意它和 #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 无关。

建议(不阻塞)

  1. 安装到 CLI home 的技能下一轮就不可见了。 这个修法会把安装器建在 home/.agents/skills/<name> 的链接删掉,用户全局安装的技能下一轮就从 CLI home 里消失了,虽然 activity 里会提示“已移除链接”。如果对应引擎会扫描 ws/ 下项目级的技能目录,那就没问题;否则建议在 PR 描述或提示文案里说明“全局安装的技能不会保留,请装到工作区里”,避免用户以为装了没生效。
  2. 新平台连旧 Runner 时,错误信息仍会带绝对路径。 这种组合下 prepare 仍会失败,返回的是旧版的纯文本错误(里面有绝对路径),会被归到 GENERATION_FAILED。PR 描述里已经说明需要升级 Runner;可以考虑在平台侧识别旧版的“会话状态包含符号链接”文案,提示用户升级 Runner。
  3. 非流式请求现在也会记录 thought 事件。 sess.Notify 在没有 emit 时也会把 thought 写进 activity,和流式路径的现有写法一致。不过 Docker 构建工具产生的事件也会因此进入非流式请求的 activity,确认一下这是预期行为。

Nit

  • reportRemovedConversationSkillLinks 已经对每条路径做了 250 字符截断,最多显示 5 条;外层的 sanitizeAssistantDiagnostic(..., 2048) 里的长度上限其实不会触发,留着也没问题。

@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.

1

@crispinhu27
crispinhu27 merged commit 88255b7 into main Nov 23, 2026
16 checks passed
@crispinhu27
crispinhu27 deleted the fix/conversation-skill-links branch November 23, 2026 12:26
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.

2 participants