Repository navigation
Incident Lifecycle and Verification
Deterministic State Machine, Dual-Actor Verification, and Anti-Fraud Guardrails
The core operating philosophy of SafaiOS is that no municipal incident may be closed based on unilateral claims. The lifecycle is managed by an authoritative server-side state machine with strict database triggers verifying actor eligibility at every step:
+----------------------------------+
| DRAFT | (Citizen creates report, runs YOLO pre-scan)
+----------------------------------+
│
▼
+----------------------------------+
| SUBMITTED | (Geotagged report confirmed by citizen)
+----------------------------------+
│
▼
+----------------------------------+
| ADMIN_REVIEW | (Duplicate assessment logged; fleet dispatch)
+----------------------------------+
│
▼
+----------------------------------+
| ASSIGNED | (Single driver assigned; en route)
+----------------------------------+
│
▼
+----------------------------------+
| CLEANUP_IN_PROGRESS | (Driver arrived on site; collecting waste)
+----------------------------------+
│
▼ (Driver submits photographic cleanup evidence)
+----------------------------------+
| AWAITING_CITIZEN_VERIFICATION |
+----------------------------------+
│ │ │
Citizen Approves Citizen Denies No Response in 7 Days
│ │ │
▼ └───────┬───────┘
+-----------------------------+ ▼
| CLOSED | +-----------------------------+
| (Idempotent Safai Coins) | | AWAITING_ADMIN_REVIEW |
+-----------------------------+ +-----------------------------+
│ │
Admin Approves Admin Rejects
│ │
▼ ▼
+-----------------+ +---------------------+
| CLOSED | | RESOLUTION_REQUIRED |
| (Reward Minted) | | (Rework / Reassign) |
+-----------------+ +---------------------+
Traditional civic reporting apps suffer from fraudulent approvals where contractors or workers sign off on their own tasks. SafaiOS enforces strict eligibility logic via database triggers and server-side checks:
A user who performed the physical cleanup (the submitter of cleanup_evidence) can never verify that cleanup, regardless of other roles they hold:
if new.status in ('APPROVED', 'DENIED') then
if new.decided_by = cleanup_performer then
raise exception 'cleanup performer cannot verify their own cleanup';
end if;
...
end if;Only the citizen who originally authored the incident report (reporter_id) is authorized to submit a CITIZEN verification decision for that incident:
if new.actor_kind = 'CITIZEN' and new.decided_by <> reporter then
raise exception 'citizen verification must be performed by the reporting citizen';
end if;If a citizen reports an incident and subsequently cleans it up themselves as an assigned driver or volunteer, they cannot verify the cleanup as a citizen or as an admin. The system forces an escalated administrative review where an independent municipal administrator performs verification:
if new.actor_kind = 'ADMIN' and new.decided_by = reporter and reporter = cleanup_performer then
raise exception 'reporter who performed cleanup cannot verify as an admin';
end if;To prevent unverified cleanups from hanging indefinitely when a citizen is inactive or unresponsive:
-
Verification Due Date: When driver evidence is submitted,
citizen_verification_due_atis set tonow() + interval '7 days'. -
Autonomous Deadline Sweeper: A background worker periodically queries for overdue verification items:
select id from public.incidents where lifecycle_status = 'AWAITING_CITIZEN_VERIFICATION' and citizen_verification_due_at <= now();
-
Escalation to Admin: Overdue incidents transition to
AWAITING_ADMIN_REVIEW. The verification record is markedEXPIRED, and the municipal admin team is alerted to inspect the driver's photographic evidence.
When a citizen or municipal admin denies cleanup evidence:
- The incident moves to
RESOLUTION_REQUIRED. - The reviewer must provide an explicit rejection note (
rejection_reason). - Prior assignments, evidence photos, statements, and audit records remain permanently preserved in the database (rework never deletes history).
- The municipal administrator can:
- Request Rework: Reopen the assignment for the same driver to address remaining debris.
- Reassign: Dispatch a different driver or specialized municipal heavy equipment.
- Escalate: Flag the location for site inspection or structural remediation.