Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-web-long-stream-backlog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@moonshot-ai/kimi-code": patch
---

web: Prevent long streaming responses from stalling after a tab is backgrounded.
14 changes: 13 additions & 1 deletion apps/kimi-web/src/api/daemon/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1434,14 +1434,26 @@ export class DaemonKimiWebApi implements KimiWebApi {
const { type, seq, session_id: sessionId, payload, offset } = frame;
const appEvents = projector.project(type, payload, sessionId, { offset });
for (const appEvent of appEvents) {
const turnId = (payload as { turnId?: unknown } | null)?.turnId;
const stream =
appEvent.type === 'assistantDelta' &&
typeof turnId === 'number' &&
typeof offset === 'number' &&
(type === 'assistant.delta' || type === 'thinking.delta')
? {
turnId,
offset,
kind: type === 'assistant.delta' ? ('text' as const) : ('thinking' as const),
}
: undefined;
// historyCompacted from the projector is either a compaction signal
// (reason auto_compact — no reload, the divider marker handles it) or
// a delta-gap recovery (reason delta_gap — a real resync, routed to
// onResync with the real frame.seq, mirroring the protocol path).
if (appEvent.type === 'historyCompacted' && !isCompactionReason(appEvent.reason)) {
handlers.onResync(sessionId, seq);
}
handlers.onEvent(appEvent, { sessionId, seq });
handlers.onEvent(appEvent, { sessionId, seq, stream });
}
},

Expand Down
14 changes: 13 additions & 1 deletion apps/kimi-web/src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,14 +507,26 @@ export interface AppSessionSnapshot {
}

export interface KimiEventHandlers {
onEvent(event: AppEvent, meta: { sessionId: string; seq: number }): void;
onEvent(event: AppEvent, meta: KimiEventMeta): void;
onResync(sessionId: string, currentSeq: number, epoch?: string): void;
onError(code: number, msg: string, fatal: boolean): void;
onConnectionChange(connected: boolean): void;
onTerminalOutput?(sessionId: string, terminalId: string, data: string, seq: number): void;
onTerminalExit?(sessionId: string, terminalId: string, exitCode: number | null): void;
}

/** Raw stream coordinates are present only for kap-server assistant/thinking
deltas. They let the render queue merge chunks without guessing continuity. */
export interface KimiEventMeta {
sessionId: string;
seq: number;
stream?: {
turnId: number;
offset: number;
kind: 'text' | 'thinking';
};
}

export interface KimiEventConnection {
subscribe(sessionId: string, cursor?: AppSessionCursor): void;
unsubscribe(sessionId: string): void;
Expand Down
Loading
Loading