Skip to content

fix(agent-core-v2): enforce goal deadlines - #1698

Merged
chengluyu merged 1 commit into
mainfrom
agent/goal-v2-07-wallclock-deadline
Jul 14, 2026
Merged

fix(agent-core-v2): enforce goal deadlines#1698
chengluyu merged 1 commit into
mainfrom
agent/goal-v2-07-wallclock-deadline

Conversation

@chengluyu

Copy link
Copy Markdown
Collaborator

Related Issue

No linked issue. This fixes the existing goal wall-clock budget behavior, which could exceed the advertised hard limit while model or tool work was in flight.

Problem

Goal prompts and tools describe wall-clock budgets as hard limits, but both the legacy behavior and the v2 implementation only checked elapsed time at loop checkpoints. A slow model request or tool execution could therefore run well past the configured deadline. User-initiated goal cancellation also needed to remain distinguishable from runtime deadline cancellation.

What changed

  • Added an App-scoped, injectable monotonic deadline scheduler for active goal elapsed time and deterministic tests.
  • Armed and cleared wall-clock deadlines with the v2 goal lifecycle. When a deadline expires, the goal is persisted as blocked before cancellation propagates to the live turn, model request, tool execution, or queued continuation.
  • Preserved user cancellation as the authoritative userCancelled reason when it happens before the deadline.
  • Added controlled-time regression coverage for long-running model requests, long-running tools, and user cancellation, without changing the existing wire schema or product wording.
  • Added a patch changeset for the bundled CLI behavior.

The change deliberately does not alter v1 checkpoint behavior or implement crash-persistence reconciliation. JavaScript cannot preempt a synchronously blocked event loop, and external work that ignores AbortSignal may continue independently after cancellation is requested.

Validation:

  • pnpm --filter @moonshot-ai/agent-core-v2 exec vitest run test/agent/goal/goal.test.ts -t 'hard wall-clock deadline'
  • pnpm --filter @moonshot-ai/agent-core-v2 exec vitest run test/agent/goal
  • pnpm --filter @moonshot-ai/agent-core-v2 typecheck
  • pnpm --filter @moonshot-ai/agent-core-v2 lint:domain
  • pnpm --filter @moonshot-ai/agent-core-v2 test
  • pnpm exec 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: 95b560b

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

commit: 95b560b

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 1a8e411598

ℹ️ 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-07-wallclock-deadline branch from 1a8e411 to 95b560b Compare July 14, 2026 14:53
@chengluyu
chengluyu merged commit 722694a into main Jul 14, 2026
14 checks passed
@chengluyu
chengluyu deleted the agent/goal-v2-07-wallclock-deadline branch July 14, 2026 15:00
@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