Skip to content

fix(agent-core): harden goal-mode budget and outcome flow - #1456

Merged
chengluyu merged 17 commits into
MoonshotAI:mainfrom
chengluyu:feat/goal-update
Jul 7, 2026
Merged

fix(agent-core): harden goal-mode budget and outcome flow#1456
chengluyu merged 17 commits into
MoonshotAI:mainfrom
chengluyu:feat/goal-update

Conversation

@chengluyu

Copy link
Copy Markdown
Collaborator
  • Fixes goal budget accounting to count model output tokens and report elapsed wall-clock budgets in hours when appropriate.
  • Fixes exhausted goal budgets so turns stop immediately and cannot continue through the Stop hook.
  • Tightens goal-mode prompts to discourage premature blocked/completed states and encourage multi-turn progress.
  • Changes terminal UpdateGoal handling so completion/blocker summary reminders are returned in the tool result.
  • Allows one final model step after terminal UpdateGoal so the model can write a concise user-facing summary.
  • Caps goal completion criteria length to keep goal prompts compact.
  • Fixes TUI goal startup failure handling so permission mode is restored correctly.
  • Fixes queued goal promotion so it waits behind a user message that arrives mid-dispatch.
  • Adds goal-mode tests covering budget exhaustion, prompt injection, terminal summaries, and TUI queue behavior.

Related Issue

None

Problem

What changed

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.

chengluyu added 12 commits July 5, 2026 19:21
normalizeCompletionCriterion only trimmed whitespace, so the objective's
4000-character cap did not apply to completionCriterion. Since the
criterion is repeated in every active/paused/blocked goal reminder, an
unbounded one bloats state.json and every continuation prompt. Truncate it
to the same limit (rather than rejecting, as it is a supplementary field).
…sted

When the model records a user-stated budget the goal has already spent
(e.g. 'one turn' after a turn was used), the tool persisted an over-budget
goal but returned an ordinary result. Because the goal driver only enforces
budgets at turn boundaries, the rest of the tool batch and the next model
step ran past the ceiling. Predict the over-budget case to stop the batch
(stopBatchAfterThis) and end the turn (stopTurn) so the driver blocks the
goal at once.
…stion

When an active goal reached its token budget, afterStep returned stopTurn,
but shouldContinueAfterStop still flushed steer messages and ran the Stop
hook, which could append a continuation and drive another model step past
the hard ceiling. Guard the steer/Stop-hook continuations on
stopForGoalBudget while the goal is still active, so a configured budget
stays a deterministic stop and the driver blocks the goal at the boundary.
A goal the model just marked terminal is no longer active, so its final
outcome message still runs.
Selecting Auto/YOLO at the goal-start prompt switched the session
permission before createGoal ran. If creation then failed (e.g. a goal
already exists and replace was not given), the session was left in a more
permissive mode with no goal started. Capture the previous mode and restore
it when the goal does not start.
finalizeTurn shifts a queued user message out of queuedMessages and then
calls setAppState({ streamingPhase: 'idle' }), which synchronously retries
queued-goal promotion before the message's deferred send is scheduled. With
the queue momentarily empty and the phase idle, promotion could start a goal
ahead of the user's earlier queued message. Track a queuedMessageDispatchPending
flag across that window and require it to be clear before promoting.
The active-goal reminder formatted wall-clock values with a minutes-only formatter, so anything over an hour rendered as a large minute count (e.g. 120m00s) in the Progress and Budgets lines. Match the app's completion-card formatter so the same value renders consistently (2h00m).
@changeset-bot

changeset-bot Bot commented Jul 7, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 6645fb2

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

@chengluyu
chengluyu marked this pull request as ready for review July 7, 2026 04:45
@pkg-pr-new

pkg-pr-new Bot commented Jul 7, 2026

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

commit: 6645fb2

@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: d359ae46f7

ℹ️ 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
@chengluyu
chengluyu merged commit e9ef939 into MoonshotAI:main Jul 7, 2026
10 checks passed
@github-actions github-actions Bot mentioned this pull request Jul 7, 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