Skip to content

completePartialMarkdown appends closing markers to complete text (snake_case, 2 * 3, arr[0], task lists) #8399

Open

Description

@trackoor

♻️ Reproduction Steps

completePartialMarkdown (exported from @copilotkit/core and @copilotkit/react-core, and called by @copilotkit/angular's renderMarkdown on every assistant message) treats any unpaired _ or * as an open emphasis and any [ not part of [text](url) as an unclosed bracket without handling closing ].

Save as repro.mjs and run npm install @copilotkit/[email protected] [email protected] && node repro.mjs:

import { completePartialMarkdown } from "@copilotkit/core";
import { marked } from "marked";

for (const s of [
  "Rename file_name.txt first.",
  "snake_case",
  "2 * 3 = 6",
  "Use arr[0] to read it.",
  "- [ ] buy milk",
]) {
  console.log(
    JSON.stringify(completePartialMarkdown(s)),
    marked.parse(completePartialMarkdown(s)).trim(),
  );
}

✅ Expected Behavior

Complete Markdown inputs are returned unchanged ("Rename file_name.txt first.", "snake_case", "2 * 3 = 6", "Use arr[0] to read it.", "- [ ] buy milk"). Under CommonMark flanking rules, an _ between alphanumeric characters or a * followed by whitespace cannot open emphasis, and a closed [...] (such as arr[0] or a GFM task-list [ ]) is not an unclosed bracket.

❌ Actual Behavior

completePartialMarkdown appends _, *, or ] to the end of the text, which renders as literal trailing punctuation:

"Rename file_name.txt first._" <p>Rename file_name.txt first._</p>
"snake_case_" <p>snake_case_</p>
"2 * 3 = 6*" <p>2 * 3 = 6*</p>
"Use arr[0] to read it.]" <p>Use arr[0] to read it.]</p>
"- [ ] buy milk]" <ul>
<li><input disabled="" type="checkbox"> buy milk]</li>
</ul>

In packages/core/src/utils/markdown.ts, the character loop toggles italic_underscore / italic_star without checking surrounding whitespace or word characters, and pushes bracket on [ when not followed by (...) while never matching ].

Screenshots

No response

𝌚 CopilotKit Version

├── @copilotkit/[email protected]

Also reproduced on main (7b88608, with @copilotkit/[email protected] and [email protected]) and on @copilotkit/[email protected] (2.0.0 branch at 9a129143b, packages/core/src/utils/markdown/complete-partial-markdown.ts), Node.js v26.13.0.

📄 Logs (Optional)

No response

Credit: https://ucsbplse.github.io/

Activity

  1. copilotkit-outpost-bot commented on Nov 14, 2026

    @copilotkit-outpost-bot

    ⚠️ This is an AI-generated response.

    This needs a maintainer review to give you a reliable next step.


    🤖 Generated by CopilotKit AI Support · Documentation


    Was this helpful? React with 👍 or 👎

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions