Skip to content

fix(agent-core-v2): reject subagent goals - #1697

Merged
chengluyu merged 2 commits into
mainfrom
agent/goal-v2-04-subagent-goal
Jul 14, 2026
Merged

fix(agent-core-v2): reject subagent goals#1697
chengluyu merged 2 commits into
mainfrom
agent/goal-v2-04-subagent-goal

Conversation

@chengluyu

Copy link
Copy Markdown
Collaborator

Related Issue

No linked issue. This is a focused fix for an inconsistent subagent goal lifecycle exposed by the v2 RPC and Service surfaces.

Problem

Goal mode is intended for the main agent: both v1 and v2 expose the goal model tools only to the main agent, and the CLI, SDK, and legacy session entry points operate on the main agent.

The v2 Agent-scoped RPC and reflected Service channels could still target a subagent. That allowed a subagent goal to be created and automatically continued even though the subagent did not receive the goal tools required to mark it complete or blocked. The result was a half-enabled lifecycle that could start but could not close itself.

What changed

  • Define the goal Service contract as main-agent-only and reject every subagent goal command with the stable goal.unsupported_agent error.
  • Avoid installing goal injection, usage accounting, budget, tool-result, and continuation hooks in subagent scopes, including for previously persisted goal records.
  • Add protocol error code 40920 and map the domain error through the v2 transport.
  • Add regression coverage for direct Service calls, RPC calls, persisted subagent goals, protocol codes, and transport mapping.
  • Add a patch changeset for the CLI bundle.

Boundaries

  • Main-agent goal creation, tools, continuation, completion, blocking, budgets, and persistence are unchanged.
  • This does not add goal tools or goal lifecycle support to subagents.
  • No unrelated goal behavior or package refactor is included.

Validation

  • pnpm --filter @moonshot-ai/agent-core-v2 exec vitest run test/agent/goal — 109 tests passed.
  • pnpm --filter @moonshot-ai/protocol test — 524 tests passed.
  • pnpm --filter @moonshot-ai/kap-server exec vitest run test/transport-errors.test.ts — 9 tests passed.
  • Type checks passed for @moonshot-ai/agent-core-v2, @moonshot-ai/protocol, and @moonshot-ai/kap-server.
  • pnpm --filter @moonshot-ai/agent-core-v2 lint:domain passed.
  • pnpm exec changeset status reports only an @moonshot-ai/kimi-code patch.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

@changeset-bot

changeset-bot Bot commented Jul 14, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4c04c6b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Jul 14, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@4c04c6b
npx https://pkg.pr.new/@moonshot-ai/kimi-code@4c04c6b

commit: 4c04c6b

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5664752d3e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/agent-core-v2/src/agent/goal/goalService.ts

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: e4d0909546

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chengluyu
chengluyu force-pushed the agent/goal-v2-04-subagent-goal branch from e4d0909 to 4c04c6b Compare July 14, 2026 15:20
@chengluyu
chengluyu merged commit 2bf009f into main Jul 14, 2026
14 checks passed
@chengluyu
chengluyu deleted the agent/goal-v2-04-subagent-goal branch July 14, 2026 15:30
@github-actions github-actions Bot mentioned this pull request Jul 14, 2026
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