Skip to content

fix(providers): sanitize Claude Code Artifact tool schema for DeepSeek - #5892

Closed
codingbooo wants to merge 1 commit into
lidge-jun:devfrom
codingbooo:fix/issue-5658-deepseek-artifact
Closed

codingbooo wants to merge 1 commit into
lidge-jun:devfrom
codingbooo:fix/issue-5658-deepseek-artifact

Conversation

@codingbooo

@codingbooo codingbooo commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes #5658.

When routing Claude Code requests to DeepSeek official Chat endpoints, the built-in Artifact tool schema caused HTTP 400 rejection due to unsupported anyOf schema structures and regex patterns.

Implemented via Codex (gpt-6-astra):

  • Sanitized Artifact tool schema when dispatching to official DeepSeek chat targets without mutating other provider definitions.
  • Relaxed pattern and anyOf constraints while preserving field types.
  • Added regression test tests/providers/deepseek-artifact-tool-schema.test.ts and updated structure docs.

Verification

  • bun run typecheck passed cleanly.
  • bun test tests/providers/deepseek-artifact-tool-schema.test.ts passed.
  • Ratchet and layout checks passed.

Checklist

  • Target branch is dev
  • Followed repository TypeScript and testing guidelines

Summary by CodeRabbit

  • Compatibility
    • Improved compatibility for Claude Code’s built-in Artifact tool when used with the official DeepSeek Chat Completions endpoint. The request now omits strict mode and relaxes certain schema constraints; inputs covered only by union constraints are no longer constrained by the schema, so the tool must validate them.
    • Other tools and providers retain their existing behavior.

Review readiness checklist

This PR stays in draft until every box below is ticked. Tick all four boxes once the requirements are met:

  • Required local validation passed; commands, results, and any full-suite exception are documented.

  • I pushed my PR to a recent dev commit (at most 10 behind; a maintainer may still ask for the exact tip before merge).

  • I resolved all correct Codex and CodeRabbit findings.

  • My PR is ready for review.

@coderabbitai

coderabbitai Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: lidge-jun/opencodex/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 9e396916-adf7-4813-ab97-40b624220515

📥 Commits

Reviewing files that changed from the base of the PR and between 03aa393 and 685e726.

📒 Files selected for processing (7)
  • docs-site/src/content/docs/reference/adapters.md
  • scripts/test-layout/layout.json
  • src/adapters/openai-chat/deepseek-artifact-schema.ts
  • src/adapters/openai-chat/tool-schema.ts
  • structure/providers/chat-compat.md
  • tests/fixtures/test-layout-expected.json
  • tests/providers/deepseek-artifact-tool-schema.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

The OpenAI chat adapter now relaxes schemas for unnamespaced Artifact tools sent to api.deepseek.com and omits strict mode for those tools. Tests and documentation describe the schema changes and confirm that other tools, hosts, and caller schemas retain their existing behavior.

Changes

DeepSeek Artifact schema compatibility

Layer / File(s) Summary
Target detection and schema transformation
src/adapters/openai-chat/deepseek-artifact-schema.ts:3-45
Adds a target check for the unnamespaced Artifact tool on api.deepseek.com. The schema transformation removes pattern and anyOf outside name-bag subtrees, clones traversed objects and arrays, and copies other values unchanged.
Chat formatting, tests, and compatibility notes
src/adapters/openai-chat/tool-schema.ts:1,552-555,564, tests/providers/deepseek-artifact-tool-schema.test.ts:1-51, scripts/test-layout/layout.json:171, tests/fixtures/test-layout-expected.json:2, structure/providers/chat-compat.md:596-600, docs-site/src/content/docs/reference/adapters.md:575-582
The adapter applies the transformation to matching tools before existing marker and Unicode-pattern stripping, and omits strict for those tools. Tests cover the resulting schema, input immutability, and unchanged behavior for other targets. The compatibility documentation describes the exception and the effect of removing anyOf constraints.

Priority: ⬆️ High

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 685e7

Claude Code's Artifact tool schema is relaxed only for the official DeepSeek endpoint. Other providers and tools keep their existing behavior. No merge-blocking issue remains.

Security Architecture Review

Security architecture risk: 🟡 Moderate · up to 685e7

DeepSeek can now receive a less restrictive Artifact tool definition. The change is narrowly targeted, but it is not established whether the tool executor checks returned arguments against the original constraints.

Retained concerns

  • Medium · security · inferred: The model-facing Artifact schema is widened without established enforcement of the original argument constraints at the execution boundary. Matching by host, name, and absence of namespace also applies to any client-supplied tool with that identity, not demonstrably only Claude Code’s built-in tool.
Security review details

Security Blast Radius

  • inferred — The independently influenceable output is the model’s returned arguments for matching DeepSeek Artifact calls. The inspected change does not establish a new endpoint, credential authority, tenant boundary, or local executor; effects after a returned call depend on the consuming client.

Security Findings and Attack Paths

  • inferred — A model influenced to return an Artifact call can propose arguments that the former pattern or union constraints described as invalid. Whether such arguments reach a sensitive tool action is unresolved; no execution bypass or verified vulnerability is established.

Trust Boundaries and Controls

  • observed — The adapter rejects malformed tool-call envelope fields and emits well-formed returned calls as events. These inspected checks address wire structure, not whether returned Artifact arguments meet the original field constraints.

Resilience and Maintainability Implications

  • observed — The test checks input immutability and unchanged output for an OpenAI URL, a DeepSeek lookalike hostname, a different tool name, and a namespaced Artifact tool. It does not exercise execution-side argument validation.

Hardening Proposals

  • proposed — Confirm that the client executing Artifact calls validates returned arguments against its original schema and authorization rules rather than relying on the relaxed provider declaration. If only the built-in tool should receive this treatment, establish a trustworthy provenance check instead of relying solely on its name.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 3 files. (4 skipped: 4… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely identifies the primary change: sanitizing the Claude Code Artifact tool schema for DeepSeek providers. This matches the implementation, documentation, and regression te…
Linked Issues check ✅ Passed The PR addresses [#5658]. src/adapters/openai-chat/deepseek-artifact-schema.ts:3-10 limits the compatibility path to the unnamespaced Artifact tool at api.deepseek.com. Lines 22-45 remove `patte…
Out of Scope Changes check ✅ Passed The changes stay within [#5658]. The adapter implementation and regression test modify DeepSeek Artifact schema handling. The adapter documentation, compatibility documentation, and layout fixture u…
Full details: Docstring Coverage

Explanation

Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 3 files. (4 skipped: 4 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Sep 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

⏳ DRAFT

  • review readiness checklist open (0/4 boxes ticked).

What to do

  • Tick all four boxes in the PR description once you're done (currently 0/4).

Review readiness checklist

  • ⬜ Required local validation passed; commands, results, and any full-suite exception are documented.
  • ⬜ I pushed my PR to a recent dev commit (at most 10 behind; a maintainer may still ask for the exact tip before merge).
  • ⬜ I resolved all correct Codex and CodeRabbit findings.
  • ⬜ My PR is ready for review.

0/4 boxes ticked.

This PR stays in draft until every box above is ticked.

@github-actions
github-actions Bot marked this pull request as draft September 26, 2026 01:59
@lidge-jun

Copy link
Copy Markdown
Owner

리뷰 · 우선순위 64 / 80

이 풀리퀘스트의 바탕은 dev예요. Claude Code가 DeepSeek 공식 주소로 말을 걸면, 기본 도구 Artifact의 입력 규칙 때문에 답이 나오기 전에 HTTP 400이 나요. 이슈 #5658이에요. 거절된 칸은 pattern, maxLength, minLength, type만 있는 문자열 규칙이에요.

이제는 도구 이름이 Artifact이고, 네임스페이스가 없고, 주소 호스트가 api.deepseek.com일 때만 그 규칙에서 pattern과 anyOf를 빼요. 그 도구는 strict도 요청에 안 실어요. 다른 도구와 다른 주소는 예전과 같아요. 테스트는 tests/providers/deepseek-artifact-tool-schema.test.ts예요. src/types.ts와 src/config.ts를 나누는 글이 아니에요. 같은 이슈를 닫는 다른 열린 풀리퀘스트는 없어요.

라인 - src/adapters/openai-chat/deepseek-artifact-schema.ts 35행 — anyOf 키를 통째로 버려요. 이슈에 찍힌 칸에는 anyOf 키가 없어요. 에러 문장의 anyOf는 DeepSeek 검사기가 규칙 모양을 고를 때 쓰는 말이에요. 합집합을 지우면 테스트 39행의 content가 {}가 되고, 글자인지 객체인지 구분이 사라져요.

라인 - src/adapters/openai-chat/deepseek-artifact-schema.ts 13행 — not, oneOf, if, then, else, contains 안까지 들어가 pattern을 빼요. 12행의 $defs, definitions, patternProperties도 그래요. src/adapters/responses-tool-schema.ts 18행은 이 칸들을 그대로 둬요. 부정이나 갈래 안에서 제약을 빼면, 맞던 값이 거절될 수 있어요.

라인 - src/adapters/openai-chat/deepseek-artifact-schema.ts 3행 — 판별은 이름 Artifact, 네임스페이스 없음, 호스트 api.deepseek.com이에요. 사용자가 같은 이름으로 넣은 도구의 pattern도 같이 빠져요. 모델이 보는 규칙과 실행기가 믿는 규칙이 달라져요.

라인 - src/adapters/openai-chat/tool-schema.ts 564행 — 그 도구 전체에서 strict를 빼요. 깨진 칸 하나만 푸는 게 아니라, Artifact 인자 전체에 추가 필드가 허용돼요.

메인테이너의 판단이 필요한 지점

이슈를 입력 규칙을 느슨하게 만드는 것으로 닫을지 정해 주세요. disallowedTools에 Artifact를 넣어도 그 규칙이 그대로 올라가는 문제는 이 글이 안 고쳐요. 라이브 DeepSeek에서 400이 사라졌는지는 아직 안 봤고, 테스트 규칙은 이슈의 그 칸이 아니에요. 설명의 준비 칸 네 개는 비어 있고, 글은 아직 초안이에요.

너의 추천

pattern만 빼세요. 이슈 칸에 남은 type, maxLength, minLength는 두세요. 사용자 규칙의 anyOf는 남기세요. not, oneOf, if, contains, $defs 안은 기존 유니코드 정리와 같이 건드리지 마세요. strict는 규칙이 아직 엄격 모드에 맞으면 그대로 두세요. 라이브 요청으로 400이 사라지는지 한 번 확인하세요. 바탕은 dev로 두세요. 닫을 중복 글은 없어요. 준비 칸을 채운 다음 초안을 푸세요.

이 댓글은 grok-bot이 작성했습니다

lidge-jun added a commit that referenced this pull request Sep 26, 2026
…600-line budget

#5869 and #5892 each added a note to chat-compat.md; together they took it to 605
lines. Both notes keep their text; the DeepSeek note drops its heading and the MiMo
note joins shorter lines.

Co-authored-by: codingbo <cnsdbo@163.com>
Co-authored-by: Vadevious <Vadevious@users.noreply.github.com>
@lidge-jun

Copy link
Copy Markdown
Owner

Thanks! This landed on dev through the bug-PR merge train batch #5901 (merge dd1e327). Your change was carried as one squashed commit that keeps you as the commit author, with a Co-authored-by trailer. Closing this PR since its content is now on dev.

@lidge-jun lidge-jun closed this Sep 26, 2026
agentHits pushed a commit to agentHits/opencodex that referenced this pull request Sep 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants