4.6 KiB
V2 Phase 3 Review Result Write Path Policy
Date: 2026-07-01
Background
Phase 3 has introduced structured review result tables:
review_risk_itemsreview_citationsreview_repair_actions
Read paths are being moved to structured-first behavior while keeping the public ReviewTask.risk_items and ReviewTask.citations response fields compatible.
The current write path still dual-writes legacy JSON and structured rows:
review_worker.execute_review_task(...)converts AI Platform review output into JSON-compatiblerisk_items,citations, andprimary_sources.SqlAlchemyReviewOrchestration.complete_review_task(...)enrichesrisk_itemswith legal asset recommendations such asclause_recommendations.ContractReviewTaskRepository.complete_review_task(...)writesreview_tasks.risk_items,review_tasks.citations,primary_sources,confidence, andai_audit_run_id.sync_structured_review_results(...)rebuildsreview_risk_itemsandreview_citationsfrom the persisted review task payload.- Clause repair writes structured repair state and still updates legacy
risk_itemswhen legacy JSON exists.
Decision
Do not stop writing legacy review_tasks.risk_items or review_tasks.citations yet.
For the current Phase 3 slice, these JSON columns are compatibility/display caches, not the primary source for structured queries or state decisions when structured rows exist.
Field Policy
| Field | Current role | Policy |
|---|---|---|
review_tasks.risk_items |
Compatibility display cache. Still carries rich UI payload such as clause_recommendations, original AI fields, related_clause, and legacy repair display fields. |
Continue dual-write. Do not treat as primary read source when structured rows exist. |
review_tasks.citations |
Compatibility display cache. Can carry metadata not yet modeled in review_citations, such as source_type, score, locator, document_id, chunk_id, and knowledge_base_id. |
Continue dual-write. Structured citations remain primary for query/search; legacy-only citations stay supplemental. |
review_tasks.primary_sources |
AI source payload cache. Not covered by the structured risk/citation migration. | Continue write. Revisit in a later source/provenance slice. |
review_tasks.risk_level |
Aggregate task-level risk. | Continue write. |
review_risk_items |
Structured risk rows for queries, action context, repair state, and structured read APIs. | Primary source for structured behavior. |
review_citations |
Structured citation rows for query/search and structured read APIs. | Primary source for structured citation behavior. |
review_repair_actions |
Structured repair action history. | Primary source for repair audit/state. |
Freeze Preconditions
Before freezing or stopping writes to review_tasks.risk_items, V2 needs one of:
- structured storage for full clause recommendation cards, or
- a serializer that can regenerate compatible
clause_recommendationsfrom published clause/rule snapshots, repair actions, and structured risk rows.
Before freezing or stopping writes to review_tasks.citations, V2 needs one of:
- structured metadata on
review_citations, or - a serializer that can regenerate compatibility fields such as
source_type,score,locator,document_id,chunk_id, andknowledge_base_id.
Guardrails
- Keep API responses compatible:
ReviewTask.risk_itemsandReviewTask.citationsremain present. - New read/query/search behavior should use structured rows first.
- Legacy JSON may supplement structured rows where it contains compatibility-only fields.
- No column removal or stop-write migration should be done until the freeze preconditions are met and verified in smoke.
Completed Follow-Up Slice
The first structured recommendation slice is complete:
review_risk_recommendationsnow stores recommendation cards structurally.StructuredReviewRisk.clause_recommendationsis available to management/read pages.ReviewTask.risk_itemscan synthesizeclause_recommendationsfrom structured recommendations when legacy risk JSON is absent.
Legacy review_tasks.risk_items is still written as a compatibility display cache. It should not be frozen until smoke backfill verifies recommendation coverage on existing review tasks.
Status Update
As of this slice, the legacy JSON fields remain writable and are intentionally treated as compatibility display caches.
Structured rows are already the primary source for query/search/repair logic, but the JSON payload is still needed for front-end compatibility until recommendation cards and citation metadata are fully modeled structurally.