Implement Decision Logging System with Context Snapshots #17

Closed
opened 2026-02-04 14:55:33 +09:00 by agentson · 0 comments
Collaborator

Goal

Implement "Log & Feedback" behavioral rule with comprehensive decision logging and context snapshots.

Implementation Tasks

1. Database Schema

Add decision_logs table:

  • decision_id (PRIMARY KEY)
  • timestamp (ISO 8601)
  • stock_code, market, exchange_code
  • action (BUY/SELL/HOLD)
  • confidence (0-100)
  • rationale (text)
  • context_snapshot (JSON: L1-L7 context at decision time)
  • input_data (JSON: price, volume, orderbook)
  • outcome_pnl (actual profit/loss, NULL until resolved)
  • outcome_accuracy (1 if correct, 0 if wrong, NULL if pending)
  • reviewed (BOOLEAN, default FALSE)
  • review_notes (text)

2. DecisionLogger Class (src/logging/decision_logger.py)

Methods:

  • log_decision(decision, context_snapshot, market_data) -> decision_id
  • get_unreviewed_decisions(min_confidence=80) -> List[DecisionLog]
  • mark_reviewed(decision_id, notes)
  • update_outcome(decision_id, pnl, accuracy)

3. GeminiClient Integration

  • Auto-generate decision_id for each TradeDecision
  • Capture context snapshot from ContextStore (all L1-L7 layers)
  • Log before sending order to broker

4. Tests (tests/test_decision_logger.py)

  • Test decision logging with context snapshot
  • Test retrieving unreviewed decisions
  • Test outcome updates
  • Test context snapshot deserialization

Acceptance Criteria

  • decision_logs table created with proper schema
  • DecisionLogger class with all methods implemented
  • GeminiClient logs all decisions automatically
  • Tests achieve >= 80% coverage
  • All decisions include L1-L7 context snapshot

Related to: Task #11, Pillar 4 (Evolution), Behavioral Rule "Log & Feedback"

## Goal Implement "Log & Feedback" behavioral rule with comprehensive decision logging and context snapshots. ## Implementation Tasks ### 1. Database Schema Add `decision_logs` table: - `decision_id` (PRIMARY KEY) - `timestamp` (ISO 8601) - `stock_code`, `market`, `exchange_code` - `action` (BUY/SELL/HOLD) - `confidence` (0-100) - `rationale` (text) - `context_snapshot` (JSON: L1-L7 context at decision time) - `input_data` (JSON: price, volume, orderbook) - `outcome_pnl` (actual profit/loss, NULL until resolved) - `outcome_accuracy` (1 if correct, 0 if wrong, NULL if pending) - `reviewed` (BOOLEAN, default FALSE) - `review_notes` (text) ### 2. DecisionLogger Class (`src/logging/decision_logger.py`) Methods: - `log_decision(decision, context_snapshot, market_data) -> decision_id` - `get_unreviewed_decisions(min_confidence=80) -> List[DecisionLog]` - `mark_reviewed(decision_id, notes)` - `update_outcome(decision_id, pnl, accuracy)` ### 3. GeminiClient Integration - Auto-generate `decision_id` for each TradeDecision - Capture context snapshot from ContextStore (all L1-L7 layers) - Log before sending order to broker ### 4. Tests (`tests/test_decision_logger.py`) - Test decision logging with context snapshot - Test retrieving unreviewed decisions - Test outcome updates - Test context snapshot deserialization ## Acceptance Criteria - [ ] `decision_logs` table created with proper schema - [ ] DecisionLogger class with all methods implemented - [ ] GeminiClient logs all decisions automatically - [ ] Tests achieve >= 80% coverage - [ ] All decisions include L1-L7 context snapshot Related to: Task #11, Pillar 4 (Evolution), Behavioral Rule "Log & Feedback"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: jihoson/The-Ouroboros#17