Skip to content

fix(zai): recognize coding quota endpoints without crossing regions - #4174

Draft
Ingwannu wants to merge 3 commits into
devfrom
ingw/fix-zai-quota-endpoints-4154
Draft

fix(zai): recognize coding quota endpoints without crossing regions#4174
Ingwannu wants to merge 3 commits into
devfrom
ingw/fix-zai-quota-endpoints-4154

Conversation

@Ingwannu

@Ingwannu Ingwannu commented Sep 10, 2026

Copy link
Copy Markdown
Owner

Summary

Closes #4154.

  • Recognize the documented international Z.ai Anthropic base (/api/anthropic) and Responses base (/api/v1) for Coding Plan quota reads.
  • Share one exact normalized-base-to-monitor mapping between admission and dispatch. New international bases must not fall through to the CN monitor/raw-key branch.
  • Preserve the CN allowlist, inference URLs, redirect refusal, parsing/cache semantics, and provider-name gating.
  • Add 15 regression cases covering supported adapters, normalization, unsupported bases, and username-only/password-only URL rejection.
  • Update provider documentation and the architectural decision record. No saved-config migration or quota-consumption policy change.

Official endpoint references: https://docs.z.ai/devpack/tool/claude and https://docs.z.ai/devpack/tool/codex

Verification

Current head: 3975c04971c506ae0374e77c20476b9877e06755; integration base: f94dd88f12a1a9aeb355aa9b2d7166ef5b002ac9.
The branch incorporates current dev without rewriting published branch history.

  • Initial source-leaf verification, with mocked fetch and no persistence: 4 base-rejected/candidate-working international variants; 5 preserved legacy host/auth combinations; 10 unsupported bases rejected before credential resolution or dispatch.
  • CI run 34428010427 at the previous head passed typecheck and several test shards, but failed privacy scanning because a dummy URL userinfo fixture looked like an email. The same scanner import stopped Linux/macOS shards. This was my fixture error, not a green suite.
  • Fixed that fixture without weakening the scanner or dropping userinfo coverage: URL setters now construct distinct dummy username/password cases.
  • The unchanged repository privacy scanner passed locally after the fixture fix, with fresh HOME, OPENCODEX_HOME, CODEX_HOME and transpiler cache. The scanner was inspected as read-only before execution.
  • Protected runtime-file existence, mode, size and SHA-256 remain unchanged. No runtime/service restarts.
  • Current-head Cross-platform CI run 34441296964 completed successfully at 3975c04. Linux's four shards and macOS's two shards passed, including all 15 added Z.ai cases; typecheck/privacy gates, Docker and packaging smoke checks passed. Windows keyring/global-install smoke passed, but the six-shard Windows suite was skipped by workflow policy, so this is not a full Windows-suite claim.
  • Independent review and the documentation-site build remain outstanding; this stays Draft. No local product suite or live provider probe was run.

Destination/auth review: international bases use api.z.ai plus Bearer; existing CN bases use open.bigmodel.cn plus raw key. Unsupported bases cause no probe. CN Anthropic support is deliberately not added.

The reporter withdrew the original 5x consumption claim; this fix does not repeat it.

Correction to my original description: current MAINTAINERS.md makes dev the only integration branch. There is no dev2-go carry obligation or needs-go-port follow-up.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.

Review readiness

  • All CI tests are green on my local testing.
  • I pushed my PR to the latest dev commit.
  • I resolved all correct Codex and CodeRabbit findings.
  • My PR is ready for review.

@coderabbitai

coderabbitai Bot commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

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 10, 2026
@Ingwannu
Ingwannu requested a review from lidge-jun September 10, 2026 02:04
@Ingwannu

Copy link
Copy Markdown
Owner Author

@lidge-jun Small, separate fix for #4154: the documented Z.ai Claude/Codex endpoints can serve requests but are excluded from quota reporting. This PR makes both use the international quota monitor and keeps the existing CN authentication separate. The original reported consumption discrepancy was withdrawn and is not part of the fix. The isolated leaf checks passed; full exact-head CI/typecheck/docs validation is still missing, so this stays Draft. Please review the host/auth mapping and integration gates before merging.

@lidge-jun

Copy link
Copy Markdown
Owner

리뷰 · 우선순위 57 / 80

이 PR은 이슈 #4154를 고칩니다. Z.ai Coding Plan을 국제 Anthropic 베이스(https://api.z.ai/api/anthropic)나 Responses 베이스(https://api.z.ai/api/v1)로 쓰는데, 추론은 되는데 쿼터 프로브만 조용히 스킵되던 구멍입니다. 지금 dev HEAD(c15a98caa)의 src/providers/quota.ts isCanonicalZaiBaseUrl / fetchZaiQuota는 국제 쪽을 루트와 …/api/coding/paas/v4만 인정하고, CN은 거기에 더해 …/api/v1까지 넣습니다. 그래서 문서에 있는 국제 Anthropic·Responses 베이스는 쿼터 대상이 아닙니다. 더 위험한 점은, 예전에 쓰던 “인정 목록 + 별도 삼항으로 모니터 고르기” 구조입니다. 국제 URL만 목록에 슬쩍 추가하면, 모니터 삼항이 “국제 루트/코딩이 아니면 CN”으로 떨어져 open.bigmodel.cn과 raw-key 인증으로 갈 수 있습니다. 이 PR은 그 함정을 피하려고 zaiQuotaMonitorHost 하나에서 승인(admission)과 모니터 선택을 같이 결정합니다.

바꾼 내용은 좁습니다. 국제 api.z.ai는 루트·코딩 Chat·/api/anthropic·/api/v1을 모두 국제 모니터 + Bearer로 보내고, CN open.bigmodel.cn은 기존 루트·코딩·/api/v1만 raw-key로 유지합니다. 추론 URL·리다이렉트 거부·파싱/캐시는 그대로입니다. 테스트는 국제 네 변형(대소문자·트레일링 슬래시 포함)이 Bearer로 api.z.ai 모니터를 치고, 지원하지 않는 열 개 베이스는 fetch 전에 거절하는 걸 잠급니다. docs-site providers 절과 structure/05_gui-and-management-api.md Decision Log도 같은 경계를 적습니다. types/config 분할 캠페인과 무관하고, Lane B 무료 모델 체인과도 겹치지 않는 독립 쿼터 수정입니다. 최근 dev 팁이 #4168 문서 마감인 상태에서, 이런 좁은 provider 수정은 합류하기 좋은 종류입니다.

다만 지금 상태는 merge-ready가 아닙니다. PR이 Draft이고, Cross-platform CI의 gates(privacy:scan)와 일부 platform job이 실패했습니다. privacy 실패 원인은 테스트 거부 목록의 https://user@api.z.ai/api/anthropic입니다. 스캐너가 user@api.z.ai를 이메일로 읽어 tests/providers/provider-quota.test.ts에서 걸린 겁니다. 의도(유저인포가 있는 URL은 거절)는 맞지만, 스캐너를 통과하는 다른 부정 예시로 바꿔야 합니다. 작성자도 로컬에서 Bun 테스트/typecheck/privacy/docs를 샌드박스 때문에 못 돌렸다고 적었고, act-head CI에 맡긴다고 했습니다. 그 전제라면 privacy 회귀는 반드시 고쳐야 합니다.

라인 문제:

tests/providers/provider-quota.test.ts · https://user@api.z.ai/api/anthropic - privacy:scan이 user@api.z.ai를 이메일로 잡아 gates가 빨갛습니다. 같은 “자격 정보/유저인포 있는 URL 거절” 의도면 스캐너가 이메일로 안 읽는 형태로 바꾸세요(예: 포트·쿼리·경로 과다 같은 이미 있는 부정 케이스만으로도 충분할 수 있음).

quota.ts · zaiQuotaMonitorHost - CN 쪽에 /api/anthropic는 넣지 않았습니다. 본문 Review boundary와도 일치합니다. 다만 BigModel CN Anthropic 계약이 나중에 확정되면 별도 PR이 필요합니다. 이 PR 범위로 넣는 건 맞습니다.

draft 체크리스트 - 로컬 검증 박스가 비어 있고, CI도 privacy 때문에 실패 중입니다. review-ready 전에 둘 다 정리해야 합니다.

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

  • privacy 픽스 후 Draft를 풀고 바로 merge할지, act-head 재실행 결과만 보고 받을지
  • CN Anthropic 베이스를 의도적으로 계속 빼둘지(본문 권고와 동일)
  • dev2-go 이식 또는 needs-go-port 기록을 이 PR에 묶을지, MAINTAINERS 후속으로 둘지
  • 작성자가 철회한 “5배 쿼터 소모” 주장과 관련해, 어댑터별 소모량 문서화 follow-up을 받을지(이 PR은 다루지 않음)

너의 추천
privacy 스캔에 걸린 테스트 URL만 고치고 CI를 초록으로 만든 뒤, Draft를 해제하면 merge 후보입니다. 매핑을 하나로 모은 설계가 맞고, 회귀 테스트도 국제/미지원을 잘 잠급니다. types/config 분할과 무관하니 close-don't-rebase 대상이 아닙니다. #4154는 이 PR이 랜딩되면 같이 닫으면 됩니다.

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

@Ingwannu

Copy link
Copy Markdown
Owner Author

@lidge-jun Addressed the confirmed privacy failure in cf45f6c and brought the branch onto current dev in 3975c04. Username-only and password-only rejection are both covered using URL setters; no scanner exception or test removal. The read-only privacy scan passed locally with isolated homes. I also corrected my stale dev2-go note: current MAINTAINERS.md requires no Go carry. New exact-head CI remains pending, so the PR stays Draft.

@Ingwannu

Copy link
Copy Markdown
Owner Author

@lidge-jun Current-head Cross-platform CI 34441296964 is now successful at 3975c04. I checked the macOS log: all 15 new Z.ai cases passed, including username-only/password-only refusal. Linux/macOS shards and typecheck/privacy gates passed. Windows keyring and global-install smoke passed; the full Windows shard matrix was skipped, not executed. The PR stays Draft for independent review and the documentation-site build. The original fixture privacy regression is resolved; no merge or local runtime change was made.

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