Cases Runtime 02 · เคส · daily queue + case portal + AI 12-stage pipeline + alerting + SLA

Planning · v0.2
เอกสาร planning · ไม่มี cron · ไม่มี AI pipeline จริง · ไม่แตะ B ops. B shells at /kb/cases + /kb/case-portal render contract only. Runtime = 07:00 queue · review SLA · alerting · sign-off.
Binding: live mock mapped-not-bound placeholder derived

Context บริบท

Phase 12E ประกอบ Case Issues Portal ครบ: schema 27 fields · 6 creation modes (manual + 5 AI) · 7 view modes · 11 lifecycle statuses · 10 mapping rules · 12-stage AI analytics · alerting 4 levels · SLA per-level · PDPA discipline. A ต้อง build runtime: cron scheduler · source-monitoring pipeline · AI inference service · review queue UI · notification escalation · SLA enforcement. Daily possible-case cap = 20/day (12E.1 locked) · 07:00 Asia/Bangkok cadence · 4h review SLA.

docs/kb/data/case_schema.json27 fields · 12 case_types · alert_level mapping · PDPA discipline
docs/kb/data/case_portal.json6 creation modes · 7 view modes · 4 export · 20/day cap · 07:00 queue
docs/kb/data/case_mapping_model.json10 mapping rules · case → signals/dashboards/actors
docs/kb/data/ai_issue_analytics.json12 pipeline stages · dual-view + proactive/reactive rule
docs/kb/data/alerting_model.json4 levels · 11 lifecycle · 3 escalation paths · 5 measures
docs/kb/data/sla_model.jsonPer-level bands · sensitive_override dual-approval
docs/kb/data/multi_source_intake.jsonSource-monitoring input for AI cases

Scope A implement อะไร

Field Mapping — case_record B schema → A runtime table

Source: case_schema.case_record (27 fields).

B Field B Type A Runtime Target A Owner Approval Gate Binding Notes
id string cases.id PK (UUID or CASE-YYMMDD-XXXX) Backend none mapped-not-bound Stable; referenced by signals/dashboards
title_th / title_en / title_zh string × 3 cases.title_{lang} columns Backend none mapped-not-bound Trilingual parity · auto-translate fallback with review flag
case_type enum(12) cases.case_type · FK → case_types lookup Backend none mapped-not-bound Drives alert_level default via case_type_to_alert_level_default
severity enum cases.severity Backend none mapped-not-bound Surfaced in alerting routing + SLA band
alert_level enum(4) cases.alert_level · triggers alerting_model.escalation_paths Backend gate-alert-routing mapped-not-bound L0/L1 = PagerDuty · L2/L3 = Slack · L0 also LINE
status enum(11) cases.status · state machine enforced at API layer Backend none mapped-not-bound 11 statuses from alerting_model.lifecycle_statuses
datetime ISO-8601 cases.occurred_at TIMESTAMPTZ · TimescaleDB hypertable dim Backend none mapped-not-bound Separate created_at for record audit
reporter object cases.reporter JSONB · PII-hashed email/phone Backend gate-pdpa mapped-not-bound SHA-256 hash per CLAUDE.md PDPA rules
location object cases.location · PostGIS point + H3 cell Backend gate-pdpa mapped-not-bound GPS fuzz ±50m before storage · k-anon on map view
issue_definition_{th/en/zh} text × 3 Text columns · full-text index Backend none mapped-not-bound pgvector embedding for semantic search
attributes object cases.attributes JSONB from pattern_extraction Backend none mapped-not-bound AI-extracted; requires_human_review flag if AI-generated
pattern object cases.pattern JSONB · ref to pattern_extraction output Backend none mapped-not-bound From AI pipeline stage 4-6
related_actors / related_services / related_signals / related_dashboards / related_source_provenance array<id> Edge tables case_links · FK pairs Backend none mapped-not-bound Drives case-detail "Connections" panel · related-card graph
owner object cases.owner_user_id FK + role Backend gate-auth mapped-not-bound Admin surface for reassignment
follow_up array case_follow_ups child table · each has action/owner/due Backend none mapped-not-bound
ai_analysis_ref string cases.ai_analysis_refai_analysis table Backend gate-faithfulness mapped-not-bound Faithfulness <0.70 → regenerate · full log retained
sensitive_surface_flag boolean cases.sensitive_flag · enforces dual-approval path Backend gate-sensitive-dual mapped-not-bound Triggers approval_matrix.row-sensitive-override
attachments array S3 URLs + metadata · PII scan before persist Backend gate-pii-scan mapped-not-bound OCR + PDF parse for AI analysis
language_detected string cases.language_detected Backend none mapped-not-bound Whisper/detector output · drives default render lang
export_log array case_exports audit table · WORM Backend none mapped-not-bound Every export (CSV/JSON/PDF/PNG) logged

Field Mapping — Daily Queue 07:00 possible-case queue

Source: case_portal.daily_possible_case_generation.

B Field A Runtime Target A Owner Binding Notes
queue_name case_queues.name Backend mapped-not-bound Registry of queues (future: multiple queues)
default_status Status assigned on queue-insert Backend mapped-not-bound Must be one of 11 lifecycle_statuses
max_items_per_day Cron rate-limit = 20 (locked 12E.1) Backend mapped-not-bound Hard cap · overflow → next day queue
sla Timer service · 4h review SLA Backend mapped-not-bound Breach → alerting escalation per sla_model.breach_consequences
requires_human_review UI banner + blocking flag Frontend mapped-not-bound AI-generated cases show review banner until signed-off

Field Mapping — AI Pipeline 12-stage inference

Source: ai_issue_analytics.pipeline_stages (12 stages · each has id + inputs + outputs + owner).

Each stage maps to an Airflow task (dag_case_ai_pipeline). Every stage output carries confidence + requires_human_review.

Stage (B) A Task A Owner Binding Notes
intakeKafka consumer → case_inboxBackendmapped-not-bound Multi-source per multi_source_intake
language_detectWhisper/langdetectBackendmapped-not-bound Populates language_detected
normaliseOCR + PDF parse + HTML stripBackendmapped-not-bound
embedVoyage AI voyage-3 → pgvectorBackendmapped-not-bound CLAUDE.md Layer E
clusterHDBSCAN or HNSW neighborsBackendmapped-not-bound Deduplicate near-duplicates
pattern_extractClaude prompt per pattern_extractionBackendmapped-not-bound Outputs → cases.pattern
attribute_extractClaude prompt per attribute_extractionBackendmapped-not-bound Outputs → cases.attributes
classifycase_type + severity inferenceBackendmapped-not-bound Haiku for speed · Sonnet if low-confidence
alert_level_decideApply case_type_to_alert_level_defaultBackendmapped-not-bound Override if severity mismatch
map_relationsApply case_mapping_model 10 rulesBackendmapped-not-bound Populates related_* edges
faithfulness_checkRAGAS score ≥0.70Backendmapped-not-bound Retry once → if still <0.70 decline
queue_or_alertDaily queue insert OR immediate alertBackendmapped-not-bound L0/L1 bypass queue

A-owned Runtime Boundary ขอบเขต A vs B

B owns (read-only for A)

  • Contract JSON (all fields listed in "Context" block above)
  • Trilingual label parity
  • honest_note + requires_human_review flags
  • Contract evolution (schema-versioned)

A owns (this runtime)

  • All tables + indexes for entities in ER diagram below
  • API endpoints in API Sketch block
  • Frontend components + chart/form rendering
  • Cache + feature flag integration
  • Auth + sign-off capture
  • Audit trail

ER Diagram A-owned tables · Cases · schema + queue + signals

Cases · schema + queue + signals
cases ● id case_type · severity alert_level · status occurred_at · language reporter (hash) location (fuzz'd) attributes JSONB ai_analysis_ref sensitive_flag owner_user_id case_queues ● id name (daily-07) default_status max_items_per_day=20 sla_hours=4 case_follow_ups case_id · action · owner due_at · status ai_analysis ● id pipeline_stage ragas_score confidence requires_human_review case_links case_id target_type target_id edge_kind (related_actors, services, signals, dashboards)

API Sketch FastAPI endpoints

POST/api/cases
Create case (manual or AI) · enforces schema · sensitive flag triggers dual
GET/api/cases/{id}
Read case · joins follow_ups + ai_analysis + links
PATCH/api/cases/{id}/status
Transition status · state machine + sign-off enforced
POST/api/cases/queue/run
Admin: run 07:00 daily queue manually · respects 20/day cap
GET/api/cases/feed?view=map
Feed for view modes (overview/search/map/table/dashboard/report/detail)

Sequence Flow Daily 07:00 queue + AI pipeline

Daily 07:00 queue + AI pipeline
Cron 07:00 Intake svc AI Pipeline Reviewer Alerting 1 07:00 Asia/Bangkok trigger 2 pull ≤20 signals · dedupe · embed 3 12-stage · faithfulness ≥0.70 ≤20 possible-cases · status=default 4 notify reviewers · 4h SLA 5 SLA breach · escalate

Dependencies

Upstream

  • Auth + JWT tier
  • Signal pipeline (multi-source intake)
  • RAG engine (Claude API)
  • Feature flags (cases.ai_pipeline_v1)
  • Approval matrix integration (sensitive dual)
  • PagerDuty / Slack / LINE integrations

Downstream

  • Dashboard runtime (cases feed dashboards)
  • Reporting (case export → PDF)
  • City Health Dashboard (case count metric)

Human Approval Gates

Risks

AI generates false-positive cases (spam)
High
20/day cap · faithfulness floor · human review SLA · reject → proposal archive (not deleted)
Sensitive case mishandled without dual-approval
High
API layer enforces sensitive_flag=true → requires two distinct reviewer identities before status transitions
4h SLA breach during off-hours
Med
Escalation to on-call via alerting_model paths · LINE for L0 · SLA pause on governance-reviewing status
PII leaks via attachment OCR output
High
PII scanner pre-OCR · hashed reporter · attachments stored in PDPA-hot S3 bucket with retention policy
Trilingual translation drift (TH→ZH auto-translate)
Med
Untranslated badge · premium_wizard.trilingual_policy native review required for sensitive
Queue overflow (>20 items/day during incident)
Med
Overflow → next-day queue + alert to platform governance · cap is locked (12E.1)

Definition of Done

  1. All 27 case_record fields persistable via API + query · schema-validated
  2. 6 creation modes end-to-end · manual form + 5 AI paths produce valid case records
  3. 7 view modes render with ≤300ms p95 filter response
  4. Cron fires 07:00 Asia/Bangkok daily · respects 20/day cap
  5. 12-stage AI pipeline produces auditable trace per case (RAGAS log retained)
  6. 4h SLA timer + escalation to PagerDuty/Slack/LINE per alert_level
  7. Sensitive-surface path requires 2 distinct reviewer signatures before transition
  8. All 6 approval gates signed off with evidence in audit trail
  9. Feature flag cases.runtime_v1 staged rollout + rollback drilled
  10. 4 export formats produce PDPA-safe output (hash/fuzz/k-anon verified)

Deferred

Cases Runtime Planning · v0.2 · Session A · A-owned ← Planning hub · B contract ↗