feat(slot,intent): slot strategy-state 저장소 (dcy-028) + sell retryable 플래그 (issue #27)

BAT-042 (dcy-028 / issue #26 C-1/C-2/C-2b/C-3, REQ-079~082 + REQ-073/074 CHG):
- slot_strategy_state 별도 테이블 + StrategyStateStore(in-memory+PG) + occupancy_seq·version CAS + opaque UTF-8 data + 2단 size cap (REQ-079)
- trex.slots.strategy_state.set write RPC — reject reason 집합, 멱등 (REQ-080)
- Slot.occupancy_seq 필드 + inactive→pending_buy bump + →INACTIVE close 삭제 훅 → 점유 전환 ABA 구조적 차단 (REQ-081)
- slots.req 응답 행에 strategy_state 맵(batched 조립)·occupancy_seq additive (REQ-073 AC-7/REQ-074 AC-6)
- 마이그레이션 014(occupancy_seq)/015(slot_strategy_state), baseline 문서 정합 (REQ-082)

BAT-043 (issue #27 / REQ-007 CHG):
- rejected SellIntent 응답에 additive retryable: bool (core 소유 reason→retryable 매핑, 미인식 기본 true, bad_request* false) — 손절매 재시도 안전 경로 decoupling

검증: 487 passed, 47 skipped (신규 41: store CAS 6+ABA, occupancy bump/close 4경로, set RPC 9, slots read 5, retryable 8, PG 게이트), ruff clean.
REQ-079·080·081·082·073·074·007 → Implemented. issue #27 close. PG 경로 실 DB 검증은 release 위임.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-15 19:27:57 +09:00
co-authored by Claude Opus 4.8
parent bfadd0d5c8
commit e0d4e71304
40 changed files with 1941 additions and 14 deletions
@@ -0,0 +1,9 @@
-- BAT-042 / dcy-028 / REQ-081: per-occupancy guard counter on the slot.
--
-- The permanent asset slot is reused across occupancies; both a closed and a
-- freshly re-entered occupancy of the same slot start strategy_state at version
-- 0, so a version-only CAS cannot distinguish them at the first write. A
-- monotonic occupancy_seq (bumped on inactive→pending_buy) lets the
-- strategy-state write CAS reject a write computed against a prior occupancy
-- (occupancy_changed). Additive, idempotent. BIGINT so it never wraps.
ALTER TABLE daily_slot ADD COLUMN IF NOT EXISTS occupancy_seq BIGINT NOT NULL DEFAULT 0;
@@ -0,0 +1,18 @@
-- BAT-042 / dcy-028 / REQ-079: opaque per-strategy state store on slots.
--
-- A strategy daemon accumulates opaque state across a slot's occupancy (e.g. a
-- TSL peak). trex-core stores it server-side keyed by (slot_id, strategy_id),
-- never interpreting `data` (opaque UTF-8, byte-capped at the app layer). The
-- state's lifecycle matches the occupancy: trex-core deletes it on close
-- (→INACTIVE) so a reused slot starts empty (dcy-028 C-3). occupancy_seq mirrors
-- the slot's value at write time for the CAS occupancy guard (dcy-028 R-1).
-- version is the compare-and-set counter (idempotent / retry-safe writes).
CREATE TABLE IF NOT EXISTS slot_strategy_state (
slot_id UUID NOT NULL,
strategy_id TEXT NOT NULL,
occupancy_seq BIGINT NOT NULL,
version BIGINT NOT NULL,
data TEXT NOT NULL,
updated_at TIMESTAMPTZ NOT NULL DEFAULT (now() AT TIME ZONE 'UTC'),
PRIMARY KEY (slot_id, strategy_id)
);