Adds 4 additive fields to GET /v1/portfolios (and single-portfolio) response:
- active_strategy_id (str|null): portfolios.active_strategy_id raw value
- strategy_name (str|null): strategy_sets.name via LEFT JOIN
- strategy_params (dict): strategy_sets.config JSON parsed; {} on missing/invalid
- markets (list[str]): assets.markets; [] on missing/empty
_SELECT_PORTFOLIO extended with LEFT JOIN strategy_sets; _row_to_portfolio
parses new columns (row[19-21]) with JSON error isolation (WARNING log, no 500).
_portfolio_to_item maps all 4 new fields. Existing 16 fields unchanged.
N+1 prevented: single SQL JOIN for both list and single-item paths.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VHtM5Ws1HKCKQ4JGi6GRb5
update_daemon_owner()에서 owner UPDATE + credential DELETE를 단일
conn.transaction() 블록으로 묶어 원자성 보장. 실패 시 두 연산 모두
롤백되므로 "새 owner + 이전 credential 잔류" leak 상태(dcy-011 OQ-3)
가 불가능해짐. 실행 순서도 DELETE-first(안전 순서)로 고정.
단위 테스트 3종 추가:
- DELETE-before-UPDATE 실행 순서 검증
- UPDATE 실패 시 rollback(commit 미호출) 검증
- 단일 transaction() 블록 안에서 두 연산 실행 검증
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VHtM5Ws1HKCKQ4JGi6GRb5
Add three approved requirements documents for dcy-011:
- REQ-052: User-owned credential management API (Interface)
- REQ-053: Admin daemon CRUD API (Interface)
- REQ-054: Credential management security with write-only constraint (Non-Functional)
Update discovery document to reference generated requirements and update index with new REQ IDs and Change Log.
Scope: Self-service credential management + admin daemon CRUD + security-isolated API for portfolio-hub.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VHtM5Ws1HKCKQ4JGi6GRb5
WAC 공식에 buy row의 fee_amount를 분자에 포함해 실현 PnL이 당일 net과 정확히 일치하도록 수정.
calculate_realized_pnl + calculate_current_wac 양 함수 동일 적용.
신규 단위 테스트 9개(TestBuyFeeInCostBasis 5 + TestCurrentWacBuyFeeInCostBasis 4) 추가.
change-req: REQ-041 AC-9/AC-10 추가, REQ-040/REQ-043 Notes 갱신, index 갱신.
전체 456 passed / 0 failed.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VHtM5Ws1HKCKQ4JGi6GRb5
batch drift 정합 — REL-001(BAT-001~016)·REL-002(BAT-017) released에 맞춰
batches/index 및 개별 index 상태를 release-candidate→released 동기화(17건).
README: bootstrap 문구 제거, dcy-007 엔드포인트(GET /trades·/pnl/realized) 추가,
planned-next 현행화. 코드 무변경.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VHtM5Ws1HKCKQ4JGi6GRb5
- GET /v1/portfolios/{id}/trades and GET /v1/portfolios/{id}/pnl/realized endpoints
- Weighted Average Cost (WAC) realized PnL calculation in app/domain/pnl.py
- cost_basis and data_completeness_warning returned in pnl API response
- Test coverage: 50 passed (WAC 20 + trades 12 + pnl 18), full 427 passed regression ✓
- WAC validated against 199,300 unit e2e test cases
- DB migration: none required
- QC: qc-reviewer PASS-WITH-NOTES; team lead confirm-batch-verification → release-candidate
- Remaining non-blocking: symbol filter edge case testing, HTTP_422 deprecation
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VHtM5Ws1HKCKQ4JGi6GRb5
- Add issue #9 hotfix (GET /v1/user_info 500 on missing broker_credentials) to
REL-001 Included scope + Revision (6b812b6 as integrated main HEAD).
- Add post-deploy smoke item for /v1/user_info 200 + daemon_id (local verified).
- Record 2026-06-06 local verification: ledger_trades absent / portfolio_ledger
consolidated schema, legacy buy/sell OpenAPI deprecated, full suite 377 passed.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
trex-core reported GET /v1/user_info returning 500 for valid service/daemon
tokens (whoami → daemon_id), degrading the daemon and holding new trades. The
reported hypothesis (service-token None deref) was a misdiagnosis. Root cause:
app/api/v1_user_info.py: credentials = repo.list_broker_credentials(...)
psycopg.errors.UndefinedTable: relation "broker_credentials" does not exist
The broker_credentials table was missing and the handler only caught
AttributeError, so the DB error propagated to a bare 500.
Two fixes:
1. Handler now degrades gracefully when broker-credential lookup fails — returns
empty brokers and still serves daemon_id/user_id/permission, which do not
depend on broker credentials. This is what trex-core's whoami needs.
2. ensure_schema() now also CREATE TABLE broker_credentials (same shape as
migration 20260502_0014). ensure_schema-bootstrapped DBs were missing it,
since previously only the alembic path created it.
Added tests/test_v1.py regression: broker-credential lookup raising a DB error
must yield HTTP 200 with daemon_id, not 500. Verified against the real DB
(was 500 → now 200 + daemon_id). Full suite 377 passed.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- fold BAT-015 and BAT-016 into REL-001 release scope
- mark split REL-002 and REL-003 plans as superseded in discovery docs
- update release and batch indexes to match the unified release plan
- expand REL-001 rollout, rollback, verification, and evidence notes
BAT-016's initial implementation passed only against mocked repositories and
broke on a real database. Two defects fixed:
1. insert_ledger_trade used `ON CONFLICT (portfolio_id, order_id, execution_id)
WHERE order_id IS NOT NULL` but portfolio_ledger is a TimescaleDB hypertable,
which cannot have that partial unique index (must include the partitioning
column recorded_at). The statement errored against Postgres. Replaced with
application-level idempotency: SELECT-before-insert inside the existing
`SELECT ... FOR UPDATE` portfolio row lock, which serializes concurrent
same-portfolio writes (race-safe). Duplicate returns current authoritative
portfolio state (dcy-006 OQ-4 b).
2. `with self._connect() as conn:` closes the shared psycopg3 connection on exit,
leaving the reused repository connection unusable. Switched to
`with conn.transaction():` (commits without closing).
Added tests/test_ledger_consolidation_integration.py — real-Postgres integration
tests (new / duplicate / negative-balance) that close the mock-only verification
gap. Full suite: 376 passed.
SDLC: REQ-036/037 CHG-20260605-03 reconcile OQ-7 (ii) (DB partial unique →
application-level idempotency) since the hypertable makes the DB constraint
infeasible. REQ-036/037/038 → Implemented; BAT-016 → release-candidate.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>