Skip to content

fix(agent): 收紧 subagent fork 复用语义#4184

Merged
esengine merged 4 commits into
esengine:main-v2from
lifu963:pr/subagent-fork-lineage
Jun 12, 2026
Merged

fix(agent): 收紧 subagent fork 复用语义#4184
esengine merged 4 commits into
esengine:main-v2from
lifu963:pr/subagent-fork-lineage

Conversation

@lifu963

@lifu963 lifu963 commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

摘要

  • fork_from 限制为只能复用当前会话或祖先会话链上的 subagent transcript,避免通过已知 sa_... ref 复用兄弟分支或无关会话的上下文。
  • 对祖先链采用保守证明语义:只有完整、可读且 ID 一致的 branch metadata 链路才能证明 ancestry;链路缺失、损坏、循环或不一致时拒绝 fork。
  • 优化 fork_from schema 描述,明确它是独立分叉而非同线程续接,并提示同一会话逻辑内应使用 continue_from

验证

  • go test ./internal/agent ./internal/skill
  • gofmt -l .(排除 desktop/,无输出)
  • git merge-tree --write-tree HEAD origin/main-v2
  • git diff --name-status origin/main-v2...HEAD

lifu963 and others added 4 commits June 12, 2026 19:22
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions github-actions Bot added skills Skill system (internal/skill, internal/tool) agent Core agent loop (internal/agent, internal/control) v2 Go rewrite (1.x) — main-v2 branch, active development labels Jun 12, 2026

@esengine esengine left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks for this — it's a real hardening, not just a surface guard.

I traced the three load-bearing assumptions against main-v2 and they all hold:

  • the subagent store lives at <sessionDir>/subagents, so filepath.Dir(s.dir) is exactly where branch metas resolve;
  • LoadBranchMeta defaults ID to the filename, so the id-consistency check is meaningful (it only rejects a meta whose declared id was renamed away from its file);
  • ParentSession is BranchID(SessionPath()), the same namespace isAncestorSession walks.

Failing closed on missing / corrupt / cyclic / inconsistent lineage is the right call for a security fix — better to reject a legitimate ancestor-fork than to let a sibling or unrelated session's transcript leak in through a known sa_... ref. Test coverage across sibling / unrelated / unprovable / corrupt-meta cases is solid.

Merging.

@esengine esengine merged commit 2e1ec21 into esengine:main-v2 Jun 12, 2026
17 checks passed
@lifu963 lifu963 deleted the pr/subagent-fork-lineage branch June 13, 2026 07:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent Core agent loop (internal/agent, internal/control) skills Skill system (internal/skill, internal/tool) v2 Go rewrite (1.x) — main-v2 branch, active development

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants