Skip to content

kimi-k2.6 main agent stream interrupted mid-generation (user did not press Esc) #132

Closed

Description

@yxlyx

Bug Summary

The kimi-k2.6 (Moonshot API) model stream drops or aborts mid-generation, causing the harness to display "× interrupted (esc)" even though the user did not press Escape. This is a model/API-side bug, not a harness timeout.

Evidence from harness.trajectory.jsonl

The exact failure chain (lines 410–418):

Line 410: turn 20, gpt-5.5  → network error: TlsInitializationFailed (gave up after 6 attempts)
Line 411: turn 21, gpt-5.5  → task about lawplain issue #91, ok=true
Line 413: turn 22, gpt-5.5  → task about recently-viewed tab, ok=false
Line 414: turn_error → network error: TlsInitializationFailed (gave up after 6 attempts)
Line 415: turn 23, gpt-5.5  → same task, ok=false
Line 416: turn_error → network error: TlsInitializationFailed (gave up after 6 attempts)
Line 417: turn 24, kimi-k2.6 → task about trajectory report, ms=182632 (3 min) ok=false
Line 418: turn_error → Interrupted

Key insight: After two GPT-5.5 TLS failures, the harness fell back to kimi-k2.6. kimi-k2.6 ran for 182,632ms (3 minutes) executing tool calls (read_file, codedb, bash) and then the Moonshot API stream dropped, which the harness interpreted as Interrupted.

Evidence from .graff/sessions/adding-recently-viewed-documents.session.json

  • msg[5] (assistant): [response interrupted by user] — after the user asked to add Recents as a separate tab
  • msg[59] (assistant): [response interrupted by user] — after the user complained about the error

After each API-side drop, the harness UI duplicated the user's message 3-4 times (auto-retry/duplicate injection).

Evidence from harness.trace.jsonl

  • First line: {"t":3,"ev":"session","detail":"kimi-k2.6"} — confirms the trace is for the correct model
  • The trace file is corrupted with null bytes (37KB binary), which likely happened when the Moonshot API stream dropped at line 418

Root Cause Analysis

This is a Moonshot API (kimi-k2.6) streaming bug, not a harness timeout:

  1. Model/API stream drops after extended generation: kimi-k2.6 ran for 3+ minutes with multiple tool calls, then the SSE stream from Moonshot abruptly closed without a finish reason.
  2. Harness interprets the drop as interruption: The harness sees the stream die and records turn_error: "Interrupted", but the root cause is the API dropping the connection.
  3. Preceding OpenAI TLS failures are unrelated: The GPT-5.5 TlsInitializationFailed errors are a separate issue (see GPT-5.5 subagent calls fail with ms=0 / resp_bytes=0 — model crashes immediately #131). The harness falling back to kimi after those failures is correct behavior; the subsequent kimi stream drop is independent.
  4. Trace corruption is a side effect: When the Moonshot stream drops, the harness is in the middle of writing trace events, causing null bytes to be written to harness.trace.jsonl.

Impact

  • User loses 3+ minutes of model work (tool calls, reasoning, partial edits)
  • The harness auto-saves [response interrupted by user] into the session JSON, which pollutes context on resume
  • Message duplication after each API drop wastes tokens and confuses the user
  • The corrupted trace file makes post-mortem debugging harder

Suggested Fixes (for harness side)

  1. Distinguish API drops from user interruption: When the stream drops without an explicit stop signal, check if the last chunk was a valid tool call or mid-sentence. If so, mark it as API_ERROR not Interrupted.
  2. Retry on API drop: If the stream drops after tool calls, automatically retry the generation with a continue prompt rather than marking [response interrupted by user].
  3. Fix trace file atomic writes: Ensure trace is flushed/closed before recording an error, so null bytes don't corrupt the file.

Suggested Fixes (for Moonshot/kimi side — requires upstream report)

  1. Report to Moonshot: kimi-k2.6 appears to drop SSE streams after ~3 minutes of generation with tool calls. This may be a server-side timeout or a bug in their streaming infrastructure.
  2. Workaround: Use shorter generation batches or reduce context size when using kimi-k2.6 for complex ultracode workflows.

Environment

  • Harness version: v0.0.14-2-g11f341f-dirty (from trajectory line 1)
  • Session model: kimi-k2.6 (Moonshot API)
  • Previous attempts: gpt-5.5 (failed 2× with TLS errors — see GPT-5.5 subagent calls fail with ms=0 / resp_bytes=0 — model crashes immediately #131)
  • Session file: .graff/sessions/adding-recently-viewed-documents.session.json
  • Trace file: harness.trace.jsonl (corrupted, 37KB with null bytes)
  • Trajectory file: harness.trajectory.jsonl (281KB, intact)

Activity

  1. justrach commented on Jul 10, 2026

    @justrach
    Owner

    Core symptom fixed on main. A kimi/Moonshot mid-generation SSE drop is no longer surfaced as interrupted (esc) / [response interrupted by user]: 370013b/accbdee (#134) distinguish a stall from Esc, and be1ce0a (#133) adds error.StreamDropped so a provider closing the stream before its terminal event is saved as [response ended early: connection dropped] (mainloop.zig:544, repl_glue.zig:251) — never a user interrupt, and never silently accepted as a complete answer. The preceding gpt-5.5 TlsInitializationFailed chain is fixed by #131 (51776b3). The Moonshot-side SSE drop after long generation is upstream (their server timeout); the harness now degrades gracefully. The message-duplication side-symptom you noted is a separate bug, still tracked in #129. Closing the mislabeling issue.

  2. added a commit that references this issue on Jul 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions