Skip to content

fix(import-mr): tolerate malformed frontmatter in AI learning output - #241

Merged
jeff-r2026 merged 1 commit into
Tencent:mainfrom
m0Nst3r873:fix/extract-mr-yaml-parse
Jul 27, 2026
Merged

jeff-r2026 merged 1 commit into
Tencent:mainfrom
m0Nst3r873:fix/extract-mr-yaml-parse

Conversation

@m0Nst3r873

Copy link
Copy Markdown
Collaborator

Problem

The CI pipeline's teamai ci extract-mr step crashed with exit 1, failing the whole pipeline. Root cause:

After the AI analysis completes, the LLM's Markdown output is parsed as YAML frontmatter via gray-matter (src/import-mr.ts). When the output contains a line starting with * (a markdown italic, e.g. *说明:本次 MR 是 8 个 GitHub PR…*), js-yaml interprets *foo as a YAML alias reference, has no matching anchor, and throws an uncaught YAMLException:

YAMLException: unidentified alias "说明:本次" at line 3, column 7
    at readAlias (.../js-yaml/lib/js-yaml/loader.js:1298:5)
Node.js v22.19.0

The matter() call had no try/catch, so the exception propagated all the way up and killed the process.

Fix

Extract the preprocessing + parse into a defensive parseLearningDraft() helper that catches parse failures and falls back to empty frontmatter (title falls back to the MR title). Any AI output — however malformed as YAML — now flows through instead of crashing.

Test Plan

  • npm run build passes
  • npx tsc --noEmit passes
  • New regression test src/__tests__/import-mr.test.ts (4 cases incl. the exact CI-failing alias string) passes
  • src/__tests__/ci-extract-mr.test.ts still passes (7/7)
  • Reproduced with the verbatim failing string from the CI log — no longer throws

🤖 Generated with Claude Code

The extract-mr command parsed the LLM's Markdown output as YAML via
gray-matter. When the output contained a line starting with `*` (a
markdown italic), js-yaml treated it as a YAML alias reference and threw
an uncaught YAMLException, crashing the process with exit 1 and failing
the CI pipeline.

Extract the preprocessing and parse into a defensive `parseLearningDraft`
helper that catches parse failures and falls back to empty frontmatter,
so any AI output flows through instead of crashing.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@jeff-r2026
jeff-r2026 merged commit db0383a into Tencent:main Jul 27, 2026
7 checks passed
Walternater pushed a commit to Walternater/teamai-cli that referenced this pull request Nov 2, 2026
…encent#241)

The extract-mr command parsed the LLM's Markdown output as YAML via
gray-matter. When the output contained a line starting with `*` (a
markdown italic), js-yaml treated it as a YAML alias reference and threw
an uncaught YAMLException, crashing the process with exit 1 and failing
the CI pipeline.

Extract the preprocessing and parse into a defensive `parseLearningDraft`
helper that catches parse failures and falls back to empty frontmatter,
so any AI output flows through instead of crashing.

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
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.

2 participants