feat: deterministic cClassTrib resolver + gated CCLASSTRIB auto-apply (default OFF), RTC panel summary; 1.1.9

- resolver (rules RTC-R0..R4/A1..A3/G1..G2) over the official cClassTrib table 2026-06-22 and LC 214/2025 annexes; local vs official catalog comparison
- ONE root-cause RTC blocker per product (missing/unresolved/ambiguous/conflict/official mismatch/catalog outdated/evidence missing)
- auto-apply: C000025.CCLASSTRIB only, three switches (FIREBIRD_WRITES + RTC_AUTO_APPLY_ENABLED + Hub authorization), per-product re-read and re-decision, never overwrites, rowcount 1, audit table rtc_write_audits (migration 0027)
- copy-only write E2E (280/280 applied, only CCLASSTRIB changed, 2nd run 0 writes, stale decision 0 writes); real databases untouched
- docs: cclasstrib_resolution, rtc_auto_apply, unified_fiscal_completeness

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
gti
2026-09-24 21:18:34 -03:00
co-authored by Claude Sonnet 5
parent 88f4318072
commit 9f08998800
51 changed files with 16461 additions and 47 deletions
+230
View File
@@ -0,0 +1,230 @@
{
"database": "scratch_rtc_e2e/TESTESOFICIAIS_RTC_COPY.FDB (gbak restore of TESTESOFICIAIS)",
"real_database_writes": 0,
"real_database_write_attempts": 0,
"copy_original_crt": [
"1"
],
"copy_crt_for_experiment": "3",
"copy_rtc_param": 1,
"coverage_before": {
"total": 521,
"complete": 0,
"blocked": 521,
"unclassified": 0,
"coverage_percent": 0.0
},
"resolution_before": {
"total": 521,
"valid_existing": 0,
"ready_to_apply": 280,
"ambiguous": 215,
"insufficient": 26,
"conflicts": 0,
"official_mismatch": 0,
"not_applicable": 0,
"other_blocked": 0,
"by_rule": {
"RTC-A1": 41,
"RTC-A3": 10,
"RTC-R2": 26,
"RTC-R4": 203,
"RTC-R3": 77,
"RTC-A2": 164
},
"catalog_compatibility": {
"compatibility": "MATERIAL_MISMATCH",
"counts": {
"MATCH": 131,
"LOCAL_ONLY": 0,
"OFFICIAL_ONLY": 19,
"MISMATCH": 11,
"EXPIRED": 3
},
"expired_present_locally": 3
}
},
"stale_decision_run": {
"write_attempts": 280,
"write_successes": 0,
"aborted_reasons": {
"RTC_NO_LONGER_ENABLED": 280
}
},
"first_run": {
"mode": "AUTO_APPLY",
"ready_total": 280,
"write_attempts": 280,
"write_successes": 280,
"aborted_reasons": {},
"audit_sample": [
{
"outcome": "APPLIED",
"product_code": "000023",
"field": "CCLASSTRIB",
"old_value": null,
"new_value": "000001",
"cst_ibscbs": "000",
"rule_id": "RTC-R4",
"confidence_type": "EXCLUSION_OF_ALL_SPECIAL_REGIMES",
"evidence": {
"inputs_used": {
"ncm": "16025000",
"crt": "3",
"rtc_enabled": true
},
"evidence": [
{
"annex_hits": 0,
"chapter": "16"
}
],
"reason": "NCM_IN_NO_ANNEX_AND_NO_NATURE_BASED_CHAPTER"
},
"official_source_version": {
"cclasstrib_table": "2026-06-22",
"cclasstrib_sha256": "1448cb63a41bdb67ea30b4e11f4dc200d9568542c6b9335b6cff87a4fd664654",
"lc214_sha256": "5c7d59b3c49e5b7c066c2ad28bedf32791193a676ec1a163bec14bea5fa2f680"
},
"local_catalog_hash": "1da77aec27fbde88488d1edf562f3af315ab2b5d06efb2e0b2f1ed606585d459",
"timestamp": "2026-09-25T00:07:47+00:00",
"job_id": 424242,
"rowcount": 1,
"verified_after": true
},
{
"outcome": "APPLIED",
"product_code": "000024",
"field": "CCLASSTRIB",
"old_value": null,
"new_value": "200034",
"cst_ibscbs": "200",
"rule_id": "RTC-R3",
"confidence_type": "ANNEX_TEXT_MATCH",
"evidence": {
"inputs_used": {
"ncm": "19022000",
"crt": "3",
"rtc_enabled": true
},
"evidence": [
{
"annex": "VII",
"item": 9,
"prefix": "19022000",
"clean": true,
"revoked": false,
"text": "Massas alimentícias dos códigos 1902.20.00 e 1902.30.00 da NCM/SH"
}
],
"reason": "ANNEX_VII_CLEAN_ITEM_UNIQUE_DEFAULT_CLASS"
},
"official_source_version": {
"cclasstrib_table": "2026-06-22",
"cclasstrib_sha256": "1448cb63a41bdb67ea30b4e11f4dc200d9568542c6b9335b6cff87a4fd664654",
"lc214_sha256": "5c7d59b3c49e5b7c066c2ad28bedf32791193a676ec1a163bec14bea5fa2f680"
},
"local_catalog_hash": "1da77aec27fbde88488d1edf562f3af315ab2b5d06efb2e0b2f1ed606585d459",
"timestamp": "2026-09-25T00:07:47+00:00",
"job_id": 424242,
"rowcount": 1,
"verified_after": true
},
{
"outcome": "APPLIED",
"product_code": "000027",
"field": "CCLASSTRIB",
"old_value": null,
"new_value": "200034",
"cst_ibscbs": "200",
"rule_id": "RTC-R3",
"confidence_type": "ANNEX_TEXT_MATCH",
"evidence": {
"inputs_used": {
"ncm": "19022000",
"crt": "3",
"rtc_enabled": true
},
"evidence": [
{
"annex": "VII",
"item": 9,
"prefix": "19022000",
"clean": true,
"revoked": false,
"text": "Massas alimentícias dos códigos 1902.20.00 e 1902.30.00 da NCM/SH"
}
],
"reason": "ANNEX_VII_CLEAN_ITEM_UNIQUE_DEFAULT_CLASS"
},
"official_source_version": {
"cclasstrib_table": "2026-06-22",
"cclasstrib_sha256": "1448cb63a41bdb67ea30b4e11f4dc200d9568542c6b9335b6cff87a4fd664654",
"lc214_sha256": "5c7d59b3c49e5b7c066c2ad28bedf32791193a676ec1a163bec14bea5fa2f680"
},
"local_catalog_hash": "1da77aec27fbde88488d1edf562f3af315ab2b5d06efb2e0b2f1ed606585d459",
"timestamp": "2026-09-25T00:07:47+00:00",
"job_id": 424242,
"rowcount": 1,
"verified_after": true
}
]
},
"rows_changed": 280,
"columns_changed": [
"CCLASSTRIB"
],
"fk_orphans": 0,
"cst_orphans": 0,
"written_by_class": {
"000001": 203,
"200014": 2,
"200034": 75
},
"catalog_rows_unchanged": 145,
"coverage_after": {
"total": 521,
"complete": 279,
"blocked": 242,
"unclassified": 0,
"coverage_percent": 53.55
},
"resolution_after": {
"total": 521,
"valid_existing": 280,
"ready_to_apply": 0,
"ambiguous": 215,
"insufficient": 26,
"conflicts": 0,
"official_mismatch": 0,
"not_applicable": 0,
"other_blocked": 0,
"by_rule": {
"RTC-A1": 41,
"RTC-A3": 10,
"RTC-R2": 26,
"RTC-R4": 203,
"RTC-R3": 77,
"RTC-A2": 164
},
"catalog_compatibility": {
"compatibility": "MATERIAL_MISMATCH",
"counts": {
"MATCH": 131,
"LOCAL_ONLY": 0,
"OFFICIAL_ONLY": 19,
"MISMATCH": 11,
"EXPIRED": 3
},
"expired_present_locally": 3
}
},
"second_run": {
"ready_total": 0,
"write_attempts": 0,
"write_successes": 0
},
"IDEMPOTENT": true,
"ONLY_CCLASSTRIB_CHANGED": true,
"PASS": true
}