Skip to content

fix(kosong): abort stalled model streams - #2643

Open
crow-1412 wants to merge 1 commit into
MoonshotAI:mainfrom
crow-1412:agent/fix-stalled-model-streams
Open

fix(kosong): abort stalled model streams#2643
crow-1412 wants to merge 1 commit into
MoonshotAI:mainfrom
crow-1412:agent/fix-stalled-model-streams

Conversation

@crow-1412

Copy link
Copy Markdown

Related Issue

Resolve #1050

Related to #2570.

Problem

Model requests could remain pending forever while waiting for response headers, the first streamed part, or the next streamed part. The generation drivers used unbounded awaits, so the caller could not recover from a silent connection without cancelling or restarting the session.

What changed

  • bound response-header and first-part waits at five minutes, while enforcing a 30-second idle deadline between streamed parts
  • abort the provider request and close acquired or late streams when a deadline or caller cancellation fires
  • surface the existing retryable APITimeoutError, preserving the repository's retry behavior and the caller's AbortError
  • apply the behavior to both v2 and legacy generation drivers
  • cover header stalls, mid-stream stalls, callback failures, cancellation, and exactly-once stream cleanup

Validation

  • @moonshot-ai/agent-core-v2 generate contract tests: 15 passed
  • @moonshot-ai/kosong generate tests: 37 passed
  • both affected packages typecheck
  • v2 import-boundary check passes
  • type-aware lint reports no warnings or errors on the changed TypeScript files
  • changeset status reports a patch bump for @moonshot-ai/kimi-code

A full v2 suite run was also attempted; the remaining failures are unrelated current-main image-compression timeout, performance-baseline, and full-compaction cases outside these paths.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

@changeset-bot

changeset-bot Bot commented Aug 5, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 13c6dbc

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@crow-1412
crow-1412 marked this pull request as ready for review August 5, 2026 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

kosong: streaming response hangs forever when no chunks arrive (no idle timeout)

1 participant