Skip to content

fix(agent-core-v2): persist active goal time#1695

Merged
chengluyu merged 5 commits into
mainfrom
agent/goal-v2-06-crash-wallclock
Jul 14, 2026
Merged

fix(agent-core-v2): persist active goal time#1695
chengluyu merged 5 commits into
mainfrom
agent/goal-v2-06-crash-wallclock

Conversation

@chengluyu

@chengluyu chengluyu commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

No linked issue. This is a focused crash-recovery correctness fix identified while hardening goal persistence in agent-core-v2.

Problem

An active goal kept its current wall-clock interval anchor only in process memory. If the process exited abnormally, replay restored the accumulated wallClockMs but cleared the in-memory anchor before pausing the goal, silently losing all active time since the last persisted lifecycle boundary. That could also make the restored wall-clock budget report undercount usage.

What changed

Persist the active interval's epoch-millisecond anchor in the existing goal.create and active goal.update wire records. During recovery, settle the persisted anchor through the first recovery clock read, fold the result into wallClockMs, and then preserve the existing active-to-paused normalization.

Wire protocol 1.5 migrates 1.4 lifecycle records that predate the new field: a missing anchor is derived from the existing epoch-millisecond time on goal.create, goal.update(status: active), and status-less goal.update wall-clock checkpoints. Advancing the anchor at a checkpoint prevents replay from counting the checkpointed interval twice. The same idempotent backfill runs before envelope-less logs are sealed with current metadata. Existing anchors remain authoritative, unrelated updates are unchanged, and persisted logs are rewritten at most once during the version upgrade or envelope repair.

The contract intentionally uses system wall time because a monotonic clock cannot span processes. It includes otherwise unobservable crash downtime and clamps clock rollback to zero. The change adds no periodic persistence writes and does not change hard-deadline or automatic blocking semantics.

Added regression coverage for create/resume anchor persistence, the 1.4-to-1.5 migration, pre-1.4 wall-clock checkpoints, and versioned plus envelope-less wire replay after an active interval, including restored elapsed time, wall-clock budget reporting, and single normalization writes.

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.

Validation:

  • pnpm --filter @moonshot-ai/agent-core-v2 exec vitest run test/agent/goal test/agent/wireRecord (128 tests)
  • pnpm --filter @moonshot-ai/agent-core-v2 lint:domain
  • pnpm --filter @moonshot-ai/agent-core-v2 typecheck
  • targeted type-aware oxlint on all review-fix files
  • pnpm changeset status
  • git diff --check

@changeset-bot

changeset-bot Bot commented Jul 14, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 76a37c9

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

commit: 76a37c9

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

ℹ️ 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/goalOps.ts
@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: 8c133066a4

ℹ️ 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/wireRecord/migration/v1.5.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: 03aae16fa4

ℹ️ 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/wireRecord/migration/v1.5.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: e8e4988fd8

ℹ️ 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-06-crash-wallclock branch from e8e4988 to 76a37c9 Compare July 14, 2026 14:21
@chengluyu chengluyu merged commit 5c0f17c into main Jul 14, 2026
14 checks passed
@chengluyu chengluyu deleted the agent/goal-v2-06-crash-wallclock branch July 14, 2026 14:29
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