# Complete - m-provider-resource-admission-ownership-alignment/02+01_lease_lifecycle

## 완료 일시

2026-07-19

## 요약

Provider lease FSM과 direct terminal/disconnect release 경로를 구현하고 node disconnect 경쟁 회귀를 보완했으며, 2회 리뷰 루프 끝에 PASS했다.

## 루프 이력

| Plan | Review | Verdict | 메모 |
|------|--------|---------|------|
| `plan_cloud_G07_0.log` | `code_review_cloud_G07_0.log` | FAIL | manager-owned lease와 direct lifecycle 구현은 통과했으나 SDD S02의 node disconnect 경쟁 race evidence가 누락되어 후속 검증을 요구했다. |
| `plan_local_G04_1.log` | `code_review_local_G04_1.log` | PASS | 일반·long lease의 node disconnect/terminal 경쟁, 다른 resource 보존, stale identity 격리 회귀와 재실행 검증이 모두 통과했다. |

## 구현/정리 내용

- 고유 provider lease를 admission critical section에서 발급하고 `reserved → tracked → released` 전이를 manager lock 아래에서 관리해 terminal 원인 간 중복 반환을 idempotent no-op으로 수렴시켰다.
- normalized run terminal, provider tunnel terminal/close, send 실패와 current-owner node disconnect를 direct lifecycle release 경로로 통합하고 correctness를 drop 가능한 event fanout에서 분리했다.
- `TestProviderLeaseNodeDisconnectRaceExactlyOnce`를 일반·long case로 추가해 `releaseNode`/`releaseRun`/`releaseLease` 경쟁 뒤 counter·lease·run index 정리, 다른 Node lease 보존, 재-admission 뒤 stale old identity 격리를 검증했다.

## 최종 검증

- `gofmt -d apps/edge/internal/service/queue_reservation_test.go apps/edge/internal/service/model_queue_release.go` - PASS; 출력 없음.
- `git diff --check` - PASS; 출력 없음.
- `GOCACHE=/tmp/iop-go-cache go test -race -count=10 ./apps/edge/internal/service -run '^TestProviderLease(NodeDisconnectRaceExactlyOnce|ConcurrentReleaseExactlyOnce|TrackAndSendFailureRace)$'` - PASS; `ok iop/apps/edge/internal/service`.
- `GOCACHE=/tmp/iop-go-cache go test -race -count=1 ./apps/edge/internal/service ./apps/edge/internal/transport ./apps/edge/internal/bootstrap -run 'Test(ProviderLease|RunTerminal|CurrentOwnerDisconnect|StaleDisconnect|ProviderTunnelRelease|RuntimeWiresTransportHandlers)'` - PASS; service, transport, bootstrap 모두 `ok`.
- `GOCACHE=/tmp/iop-go-cache go test -count=1 ./apps/edge/...` - PASS; Edge 전체 패키지 fresh test 모두 `ok`.

## Roadmap Completion

- Milestone: `agent-roadmap/phase/operational-observability-provider-management/milestones/provider-resource-admission-ownership-alignment.md`
- Milestone link: [Milestone 문서](agent-roadmap/phase/operational-observability-provider-management/milestones/provider-resource-admission-ownership-alignment.md)
- Completed task ids:
  - `lease-lifecycle`: PASS; evidence=`agent-task/archive/2026/07/m-provider-resource-admission-ownership-alignment/02+01_lease_lifecycle/plan_cloud_G07_0.log`, `agent-task/archive/2026/07/m-provider-resource-admission-ownership-alignment/02+01_lease_lifecycle/code_review_cloud_G07_0.log`, `agent-task/archive/2026/07/m-provider-resource-admission-ownership-alignment/02+01_lease_lifecycle/plan_local_G04_1.log`, `agent-task/archive/2026/07/m-provider-resource-admission-ownership-alignment/02+01_lease_lifecycle/code_review_local_G04_1.log`; verification=`GOCACHE=/tmp/iop-go-cache go test -race -count=10 ./apps/edge/internal/service -run '^TestProviderLease(NodeDisconnectRaceExactlyOnce|ConcurrentReleaseExactlyOnce|TrackAndSendFailureRace)$'`, `GOCACHE=/tmp/iop-go-cache go test -race -count=1 ./apps/edge/internal/service ./apps/edge/internal/transport ./apps/edge/internal/bootstrap -run 'Test(ProviderLease|RunTerminal|CurrentOwnerDisconnect|StaleDisconnect|ProviderTunnelRelease|RuntimeWiresTransportHandlers)'`, `GOCACHE=/tmp/iop-go-cache go test -count=1 ./apps/edge/...`
- Not completed task ids: 없음

## 잔여 Nit

- 없음

## 후속 작업

- 없음
