# PRD: Mitra Force-Close — Re-enable Plan # Overview **Goal:** Restore the mitra-side ability to force-close (early-end) an active session, gated behind the existing backend `early_end_mitra_enabled` config flag. **Status:** Currently **disabled in the mitra app** (button hidden). Backend support already exists and is gated by `app_config.early_end_mitra_enabled` (default `false`). **Affects:** `mitra_app`, `control_center` (config UI), backend (no functional change — already implemented) ## Background - Backend has `initiateEarlyEnd(sessionId, UserType.MITRA)` ([closure.service.js:88-137](backend/src/services/closure.service.js#L88-L137)) which moves an `active`/`extending` session to `closing` (with the 5-min grace + goodbye composer flow), guarded by the `early_end_mitra_enabled` flag. - The mitra app previously surfaced an **"Akhiri"** button on the **Sesi Aktif** screen ([mitra_app/lib/features/chat/screens/active_sessions_screen.dart](mitra_app/lib/features/chat/screens/active_sessions_screen.dart)) which called `POST /api/mitra/chat-requests/sessions/:id/end`. - The button (and the surrounding confirmation dialog) was **removed** during testing because the UX was abruptly terminating sessions without enough guardrails. The endpoint and its config flag were intentionally left in place on the backend. --- # Functional Requirement ## 1. Visibility - The "Akhiri" CTA on **Sesi Aktif** is rendered **only when** `app_config.early_end_mitra_enabled = true` (read at app startup via `/api/shared/config/...` or whichever config-fetch path the mitra app already uses). - When the flag is `false`, the row's trailing affordance is the chevron-only state (current state after this round of cleanup). ## 2. Confirmation UX When re-enabling, restore the existing confirmation dialog: - **Title:** "Akhiri Sesi?" - **Body:** "Apakah kamu yakin ingin mengakhiri sesi ini?" - **Buttons:** Batal / Ya, Akhiri. Open question for the next phase: do we want to require a **reason** from the mitra (free-text or radio list — e.g., "Customer abusive", "Customer left", "Out of scope")? If yes, capture it in `session_closures.reason` (new column) for downstream QC/auto-flag analytics. ## 3. Backend - No new endpoint or service work required — `initiateEarlyEnd` already handles this. - If a reason field is added (Section 2 open question), extend the request body and persist it. ## 4. Control Center - The existing config screen already exposes the toggle; no UI change needed unless reason capture is added. --- ## Non-Goals (this phase) - Adding a force-close from the chat screen (only Sesi Aktif). - Auto-flagging mitras with high force-close counts (covered by separate "Mitra QC Auto-Flag" memory item). - Customer-side force-close (separate `early_end_customer_enabled` flag, not in scope here). --- # Open Questions - Capture a reason on force-close? (Recommended yes — feeds into QC.) - Should there be a per-day cap on mitra force-closes before triggering CC review?