# BAT-039: paper 브로커 order seq Redis 영속화 (CHG-20260612-01) - Status: release-candidate - Profile: standard - Source Discovery: 없음 (issue #4, dcy-003/REQ-011 change-req) - Included REQ: REQ-011 (CHG-20260612-01) - Excluded REQ: 없음 ## Summary - paper 브로커 order seq 가 데몬 재시작 시 0 으로 리셋되어 `PAPER-000001` 부터 재발번 → 결정적 `execution_id` 재생성 → 원장 멱등 키 `correlation_id`(side 미포함)가 직전 run 매수와 충돌 → `ON CONFLICT DO NOTHING` dedup 으로 정상 매도 원장이 조용히 누락되는 paper 한정 결정성 버그(issue #4)를 닫는다. paper 어댑터에 optional seq store(Redis INCR 영속, REQ-016 token_cache 패턴)를 주입하고 미구성 시 in-memory 폴백. ## Scope - In Scope: - `trex_core/adapters/broker/seq_store.py` 신규 — `SeqStore` 포트 + `RedisSeqStore`(INCR) + `InMemorySeqStore` - `trex_core/adapters/broker/paper.py` — optional `seq_store` 주입, `submit_order` 발번 경로 - `trex_core/runtime/config.py` — `PaperBrokerConfig.redis_url`(`TREX_PAPER_REDIS_URL`) - `trex_core/runtime/daemon.py` — `_build_broker` paper 경로 seq store wiring - 테스트: 재시작 모사(seq store 공유) 단조성 + correlation_id 비충돌 + in-memory 폴백 - Out of Scope: - 원장 `correlation_id` 에 side 추가(대안 미채택 — 프로덕션 계약 영향) - KIS 어댑터(odno 고유, 충돌 없음) - 과거 누락 원장 행 소급 보정 ## Documents - Planning: [planning.md](./planning.md) - Design: [design.md](./design.md) - Implementation: [implementation.md](./implementation.md) - Verification: [verification.md](./verification.md) ## Notes - paper 한정 테스트 하네스 결정성 문제 — 실 KIS 는 broker `odno` 가 주문마다 고유해 충돌 없음(프로덕션 버그 아님). - seq store 미주입(Redis 미구성) 시 기존 in-memory `_seq` 동작을 byte-for-byte 유지(AC-1~3 불변, CI 영향 최소). - Redis 인프라는 REQ-016 `RedisTokenCache` 패턴(best-effort, `from_url(socket_connect_timeout=2)`)을 재사용.