Skip to content

[AI 연동] AI Runtime HTTP 연결과 장애 격리 구현 - #56

Merged
hywznn merged 12 commits into
mainfrom
agent/8-ai-runtime-http
Aug 3, 2026
Merged

[AI 연동] AI Runtime HTTP 연결과 장애 격리 구현#56
hywznn merged 12 commits into
mainfrom
agent/8-ai-runtime-http

Conversation

@hywznn

@hywznn hywznn commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

연결

목표

Server가 fowoco/ai Runtime을 REST로 한 번 호출하고, 인증·timeout·응답 검증·장애 격리를 담당합니다.

최종 최소 요청 계약

Endpoint: POST /internal/v1/analyses

PLAN

{
  "requestId": "10000000-0000-0000-0000-000000000001",
  "phase": "PLAN",
  "analysisInput": {
    "instruction": "응웬반안 체류연장 준비해줘, EXPIRY_RENEWAL"
  }
}

ANALYZE 핵심

{
  "requestId": "10000000-0000-0000-0000-000000000001",
  "phase": "ANALYZE",
  "analysisInput": {
    "instruction": "응웬반안 체류연장 준비해줘, EXPIRY_RENEWAL",
    "requestedFieldKeys": ["worker_id", "stay_expiry_date", "due_at"],
    "workers": [{
      "workerRef": "worker-uuid",
      "requestedFields": {
        "worker_id": "worker-uuid",
        "stay_expiry_date": "2026-09-30"
      }
    }]
  }
}
  • Runtime에 보내는 공통 식별자는 requestId 하나입니다.
  • attemptId, contract/knowledge version, deadline은 Server 내부에서 관리합니다.
  • PLAN의 빈 context field는 전송하지 않습니다.
  • 선택 태그는 별도 필드가 아니라 발화문, INTENT_TAGinstruction에 포함합니다.

Server 내부 관리

  • attemptId: PLAN·ANALYZE·retry 호출을 구분해 [AI Run] 비동기 실행 상태·재시도·멱등성 구현 #24 AiAttempt에 저장
  • contract/knowledge version: Server 설정과 Runtime 응답 version을 비교
  • deadline: RemoteAiRuntimeClient가 Server timeout으로 적용
  • Runtime 응답의 requestId, version, Worker·Workflow·Slot 핵심값을 다시 검증

구현 범위

  • Bearer service 인증, X-Request-Id, 선택적 traceparent
  • strict camelCase JSON과 응답 크기 제한
  • 전체 timeout, bulkhead, circuit breaker
  • HTTP·timeout·parsing·contract 오류 분류
  • 투명 HTTP retry 금지: #24가 새 AiAttempt를 기록한 뒤에만 재호출
  • 기본 비활성화: AI_RUNTIME_ENABLED=false

데이터 경계

검증

  • AI 연동 단위·WireMock 테스트
  • 전체 ./gradlew clean test
  • Server CI
  • 최소 요청 JSON 직렬화가 위 계약과 정확히 일치
  • fowoco/ai#6에서 최소 계약 확인
  • staging smoke test

범위 밖

hywznn added 3 commits July 26, 2026 20:47
표준 Bearer 인증과 요청 추적 헤더를 사용해 versioned internal API를 정확히 한 번 호출합니다.

기본 비활성화 설정, 전체 deadline, 동시 호출 제한, circuit breaker, 응답 크기 및 JSON 검증을 추가합니다.
WireMock standalone으로 인증·추적 헤더, camelCase 요청, strict JSON 응답을 검증합니다.

자동 재시도 금지, deadline, 응답 크기, bulkhead와 circuit breaker 동작을 함께 확인합니다.
초보자도 설정과 장애 코드를 이해할 수 있도록 기본 비활성화 이유, 배포 순서, 오류별 대응을 문서화합니다.

ADR에 맞춰 표준 Authorization Bearer 인증과 요청 추적 규칙을 명시합니다.
@hywznn
hywznn requested review from chaeliki and krestar July 26, 2026 15:24
@hywznn hywznn added area:server Spring Boot API·도메인·DB·tenant·Task Workflow 영역; Prompt·모델·Provider 구현 제외 area:ai-integration Server ↔ AI Runtime 내부 계약·Client·검증·trace 연동 영역; Prompt·모델·Provider 구현은 ai 저장소 소유 priority:P0 MVP 진행을 막는 최우선 핵심 작업 status:in-review 구현을 마치고 리뷰 또는 병합을 기다리는 작업 security:privacy 개인정보·접근권한·토큰·보안 영향이 있는 작업 type:integration 외부 LLM·DB·스토리지 등 시스템 간 연동 작업 labels Jul 26, 2026
AI 후보가 요청에 포함된 stay_expiry_date를 다른 값으로 바꾸면 CORE_VALUE_MISMATCH로 거부합니다.
@hywznn hywznn closed this Jul 27, 2026
@hywznn hywznn reopened this Jul 27, 2026
@hywznn
hywznn marked this pull request as draft July 27, 2026 23:37
krestar
krestar previously approved these changes Jul 28, 2026

@krestar krestar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

408 타임아웃이 INVALID_REQUEST_CONTRACT로 처리되는걸로 보이는데, 문제 없을 것 같으면 나머지 리뷰 포인트 2~4번은 적절해보여서 PR 내용 괜찮아 보입니다

@hywznn hywznn changed the title [AI Integration] AI Runtime HTTP 연결과 장애 격리 구현 feat: AI Runtime HTTP 연결과 장애 격리 구현 Jul 28, 2026
analysisInput과 requestedFields 계약을 원격 호출에 반영하고 Server 기준 체류만료일 보존 검증을 유지합니다.

V11은 Worker Link 브랜치 소유로 두며 이 PR에는 Flyway migration을 추가하지 않습니다.
@hywznn hywznn changed the title feat: AI Runtime HTTP 연결과 장애 격리 구현 [AI 연동] AI Runtime HTTP 연결과 장애 격리 구현 Aug 3, 2026
리뷰 의견에 따라 HTTP 408을 요청 계약 오류가 아닌 DEADLINE_EXCEEDED로 변환하고 WireMock 회귀 테스트를 추가합니다.
@hywznn
hywznn marked this pull request as ready for review August 3, 2026 02:52
@hywznn
hywznn requested a review from krestar August 3, 2026 02:52
@hywznn

hywznn commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

참고용 형식 joson

{
  "analysisInput": {
    "instruction": "응웬반안 체류연장 준비해줘",
    "workers": [
      {
        "workerRef": "...",
        "displayName": "응웬반안",
        "requestedFields": {
          "legal_name": "NGUYEN VAN AN",
          "passport_number": "M12345678"
        }
      }
    ]
  }
}

@hywznn

hywznn commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

헤더 인증 관련 형식

            HttpRequest.Builder requestBuilder = HttpRequest.newBuilder(endpoint)
                    .timeout(Duration.ofMillis(remainingMillis))
                    .header("Content-Type", "application/json")
                    .header("Accept", "application/json")
                    .header(AUTHORIZATION, authorizationHeader)
                    .header(REQUEST_ID, request.requestId().toString())
                    .POST(HttpRequest.BodyPublishers.ofByteArray(requestBody));
            if (context.traceParent() != null) {
                requestBuilder.header(TRACEPARENT, context.traceParent());
            }

krestar
krestar previously approved these changes Aug 3, 2026

@krestar krestar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

기존에 커멘트했던 408 응답이 DEADLINE_EXCEEDED로 분리된 것 확인했습니다.
analysisInput.workers[].requestedFields 구조와 camelCase 전송은 현재 Server 문서, fixture 기준으로 적절해 보입니다.
AiRuntimeFailureCode도 #24 진단에 필요한 주요 유형 포함하고 있는 것 같네요.
15초 timeout, 동시 호출 8개, 5회 실패, 30초 차단은 데모 기본값으로 무난하며, 기본 비활성화와 Secret 주입 방식도 적절해 보입니다.

@hywznn
hywznn marked this pull request as draft August 3, 2026 06:06
@hywznn hywznn added status:blocked 선행 작업이나 외부 조건 때문에 현재 진행할 수 없는 작업 and removed status:in-review 구현을 마치고 리뷰 또는 병합을 기다리는 작업 labels Aug 3, 2026
@hywznn

hywznn commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

PLAN/ANALYZE 통신 계약을 최신 요구사항에 맞춰 추가했습니다.

  • 최초 PLAN: instruction + optional intentHint, Worker DB context 없음
  • CONTEXT_REQUIRED: contextRequirement.detectedIntent/targetDisplayName/requiredFieldKeys
  • 후속 ANALYZE: Server가 허용된 requestedFields를 넣어 새 attempt로 재호출
  • NEEDS_INFO: HR 질문, REVIEW_REQUIRED: 검토 후보
  • Agent의 직접 DB/SQL 접근 없음, MVP Worker 1명

커밋: 6af9bb6
검증: 로컬 ./gradlew clean test 및 GitHub Test and build 성공

AI팀에는 fowoco/ai#6 에서 contextRequirement 구조와 contractVersion: 1.0.0 확인을 요청했습니다. 해당 계약 확인 후 Draft를 해제하겠습니다.

@hywznn

hywznn commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

후속 #74 오케스트레이션 검토 결과, ANALYZE 재호출에 필요한 문맥 보존 필드를 추가했습니다.

  • extractedSlots: PLAN 추출값 보존
  • requestedFieldKeys: DB 누락 여부와 관계없이 Agent가 요청한 전체 key 보존
  • requestedFields: Server가 실제로 해결한 값만 포함
  • timeout 테스트가 서버 기동 속도에 따라 HTTP 요청 전 실패하지 않도록 시간 여유를 조정

커밋: 35ee1b7
검증: AI 연동 테스트 및 전체 clean test 성공

@hywznn

hywznn commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

입력 계약을 단순화했습니다 (adc486c).

  • 별도 analysisInput.intentHint 제거
  • 선택 태그는 "발화문, INTENT_TAG" 형태로 instruction에 포함
  • PLAN과 ANALYZE에서 같은 단일 instruction 유지
  • JSON에 intentHint가 생성되지 않는 계약 테스트 추가

로컬 전체 테스트: ./gradlew clean test 성공

@hywznn
hywznn marked this pull request as ready for review August 3, 2026 08:23

@krestar krestar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

확인했습니다
직접 접근 논의 있던걸로 기억하는데, AI 모델이 DB 직접 접근 안하는걸로 반확정 났나보네요

@hywznn

hywznn commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

확인했습니다 직접 접근 논의 있던걸로 기억하는데, AI 모델이 DB 직접 접근 안하는걸로 반확정 났나보네요

어쩔수없죠 .. 원래는 그게 맞으니까

@hywznn
hywznn merged commit 8e255da into main Aug 3, 2026
4 of 5 checks passed
@hywznn
hywznn deleted the agent/8-ai-runtime-http branch August 3, 2026 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ai-integration Server ↔ AI Runtime 내부 계약·Client·검증·trace 연동 영역; Prompt·모델·Provider 구현은 ai 저장소 소유 area:server Spring Boot API·도메인·DB·tenant·Task Workflow 영역; Prompt·모델·Provider 구현 제외 priority:P0 MVP 진행을 막는 최우선 핵심 작업 security:privacy 개인정보·접근권한·토큰·보안 영향이 있는 작업 status:blocked 선행 작업이나 외부 조건 때문에 현재 진행할 수 없는 작업 type:integration 외부 LLM·DB·스토리지 등 시스템 간 연동 작업

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants