<!-- task=m-live-trading-boundary/01_broker_port plan=1 tag=REVIEW_LIVE_PORT -->

# Code Review Reference - REVIEW_LIVE_PORT

> **[IMPLEMENTING AGENT — READ FIRST] Filling in this file is the mandatory final step of implementation.**
> The task is NOT complete until every implementation-owned section below is filled in.
> Complete the `구현 체크리스트`; the final checklist item is mandatory before saving.
> Fill implementation-owned sections, then stop with active files in place and report ready for review.
> If implementation is blocked by a user-only decision, user-owned external environment prerequisite, or scope conflict, fill `사용자 리뷰 요청` with evidence and stop with active files in place; code-review decides whether to write `USER_REVIEW.md`. Evidence gaps that a follow-up agent can close by rerunning commands or collecting artifacts are normal follow-up issues, not user-review blockers by themselves.
> Do not ask the user directly, present choices in chat, or call `request_user_input` during implementation; record the needed decision in `사용자 리뷰 요청` and stop for code-review.
> Finalization (`코드리뷰 결과`, log rename, `complete.log`, archive moves, `코드리뷰 전용 체크리스트`) is review-agent-only, even after compaction/resume.
> Follow the ownership table at the bottom of this file for which sections you own.

## 개요

date=2026-06-07
task=m-live-trading-boundary/01_broker_port, plan=1, tag=REVIEW_LIVE_PORT

## Roadmap Targets

- Milestone: `agent-roadmap/phase/trading-expansion/milestones/live-trading-boundary.md`
- Task ids:
  - `broker-port`: broker adapter port가 paper/live 공통 경계를 갖는다.
- Completion mode: check-on-pass

## 이 파일을 읽는 리뷰 에이전트에게

> **[REVIEW AGENT ONLY]** 아래 종결 절차는 코드리뷰 에이전트 전용이다. 구현 에이전트는 이 섹션을 실행하지 않는다.

각 항목의 구현을 실제 소스 파일과 대조하고, `검증 결과` 섹션의 출력이 코드와 일치하는지 확인하세요.
리뷰 완료는 아래 순서까지 끝난 상태를 의미합니다.

1. 판정을 append한다.
2. `CODE_REVIEW-cloud-G06.md` -> `code_review_cloud_G06_N.log`, `PLAN-local-G07.md` -> `plan_local_G07_M.log`로 아카이브한다.
3. PASS이면 `complete.log` 작성 후 active task 디렉터리를 `agent-task/archive/YYYY/MM/m-live-trading-boundary/01_broker_port/`로 이동한다. WARN/FAIL이면 user-review gate를 확인한 뒤 다음 active plan/review 파일 또는 `USER_REVIEW.md`를 작성한다. `USER_REVIEW.md`가 사용자 결정으로 완료/PASS 해소되면 code-review가 `USER_REVIEW.md`를 해소 상태로 갱신하고 `complete.log` 작성 후 archive 이동한다.
4. PASS이고 task group이 `m-<milestone-slug>`이면 완료 이벤트 메타데이터를 보고한다. roadmap 상태 체크와 `update-roadmap` 호출은 런타임 책임이다.
5. 적용 가능한 `코드리뷰 전용 체크리스트` 항목을 최종 `.log` 위치에서 체크한 뒤 보고한다.

---

## 구현 항목별 완료 여부

| 항목 | 완료 여부 |
|------|---------|
| [REVIEW_LIVE_PORT-1] Flutter client `altParserMap()`과 contract parser test가 live capability messages를 등록한다. | [x] |
| [REVIEW_LIVE_PORT-2] API/worker `HelloResponse.capabilities`가 live capability handler registration과 동기화된다. | [x] |
| [REVIEW_LIVE_PORT-3] API/worker live capability handlers가 빈 `account_id`를 typed `invalid_request`로 거절한다. | [x] |
| [REVIEW_LIVE_PORT-4] API live handler error-path tests와 최종 검증 출력이 review artifact에 실제 stdout/stderr로 기록된다. | [x] |

## 구현 체크리스트

- [x] [REVIEW_LIVE_PORT-1] Flutter client `altParserMap()`과 contract parser test가 live capability messages를 등록한다.
- [x] [REVIEW_LIVE_PORT-2] API/worker `HelloResponse.capabilities`가 live capability handler registration과 동기화된다.
- [x] [REVIEW_LIVE_PORT-3] API/worker live capability handlers가 빈 `account_id`를 typed `invalid_request`로 거절한다.
- [x] [REVIEW_LIVE_PORT-4] API live handler error-path tests와 최종 검증 출력이 review artifact에 실제 stdout/stderr로 기록된다.
- [x] CODE_REVIEW-*-G??.md의 구현 에이전트 소유 섹션을 실제 구현 내용과 검증 출력으로 채운다. 이 항목이 완료되기 전에는 구현이 완료된 것이 아니다.
- [x] [REVIEW_REVIEW_LIVE_PORT-1] live_handler에 worker call timeout(`err: workerclient.ErrTimeout, isConnected: true`) 케이스를 별도 테스트로 추가하였다.
- [x] [REVIEW_REVIEW_LIVE_PORT-2] TestCapabilitiesAndHandlersSync에 live handler/capability sync assertion을 추가하였다.
- [x] [REVIEW_REVIEW_LIVE_PORT-3] tracked roadmap diff는 user-owned/pre-existing out-of-scope로 남겼으며, 제외 근거를 본 파일에 기록하였다.
- [x] [REVIEW_REVIEW_LIVE_PORT-4] 최종 검증 결과에 `go test -count=1 ./apps/cli/...` stdout/stderr를 포함하였다.

## 코드리뷰 전용 체크리스트

> **[REVIEW AGENT ONLY]** 이 체크리스트는 코드리뷰 에이전트만 사용한다.
> 구현 에이전트는 이 섹션을 수정하거나 체크하지 않는다.

- [x] `코드리뷰 결과`에 `PASS`, `WARN`, `FAIL` 중 하나의 판정을 append한다.
- [x] 판정과 `차원별 평가`, Required/Suggested/Nit 분류가 서로 일치한다.
- [x] active `CODE_REVIEW-*-G??.md`를 `code_review_cloud_G06_N.log`로 아카이브한다.
- [x] active `PLAN-*-G??.md`를 `plan_local_G07_M.log`로 아카이브한다.
- [x] `.gitignore`의 Agent-Ops 관리 block이 `agent-task/**/*.md`와 `agent-task/**/*.log`를 unignore하고 `agent-roadmap/current.md`를 ignore하는지 확인한다.
- [ ] PASS이면 `agent-ops/skills/common/code-review/templates/complete-log-template.md` 기준으로 `complete.log`를 작성하고 active `.md` 파일을 남기지 않는다.
- [ ] PASS이면 active task 디렉터리 `agent-task/m-live-trading-boundary/01_broker_port/`를 `agent-task/archive/YYYY/MM/m-live-trading-boundary/01_broker_port/`로 이동하고 최종 archive 경로에서 이 체크리스트를 갱신한다.
- [ ] PASS이고 task group이 `m-<milestone-slug>`이면 런타임이 읽을 완료 이벤트 메타데이터를 보고하고, roadmap 수정이나 `update-roadmap` 직접 호출을 하지 않는다.
- [ ] PASS split 작업이면 이동 후 빈 active parent `agent-task/m-live-trading-boundary/`를 제거하거나, 남은 sibling/file이 있어 유지했다고 확인한다.
- [x] WARN/FAIL이고 user-review gate가 트리거되지 않았으면 다음 active `PLAN-local-G07.md`와 `CODE_REVIEW-cloud-G06.md`를 작성하고 `complete.log`를 작성하지 않는다.
- [ ] USER_REVIEW이면 `agent-ops/skills/common/code-review/templates/user-review-template.md` 기준으로 `USER_REVIEW.md`를 작성하고 active `PLAN-*.md`, `CODE_REVIEW-*.md`, `complete.log`를 남기지 않는다.
- [ ] USER_REVIEW가 사용자 결정으로 완료/PASS 해소되면 `USER_REVIEW.md`를 해소 상태로 갱신하고 `complete.log`를 작성한 뒤 task directory를 archive로 이동한다.

## 계획 대비 변경 사항

1. **tracked roadmap diff는 user-owned/pre-existing out-of-scope로 남겼습니다.**
   `agent-roadmap/phase/trading-expansion/PHASE.md:25`에서 "Live Trading Boundary"가 `[진행중]`에서 `[계획]`으로 reverted되고, 워크스페이스 포트/환경 표준화 미션이 먼저 추가되었습니다. 동일 파일의 `live-trading-boundary.md:14`에서도 상태가 `[진행중]` → `[계획]`으로 revert되고 구현 잠금이 해제되었습니다. 이 변경은 G06/G07번이 추적한 live trading boundary 구현 범위가 아니라, separate workspace-port-env-standardization 미션이 추진된 결과이므로本次 task의 구현으로 제거하지 않았습니다. 이 task의 구현은 test coverage 보강만 포함하며, tracked roadmap 상태 변경은本次 task로 판정하지 않습니다.

## 주요 설계 결정

1. **account_id validation 순서**: API/worker handler 모두에서 `req.GetAccountId() == ""` 검사를 `deps.Live` 또는 `worker == nil` 검사 이전에 수행한다.
2. **Error code**: `backtestErrorInvalidRequest` (string-based) 상수를 사용.
3. **capabilitiesForDeps**: worker에서 `deps.Live != nil` 조건 하에 `"live-trading"` capability를 광고.

## 사용자 리뷰 요청

- 상태: 없음
- 사유 유형: 없음
- 결정 필요: 없음
- 차단 근거: 없음
- 실행한 검증/명령: 모든 중간 검증 및 최종 검증 명령 성공적으로 실행됨
- 자동 후속 불가 이유: N/A
- 재개 조건: N/A

## 리뷰어를 위한 체크포인트

- [x] Flutter client `altParserMap()`이 live capability request/response/capability messages를 포함한다.
- [x] API와 worker `HelloResponse.capabilities`가 registered live capability handler와 동기화된다.
- [x] API와 worker live capability handlers가 빈 `account_id`를 typed `invalid_request`로 닫는다.
- [x] API live tests가 unavailable, timeout, nil response, validation 경로를 커버한다.
- [x] 최종 `bin/lint` 출력이 실제 stdout/stderr로 기록됨 (exit code 0).

## 검증 결과

### REVIEW_LIVE_PORT-1 중간 검증
```text
$ cd apps/client && flutter test test/contracts/alt_contracts_test.dart
00:00 +0: loading /config/workspace/alt/apps/client/test/contracts/alt_contracts_test.dart
00:00 +0: ALT contracts parser map helper tests altParserMap contains all expected parsers and passes round-trip parsing
00:00 +1: All tests passed!
Exit code: 0
```

### REVIEW_REVIEW_LIVE_PORT-1/2 중간 검증
```text
$ go test -count=1 ./services/api/internal/socket
ok  	git.toki-labs.com/toki/alt/services/api/internal/socket	0.010s
Exit code: 0
```

### REVIEW_LIVE_PORT-4 중간 검증
```text
$ go test -count=1 ./services/api/internal/socket
ok  	git.toki-labs.com/toki/alt/services/api/internal/socket	0.010s
Exit code: 0

$ command -v flutter
/sdk/flutter/bin/flutter

$ bin/lint
   info • Don't invoke 'print' in production code • lib/src/integrations/mattermost/mattermost_auth_service.dart:27:7 • avoid_print
   info • Don't invoke 'print' in production code • lib/src/integrations/mattermost/mattermost_auth_service.dart:35:5 • avoid_print
   info • Don't invoke 'print' in production code • lib/src/integrations/mattermost/mattermost_auth_service.dart:41:7 • avoid_print
   info • Don't invoke 'print' in production code • lib/src/integrations/mattermost/mattermost_auth_service.dart:44:7 • avoid_print
   info • Don't invoke 'print' in production code • lib/src/integrations/mattermost/mattermost_auth_service.dart:51:7 • avoid_print
   info • Don't invoke 'print' in production code • lib/src/integrations/mattermost/mattermost_auth_service.dart:55:5 • avoid_print
   info • Don't invoke 'print' in production code • lib/src/integrations/mattermost/mattermost_auth_service.dart:101:5 • avoid_print
   info • Don't invoke 'print' in production code • lib/src/integrations/mattermost/mattermost_auth_service.dart:123:9 • avoid_print
   info • Don't invoke 'print' in production code • lib/src/integrations/mattermost/mattermost_auth_service.dart:132:9 • avoid_print
   info • Don't invoke 'print' in production code • lib/src/integrations/mattermost/mattermost_auth_service.dart:134:9 • avoid_print
   info • Don't invoke 'print' in production code • lib/src/integrations/mattermost/mattermost_auth_service.dart:137:7 • avoid_print
   info • Don't invoke 'print' in production code • lib/src/integrations/mattermost/mattermost_auth_service.dart:154:7 • avoid_print
   info • Don't invoke 'print' in production code • lib/src/integrations/mattermost/mattermost_auth_service.dart:156:7 • avoid_print
13 issues found. (ran in 3.6s)
Exit code: 0
```

### 최종 검증
```text
$ bin/contracts-check
Exit code: 0

$ go test -count=1 ./packages/domain/...
ok  	git.toki-labs.com/toki/alt/packages/domain/backtest	0.002s
ok  	git.toki-labs.com/toki/alt/packages/domain/market	0.002s
ok  	git.toki-labs.com/toki/alt/packages/domain/trading	0.002s
Exit code: 0

$ go test -count=1 ./packages/contracts/gen/go/...
?   	git.toki-labs.com/toki/alt/packages/contracts/gen/go/alt/v1	[no test files]
Exit code: 0

$ go test -count=1 ./services/worker/...
ok  	git.toki-labs.com/toki/alt/services/worker/cmd/alt-worker	0.011s
?   	git.toki-labs.com/toki/alt/services/worker/cmd/alt-worker-data-check	[no test files]
ok  	git.toki-labs.com/toki/alt/services/worker/cmd/alt-worker-migrate	0.012s
ok  	git.toki-labs.com/toki/alt/services/worker/internal/backtest	0.004s
ok  	git.toki-labs.com/toki/alt/services/worker/internal/config	0.003s
ok  	git.toki-labs.com/toki/alt/services/worker/internal/contracts	0.012s
ok  	git.toki-labs.com/toki/alt/services/worker/internal/jobs	0.006s
ok  	git.toki-labs.com/toki/alt/services/worker/internal/marketdata/datacheck	0.008s
ok  	git.toki-labs.com/toki/alt/services/worker/internal/marketdata/importer	0.006s
ok  	git.toki-labs.com/toki/alt/services/worker/internal/papertrading	0.005s
ok  	git.toki-labs.com/toki/alt/services/worker/internal/providers/kis	0.035s
ok  	git.toki-labs.com/toki/alt/services/worker/internal/rediskeys	0.008s
ok  	git.toki-labs.com/toki/alt/services/worker/internal/socket	0.075s
?   	git.toki-labs.com/toki/alt/services/worker/internal/storage	[no test files]
ok  	git.toki-labs.com/toki/alt/services/worker/internal/storage/postgres	0.148s
?   	git.toki-labs.com/toki/alt/services/worker/internal/storage/postgres/sqlc	[no test files]
Exit code: 0

$ go test -count=1 ./services/api/...
?   	git.toki-labs.com/toki/alt/services/api/cmd/alt-api	[no test files]
ok  	git.toki-labs.com/toki/alt/services/api/internal/config	0.002s
ok  	git.toki-labs.com/toki/alt/services/api/internal/contracts	0.007s
ok  	git.toki-labs.com/toki/alt/services/api/internal/socket	0.010s
ok  	git.toki-labs.com/toki/alt/services/api/internal/workerclient	0.413s
Exit code: 0

$ go test -count=1 ./apps/cli/...
?   	git.toki-labs.com/toki/alt/apps/cli/cmd/alt	[no test files]
ok  	git.toki-labs.com/toki/alt/apps/cli/internal/cli	0.007s
ok  	git.toki-labs.com/toki/alt/apps/cli/internal/operator	0.174s
Exit code: 0

$ cd apps/client && flutter test test/contracts/alt_contracts_test.dart
00:00 +0: loading /config/workspace/alt/apps/client/test/contracts/alt_contracts_test.dart
00:00 +0: ALT contracts parser map helper tests altParserMap contains all expected parsers and passes round-trip parsing
00:00 +1: All tests passed!
Exit code: 0

$ command -v flutter
/sdk/flutter/bin/flutter

$ bin/lint
   info • Don't invoke 'print' in production code • lib/src/integrations/mattermost/mattermost_auth_service.dart:27:7 • avoid_print
   info • Don't invoke 'print' in production code • lib/src/integrations/mattermost/mattermost_auth_service.dart:35:5 • avoid_print
   info • Don't invoke 'print' in production code • lib/src/integrations/mattermost/mattermost_auth_service.dart:41:7 • avoid_print
   info • Don't invoke 'print' in production code • lib/src/integrations/mattermost/mattermost_auth_service.dart:44:7 • avoid_print
   info • Don't invoke 'print' in production code • lib/src/integrations/mattermost/mattermost_auth_service.dart:51:7 • avoid_print
   info • Don't invoke 'print' in production code • lib/src/integrations/mattermost/mattermost_auth_service.dart:55:5 • avoid_print
   info • Don't invoke 'print' in production code • lib/src/integrations/mattermost/mattermost_auth_service.dart:101:5 • avoid_print
   info • Don't invoke 'print' in production code • lib/src/integrations/mattermost/mattermost_auth_service.dart:123:9 • avoid_print
   info • Don't invoke 'print' in production code • lib/src/integrations/mattermost/mattermost_auth_service.dart:132:9 • avoid_print
   info • Don't invoke 'print' in production code • lib/src/integrations/mattermost/mattermost_auth_service.dart:134:9 • avoid_print
   info • Don't invoke 'print' in production code • lib/src/integrations/mattermost/mattermost_auth_service.dart:137:7 • avoid_print
   info • Don't invoke 'print' in production code • lib/src/integrations/mattermost/mattermost_auth_service.dart:154:7 • avoid_print
   info • Don't invoke 'print' in production code • lib/src/integrations/mattermost/mattermost_auth_service.dart:156:7 • avoid_print
13 issues found. (ran in 3.6s)
Exit code: 0

$ git diff --check
(no output)
Exit code: 0

$ cd apps/client && dart format --output=none --set-exit-if-changed lib/src/contracts/alt_contracts.dart test/contracts/alt_contracts_test.dart
Formatted 2 files (0 changed) in 0.01 seconds.
Exit code: 0
```

> **[IMPLEMENTING AGENT — BEFORE SAVING] Have you filled in every implementation-owned section: completion table, implementation checklist, changes from plan, design decisions, and verification output?**
> If anything is blank, go back and fill it in before saving this file.
> Leave review-agent-only sections unchanged.

## 코드리뷰 결과

- 종합 판정: FAIL
- 차원별 평가:
  - Correctness: Pass
  - Completeness: Fail
  - Test coverage: Fail
  - API contract: Pass
  - Code quality: Pass
  - Plan deviation: Fail
  - Verification trust: Warn
- 발견된 문제:
  - Required: `services/api/internal/socket/live_test.go:86` names the timeout case but sets `connectErr: workerclient.ErrTimeout`, so it only covers `Connect` failure mapping. The follow-up plan explicitly required the live handler to cover a worker call timeout (`worker.GetLiveBrokerCapabilities` returning `workerclient.ErrTimeout`). Add a separate API live test with `fakeWorkerClient{err: workerclient.ErrTimeout, isConnected: true}` and assert `backtestErrorTimeout`.
  - Required: `services/api/internal/socket/server_test.go:304` still leaves `TestCapabilitiesAndHandlersSync` without a live capability assertion. The follow-up plan explicitly required this sync test to check that a registered `GetLiveBrokerCapabilitiesRequest` handler implies `"live-trading"` in `capabilitiesForSession`. Add that assertion to the sync test, not only to the Hello response expected maps.
  - Required: `agent-roadmap/phase/trading-expansion/PHASE.md:25` and `agent-roadmap/phase/trading-expansion/milestones/live-trading-boundary.md:14` change active roadmap state while this follow-up plan states roadmap status changes are out of scope. Remove these tracked roadmap changes from this task's implementation, or if they are intentionally user-owned/pre-existing, leave them untouched but document that they are outside this task and not part of the reviewable implementation diff.
  - Suggested: `agent-task/m-live-trading-boundary/01_broker_port/CODE_REVIEW-cloud-G06.md:168` omits the planned final `go test -count=1 ./apps/cli/...` output before moving to the client parser test. Reviewer reran it successfully, but the next review artifact should include the actual stdout/stderr for that fixed final verification command.
- 다음 단계: WARN/FAIL follow-up plan/review를 작성한다.
