fix(agent-core-v2): align goal turn budgets - #1692
Conversation
🦋 Changeset detectedLatest commit: 66b543b The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
commit: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 969479ec1c
ℹ️ 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".
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
b8b9992 to
1a5358f
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1a5358f96a
ℹ️ 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".
|
@codex review |
a429b6e to
66b543b
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. 🚀 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 66b543b50e
ℹ️ 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".
| this.emitGoalUpdated(this.toSnapshot(next)); | ||
| this.telemetry.track2('goal_continued', { turns_used: next.turnsUsed }); | ||
| return this.blockIfBudgetReached(next) ?? this.toSnapshot(next); | ||
| return this.toSnapshot(next); |
There was a problem hiding this comment.
Defer turn-budget blocking during usage records
When a final allowed goal turn starts, this now leaves the goal active with turnsUsed === turnBudget; however the real loop records LLM usage before executing any requested tools, and accountTokenUsage() still calls blockIfBudgetReached(). In a turn-budgeted goal where the Nth turn tries to call UpdateGoal complete, the usage record blocks the goal first, so the tool executes against a blocked goal and cannot complete it. Please make usage accounting ignore turn-budget exhaustion for the currently admitted turn, or otherwise defer turn-budget enforcement until turn.ended.
Useful? React with 👍 / 👎.
Related Issue
No linked issue. The problem is described below.
Problem
A goal with a turn budget of N could use only N-1 complete logical goal turns in agent-core-v2. The final allowed turn was counted at step start and immediately transitioned the goal to blocked, so it could be stopped before completing and could not report completion on that turn.
The root cause was that turn accounting and turn-budget enforcement happened in the same operation. This differed from the v1 contract, which checks admission before a turn, counts the admitted turn, lets it finish, and enforces the budget at the next turn boundary.
What changed
Boundaries
This change only adjusts agent-core-v2 goal turn-budget timing. It does not alter token or wall-clock budget semantics, other goal lifecycle behavior, or the existing behavior where a user prompt submitted after exhaustion may run as a non-goal turn.
Validation
pnpm --filter @moonshot-ai/agent-core-v2 lint:domainpnpm --filter @moonshot-ai/agent-core-v2 typecheckpnpm --filter @moonshot-ai/agent-core-v2 exec vitest run test/agent/goal/goal.test.ts test/agent/goal/goalOps.test.ts test/agent/goal/injection/goalInjection.test.ts test/agent/goal/tools/goal-tools.test.ts— 96 tests passedpnpm --filter @moonshot-ai/agent-core-v2 test— 3352 tests passedpnpm changeset statusgit diff --checkChecklist
gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.