# NG Natural-Terminal Display Events

## Analysis

This change is limited to the `dataflow-service-ng` business implementation. The root-module Dedicated Import and Dedicated DM publishers are intentionally out of scope.

| Area | Current behavior | Target behavior | Verification |
| --- | --- | --- | --- |
| EventCenter | Accepts every display status and falls back to `running` for unknown message statuses | Remain a transport-only publisher; producers decide which statuses are user-visible | Producer unit tests and `rg` for running-status symbols |
| Import Into | Publishes `running` for importing/scaling | Keep preparing and natural terminal events; suppress intermediate states | Import Into event unit tests |
| Premium DM | Uses one `DataMigration` Event Name for all operations | Use operation-specific Event Names (`CreateDataMigration`, `DeleteDataMigration`, `PauseDataMigration`, `ResumeDataMigration`) while retaining explicit result statuses and reliable terminal outcomes | Premium DM event and controller/worker tests |
| Changefeed/Private Endpoint | Changefeed maps lifecycle states to display events; Private Endpoint has reliable boundaries | Publish Create `started → running`, operation-specific `paused`/`resumed`, and preserve Private Endpoint producer behavior | Existing NG unit tests |

No public API, database schema, event schema, outbox, backfill, or historical-event migration is required. No compatibility branch is needed because the NG event behavior has not been released.

## Execution Steps

1. Keep the NG EventCenter transport-only. Verify producer-owned running/paused/resumed behavior with unit tests and inspect all NG display-event producers.
2. Suppress Import Into importing, scaling-up, and canceling events while retaining preparing and natural terminal events. Update table-driven tests.
3. Refactor Premium DM event construction to use explicit operation/result inputs instead of action strings and Stage inference. Assign operation-specific Event Names for create/delete/pause/resume, emit create-started/create-running, delete-started/delete-succeeded, pause-paused/resume-resumed, explicit command failures, and known task failures; do not emit unrelated internal stages. Update controller and worker call sites and tests.
4. Update Changefeed Create to expose `running` at `normal`, use `paused`/`resumed` for pause/resume, suppress unknown producer statuses, and review Private Endpoint publishers to ensure each producer owns its intermediate-state filtering. Add regression coverage.
5. Update the English domain-knowledge sections for NG Import Into, Premium DM, and CDC/private endpoints to document the natural-terminal rule.
6. Run:
   - `git diff --check`
   - `make -C dataflow-service-ng generate4test`
   - `make -C dataflow-service-ng app-unit-test-local`
   - `make -C dataflow-service-ng lint-golang`
   - `rg -n "EventStatusRunning|RunningStatus" dataflow-service-ng/app --glob '*.go'`
7. Verify the four new Premium DM Event Names are added to the downstream `nextgen_type_white_list`; this repository does not own the app-delivery configuration.

## Dead Code Cascade

- Retain NG `RunningStatus` and `EventStatusRunning` for long-running Premium DM and CDC tasks; do not use them for Import Into or Private Endpoint internal retries.
- Remove Premium DM pause/resume action-string constants and the Stage-to-display-event switch; retain only the operation-to-Event-Name mapping.
- Retain internal entity stages such as running, stopped, deleting, and unknown because they remain part of the state machine. Emit `running` only at the explicit long-running DM/CDC lifecycle boundary; keep unrelated internal transitions silent.

## Risk Assessment

- Long-running Premium DM and CDC create operations may expose `started → running` without a later `succeeded` event; this is intentional.
- Existing asynchronous retries remain silent and do not create duplicate intermediate events.
- Future NG producers must explicitly decide which internal states are user-visible; the shared EventCenter does not impose a global status allowlist.
