Skip to content

fix(agent-core-v2): skip no-op agent registration on session resume - #1784

Merged
sailist merged 1 commit into
MoonshotAI:mainfrom
sailist:fix/session-resume-updated-at
Jul 16, 2026
Merged

fix(agent-core-v2): skip no-op agent registration on session resume#1784
sailist merged 1 commit into
MoonshotAI:mainfrom
sailist:fix/session-resume-updated-at

Conversation

@sailist

@sailist sailist commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

No linked issue — the problem is explained below.

Problem

Opening an idle session from the session list (or hitting any read-only endpoint that resolves the session's main agent, such as the status rollup) refreshed the session's "updated" timestamp with no real activity. On the first resume per server process, main-agent materialization re-registered the agent in the session metadata even though the persisted entry was already identical, and that write bumped updatedAt. The session list then re-sorted the session to the top and the client rendered it as active "just now". Each session was affected once per server process, and again after every server restart.

What changed

  • Re-registering an agent whose metadata is unchanged is now a no-op in the session metadata store: no write to state.json, no read-model mirror, no change event. The comparison tolerates persisted-JSON artifacts — dropped undefined keys, parentAgentId: null vs absent, label key order, empty vs missing labels — so a pure resume never dirties the document, while any genuine change (a new agent, changed labels, a moved home directory) still goes through the full update path and bumps updatedAt as before.
  • This keeps the fix precise: read paths that resume a session become side-effect-free reads, instead of masking the issue with a blanket no-op diff on every metadata update.
  • Added regression tests covering same-process re-registration, re-registration against the persisted document (simulating a server restart), and the changed-fields update path.

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.

- SessionMetadata.registerAgent now compares the incoming metadata with
  the persisted entry (tolerating persisted-JSON artifacts: dropped
  undefined keys, null parentAgentId, label order) and skips the write
  entirely when nothing changed
- previously the first resume per server process rewrote state.json via
  the status rollup's ensureMainAgent -> doCreate path, bumping
  updatedAt and pushing the session to the top of the list
@changeset-bot

changeset-bot Bot commented Jul 16, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ecc9ab8

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

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@ecc9ab8
npx https://pkg.pr.new/@moonshot-ai/kimi-code@ecc9ab8

commit: ecc9ab8

@sailist
sailist merged commit d465591 into MoonshotAI:main Jul 16, 2026
18 checks passed
This was referenced Jul 16, 2026
ywh114 pushed a commit to ywh114/kimi-code that referenced this pull request Jul 19, 2026
…oonshotAI#1784)

- SessionMetadata.registerAgent now compares the incoming metadata with
  the persisted entry (tolerating persisted-JSON artifacts: dropped
  undefined keys, null parentAgentId, label order) and skips the write
  entirely when nothing changed
- previously the first resume per server process rewrote state.json via
  the status rollup's ensureMainAgent -> doCreate path, bumping
  updatedAt and pushing the session to the top of the list
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