Skip to content

fix(agent-core-v2): skip known legacy wire records on restore#2211

Open
ktao732084-arch wants to merge 1 commit into
MoonshotAI:mainfrom
ktao732084-arch:fix/skip-retired-wire-records
Open

fix(agent-core-v2): skip known legacy wire records on restore#2211
ktao732084-arch wants to merge 1 commit into
MoonshotAI:mainfrom
ktao732084-arch:fix/skip-retired-wire-records

Conversation

@ktao732084-arch

Copy link
Copy Markdown

Related Issue

Resolve #2003

Problem

Resuming a session whose wire.jsonl was written by an earlier version reports unexpected errors during restore:

[unexpected] WireError: Unknown wire record type 'micro_compaction.apply' skipped during restore

micro_compaction.apply was persisted by the micro-compaction experiment while it was live. The feature has since been retired (removed from the v1 engine in #1317), and the v2 engine never registered an op for it, so WireService.replayRecord treats every occurrence as an unknown record and routes it through onUnexpectedError — once per record, which for a long session means hundreds of reports (the linked issue shows index: 1035), even though skipping the record is exactly the intended outcome.

context.update_token_count is in the same situation: v1-only bookkeeping (v1 still writes it on the import-context path) that v2 deliberately does not replay because it recomputes context size live.

Reproduced against the 0.29.1 release build (v2 print mode) by adding a micro_compaction.apply record to a session journal: restore prints the exact error and stack from the issue. With this patch, the same session restores silently.

What changed

WireService.replayRecord now consults a small allowlist (LEGACY_RECORD_TYPES) before reporting a skipped record. The two legacy types are still skipped, but silently; genuinely unknown types keep raising wire.unknown_record, so the report stays meaningful for real journal corruption or version skew. The journal itself is untouched — healing rewrites preserve legacy records, since the v1 engine and the vis replay tooling still understand them.

Two cases added to the existing wire-compat round-trip suite: a journal carrying both legacy types restores with no unexpected error while later records still replay, and a metadata-first 1.4 journal keeps its legacy record through the healing rewrite while its metadata upgrades to 1.5.

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 26, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 45c0453

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

@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: 45c0453427

ℹ️ 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 on lines +9 to +13
* identity. Replay silently skips `LEGACY_RECORD_TYPES` — journal vocabulary
* this engine knows of but deliberately does not replay: records of retired
* features (micro compaction) and v1-only bookkeeping it recomputes live
* (context token counts). Genuinely unknown types are still reported, and
* healing rewrites preserve legacy records for readers that understand them.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Limit the module header to its external role

Remove the new replay/allowlist details from this header: they narrate branch behavior and enumerate implementation decisions, so the comment will become stale whenever the legacy set or rewrite logic changes. The scoped guide requires top-of-file comments to describe only the module’s external responsibility and explicitly forbids narrating implementation steps.

AGENTS.md reference: packages/agent-core-v2/AGENTS.md:L11-L15

Useful? React with 👍 / 👎.

expect(target.wire.getModel(CounterModel)).toEqual({ value: 3 });
});

it('skips legacy records in a metadata-first journal and preserves them through the healing rewrite', async () => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Split the healing rewrite into a separate test

This single it checks both silent replay and preservation during a protocol migration, so a failure does not identify which contract regressed and the skip behavior is unnecessarily coupled to rewrite mechanics. Keep the silent-skip/replay assertion in one scenario and move the metadata upgrade plus record-preservation assertions into a separately named test.

Useful? React with 👍 / 👎.

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.

kimi web bug:”WireError: Unknown wire record type 'micro_compaction.apply' skipped during restore”

1 participant