Skip to content

fix(agent-core-v2): preserve goal continuations - #1696

Merged
chengluyu merged 2 commits into
mainfrom
agent/goal-v2-02-continuation-abort
Jul 14, 2026
Merged

fix(agent-core-v2): preserve goal continuations#1696
chengluyu merged 2 commits into
mainfrom
agent/goal-v2-02-continuation-abort

Conversation

@chengluyu

Copy link
Copy Markdown
Collaborator

Related Issue

No linked issue.

Problem

Automatic goal continuations keep their enqueue receipt until the assigned turn settles. When a continuation reached its token budget or the model called UpdateGoal(blocked), the goal lifecycle transition treated that receipt as pending work and aborted the currently running continuation. The turn therefore stopped before it could produce the required tool-free final status or blocker explanation.

User-initiated pause, cancel, and goal replacement must still cancel live goal work.

What changed

  • Preserve a continuation during blocked and budget transitions only when its assigned turn is the current live turn.
  • Continue aborting queued or non-current continuations, and keep user pause, cancel, and replacement cancellation behavior unchanged.
  • Add regression coverage for automatic continuation budget crossing and UpdateGoal(blocked) blocker explanations while retaining pause/cancel cancellation coverage.
  • Add a patch changeset for the CLI bundle.

Validation:

  • pnpm --filter @moonshot-ai/agent-core-v2 exec vitest run test/agent/goal/goal.test.ts test/agent/goal/goalOps.test.ts test/agent/goal/tools/goal-tools.test.ts test/agent/goal/injection/goalInjection.test.ts (97 tests)
  • pnpm --filter @moonshot-ai/agent-core-v2 test (3353 tests)
  • pnpm --filter @moonshot-ai/agent-core-v2 typecheck
  • pnpm --filter @moonshot-ai/agent-core-v2 lint:domain
  • pnpm changeset status
  • git diff --check

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: e511716

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@e511716
npx https://pkg.pr.new/@moonshot-ai/kimi-code@e511716

commit: e511716

@chengluyu

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

if (preserveLiveContinuation && pending?.turnId === this.liveTurnId) return;

P2 Badge Cancel the live turn after preserving its receipt

When a live continuation is preserved here, pendingContinuation still holds the original MessageStepRequest receipt. After that first step completes and the budget/blocker path starts the tool-free final-status step, a later SDK/RPC pauseGoal, cancelGoal, or replacement still reaches cancelPendingContinuation(false) and only aborts that already-completed step receipt; the real loop does not cancel the active turn in that case, so the supposedly cancelled continuation can keep streaming to completion. Keep a handle to the assigned turn or call loop.cancel(turnId) when cancelling a live preserved continuation.

ℹ️ 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

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 8ed908a69c

ℹ️ 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-02-continuation-abort branch from 8ed908a to e511716 Compare July 14, 2026 12:38
@chengluyu

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: e511716244

ℹ️ 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 merged commit b781e8c into main Jul 14, 2026
14 checks passed
@chengluyu
chengluyu deleted the agent/goal-v2-02-continuation-abort branch July 14, 2026 12:46
@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