# req-024: RabbitMQ 가용성 degrade 정책 (버퍼링 금지 + 보수적 중단 + core 안전 매도 독립) - Status: Implemented - Type: Non-Functional - Priority: High - Owner: project maintainers ## Intent - HTTP fallback 없이 RabbitMQ 단일 transport 로 전환되므로(dcy-006 OQ-1, R-3 High), broker 장애가 trex-core 의 신규 매매를 통제 불능 상태로 만들지 않도록 명시적인 degrade 정책을 강제한다. 열린 포지션은 core 자율 안전 매도가 transport·전략과 독립으로 보호하는 전제를 별도 backlog 로 가시화한다. ## Requirement - RabbitMQ broker 가 불가용일 때 trex-core 는 아래 정책을 따른다(dcy-006 OQ-4). 1. **버퍼링 금지**: 새 intent 메시지를 로컬 디스크/큐에 적재해 복구 후 자동 재생하지 않는다. 지나간 결정의 지연 실행 위험을 차단한다. 2. **신규 매매 보수적 중단**: 스냅샷 RPC 타임아웃·intent 발행 실패 시 전략 측은 매매를 보류하고, trex-core 는 신규 슬롯 전이를 유입시키지 않는다(복구 후 신선 데이터로 재판단). - `MessagingTransport` 어댑터는 connection drop / 재연결 백오프 / 신선도(staleness) 상태를 명확히 노출해 application 레이어가 위 정책을 일관되게 적용할 수 있게 한다. - core 자율 안전 매도(손절 stop-loss, 시간 만기 forced_close) 는 RabbitMQ 가용성 및 전략 모듈 동작 여부와 **독립**으로 수행되어야 한다는 architecture 전제를 본 REQ 의 명시적 contract 로 둔다(현재 미구현, dcy-006 A-5 — 본 REQ 는 정책 contract 만 정의하고 구현은 별도 Discovery 로 위임). ## Acceptance Criteria 1. Given RabbitMQ broker 가 불가용, When 전략이 intent 를 발행하려 시도, Then trex-core 는 새 슬롯 전이를 일으키지 않는다(보수적 중단). 2. Given RabbitMQ broker 가 일시 불가용 후 복구, When 복구 시점에 broker 또는 클라이언트에 누적된 intent 가 있는지 확인, Then trex-core 측에 로컬 버퍼링된 intent 가 없고 자동 재생도 일어나지 않는다(버퍼링 금지). 3. Given RabbitMQ connection drop, When 어댑터 상태를 조회, Then `connected/disconnected/reconnecting` 신선도 상태가 application 레이어에 노출되어 degrade 분기에 사용된다. 4. Given dcy-006 A-5(core 자율 안전 매도)가 본 변경 범위 외에 별도 트랙으로 존재함, When 본 REQ 를 검증, Then 본 REQ 는 정책 contract(독립 동작 전제)만 강제하고 구현 자체는 후속 Discovery/REQ 로 추적되도록 Notes 에 명시되어 있다. 5. Given 복구 후 첫 사이클, When 전략이 신규 매매를 결정, Then 결정은 복구 후 신선 스냅샷에 근거하고, 복구 전 결정의 자동 실행은 없다. ## Impacted Area - Docs: docs/runtime-flows.md(degrade 분기 흐름), docs/interface-contract.md(어댑터 신선도 상태 노출) — REQ-026 에서 정합. - Modules: REQ-022 어댑터의 connection 상태/재연결 루프 노출, application 레이어의 broker-down 분기. - Tests: broker 중단 주입 후 신규 intent 전이 없음, 복구 후 자동 재생 없음, connection 상태 전이 노출 테스트. ## Notes - 출처: dcy-006 NFR-3, OQ-4, R-3, A-5. - core 자율 안전 매도(stop-loss, forced_close) 는 현재 미구현(`forced_close_at` 필드만 존재, 자동 트리거 로직 없음, stop-loss 부재). 본 REQ 는 그 capability 가 RabbitMQ·전략과 **독립**이어야 한다는 architecture contract 만 backlog 로 둔다 — 실제 구현은 본 transport 범위 밖이며 별도 Discovery 로 추적해야 한다. - dcy-005 OQ-5(스냅샷 read 가용성) 와 공통 "보수적 안전" 철학을 따른다. - 본 REQ 의 검증은 stub broker 가용성 토글로 충분히 수행 가능하며, 실 RabbitMQ 인프라 의존성을 강제하지 않는다. ## Change Log ### CHG-20260605-01 - Date: 2026-06-05 - Author: Justin Ko #### Change Summary - dcy-006 NFR-3 로부터 최초 생성(Proposed). HTTP fallback 부재로 High 영향 가용성 결합(R-3) 처리 방침을 backlog 로 정규화. #### Intent - broker 장애 시 trex-core 의 보수적 중단·버퍼링 금지 정책과 core 자율 안전 매도 독립 전제를 별도 NFR REQ 로 분리해 운영 가시성 확보. #### Acceptance Criteria Delta - Added: - 보수적 중단, 버퍼링 금지, connection 신선도 노출, A-5 정책 contract 분리, 복구 후 신선 결정 (총 5개 기준) - Updated: - 없음 - Removed: - 없음 #### Impacted Area Delta - Docs: - docs/runtime-flows.md, docs/interface-contract.md - Modules: - adapters/messaging connection 상태 노출, application degrade 분기 - Tests: - broker 중단/복구 시나리오 3종 #### Delivery Trace Delta - Batches: - none - Releases: - none #### Revalidation Impact - Reverification Needed: no - Existing Implementation Invalidated: no - Status Recommendation: keep-current - Follow-up Action: confirm-req 후 batch 편성. core 자율 안전 매도 구현은 별도 Discovery 로 분리 트래킹. #### Validation Plan - stub broker 가용성 토글로 보수적 중단·버퍼링 금지·신선도 상태를 검증. A-5 항목은 정책 contract review. ### CHG-20260605-02 - Date: 2026-06-05 - Author: Justin Ko #### Change Summary - Status 변경: Proposed -> Approved. confirm-req 승인 게이트 통과. #### Intent - RabbitMQ 가용성 degrade 정책(버퍼링 금지 + 보수적 중단 + core 자율 안전 매도 독립 contract)을 delivery input 으로 승인. #### Acceptance Criteria Delta - Added/Updated/Removed: 없음 #### Impacted Area Delta - Docs/Modules/Tests: 없음 #### Delivery Trace Delta - Batches: - none - Releases: - none #### Revalidation Impact - Reverification Needed: no - Existing Implementation Invalidated: no - Status Recommendation: Approved - Follow-up Action: REQ-022 어댑터의 connection 상태 노출과 동일 batch 편성 권장. core 자율 안전 매도 구현은 별도 Discovery 로 분리 트래킹. #### Validation Plan - 기존 Acceptance Criteria 로 batch delivery 에서 검증. ### CHG-20260605-03 - Date: 2026-06-05 - Author: Justin Ko #### Change Summary - Status 변경: Approved -> Implemented. BAT-007 release-candidate verification evidence 기반. #### Intent - RabbitMQ 가용성 degrade 정책(버퍼링 금지 + 보수적 중단 + core 자율 안전 매도 독립 contract)을 구현 완료 상태로 동기화. #### Acceptance Criteria Delta - Added/Updated/Removed: 없음 #### Impacted Area Delta - Docs/Modules/Tests: 없음 #### Delivery Trace Delta - Batches: - BAT-007 (release-candidate) - Releases: - none #### Revalidation Impact - Reverification Needed: no - Existing Implementation Invalidated: no - Status Recommendation: Implemented - Follow-up Action: core 자율 안전 매도 구현은 별도 Discovery 로 분리 트래킹. #### Validation Plan - AC-1: tests/adapters/messaging/test_in_memory_transport.py::test_unavailable_transport_raises_on_publish_and_rpc + tests/application/test_messaging_event_publisher.py::test_publish_failure_does_not_break_execution_loop. - AC-2: MessagingTransport Protocol 에 enqueue 가 없음 + 어댑터 코드 review (publish 실패 → 즉시 raise/DLQ, 로컬 보관 0). - AC-3: TransportHealth enum + 어댑터 상태 머신 코드 + AC-1 테스트가 disconnected 노출 검증. - AC-4: REQ-024 본문 Notes + BAT-007 implementation/verification Remaining Risks 에 명시. - AC-5: 발행 실패가 슬롯 전이를 롤백하지 않음 (test_publish_failure_does_not_break_execution_loop).