Deliver BAT-002: slot-core daemon + HTTP intent API + PostgreSQL
Implement REQ-005~009 (dcy-002 slice 1) as an onion stack on top of the
BAT-001 pure domain:
- application: IntentService (admission + single-writer transition +
intent_id idempotency via durable intent_log)
- adapters/persistence: PostgreSQLSlotRepository + PostgreSQLIntentStore +
trex-core-owned migrations (daily_slot per Appendix A, daily_symbol_entries,
slot_transition_log, intent_log) + in-memory intent store
- adapters/api: FastAPI /v1 (healthz, intents/buy|sell|{id}, slots, capacity)
- runtime: trex-core-daemon entrypoint with lifespan migrate+preallocate
Verification (against local PostgreSQL 18): 74 passed, ruff clean, domain
import sweep shows zero web/db deps (NFR-1), 20-thread concurrency admits
exactly the idle count (NFR-2), idempotent resubmit causes no double
transition (NFR-3), EXPECTED_SLOT_FIELDS<->information_schema drift test
(realizes dcy-001 OQ-2's deferred DB-side check), and a daemon E2E smoke.
Align all four baseline docs to the new daemon/API/persistence layers.
BAT-002 -> release-candidate; REQ-005~009 -> Implemented. Full async outbox,
broker execution, safety floor, and strategy daemons remain deferred to a
follow-up Discovery.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
"""Application ports (REQ-007). The intent dedup/audit store contract.
|
||||
|
||||
Kept in the application layer (not domain) so the pure slot domain stays
|
||||
unaware of the intent concept. Concrete implementations live in adapters.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Optional, Protocol
|
||||
from uuid import UUID
|
||||
|
||||
|
||||
class IntentStore(Protocol):
|
||||
"""Durable idempotency + audit store for accepted intents (dcy-002 OQ-1).
|
||||
|
||||
`try_insert` is the dedup gate: it returns False if `intent_id` already
|
||||
exists, which prevents a duplicate intent from re-driving a slot
|
||||
transition (NFR-3). `finalize` records the decision after processing.
|
||||
"""
|
||||
|
||||
def try_insert(self, intent_id: str, intent_type: str, payload: dict) -> bool:
|
||||
"""Insert a new intent row in 'processing' state.
|
||||
|
||||
Returns True if newly inserted, False if `intent_id` already exists.
|
||||
"""
|
||||
...
|
||||
|
||||
def get(self, intent_id: str) -> Optional["IntentRecord"]:
|
||||
"""Return the stored intent record, or None."""
|
||||
...
|
||||
|
||||
def finalize(
|
||||
self,
|
||||
intent_id: str,
|
||||
status: str,
|
||||
slot_id: Optional[UUID],
|
||||
reason: Optional[str],
|
||||
) -> None:
|
||||
"""Update an intent row with its final decision (admitted/rejected)."""
|
||||
...
|
||||
|
||||
|
||||
class IntentRecord:
|
||||
"""Snapshot of an intent_log row (duck-typed; see adapters)."""
|
||||
|
||||
intent_id: str
|
||||
intent_type: str
|
||||
status: str
|
||||
slot_id: Optional[UUID]
|
||||
reason: Optional[str]
|
||||
Reference in New Issue
Block a user