#14643·kilocode

Agent Manager peer messages flip in and out of the prompt (KW-PEER-TURNS, 7.8.1)

Author: michaelkarrer81Created Sep 28, 2026Updated Sep 28, 2026
Labelsbug

Description

Agent Manager peer messages are hidden in typed turns and visible in peer turns: lost work and a full prompt-cache rewrite on every switch

Version: Kilo Code 7.8.1 (VS Code extension + kilo serve), Linux. Model: Claude Opus 5.5 via OpenRouter (Google Vertex); the effect does not depend on the model.

What happens

A session receives prompts from two sources: the user types in the chat, and other sessions send Agent Manager peer requests (agent_manager action: "prompt", including replyTo replies). The message history sent to the model is different depending on which kind of prompt started the turn:

  • In a turn started by a peer request, earlier peer requests and the assistant turns that answered them are part of the prompt.
  • In a turn started by a typed prompt, the same earlier peer requests and their answers are missing.

Two consequences:

  1. Work done while answering a peer request disappears from later typed turns. The agent denies or redoes things it already did (e.g. a merge or a deploy it ran in the peer turn).
  2. The prompt cache is invalidated on every switch between the two kinds of turns. The first old peer message is often near the start of the context, so the whole context is re-written at the cache-write price.

Evidence

We log a fingerprint of every model request (message count, bytes, and the first message that differs from the previous request of the same session). Example from one session (n = messages in the request):

time (UTC) turn started by first changed message before → after
16:38:48 peer request #4, user text please go on the pc rebooted unexpected → [Agent Manager peer request] Request ID: amr_…
16:51:46 typed prompt #4, user text [Agent Manager peer request] … → please go on the pc rebooted unexpected
17:19:43 peer request #4, user text please go on … → [Agent Manager peer request] …

The same position keeps flipping as long as the session alternates. Across our fleet: 84 such flips since 2026-09-25, 69 of them on 2026-09-28. In one 70-minute window on 2026-09-28, 11 flips in 4 sessions cost about $11 of extra cache writes, the biggest single miss cause after the reload itself (each flip re-wrote 225–356k tokens).

Cause (7.8.1 source)

  1. Peer prompts get a non-monotonic message id: packages/kilo-vscode/src/agent-manager/orchestration-domain.ts:417

    typescript
    messageID: `msg_agent_manager_${input.messageID}`,

    Normal ids are ascending msg_0… strings, so msg_agent_manager_… always sorts after every normal id, however old it is.

  2. The prompt queue hides "later queued" user messages by string comparison of ids: packages/opencode/src/kilocode/session/prompt-queue.ts:176-183 (scope())

    typescript
    .filter((item) => item.info.role === "user" && item.info.id > target.base && !target.extras.has(item.info.id))

    Assistant messages whose parentID is hidden are removed too.

    • Typed turn: target.base is a normal msg_0… id, so every peer message ever received (msg_agent_manager_… > msg_0…) counts as queued later and is hidden, together with its answers.
    • Peer turn: target.base is a msg_agent_manager_… id, so the earlier peer messages sort below it and stay visible.

    The same scope() then moves the target's own messages to the end, so the order changes too.

Expected

The history sent to the model does not depend on who sent the prompt that started the turn. Messages that were already processed stay visible in every later turn and keep their chronological position, so the prompt prefix stays stable and the cache stays warm.

Suggested fixes (either works)

  • Give peer prompts a normal ascending id (the same generator as typed prompts) and carry the Agent Manager request id in metadata instead of the message id; or
  • In scope(), decide "queued after the running turn" from the queue state (the ids the queue actually holds as waiting) or from time_created, not from lexicographic id order.

A regression test: send a peer prompt, then a typed prompt, and assert that the second request's message list contains the peer message and its answer at the same index as in the first request.

Workaround on our side

None that keeps the cache warm. Rewriting the history in a plugin would itself change the prefix. We record the effect in telemetry, and a plugin reminds the agent that its peer-turn work may be invisible (hidden_turns.py --self-check).

Plugins

No response

Kilo version

No response

Steps to reproduce

No response

Screenshot and/or share link

No response

Operating System

No response

Terminal

No response