Repository navigation
Description
Describe the bug
The gateway uses a request's last user-role message as the turn's user message. Its text is the prepare query, the block goes into it, and the captured turn starts there: turn_transcript records that message as user and only the items after it as steps. The replay anchor and the turn digest also cover the messages up to it. Five functions pick the message the same way: last_user_index, last_user_text, and turn_digest in gateway/crates/pc-gateway-core/src/executor.rs, message_anchor in replay_cache.rs, and turn_transcript in transcript.rs.
Kimi Code and ZCode add harness reminders as separate user messages, whose text is wrapped in <system-reminder>…</system-reminder>:
- Kimi Code 2.1.1 puts them right after the prompt: the date and the PowerContext plugin's session-start skill on a session's first turn, and on every
-pturn the notice that auto permission mode is active. - ZCode 0.16.9 adds them inside a turn's tool loop, after the tool results: after the third identical tool call (
model_anomaly), and after ten assistant messages without TodoWrite (todo_reminder). The TodoWrite count runs across the session, so any long agentic turn reaches it.
From then on, the gateway takes the reminder as the turn's message. So neither host can leave prompt-time recall to the gateway yet (#2250, step 5).
Steps to reproduce
ZCode, with real processes and a scripted model:
- Build ZCode CLI 0.16.9 from zai-org/ZCode 29628c9a, the commit that
zcode-acceptance.ymlpins. - In ZCode's legacy CLI config, add a provider with
kindset to"openai", which ZCode maps toopenai-responses, and withbaseURLset to the gateway's/gateway/v1. - Run the gateway built from
gateway/withPC_GATEWAY_INJECTION=on, because ZCode sends no conversation header the gateway recognizes.- Its Core is a PowerContext Server with inference protection in
advisorymode, a target for the gateway profile, and one Memory that the prompt recalls. ZCode's Responses requests carry nostore: false, so enforcing protection withholds them. - The upstream is a Responses model that calls one tool with the same input many times. We used
ResponsesModelFixturefromtests/e2e/host_models/responses.py, with thestream: falsehandling from feat(pi): leave prompt-time context to the gateway #2755, scripted to callsearch_memory12 times.
- Its Core is a PowerContext Server with inference protection in
- Run three headless turns in one session:
--prompt … --output-format stream-json, then--resume <sessionId>for the next two. The second turn runs the tool loop.
Expected behavior
Every request of a turn uses the prompt as the turn's message. The prompt is the prepare query, and every request carries the block in the prompt message. The turn is captured with the prompt as user, with all of its tool steps, and without the reminders.
Actual behavior
ZCode, three turns and 15 upstream requests:
- The first and third turns end with the prompt and work. Each request carries the block in the prompt message, and the captured
useris the prompt. - The second turn has 13 requests, and only the first three carry the block. ZCode appends the
model_anomalyreminder after the third call's result, and thetodo_reminderafter the ninth. In the last 10 requests the last user message is a reminder. No block is injected, and the prompt message goes upstream without the block it had in the first three. - That turn's Source (
gw-turn-…) has the TodoWrite reminder asuser. Sinceturn_transcriptstarts the turn at that message, the prompt and the tool steps before the reminder are not in the captured turn.
Kimi Code 2.1.1: on the affected turns, the gateway prepares with the reminder as the query, injects no block into the prompt, and captures the reminder as user. In Kimi's ACP mode, which has no auto-mode notice, the turns after the first end with the prompt and work.
A rule that covers both hosts: take the last user message that is not made up only of <system-reminder>…</system-reminder> blocks, in one helper that the five functions share.
ZCode's --force-mcs flag sends these reminders as system items, and the gateway then picks the prompt. It is not a workaround: the flag also moves the hook context and the skills listing to system items after the prompt, and turn_transcript captures them as the turn's steps.
Environment
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity