5.7 KiB
5.7 KiB
M4 Verification Architecture Contract (Attire, Government ID, Certification)
Status: Proposed (next implementation slice)
Date: 2026-02-24
Owner: Technical Lead
1) Goal
Define a single backend verification pipeline for:
attiregovernment_idcertification
This contract gives the team exact endpoint behavior, state flow, and ownership before coding.
2) Principles
- Upload is evidence intake, not final verification.
- Verification runs asynchronously in backend workers.
- Model output is a signal, not legal truth.
- High-risk identity decisions require stronger validation and human audit trail.
- Every decision is traceable (
who,what,when,why).
3) Verification types and policy
3.1 Attire
- Primary check: vision model + rule checks.
- Typical output:
AUTO_PASS,AUTO_FAIL, orNEEDS_REVIEW. - Manual override is always allowed.
3.2 Government ID
- Required path for mission-critical use: third-party identity verification provider.
- Model/OCR can pre-parse fields but does not replace identity verification.
- Final status should require either provider success or manual approval by authorized reviewer.
3.3 Certification
- Preferred path: verify against issuer API/registry when available.
- If no issuer API: OCR extraction + manual review.
- Keep evidence of the source used for validation.
4) State model
PENDINGPROCESSINGAUTO_PASSAUTO_FAILNEEDS_REVIEWAPPROVEDREJECTEDERROR
Rules:
AUTO_*andNEEDS_REVIEWare machine outcomes.APPROVEDandREJECTEDare human outcomes.- All transitions are append-only in audit events.
5) API contract
5.1 Create verification job
- Route:
POST /core/verifications - Auth: required
- Purpose: enqueue verification job for previously uploaded file.
- Request:
{
"type": "attire",
"subjectType": "staff",
"subjectId": "staff_123",
"fileUri": "gs://krow-workforce-dev-private/uploads/<uid>/item.jpg",
"rules": {
"attireType": "shoes",
"expectedColor": "black"
},
"metadata": {
"shiftId": "shift_123"
}
}
- Success
202:
{
"verificationId": "ver_123",
"status": "PENDING",
"type": "attire",
"requestId": "uuid"
}
5.2 Get verification status
- Route:
GET /core/verifications/{verificationId} - Auth: required
- Purpose: polling from frontend.
- Success
200:
{
"verificationId": "ver_123",
"type": "attire",
"status": "NEEDS_REVIEW",
"confidence": 0.62,
"reasons": ["Color uncertain"],
"extracted": {
"detectedType": "shoe",
"detectedColor": "dark"
},
"provider": {
"name": "vertex",
"reference": "job_abc"
},
"review": null,
"createdAt": "2026-02-24T15:00:00Z",
"updatedAt": "2026-02-24T15:00:04Z",
"requestId": "uuid"
}
5.3 Review override
- Route:
POST /core/verifications/{verificationId}/review - Auth: required (reviewer role later; auth-first now + explicit reviewer id logging)
- Purpose: final human decision and audit reason.
- Request:
{
"decision": "APPROVED",
"note": "Document matches required certification",
"reasonCode": "MANUAL_REVIEW"
}
- Success
200:
{
"verificationId": "ver_123",
"status": "APPROVED",
"review": {
"decision": "APPROVED",
"reviewedBy": "user_456",
"reviewedAt": "2026-02-24T15:02:00Z",
"note": "Document matches required certification",
"reasonCode": "MANUAL_REVIEW"
},
"requestId": "uuid"
}
5.4 Retry verification job
- Route:
POST /core/verifications/{verificationId}/retry - Auth: required
- Purpose: rerun failed or updated checks.
- Success
202: status resets toPENDING.
6) Worker execution flow
- API validates payload and ownership of
fileUri. - API writes
verification_jobsrow withPENDING. - Worker consumes job, marks
PROCESSING. - Worker selects processor by type:
attire-> model + rule scorergovernment_id-> provider adapter (+ optional OCR pre-check)certification-> issuer API adapter or OCR adapter
- Worker writes machine outcome (
AUTO_PASS,AUTO_FAIL,NEEDS_REVIEW, orERROR). - Frontend polls status route.
- Reviewer finalizes with
APPROVEDorREJECTEDwhere needed.
7) Data model (minimal)
7.1 Table: verification_jobs
id(pk)type(attire|government_id|certification)subject_type,subject_idowner_uidfile_uristatusconfidence(nullable)reasons_jsonextracted_jsonprovider_name,provider_refcreated_at,updated_at
7.2 Table: verification_reviews
id(pk)verification_id(fk)decision(APPROVED|REJECTED)reviewed_bynotereason_codereviewed_at
7.3 Table: verification_events
id(pk)verification_id(fk)from_status,to_statusactor_type(system|reviewer)actor_iddetails_jsoncreated_at
8) Security and compliance notes
- Restrict verification file paths to owner-owned upload prefixes.
- Never expose raw private bucket URLs directly.
- Keep third-party provider secrets in Secret Manager.
- Log request and decision IDs for every transition.
- For government ID, keep provider response reference and verification timestamp.
9) Frontend integration pattern
- Upload file via existing
POST /core/upload-file. - Create verification job with returned
fileUri. - Poll
GET /core/verifications/{id}until terminal state. - Show machine status and confidence.
- For
NEEDS_REVIEW, show pending-review UI state.
10) Delivery split (recommended)
- Wave A (fast): attire verification pipeline end-to-end.
- Wave B: certification verification with issuer adapter + review.
- Wave C: government ID provider integration + reviewer flow hardening.