Skip to content

fix(agent-core-v2): treat cache entries missing required fields as cold misses - #2395

Merged
sailist merged 2 commits into
MoonshotAI:mainfrom
sailist:fix/session-index-cold-miss
Jul 30, 2026
Merged

fix(agent-core-v2): treat cache entries missing required fields as cold misses#2395
sailist merged 2 commits into
MoonshotAI:mainfrom
sailist:fix/session-index-cold-miss

Conversation

@sailist

@sailist sailist commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

None — the problem is explained below.

Problem

Sessions whose on-disk metadata predates the archived field could disappear from the session picker (the TUI would misleadingly show "No sessions found."). Two things combined to cause this:

  1. When mirroring session metadata to the session-index read model, archived was passed through as undefined for older sessions. JSON serialization then dropped the key entirely, writing a cache entry that violates the session-summary contract.
  2. Read-model cache hits were trusted unconditionally, so once such a poisoned entry existed, the session summary read back from the cache was missing required fields and the session effectively vanished from listings.

What changed

1. Normalize archived when mirroring metadata

Problem: SessionMetadata forwarded data.archived as-is, so pre-archived sessions wrote cache entries without the key.

What was done:

  • archived is now normalized to a boolean (this.data.archived === true) before being put into the read model, matching the normalization readSummary already applies.

2. Self-healing shape check on cache hits

Problem: Poisoned entries written before the fix stayed in the cache forever and kept failing contract validation.

What was done:

  • Added a runtime shape check (isSessionSummaryShape) on read-model cache hits in FileSessionIndex. Entries missing required fields are treated as cold misses, rebuilt from disk, and the disk backfill overwrites the bad cache entry.
  • Added tests covering both the list cold-miss path (bad entry overwritten by backfill) and the get fallback-to-disk path.

3. Log picker fetch failures in the TUI

Problem: When fetching sessions for the picker failed, the error was silently swallowed and the picker showed "No sessions found.", hiding the real failure.

What was done:

  • The TUI session picker now logs a warning with the error instead of silently ignoring it; the picker still renders its empty state as before.

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.

sailist added 2 commits July 30, 2026 14:15
…ld misses

- normalize `archived` to a boolean when mirroring session metadata to the
  read model, so entries for pre-`archived` sessions no longer lose the key
  during JSON serialization
- add a runtime shape check on read-model cache hits; entries missing
  required fields are rebuilt from disk and overwritten, self-healing
  poisoned entries written before the fix
- log a warning when the TUI session picker fails to fetch sessions instead
  of silently showing "No sessions found."
@changeset-bot

changeset-bot Bot commented Jul 30, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ac32b14

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

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

commit: ac32b14

@sailist
sailist merged commit d10b1c1 into MoonshotAI:main Jul 30, 2026
15 checks passed
@github-actions github-actions Bot mentioned this pull request Jul 30, 2026
Pidbid added a commit to Pidbid/kkm that referenced this pull request Jul 31, 2026
Pidbid added a commit to Pidbid/kkm that referenced this pull request Jul 31, 2026
Pidbid added a commit to Pidbid/kkm that referenced this pull request Jul 31, 2026
Pidbid added a commit to Pidbid/kkm that referenced this pull request Jul 31, 2026
Pidbid added a commit to Pidbid/kkm that referenced this pull request Jul 31, 2026
Pidbid added a commit to Pidbid/kkm that referenced this pull request Jul 31, 2026
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