Skip to content

fix(skills): allow verified managed subagent worktrees in workspace observation - #7134

Merged
M4n5ter merged 2 commits into
rust-previewfrom
fix/skills-managed-worktree
Nov 21, 2026
Merged

M4n5ter merged 2 commits into
rust-previewfrom
fix/skills-managed-worktree

Conversation

@M4n5ter

@M4n5ter M4n5ter commented Nov 21, 2026

Copy link
Copy Markdown
Member
English

Root Cause

When an agent (or user) creates a session with workspace: { kind: "worktree" }, Maka allocates a managed Git worktree under <state_root>/subagent-worktrees/<hash>/worktree and attaches workspace.worktree = Some(binding).

While maka-workspace-support (and the files/git/process/computer/web plugins) explicitly validate workspace.worktree via Worktrees::inspect(binding) and carve out a subpath rule underneath the state_root deny policy, plugins/skills/native/src/sources.rs (Library::for_observation) had not been updated for managed worktrees:

  1. path.starts_with(&library.private) was always true because subagent-worktrees lives inside library.private (state_root).
  2. It checked library.projects against the worktree path itself instead of validating binding via Worktrees::inspect and checking binding.source().
  3. library.policy denied the entire library.private subtree without carving out read-only access for the verified worktree directory.

As a result, every SessionSend to a workspace: { kind: "worktree" } session failed during skills.prepare and returned SendResult::Rejected { reason: "skills_unavailable", skills: null }.

Fix

  • Updated plugins/skills/native/src/sources.rs (Library::for_observation) to validate workspace.worktree consistently with maka-workspace-support:
    • Verifies binding.directory() == Path::new(&directory.path).
    • Validates the binding through Worktrees::open(&library.private.join("subagent-worktrees")).inspect(binding).
    • Authorizes binding.source() against library.projects.
    • Compiles a read-only policy that keeps library.private denied while carving out Access::Read strictly for the verified worktree directory.
  • Added regression test managed_subagent_worktree_allows_project_skills_while_protecting_private_root covering:
    • prepare and search discovering project skills inside a managed subagent worktree;
    • Unix symlink inside the worktree pointing back to another path under private staying denied;
    • Plain directory workspaces pointing into private/subagent-worktrees without a verified binding staying rejected;
    • Managed worktrees sourced from repositories outside projects/ staying rejected.

Verification

  • cargo test -p maka-skills-native (4/4 passed)
  • cargo clippy -p maka-skills-native --all-targets -- -D warnings (passed)
  • rustfmt --edition 2024 --check plugins/skills/native/src/sources.rs (passed)
  • node scripts/ci.mjs check licenses (passed)
简体中文

根因

使用 SessionCreate({ workspace: { kind: "worktree" } }) 创建隔离工作区会话时,Maka 会在 <state_root>/subagent-worktrees/<hash>/worktree 下分配托管 Git worktree,并在 Workspace 上附带 worktree: Some(binding)。

maka-workspace-support 以及 files/git/process/computer/web 插件都已经通过 Worktrees::inspect(binding) 校验并放行托管 worktree,但 plugins/skills/native/src/sources.rs 的 Library::for_observation 遗漏了这一路径:

  1. subagent-worktrees 位于 library.private(即 state_root)下,直接命中 path.starts_with(&library.private);
  2. 项目根目录校验拿 worktree 路径本身去匹配 library.projects,而没有校验 Worktrees::inspect(binding) 与 binding.source();
  3. library.policy 对整个 library.private 设置了 Access::Deny,没有为已校验的 worktree 目录开只读例外。

导致只要启用了 skills 插件,向任意托管 worktree 会话发起 SessionSend 都会在 skills.prepare 阶段报 skills_workspace_unavailable,最终被 plugins/agent/native/src/owner/skills.rs 映射为 SendResult::Rejected { reason: "skills_unavailable", skills: null }。

修复内容

  • 在 plugins/skills/native/src/sources.rs 的 Library::for_observation 中补齐托管 worktree 校验(与 maka-workspace-support 保持同一安全边界):
    • 校验 binding.directory() == Path::new(&directory.path);
    • 通过 Worktrees::open(&library.private.join("subagent-worktrees")).inspect(binding) 验证为合法托管 worktree;
    • 校验源仓库 binding.source() 属于已授权的 library.projects;
    • 编译只读沙箱策略:保持整个 library.private 为 Deny,仅对已校验的该 worktree 目录放行 Access::Read。
  • 新增回归测试 managed_subagent_worktree_allows_project_skills_while_protecting_private_root,覆盖:
    • 托管 worktree 正常通过 prepare 与 search 并发现 worktree 内的项目技能;
    • worktree 内指向 private 其它目录的符号链接仍被策略拒绝(Unix);
    • 不带合法 worktree 绑定的普通目录指向 private/subagent-worktrees 仍被拒绝;
    • 源仓库不在 projects/ 下的托管 worktree 仍被拒绝。

验证记录

  • cargo test -p maka-skills-native(4/4 通过)
  • cargo clippy -p maka-skills-native --all-targets -- -D warnings(通过)
  • rustfmt --edition 2024 --check plugins/skills/native/src/sources.rs(通过)
  • node scripts/ci.mjs check licenses(通过)

…tree test

Address review feedback on #7134:
- Extract open_workspace_observation_sync in maka-workspace-support and reuse it from maka-skills-native so managed worktree validation cannot drift while preserving skills' stricter private-root deny and read-only policy.
- Isolate git config and index env vars in the worktree test fixture so host global excludes or commit signing cannot break test setup.
- Write wt-skill only inside the child worktree after ensure() and assert prepare's metadataPrompt contains it, proving skills are scanned from the worktree rather than binding.source().
- Drop the redundant Unix symlink assertion already covered by skills core ReadRoot containment tests.

Generated-by: Maka (Antigravity)
@M4n5ter
M4n5ter merged commit c392d9b into rust-preview Nov 21, 2026
18 checks passed
@M4n5ter
M4n5ter deleted the fix/skills-managed-worktree branch November 21, 2026 17:01
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.

1 participant