← Back to Pull requests

fix(kimi-k3): recover abandoned tool calls (DIS-3537) #647

Open
unknown opened this pull request with 558 lines diff across 6 files
View on GitHub
unknown unknown commented on Nov 21, 2026 00:45 UTC
Author

Overview

The Kimi K3 v1 jail suppresses markup from an abandoned call. The v2 Unified parser keeps a valid retry separate from the abandoned call and preserves early argument streaming on well-formed calls.

Details

  • Bound v1 response text at the unfinished tool call. When a fresh tools section has a valid call, recover its calls and warn as the earlier malformed call is dropped.

  • Track the v2 response-close, tools-open, and call-open sequence incrementally. Preserve already complete calls, explicit response boundaries, and complete outer strings that own literal XTML. The abandoned call stays incomplete if argument chunks were already emitted.

  • Add a Kimi K3 regression and refresh the latest Dynamo v2 observations with unpublished parser version 0.10.10.
  • Bug Fix Evidence

    1. Minimal Sample Input

    Native Kimi K3 with a bash tool that takes one string argument named command. The first argument remains open when the second tools section starts. The tests replay whole input and every split. V2 also exercises one Unicode scalar per push.

    <|open|>response<|sep|>Visible text<|close|>response<|sep|><|open|>tools<|sep|><|open|>call tool="bash" index="1"<|sep|><|open|>argument key="command" type="string"<|sep|>echo first<|close|>response<|sep|><|open|>tools<|sep|><|open|>call tool="bash" index="1"<|sep|><|open|>argument key="command" type="string"<|sep|>echo retry<|close|>argument<|sep|><|close|>call<|sep|><|close|>tools<|sep|><|close|>message<|sep|>
    

    2. Buggy Output (Before)

    V1 11.0.13 leaked the abandoned call into assistant text at a split after the response. V2 0.10.9 kept visible text and completed one bash call whose command contained both attempts and the intervening XTML.

    v1 assistant text (no-retry variant): Visible text<|open|>tools<|sep|><|open|>call tool="bash" index="1"<|sep|><|open|>argument key="command" type="string"<|sep|>echo first
    v2 command: echo first<|close|>response<|sep|><|open|>tools<|sep|><|open|>call tool="bash" index="1"<|sep|><|open|>argument key="command" type="string"<|sep|>echo retry
    

    3. Expected/Fixed Output (After)

    assistant text: Visible text
    completed tool calls: bash({"command":"echo retry"})
    

    The v1 variant without a retry returns the visible text and zero calls. In v2, a partial chunk emitted before the restart can still reach the client. The parser never completes that abandoned index.

    4. Unified Regression Cases

    UNIFIED.kimi-abandoned_argument_then_retry starts in Reasoning and replays the retry group in 64-character chunks before finish. GOLDEN has reasoning, visible text, and one completed bash call with echo retry. This case applies to Kimi K3 because it uses the XTML response, tools, call, and typed-argument sequence. Shared marker cases cover the other families in their native syntax.

    5. Visual Conformance Verification

    Regenerated conformance/CONFORMANCE_v2.html with the native publisher bound to the final candidate tree. Chrome 158 showed the clean retry and the preserved earlier kimi-typed_response_then_call case in the Dynamo v2 0.10.10 popups. Kimi K3 qualification reported zero red and zero empty cells.

    Verification

    110 focused v1 tests and 92 focused v2 tests passed. The fresh capture replay covered 5,044 cases with zero Dynamo disagreements. The strict current-capture replay passed on all 4,829 native observations. The capture refresh preserves 4,828 prior observations and adds one case.

    Validation

    cargo test --locked -p dynamo-parsers --lib --test jail kimi_k3, cargo test --locked -p dynamo-parsers-v2 --lib kimi_k3, and the strict replay committed_dynamo_capture_matches_the_live_parsers in unified_render. The independent parser audit replayed the completed-call checkpoint, literal XTML with a following call, invalid restart prefix, whitespace, multiple retries, and the response transition.

    Review scope and follow-up

    I’ll only address P0 and P1 findings in this PR. P2 through P4 belong in a separate scope.

    Tracking DIS-3537 and DIS-3536. Validation exercised the parser and native conformance paths. Dynamo HTTP replay remains open.

    Where should the reviewer start?

    parsers/v1/src/tool_calling/xtml/kimi_k3_parser.rs, parsers/v2/src/unified/kimi_k3.rs

    Internal use only: DIS-3537

    Diff: 558 lines (+418 / -140) across 6 files Reviewer: luckyq Review duration: 20682m
    All Vouch review confidence checks passed
    Residual risk 0.27 = Change Risk (0.48) × (1 − Review Confidence (0.43)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.48 · 558 lines diff across 6 files
    0.48
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    42%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.378
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #647"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 43.0% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 48.2% (MEDIUM) · Higher = larger blast radius
    48.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 43.0% · Lower = rushed or shallow review
    43.0%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 27.5% · Safe to merge
    27.5%