fix(ai-connectors): preserve workspace fallback chain and node fallbackProviderKey when overrideProviderKey is set

Đang mở
#52 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
78/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
typescript
Lĩnh vực
ai, backend-api-design

Hướng nghiên cứu

Start with dispatchWithFallback in packages/ai-connectors/src/gateway.ts and dispatchCompletion in apps/api/src/ai-connectors/ai-connectors.service.ts to trace how provider options reach the gateway and how candidates are ordered. Then read packages/ai-connectors/src/gateway.spec.ts and add coverage for fallback after an overridden provider fails. Done means the override is tried first, configured fallback providers are tried in order, and full-chain failure still triggers handoff.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

backend bug good first issue
Problem Description
  1. Node-level overrideProviderKey drops all configured backups:
    In packages/ai-connectors/src/gateway.ts (AiGatewayService.dispatchWithFallback, lines 50-98), when request.overrideProviderKey matches an active connector, candidates is populated with only that single provider. Because the remaining workspace connectors (fallbackTier 1, 2, 3) and optional systemFallbackKey are wrapped in if (candidates.length === 0) (lines 69 & 92), they are all skipped for that request.
    If the overridden provider returns 429 or times out, dispatchWithFallback immediately fails and triggers onFullChainFailure instead of falling back through the workspace's configured tiers.

  2. fallbackProviderKey and fallbackModelId are ignored:
    AiConnectorsService.dispatchCompletion (apps/api/src/ai-connectors/ai-connectors.service.ts, lines 475-494) accepts options.fallbackProviderKey and options.fallbackModelId (and AiCompletionRequest in packages/types/src/ai-connectors.ts lines 95-96 defines them), but mergedRequest never forwards them and gateway.ts never reads them.


Expected Behavior
  1. Setting overrideProviderKey should try that provider first — not discard the rest of the fallback chain.
  2. candidates should be built as an ordered, deduplicated list:
    1. overrideProviderKey / overrideModelId (if set and usable)
    2. fallbackProviderKey / fallbackModelId (if set and usable)
    3. Remaining active workspace connectors sorted by fallbackTier (Tier 1 -> Tier 2 -> Tier 3)
    4. Optional systemFallbackKey (only if configured)
  3. If every provider in the chain fails, onFullChainFailure (Human Handoff) still triggers as before.

Where to Look
  • packages/ai-connectors/src/gateway.ts (dispatchWithFallback, lines 40-102)
  • apps/api/src/ai-connectors/ai-connectors.service.ts (dispatchCompletion, lines 475-494)
  • packages/types/src/ai-connectors.ts (AiCompletionRequest, lines 88-99)
  • packages/ai-connectors/src/gateway.spec.ts

Solution / Implementation Guide
  1. Forward fallback options (ai-connectors.service.ts):
    • In dispatchCompletion (lines 490-494), include fallbackProviderKey and fallbackModelId in mergedRequest when provided in options.
  2. Build a deduplicated ordered candidates list (gateway.ts):
    • Remove the if (candidates.length === 0) guard around workspace connectors and systemFallbackKey.
    • Add a small helper addCandidate(...) keyed by ${providerKey}:${modelId} to append in order:
      1. request.overrideProviderKey / request.overrideModelId
      2. request.fallbackProviderKey / request.fallbackModelId
      3. Active connectors sorted by fallbackTier
      4. systemFallbackKey (when present)
  3. Add unit test (gateway.spec.ts):
    • Verify that when overrideProviderKey fails, dispatchWithFallback cascades to fallbackProviderKey / Tier 1 / Tier 2 connectors instead of failing immediately.
Ngôn ngữ chính
TypeScript
Star
2
Fork
1
Merge trung bình
6 phút
Pull request đã merge (30 ngày)
27

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của sumamakhan761/tryinstance

Tất cả issue của sumamakhan761/tryinstance

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.