Skip to content

ai-gateway validate rule: \d+-\d+[)'"] regex matches ISO dates as false positive #85

@Engccer

Description

@Engccer

Summary

The posttooluse-validate hook's ai-gateway skill includes a validation rule intended to catch model slugs that use hyphens for version numbers (e.g., claude-sonnet-4-6 instead of claude-sonnet-4.6). The rule's regex \d+-\d+[)'"] is too broad and produces false positives on ISO 8601 date literals like 2026-05-16) in unrelated documents.

Reproduction

  1. Use Edit/Write on any .md file under a project where the ai-gateway skill is matched (e.g., a doc that mentions Supabase + Vercel AI SDK in nearby content).

  2. Include any text containing an ISO date followed by a closing paren, single quote, or double quote. Example:

    | 문서 버전 | v2 (2026-05-16) — 마크다운 정본 + 도구 어댑터 framing |
  3. Hook blocks with:

    VALIDATION (1 error):
    - Line N [ERROR]: Model slug uses hyphens — use dots not hyphens for version numbers (e.g., claude-sonnet-4.6)
    

The 05-16) substring in 2026-05-16) matches \d+-\d+[)'"] and triggers the rule even though the line has nothing to do with a model identifier.

Expected

The rule should fire only on actual model slug contexts (e.g., claude-sonnet-4-6), gpt-4-1), or strings near model: or provider prefixes like anthropic/, openai/, google/).

Actual

Any MM-DD), MM-DD', or MM-DD" pattern fires the rule. This affects any markdown/docs that include dates such as authoring dates, changelogs, or YAML frontmatter dates rendered into text.

Root Cause

skills/ai-gateway/SKILL.md — the validate rule entry:

- pattern: \d+-\d+[)'"]
  message: 'Model slug uses hyphens — use dots not hyphens for version numbers (e.g., claude-sonnet-4.6)'
  severity: error

The pattern has no boundary anchoring or context requirement, so it matches numeric-hyphen-numeric substrings wherever they appear.

Suggested Fixes (any of)

  1. Anchor to model slug context — require a known model family prefix:

    pattern: (?:claude|gpt|gemini|llama|mistral|sonnet|opus|haiku|flash|pro)-?\d+-\d+[)'"]
  2. Negative lookbehind for digits — prevent matching the inside of larger numeric sequences (e.g., dates have 4-digit year preceding):

    pattern: (?<![\d-])\d+-\d+[)'"]

    This won't fix 05-16) after 2026- because of the hyphen, but combining with a length check on the left number would: model versions are typically \d{1,2}-\d{1,2}, dates have \d{4}-\d{2}-\d{2}.

  3. skipIfMatchContains for date-like context — add a guard:

    pattern: \d+-\d+[)'"]
    skipIfFileContains: \d{4}-\d{2}-\d{2}

    This is coarse — better is per-match guard, but the skill rule schema may not support it yet.

  4. Tighten to model assignment context — only fire inside string literals adjacent to model: or provider slashes:

    pattern: ['"][\w-]+/[\w-]*\d+-\d+[)'"]

    This narrows to actual provider/model slug strings such as 'anthropic/claude-sonnet-4-6'.

Environment

  • vercel-plugin version: 0.22.0
  • Cache path: ~/.claude/plugins/cache/claude-plugins-official/vercel/0b375ac333f1
  • Triggered hook event: PostToolUse:Edit
  • Matched skills (from hook output): ai-elements, ai-gateway, ai-generation-persistence, ai-sdk
  • File that triggered: a Korean-language webfortd KB architecture doc containing the date 2026-05-16) in a metadata table row

Impact

Low severity but blocks Edit/Write until the false-positive line is reformatted. Korean date convention frequently uses ISO format with hyphens, so any documentation/changelog work in repos that match the ai-gateway skill paths hits this. Workaround on user side: use slashes or Korean text format for dates (2026/05/16 or 2026년 5월 16일), but that is an unrelated cost to a documentation author.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions