kimi-code icon indicating copy to clipboard operation
kimi-code copied to clipboard

Server 0.37.2: prompt queued behind a phantom-busy session is silently dropped (never executed, no trace)

Open larryluozhang opened this issue 3 months ago • 4 comments

Summary

When a session is in a phantom-busy state (the server reports busy: true / queues new prompts, but no turn is actually running), a prompt submitted via POST /api/v1/sessions/{id}/prompts is accepted with status: "queued" and then silently vanishes: it never executes, never appears in GET /messages, disappears from the queue, and produces no prompt.upsert/error events. From the user's perspective the message was sent and simply disappeared.

Environment

  • Server: kimi-code server 0.37.2 (GET /api/v1/meta), macOS, accessed over HTTP API from a third-party client

What we observed (two independent occurrences, both 100% reproducible in the wild)

Case A — session session_05774b9d…:

  1. No new messages in history since 05:13 UTC, yet the session was considered busy for hours.
  2. 09:11:42 UTC — client POSTs a prompt → {"code":0, "data":{"status":"queued", ...}}, WS prompt.queued event received.
  3. The prompt never started. Hours later: GET /sessions/{id}/prompts?status=queued → {"active": null, "queued": []}, and the user message is not in GET /messages (checked page_size=100). Gone without a trace.

Case B — session session_85455226…:

  1. Assistant turn completed 09:27:36 UTC. No messages after that.
  2. 09:29:22 UTC — client POSTs a 2-char prompt → status: "queued", prompt.queued event received. (So the server still considered the session busy ~2 minutes after the turn ended.)
  3. 09:37:37 UTC — the next user prompt runs immediately (session idle again). The 09:29:22 prompt: not in the queue, not in history, never executed.

What works correctly (control experiments on the same server)

  • Prompt queued behind a genuinely running turn is promoted and executed when the turn completes naturally. ✓
  • Prompt queued behind a running turn is promoted and executed after POST /sessions/{id}:abort. ✓

So the queue mechanism itself is fine — the failure mode is specifically: queued behind a busy state that has no real active prompt underneath. The queued entry then waits forever and is eventually dropped instead of promoted (or dropped when the phantom state is GC'd).

How to detect the phantom state

  • GET /api/v1/sessions/{id} → busy: true, main_turn_active: true
  • GET /api/v1/sessions/{id}/prompts?status=queued → active: null
  • GET /messages shows no activity for minutes/hours

We hit phantom-busy on two different sessions without doing anything exotic (normal prompts from a REST client, occasional :abort, one session had a turn interrupted earlier).

Expected behavior

  • A session with no live turn should not report busy: true / queue prompts; and
  • a queued prompt should never be silently discarded — it should either execute, or be surfaced with a terminal status (cancelled/failed) via prompt.upsert and the queue endpoint.

Related

  • #2817 (prompt sent during an untracked live turn vanishes until the turn ends) — similar symptom, but in our case the message never comes back at all.

larryluozhang avatar Aug 20 '26 10:08 larryluozhang

Additional diagnostics (same day, same server 0.37.2):

  1. The phantom-busy state is sticky per session and queues prompts even when the API reports idle. Session session_05774b9d…: every prompt posted today returned status: "queued" — while GET /sessions/{id} showed busy: false, main_turn_active: false, pending_interaction: none, and prompts?status=queued showed active: null. Each queued prompt was then silently dropped (never in GET /messages, queue empties later).

  2. So the queueing decision appears to key off an internal "active prompt" record that is not visible through any public field — busy/main_turn_active/active can all read idle while new prompts still queue.

  3. Workaround found: POST /api/v1/sessions/{id}:abort on such a session returns {"aborted": true} (confirming a zombie active prompt existed despite all idle indicators) and clears the state — subsequent prompts run normally again.

  4. Suspected trigger on our side: one of the affected sessions had a turn interrupted mid-run the previous day ("The previous turn was interrupted by the user") plus plan/swarm mode reminders active; since then (10+ hours) every prompt queued-and-dropped. A turn that ends abnormally seems to leave the active-prompt slot occupied forever.

Happy to provide more server-side evidence if you tell me where prompt/queue state lives on disk.

larryluozhang avatar Aug 20 '26 11:08 larryluozhang

Final forensics from the affected session (now healed):

  • The phantom-busy session's active slot was held by a prompt from the previous day whose turn had long completed (its assistant reply is in history) — the slot was simply never released. Every subsequent prompt queued behind it.
  • The queue itself retained all messages (6 of them, spanning 22 hours) — they were not deleted, just never promoted, and the queue endpoint intermittently reported active: null, queued: 0 while the queue was in fact populated.
  • POST :abort kills the slot-holding zombie and promotes the next queued prompt. Repeated :abort calls drained the backlog one by one. After the drain, a fresh prompt returns status: "running" and executes normally.

So the root cause seems to be: turn-completion fails to release the active-prompt slot under some conditions (in our case: a turn interrupted by the user the previous day, plan mode active), and from then on the session is permanently 'queue-and-never-promote'.

larryluozhang avatar Aug 20 '26 11:08 larryluozhang

New occurrence, and the worst one yet — the session was healthy this time:

Timeline (2026-08-21, server 0.37.2, session with long-running turns):

  1. 19:34:41 — client POSTs a prompt → 200, status: "queued" (a turn was genuinely running). prompt.queued event received.
  2. The running turn ended naturally minutes later.
  3. The queued prompt was never promoted. When a new prompt arrived (from another client) at 19:44, that one ran immediately; the queued one is gone: not in prompts?status=queued (empty), not in GET /messages, no prompt.upsert terminal event.

So it's not only phantom-busy sessions: a queued prompt can be silently dropped on natural turn completion when a newer prompt arrives around the same time — looks like a race between queue promotion and new submission where the newer prompt wins and the queued entry is discarded.

Client-side impact: any message sent while the agent is busy is at risk of vanishing without a trace. Our client now marks such messages as "undelivered (discarded by server)" after 60s of absence from both queue and history, but the message content is unrecoverable server-side.

larryluozhang avatar Aug 21 '26 11:08 larryluozhang

Major correction: the environment where I reproduced this had two server processes sharing the same ~/.kimi-code session directory (an old 0.34.0 standalone daemon on the Tailscale IP, and a 0.37.2 CLI-embedded server on 127.0.0.1, same machine, same port number on different interfaces). The "silently dropped" queued prompts were in fact still sitting in the other process's in-memory queue — my verification queries went to the wrong process. The queue of the old process even held a zombie active prompt whose turn had completed ~29h earlier.

So my "queued prompt dropped" evidence is confounded by the two-process setup and should not be trusted as-is. What remains genuinely observed on a single server (0.35.0, Linux): a session stuck busy for 22h on a pending tool approval that no client could answer — that's arguably by design (pending_interaction=approval), and it made the session invisible to clients filtering busy=false (client-side issue, since fixed on our side).

The one thing still worth a look upstream: two processes sharing the same session store silently corrupt each other's view (each keeps its own in-memory queue/active state for the same session id; user messages written by one process surface in the other only via disk reconciliation). If running a second server against the same data dir is unsupported, a lock/warning would save others from the confusion I just went through. Sorry for the earlier overclaim.

larryluozhang avatar Aug 21 '26 11:08 larryluozhang