Skip to content

fix(agent-core): continue goal pursuit when a goal turn hits the per-turn step limit#2210

Merged
chengluyu merged 4 commits into
mainfrom
feat/goal-max-steps-continue
Jul 26, 2026
Merged

fix(agent-core): continue goal pursuit when a goal turn hits the per-turn step limit#2210
chengluyu merged 4 commits into
mainfrom
feat/goal-max-steps-continue

Conversation

@chengluyu

Copy link
Copy Markdown
Collaborator

Related Issue

None — this is a clear, reproducible behavior fix requested by downstream users; the problem is explained below.

Problem

loop_control.max_steps_per_turn caps the steps of every turn — including goal continuation turns. Today, when a goal turn hits that cap, the turn fails with loop.max_steps_exceeded and the goal driver treats it like any runtime failure: the goal is paused ("Paused after runtime error: Turn exceeded maxSteps=N…") and autonomous pursuit stops until someone resumes it.

Downstream users set max_steps_per_turn to bound each turn — and they do want goal turns bounded by it too — but they do not want the goal itself interrupted by the cap. The per-turn limit should fragment goal work into more continuation turns, not stop the goal.

What changed

In both engines, a turn that fails only by reaching the per-turn step limit is no longer treated as a goal failure. The cap fires at a clean step boundary (the check runs before the next step starts), so the driver simply continues the goal with the next continuation turn, and that turn's prompt tells the model why: "The previous goal turn reached the per-turn step limit before finishing its work, so a new turn was started for you…" (followed by the usual continuation guidance).

  • v1 (packages/agent-core): TurnFlow.driveGoal detects loop.max_steps_exceeded in the failed-turn branch and falls through to the normal continuation decision (goal-status and budget checks still apply) instead of pausing; the turn.ended event still reports the failure so hosts keep full observability.
  • v2 (packages/agent-core-v2): AgentGoalService.handleTurnEnded skips the abnormal-turn settlement for max-step failures and launches the continuation with the step-cap prompt; goal budgets (blockIfBudgetReached) still bound the pursuit.
  • Everything else is unchanged: non-goal turns still fail visibly at the cap, and goals still pause on real runtime failures, cancel, prompt-hook blocks, and budget exhaustion.
  • Tests: v1 harness test drives a goal through two capped turns into completion, asserting no paused/blocked status is ever emitted and the step-cap prompt lands; v2 service test asserts a capped turn keeps the goal active and launches a continuation carrying the step-cap notice.
  • Includes a changeset (@moonshot-ai/kimi-code, patch) — both engines ship inside the CLI bundle.

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 26, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 085b8e1

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 26, 2026

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

commit: 085b8e1

@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: 2a3bf9a7cf

ℹ️ 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/src/agent/turn/index.ts Outdated
Comment thread packages/agent-core-v2/src/agent/goal/goalService.ts Outdated
@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

Here are some automated review suggestions for this pull request.

Reviewed commit: ba7ce8a1f0

ℹ️ 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 Outdated
Comment thread packages/agent-core-v2/test/agent/goal/goal.test.ts Outdated
@chengluyu

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 085b8e13a0

ℹ️ 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 0cef160 into main Jul 26, 2026
14 checks passed
@chengluyu
chengluyu deleted the feat/goal-max-steps-continue branch July 26, 2026 16:30
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