[Desktop] Transcript API serves stale turns in long sessions (post-compaction); turn-list rebuild renders duplicates / drops latest turns
Environment
- Kimi Code Desktop
1.0.0-beta.1(Windows, Electron) - Embedded local server reports
kimi-code-cli 0.43.0, listening on127.0.0.1:3766 - OS: Windows 11 x64
Summary
The desktop client's conversation view loses track of the latest turns. Two user-visible symptoms point at the same surface — the turn-list rebuild fed by GET /api/v1/sessions/{id}/transcript:
A. Long session (65+ turns, wire.jsonl ≈ 4.2 MB, has undergone full_compaction) — stable repro.
Sending a new message works end-to-end (the backend persists it, the agent run completes), but the UI history never advances past turns from the previous day. The transcript API itself returns only the old turns — this is reproducible with plain GET requests, no UI involved.
B. Normal short session — intermittent. A freshly streamed reply is replaced by a duplicate of the previous reply in the view, or the entire latest turn vanishes a few seconds after streaming finishes. Opening a new session usually "fixes" it.
In both cases the on-disk wire.jsonl is intact (every user message present, every assistant reply distinct) — this is an API/UI-layer issue, not data loss.
Server-side reproduction (no UI needed)
Against the embedded server of the running desktop app:
GET http://127.0.0.1:3766/api/v1/sessions/<long-session-id>/transcript?agent_id=main
→ items cover turns ord 45..64 only (latest endedAt = previous day), has_more=true
while at the same moment:
GET http://127.0.0.1:3766/api/v1/sessions/<long-session-id>
→ last_prompt = the message sent seconds ago, last_turn_reason = completed
Cursor behavior is broken in a self-contradictory way:
| Request | Returned turn range | Problem |
|---|---|---|
?page_size=5 |
ord 60..64 | oldest page, not newest |
?after_turn=64&page_size=30 |
ord 5..34 | cursor moved forward, results regressed |
?after_turn=70&page_size=30 |
ord 1..30 | same regression |
?after_turn=64&page_size=200 |
0 turns | large page degenerates |
?before_turn=64&page_size=30 |
ord 0..3 | contradicts has_more=true on the same response |
Notably, the same response carries meta.agent.phase.turnId = 35 (live value, matches the actual turn count in wire.jsonl), while items serve a stale generation ending at t64. The cursor/ordinal space and meta appear to belong to two different generations.
Control group: a small session (~10 turns) returns fully self-consistent results (t0..t5, has_more=false).
Additional observation (short session, during an in-progress turn)
While a turn is running, the transcript returns the conversation wrapped in live-m*-prefixed undo/hook markers carrying start / deleteCount / payload.messages; the actual turn entries have empty message lists. If the client applies these incremental marker instructions with a wrong offset — or mis-handles the handoff between live markers and the persisted turn list at turn completion — that would explain both symptom-B variants (duplicate render = content written at the wrong position; vanishing turn = finalized turn replaced by stale/empty data).
Suggested investigation
- Check whether the transcript cursor/ordinal generation is rebuilt after
full_compaction(the affectedwire.jsonlcontainsfull_compaction.begin/complete,context.apply_compaction,token_counting.rebasedevents). The returned cursor space looks pre-compaction whilemetais post-compaction. - Check the client-side application of live undo markers (
start/deleteCount) and the merge path when a turn finalizes. - The
after_turncursor regression (after_turn=64→ ord 5..34,page_size=200→ empty) looks like a fallback branch bug and can serve as a minimal regression test.
Notes
- I can provide the full debug ZIP (
kimi export) privately on request — it contains complete conversation content, so I'd rather not attach it to a public issue. - Local id of the affected long session:
session_6c3d649b-41bd-4b35-b88c-95b662d8ac68(workspacewd_admin_71f05fd26cc4). - Side note: the docs describe
/feedbackas available in the interactive UI, but typing/feedbackin the desktop app's input box sends it as a plain chat message — the desktop build seems to lack that command entry. Not a big deal, but worth aligning.
fixed in 1.0.2