Skip to content

[AI Integration] AiRuntimeClient·계약 검증·장애 격리 구현 #8

Description

@hywznn

한 줄 목표

Server가 Prompt나 Provider를 직접 소유하지 않고, 비식별 요청을 별도 AI Runtime에 전달한 뒤 응답을 불신 경계에서 다시 검증하도록 AiRuntimeClient를 구현합니다.

호출 경계

AiRunWorker (#24)
  → AiRuntimeClient (Server port)
    → RemoteAiRuntimeClient
      → POST /internal/v1/analyses (fowoco/ai)
        → Agent Pipeline → pinned Knowledge Bundle → LLM Provider

Server가 구현하는 것은 첫 두 계층과 응답의 최종 방어 검증입니다.

내부 요청 계약

최소 필드:

  • Header: Service-Authorization, X-Request-Id, traceparent
  • Body: requestId, attemptId, contractVersion, requiredKnowledgeVersion, deadlineMs, maskedInput
  • Worker 정보: 원문 식별번호가 아닌 workerRef, language, expiryDate, employmentStatus 등 최소 context

실제 외국인등록번호, 여권번호, 전화번호, 계좌번호, JWT, Worker Link token은 AI 경계로 보내지 않습니다.

내부 응답 계약

  • requestId, outcome, candidates, validationErrors
  • agentVersion, modelProvider, modelName, modelVersion
  • promptVersion, contextPackVersion, workflowCatalogVersion, contractVersion
  • providerAttemptCount, latencyMs

낮은 신뢰도와 누락정보는 200의 정상 NEEDS_INFO/REVIEW_REQUIRED 결과입니다. Schema/버전 불일치는 422, AI 생성 파싱 실패는 502, 일시 장애는 503, deadline 초과는 504로 매핑합니다.

Server 구현 범위

  • AiRuntimeClient port와 Provider-neutral DTO
  • FakeAiRuntimeClient — Server 단위·통합 테스트 전용
  • RemoteAiRuntimeClient — service auth, request/trace propagation
  • PII allow-list/redaction과 outbound request test
  • 전체 deadline, timeout, circuit breaker, concurrency bulkhead
  • Runtime 응답 JSON Schema와 requestId 상관관계 재검증
  • 날짜·금액·서류명·대상 workerRef 핵심값 보존 검증
  • 지원하지 않는 contract/knowledge version을 안전하게 실패 처리
  • version, latency, error code를 [AI Run] 비동기 실행 상태·재시도·멱등성 구현 #24 AiRun에 전달
  • contract fixture test와 WireMock integration test

Retry 소유권

  • Server: 영속 AiRun attempt 생성, 재시작 복구, 사용자 수동 retry, 전체 deadline/budget
  • AI Runtime: 한 attempt 안에서만 제한된 Provider retry
  • RemoteAiRuntimeClient는 투명한 다중 retry를 하지 않습니다. 두 계층의 retry가 곱해지지 않게 합니다.

이 이슈에서 하지 않는 것

  • Prompt/Context 조립, Agent Router, Intent 추출
  • OpenAI/Gemini/Anthropic/LM Studio client
  • 모델 선택·fallback·fine-tuning·evaluation runner
  • Knowledge YAML/Schema의 원본 소유
  • Task 생성·승인·발송

위 항목은 각각 fowoco/ai, fowoco/knowledge, Server #24/#11의 책임입니다.

완료 조건

  • Fake와 Remote 구현을 바꿔도 Server application 계약이 같습니다.
  • 민감정보가 outbound body, log, metric, exception에 없습니다.
  • 잘못된 JSON, 다른 requestId, 핵심값 손실, 미지원 version이 후보로 저장되지 않습니다.
  • Runtime timeout/429/5xx에서 일반 HR API thread가 고갈되지 않습니다.
  • 서버 저장소에 Provider SDK/API Key/Prompt 전문이 없습니다.

관계

Metadata

Metadata

Assignees

Labels

area:ai-integrationServer ↔ AI Runtime 내부 계약·Client·검증·trace 연동 영역; Prompt·모델·Provider 구현은 ai 저장소 소유area:serverSpring Boot API·도메인·DB·tenant·Task Workflow 영역; Prompt·모델·Provider 구현 제외priority:P0MVP 진행을 막는 최우선 핵심 작업security:privacy개인정보·접근권한·토큰·보안 영향이 있는 작업status:in-progress담당자가 현재 구현 중인 작업type:integration외부 LLM·DB·스토리지 등 시스템 간 연동 작업

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions