-
Notifications
You must be signed in to change notification settings - Fork 938
fix(agent-core-v2): persist active goal time #1695
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0ab087d
fix(agent-core-v2): persist active goal time
chengluyu 612c434
fix(agent-core-v2): migrate active goal anchors
chengluyu 4024ad8
fix(agent-core-v2): migrate envelope-less goal logs
chengluyu 70373e5
fix(agent-core-v2): advance migrated goal checkpoints
chengluyu 76a37c9
fix(agent-core-v2): align crash recovery with wire domain
chengluyu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@moonshot-ai/kimi-code": patch | ||
| --- | ||
|
|
||
| Preserve active goal elapsed time across crash recovery. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /** | ||
| * Wire protocol 1.5 persists an epoch-ms anchor at every goal create/resume | ||
| * boundary and wall-clock checkpoint. Version 1.4 records already carry an | ||
| * epoch-ms `time`, so the migration can recover that boundary without | ||
| * inventing a crash timestamp or adding periodic checkpoint writes. Existing | ||
| * anchors are authoritative. | ||
| */ | ||
| import type { WireMigration, WireMigrationRecord } from './migration'; | ||
|
|
||
| export const migrateV1_4ToV1_5: WireMigration = { | ||
| sourceVersion: '1.4', | ||
| targetVersion: '1.5', | ||
| migrateRecord(record: WireMigrationRecord): WireMigrationRecord { | ||
| if (!advancesActiveInterval(record)) return record; | ||
| if (record['wallClockResumedAt'] !== undefined) return record; | ||
| if (typeof record['time'] !== 'number') return record; | ||
| return { ...record, wallClockResumedAt: record['time'] }; | ||
| }, | ||
| }; | ||
|
|
||
| function advancesActiveInterval(record: WireMigrationRecord): boolean { | ||
| return ( | ||
| record.type === 'goal.create' || | ||
| (record.type === 'goal.update' && | ||
| (record['status'] === 'active' || | ||
| (record['status'] === undefined && typeof record['wallClockMs'] === 'number'))) | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| /** | ||
| * Scenario: migrate persisted goal lifecycle records from wire protocol 1.4 to 1.5. | ||
| * Responsibilities: recover missing active wall-clock anchors without replacing persisted ones. | ||
| * Wiring: pure migration exercised through the shared migration test surface. | ||
| * Run: `pnpm --filter @moonshot-ai/agent-core-v2 exec vitest run test/wire/migration/v1.5.test.ts`. | ||
| */ | ||
| import { describe, expect, it } from 'vitest'; | ||
|
|
||
| import { migrateV1_4ToV1_5 } from '#/wire/migration/migration'; | ||
| import { runMigration } from './utils'; | ||
|
|
||
| describe('1.4 to 1.5 active wall-clock anchor migration', () => { | ||
| it('backfills missing anchors from create and resume record timestamps', () => { | ||
| expect( | ||
| runMigration(migrateV1_4ToV1_5, [ | ||
| { | ||
| type: 'metadata', | ||
| protocol_version: '1.4', | ||
| created_at: 1, | ||
| }, | ||
| { | ||
| type: 'goal.create', | ||
| goalId: 'goal-1', | ||
| objective: 'ship the feature', | ||
| time: 10, | ||
| }, | ||
| { | ||
| type: 'goal.update', | ||
| status: 'paused', | ||
| wallClockMs: 20, | ||
| time: 30, | ||
| }, | ||
| { | ||
| type: 'goal.update', | ||
| status: 'active', | ||
| time: 40, | ||
| }, | ||
| ]), | ||
| ).toMatchInlineSnapshot(` | ||
| [wire] metadata { "protocol_version": "<protocol-version>", "created_at": "<time>" } | ||
| [wire] goal.create { "goalId": "goal-1", "objective": "ship the feature", "time": "<time>", "wallClockResumedAt": 10 } | ||
| [wire] goal.update { "status": "paused", "wallClockMs": 20, "time": "<time>" } | ||
| [wire] goal.update { "status": "active", "time": "<time>", "wallClockResumedAt": 40 } | ||
| `); | ||
| }); | ||
|
|
||
| it('preserves an existing active wall-clock anchor', () => { | ||
| expect( | ||
| runMigration(migrateV1_4ToV1_5, [ | ||
| { | ||
| type: 'goal.update', | ||
| status: 'active', | ||
| wallClockResumedAt: 35, | ||
| time: 40, | ||
| }, | ||
| ]), | ||
| ).toMatchInlineSnapshot(`[wire] goal.update { "status": "active", "wallClockResumedAt": 35, "time": "<time>" }`); | ||
| }); | ||
|
|
||
| it('advances a missing anchor from a wall-clock checkpoint timestamp', () => { | ||
| expect( | ||
| runMigration(migrateV1_4ToV1_5, [ | ||
| { | ||
| type: 'goal.update', | ||
| wallClockMs: 3_000, | ||
| time: 4_000, | ||
| }, | ||
| ]), | ||
| ).toMatchInlineSnapshot( | ||
| `[wire] goal.update { "wallClockMs": 3000, "time": "<time>", "wallClockResumedAt": 4000 }`, | ||
| ); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.