Skip to content

fix(codemode): send catalog deltas instead of restating the whole catalog - #60129

Closed
Neko-Yukari wants to merge 1 commit into
anomalyco:devfrom
Neko-Yukari:codemode-delta-catalog
Closed

Neko-Yukari wants to merge 1 commit into
anomalyco:devfrom
Neko-Yukari:codemode-delta-catalog

Conversation

@Neko-Yukari

Copy link
Copy Markdown

Issue for this PR

Closes #60128

Type of change

  • Bug fix

What does this PR do?

The catalog identity is now the inventory instead of the inline sample. snapshot() keeps the sorted listings plus a fingerprint of them, select() still picks what to inline for rendering, and update() describes the difference: a new namespace with its tool count, a changed namespace inventory, new or changed listing lines, and removed tools named by their call expression. The whole block is still sent when a delta would not be shorter: no previous state, an emptied catalog, or a delta that loses on length.

Because the sample is no longer part of the identity, rotation between steps stops counting as a change by itself.

Stored state changes shape from Summary to Snapshot. An older value fails to decode and is treated as absent, so the first change after upgrading sends one full block and then continues with deltas. No migration is needed.

How did you verify your code works?

Two builds, one session each, the same six MCP disconnect/connect toggles after a 15 s warm-up so the baseline catalog is the full inventory:

injection 2.2.0 patched
total, six changes 48,288 chars 5,063 chars
removed tool 8,784 136
re-added tool 9,715 96
first change, 12 → 74 tools 12,189 3,574

From packages/core: bun test test/codemode (33 pass), bun test test/instructions (17 pass), bun run typecheck:tsc (clean).

New cases cover an added namespace, a changed namespace inventory, a changed listing that must not be reported as a removal, a description-only change, the "never longer than the whole block" invariant, and sample independence — the same change under budget: 0 and the default budget produces identical text. Two assertions were rewritten for the new semantics: a partial catalog now announces a new namespace instead of inlining its tools.

Visual

<svg xmlns="http://www.w3.org/2000/svg" width="240" height="72" viewBox="0 0 240 72" fill="currentColor" role="img" aria-label="The whole catalog collapsing into a short delta">
  <style>
    .whole { animation: whole 5s ease-in-out infinite; }
    .bar { transform-origin: 20px 40px; animation: bar 5s ease-in-out infinite; }
    @keyframes whole {
      0%, 30% { opacity: .32; }
      55%, 88% { opacity: 0; }
      100% { opacity: .32; }
    }
    @keyframes bar {
      0%, 30% { transform: scaleX(1); opacity: .9; }
      55%, 88% { transform: scaleX(.07); opacity: 1; }
      100% { transform: scaleX(1); opacity: .9; }
    }
    @media (prefers-reduced-motion: reduce) {
      .whole, .bar { animation: none; }
      .whole { opacity: 0; }
      .bar { transform: scaleX(.07); opacity: 1; }
    }
  </style>
  <g class="whole">
    <rect x="20" y="16" width="196" height="5" rx="2.5"/>
    <rect x="20" y="28" width="196" height="5" rx="2.5"/>
    <rect x="20" y="40" width="196" height="5" rx="2.5"/>
    <rect x="20" y="52" width="196" height="5" rx="2.5"/>
  </g>
  <rect class="bar" x="20" y="37.5" width="196" height="5" rx="2.5"/>
</svg>

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@opencodejr

opencodejr Bot commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Thanks for this, and for the before/after measurements. They're really useful.

I think this duplicates #57090, which tackles the same problem: when the tool inventory changes, update() sends the whole Code Mode catalog again because the inline sample moves.

Your approach goes further: real deltas, and the inline sample no longer counts as a change. If you think #57090 is missing that, it would help to say so on #57090 or #55529, with your MCP toggle numbers, so the maintainers can decide which direction to take.

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.

Code Mode resends the whole tool catalog on every inventory change

1 participant