## Analysis

### Impact Table

| Area | Files | Risk | Verification |
| --- | --- | --- | --- |
| Premium DM worker runtime assembly | `dataflow-service-ng/app/models/premium_dm/worker.go` | Worker can keep processing NG tasks after DM cluster lookup/provisioning failed, leaving routing undecided | `cd dataflow-service-ng && go test ./app/models/premium_dm -run 'Test(CreateOrScaleOutDMClustersUsesResolvedDMClusterID|BuildRuntimeForTask|DeleteDMClusterIfNoWorkers)'` |
| Premium DM proxy routing | `dataflow-service-ng/app/models/premium_dm/proxy.go` | `nil` DM cluster currently falls through to the legacy DM proxy path and can misroute operator-v2 traffic | `cd dataflow-service-ng && go test ./app/models/premium_dm -run 'Test(NewPremiumDMProxy|PremiumDMProxyRoutesOperatorV2ToServiceProxy|PatchDMTargetConn)'` |
| Premium DM domain knowledge | `.domain-knowledge/ng-premium-dm.md` | Routing rules can drift from the verified fail-fast behavior | Re-read updated section after tests pass |

### Symbols To Keep

- `PremiumDMTaskRuntime.DMCluster`
- `PremiumDMTaskWorker.createOrScaleOutDMClustersIfNeeded`
- `ResolveDMClusterForTiDBID`
- Legacy `agentCli.DMOpenAPIProxy(...)` path for explicitly resolved non-operator-v2 backends

### Symbols To Change

- `NewPremiumDMProxy(...)` nil-DM-cluster behavior
- Premium DM proxy tests around routing selection

### Dead-Code / Regression Checks

1. Keep service-proxy routing for operator-v2 DM clusters.
2. Keep legacy agent proxy routing only when DM cluster resolution succeeds and the backend is not operator-v2.
3. Ensure a missing DM cluster for a NextGen shared-pool task returns an error instead of silently selecting legacy routing.
4. Keep target-connection patching limited to the service-proxy path.

## Execution Steps

1. Update the Premium DM execution plan for this routing fix.
   Verification:
   - `sed -n '1,220p' docs/coding-with-agents/0000-premium-dm-operator-v2-proxy-fix.md`
   Success criteria:
   - The document describes the nil-DM-cluster misrouting bug, concrete edit scope, and focused verification commands.

2. Change Premium DM proxy construction so that a `nil` DM cluster for a NextGen shared-pool task triggers DM cluster re-resolution, and only an explicit non-operator-v2 result may use the legacy proxy path.
   Verification:
   - `cd dataflow-service-ng && go test ./app/models/premium_dm -run 'Test(NewPremiumDMProxy|PremiumDMProxyRoutesOperatorV2ToServiceProxy)'`
   Success criteria:
   - Tests prove `nil` no longer causes silent legacy fallback for unresolved NextGen DM routing.

3. Add regression coverage for unresolved-DM-cluster failure and resolved legacy/service-proxy routing.
   Verification:
   - `cd dataflow-service-ng && go test ./app/models/premium_dm -run 'Test(NewPremiumDMProxy|PremiumDMProxyRoutesOperatorV2ToServiceProxy|PatchDMTargetConn)'`
   Success criteria:
   - Tests cover `nil` re-resolution behavior and preserve existing service-proxy request handling.

4. Update Premium DM domain knowledge with the verified routing rule.
   Verification:
   - `sed -n '1,260p' .domain-knowledge/ng-premium-dm.md`
   Success criteria:
   - The document states that unresolved DM cluster routing for NextGen/shared-pool tasks is an error, not a legacy fallback.

5. Run final focused verification for touched Premium DM code.
   Verification:
   - `cd dataflow-service-ng && go test ./app/models/premium_dm`
   Success criteria:
   - The Premium DM package tests pass with the routing fix in place.

## Risks

- `NewPremiumDMProxy(...)` runs on hot worker paths, so the re-resolution branch must stay narrow and only apply when the worker did not inject a DM cluster.
- Some tests in this package already stub proxy construction heavily; new coverage must exercise the real constructor to prove routing decisions instead of only mock wiring.
