feat(reconcile): safely seed canonical cost basis

This commit is contained in:
Hermes Agent
2026-07-17 09:57:08 +09:00
parent 18bd8d9f0b
commit 81a853a314
25 changed files with 1689 additions and 66 deletions
+1
View File
@@ -19,3 +19,4 @@
| REL-009 | app-service | feedback-captured | BAT-047, BAT-048, BAT-049 | dcy-031/OPS-005 (이벤트 발행 신뢰성 — idle keepalive·재시도·DLQ 경보) + dcy-032 (체결가 0/None 백필 가드·WARN 로깅) + dcy-033 (알람 emitter + trex.alerts exchange 1단계) + dcy-017 후속(무데이터/죽은 종목 위생 런북 docs-only) — M2 통합 릴리즈. 환류: OPS-005 해소 확인, slot_filled NO_ROUTE/DLQ 신규 발견(M3 Discovery 입력) | [rel-009](rel-009_20260625_event-reliability-fill-guard-alarm-runbook.md) |
| REL-010 | app-service | released | BAT-050, BAT-051, BAT-052, BAT-053, BAT-054 | dcy-034 (차단형 reconcile + sync/verify cold-start) + dcy-035 (WAC 실현손익 운영리포트) + dcy-036 (KIS 인증정보 휴면 배포 — credential_fetch_enabled=OFF) — M3 통합 릴리즈. 배포 revision `314047b`(2026-06-30). verify ImportError 핫픽스 `51cc3cc` 포함. | [rel-010](rel-010_20260629_reconcile-coldstart-wac-report-credential-dormant.md) |
| REL-011 | app-service | draft | BAT-057 | dcy-037 (operator broker truth / managed non-holding divergence hotfix) — **M5 trex-core P0 release**. Source pin `6d90f89`; production daemon restart와 read/dry-run smoke만 대상이며 `sync --live`, config activation, DB migration은 별도 gate. | [rel-011](rel-011_20260716_m5_operator-broker-truth-hotfix.md) |
| REL-012 | app-service | draft / release-pending | BAT-058 | dcy-038 / REQ-123 (cost-basis canonical parse + unavailable WAC safe sync seed) — **긴급 consumer hotfix**. Immutable source pin은 commit/push 후 확정하며, daemon restart와 read/dry-run smoke만 release scope; `sync --live`, config activation, DB migration은 별도 gate. | [rel-012](rel-012_20260717_cost-basis-safe-sync-seed-hotfix.md) |
@@ -0,0 +1,73 @@
# REL-012: cost-basis canonical parse 및 안전 sync seed 긴급 핫픽스
- Status: **Draft / Release-Pending**
- Profile: `app-service`
- Priority: **urgent**
- Owner: 팀장 / 운영팀
- Included batch: **BAT-058** (`REQ-123`)
- Source discovery: [`dcy-038`](../discovery/dcy-038_20260716_cost-basis-response-contract-and-safe-sync-seeding.md)
- Batch verification: [`BAT-058 verification`](../batches/bat-058_20260716_cost-basis-safe-sync-seed/verification.md) — lead `confirm-batch-verification`, QC-7 `PASS-WITH-NOTES`
- Operations handoff: [`REL-012 deployment request`](../runbooks/rel-012-cost-basis-safe-sync-seed-ops-handoff.md)
## Release intent
portfolio-hub의 기존 cost-basis 응답에서 canonical `cost_basis_per_unit`을 우선 해석하고, broker quantity가 양수인 inactive-slot onboarding에서 WAC/avg_price를 얻지 못하면 live sync가 slot status/qty/avg_price/warning을 쓰지 않은 채 non-zero로 fail-closed하도록 한다. dry-run은 sanitized source/reason과 no-write preview를 제공한다.
## Source publication boundary
| Item | Current evidence | Release constraint |
| --- | --- | --- |
| Remote `origin/main` | `18bd8d9f0b7bb76b08303bbf8743e6ddf916de89` (2026-07-17 fetch) | BAT-058 source is **not included** in this remote revision. |
| BAT-058 candidate | delivery worktree `sp/trex-bat-058-lead-kickoff-delivery`, currently uncommitted | A local worktree is not a deployable source pin. |
| Immutable deploy target | **PENDING_COMMIT_AND_PUSH** | Git-ops must publish an exact reviewed commit SHA and verify that the remote tree contains this REL/runbook before ops execution. |
This document is a release draft and a preflight request only. It does **not** authorize deployment, daemon restart, broker/portfolio access, `sync --live`, database writes, configuration activation, or credential access.
## Included scope
1. `cost_basis_per_unit` canonical priority parsing and approved legacy compatibility chain (`avg_cost` → `wac` → `cost_basis`) only when canonical is absent.
2. Canonical invalid/null/non-numeric/zero/negative values are not silently masked by a legacy value; diagnostic reasons remain sanitized.
3. Inactive slot + positive broker quantity + unavailable WAC: dry-run no-write preview; live non-zero fail-closed with no slot/warning mutation.
4. Existing HOLDING reconciliation remains compatible; sanitized CLI/operator diagnostics preserve `seeded_avg_price`, source, and absence reason.
## Explicit exclusions / no-go
- portfolio-hub API/schema/auth changes, token/config changes, dependency upgrade, DB migration, direct DB edit/delete, AMQP wire/topology change.
- Any `sync --live`, `--yes` live write, automatic remediation, order action (`enter`/`exit`/`cancel`), or target portfolio selection.
- Changing `credential_fetch_enabled`, break-glass mode, instance configuration, endpoint, or secrets.
- Strategy daemon deployment.
A single-target `sync --live --yes` remains a separately approved post-release action even after this source rollout. It must not be used as a deployment smoke shortcut.
## Draft verification evidence
| Check | Result | Evidence / limitation |
| --- | --- | --- |
| Independent QC-7 | **PASS-WITH-NOTES** | Legacy-invalid focused `8 passed, 19 deselected`; affected suite `113 passed`; full suite `833 passed, 47 skipped`; Ruff/compileall/diff hygiene pass. |
| Release-prep full regression | **PASS** | 2026-07-17 delivery worktree: `833 passed, 47 skipped in 1.88s`. |
| Focused Ruff | **PASS** | Changed adapter/reconcile/CLI and relevant tests: `All checks passed!`. |
| Focused compile check | **PASS** | Six changed source/test paths, `compileall -q`, exit `0`. |
| Live broker, live PostgreSQL, production deploy | **NOT EXECUTED** | Outside batch verification and this draft; no claim is made. |
| Source publication | **PENDING** | No immutable remote candidate SHA exists yet. |
## Release approval gates
All items must be satisfied before operations executes the runbook:
- [ ] Git-ops publishes the reviewed source and these release documents; lead records the exact remote immutable target SHA.
- [ ] Operations verifies that exact target SHA contains REL-012 and its runbook, and captures the actual deployed revision as `ROLLBACK_REVISION`.
- [ ] User/approver explicitly authorizes production execution and the approved off-market window is recorded.
- [ ] Operations confirms the source checkout is clean; existing runtime configuration and credential/break-glass modes will not change.
- [ ] Operations confirms no dependency or migration delta exists between `ROLLBACK_REVISION` and the exact target SHA.
- [ ] Operations records the approved supervisor method, instance key (redacted as necessary), and post-deploy observation owner.
## Rollout and rollback policy
1. Use the pinned immutable source only; use the host’s existing approved supervisor to restart the same daemon with unchanged approved configuration.
2. After startup acceptance, run only the read/dry-run commands in the REL-012 runbook.
3. Stop and roll back on startup failure, traceback/error regression, unexpected credential/source-mode behavior, unexpected mutation indication, or smoke output that violates the no-write/fail-closed contract.
4. Roll back by restoring the actual captured `ROLLBACK_REVISION` and restarting with unchanged configuration. Do not run database rollback commands, direct DB edits, or live sync.
## Evidence required for `confirm-release`
Operations returns a secret-free record containing: approver/window/operator; `ROLLBACK_REVISION` and target SHA; clean-checkout/preflight result; restart/startup result; dry-run smoke and `verify` exit/status summaries; observed no-write/fail-closed classifications; and rollback disposition. The lead then reviews that evidence before changing REL-012 from Draft / Release-Pending.