fix(agent-core-v2): persist active goal time#1695
Conversation
🦋 Changeset detectedLatest commit: 76a37c9 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: 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".
|
@codex review |
There was a problem hiding this comment.
💡 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".
|
@codex review |
There was a problem hiding this comment.
💡 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".
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep it up! 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". |
e8e4988 to
76a37c9
Compare
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
wallClockMsbut 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.createand activegoal.updatewire records. During recovery, settle the persisted anchor through the first recovery clock read, fold the result intowallClockMs, 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
timeongoal.create,goal.update(status: active), and status-lessgoal.updatewall-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
gen-changesetsskill, or this PR needs no changeset.gen-docsskill, 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:domainpnpm --filter @moonshot-ai/agent-core-v2 typecheckoxlinton all review-fix filespnpm changeset statusgit diff --check