9.4 KiB
9.4 KiB
PRECISION V4 SURGICAL AUDIT
System: MTO2Doc / SID-AI Universal Engineering Graph
Branch: precision
Phase: Precision Stabilization v4 — Surgical Entity-Boundary Repair
Target Regression Fixtures:
- Drawing A:
26-KA-901(3rd Stage HP Gas Lift Compressor) - Drawing B:
26-KA-902(3rd Stage HP Gas Export Compressor, PID(9)) - Drawing C:
26-KA-902(3rd Stage HP Gas Export Compressor, PID(10))
1. Current Runtime Architecture
The authoritative MTO2Doc processing pipeline runs in strict sequence:
IngestionAgent (PDF / raster load)
↓
Supervisor / GridRouter (Metadata & layout segmentation)
↓
ParallelVision (TextRecognitionAgent [PaddleOCR + TypoRectifier]
+ SymbolRecognitionAgent [YOLO ISA-5.1]
+ PipelineRecognitionAgent [LineTracer])
↓
Dual-Anchor Universal Engineering Object Compiler (CompilerAgent)
↓
ValidationAgent (VAL-005 consistency & deterministic gates)
↓
CompletenessChecker (Targeted re-extraction router)
↓
OutputGenerator (Excel, Master JSON Graph, AVEVA XML, COMOS JSON, SPPID CSV)
No downstream exporter performs entity reasoning, dataframe mutations, or row deletions. The CompilerAgent produces the authoritative UniversalEngineeringGraph.
2. Current Candidate Lifecycle
- Raw OCR Observations: Extracted as
text,confidence,bbox,center_x,center_y. - Pre-Stitching:
stitch_fragmented_tagscleans OCR typos, stitches size-to-core line fragments, split valve prefixes, and symbol bubbles (stitch_symbol_bubbles). - Classification Pass (
classify_paddle_results): Evaluates regexes for PSV, LINE, INSTRUMENT, VALVE, EQUIPMENT, ELECTRICAL, and NOTE. - Candidate Post-Deduplication Pass: Merges observation variants sharing canonical keys with priority scoring (
_tag_priority_score) and preserves aliases, alarms, and provenance. - Compiler Ingestion:
CompilerAgentconsumes classified candidates and compiles canonical domain items.
3. Current Entity Lifecycle & Separation
The universal graph separates items into distinct collections:
graph.equipment: List[EquipmentItem]graph.lines: List[LineItem]graph.instruments: List[InstrumentItem]graph.valves: List[ValveItem]graph.safety_relief_valves: List[SafetyReliefValveItem]graph.references: List[ReferenceItem]graph.generic_components: List[GenericComponentItem]graph.annotations: List[AnnotationItem]graph.relationships: List[Relationship]
4. Problem Audits & Exact Root Causes
A. Reference vs. Note / Annotation Contamination
- Problem: Ordinary drawing notes containing the word
TOorFROM(e.g.BE FINALIZED BY PIPING AS PER PIPING,START-UP. PUSH BUTTON WITH PERMISSIVE TO START,SAFE LOCATION,AVOID DAMAGE DUE TO,BE TAKEN INTO CONSIDERATION ON TW SELECTION,SEAL GAS SYSTEM RUPTURE DISCS,PDIT FOR PRIMARY SEAL GAS) were promoted toReferenceItem. - Runtime Path:
compiler.py\rightarrow_compile_references(texts). - Root Cause: Line 1473 contained an open fallback:
Any text following
m_sub = re.search(r'((?:\d{2}-)?[A-Z]{2,4}-\d{3,5}[A-Z]?)', captured) if m_sub: ref_tag = m_sub.group(1) else: ref_tag = captured.split('\n')[0].strip() # <-- PROMOTES ARBITRARY SENTENCESTOorFROMwas converted into aReferenceItemeven if it contained no engineering reference tag or recognized plant boundary destination. - Correction: Restrict reference promotion so that
capturedtext MUST resolve to:- An engineering tag (
r'((?:\d{2}-)?[A-Z]{2,4}-\d{3,5}[A-Z]?)'), OR - A recognized process continuation sink/source header (
HP FLARE,LP FLARE,CLOSED DRAIN,OPEN DRAIN,HAZ. OPEN DRAIN,ATMOSPHERE,SUCTION SCRUBBER,INLET HEADER,DISCHARGE HEADER), OR - A continuation drawing reference number (
r'\b(?:\d{2}-)?\d{6}-\d{3}\b'). If no engineering tag, header, or drawing reference is present, the item remains aNOTE/ANNOTATION.
- An engineering tag (
B. Reference vs. Local Physical Entity Resolution
- Problem: External off-sheet instrument and equipment references (
FROM 27-PIT-0001B,FROM 26-PIT-9087,FROM 26-PIT-9077) risk becoming local physical equipment or instruments. - Runtime Path:
tag_classifier.py\rightarrowcompiler.py(_compile_equipment,_compile_instruments). - Root Cause: In
_compile_instrumentsand_compile_equipment, reference tags were checked againstref_keys. However, suffix variants like26-PIT-9087-GASor26-PIT-9077-GAS-HPhad their suffixes stripped after the reference check, allowing them to evade the filter. - Correction: Suffix cleaning occurs before reference key matching. An item is marked as an external reference only when it is explicitly a
FROM/TOcontinuation AND lacks a local symbol/bubble on the current drawing.
C. Local Instrument Recall
- Problem: Instrument recall must be protected so that legitimate local instruments with graphical bubbles or tag grammar (
PIT,PI,PDIT,PDI,TIT,TI,FE,FI,PY) are never erroneously suppressed by reference filters. - Runtime Path:
compiler.py\rightarrow_compile_instruments. - Root Cause: Over-broad reference keywords (such as
VENDOR,BY PIPING,HEADER) in regexes previously matched notes that mentioned local instruments (e.g.26-TIT-9211, SUCTION PRESSURE 26-PIT-9055...), causing real local transmitters to be misflagged as references. - Correction: Strictly limit reference pre-scanning to direct flow continuations (
^\s*(?:FROM|TO)\s+). If an object exists as a local symbol bubble or standalone tag on the drawing, local graphical evidence overrides note mentions.
D. Malformed Line Candidate Promotion
- Problem: Non-line text strings (such as
CX-9122,G-150,A-26-9122-AC21-00,A-2500-26BL9073-4,B-300-2500,PSI-9758-HH) were promoted toLineItem. - Runtime Path:
tag_classifier.py(_LINE_SEARCH)\rightarrowcompiler.py(_compile_lines). - Root Cause:
_LINE_SEARCHbranch 2 allowed single-letter service codes ([A-Z]{1,4}) without pipe size, matching rating strings (A-2500-...,B-300-...) and pressure units (PSI-9758-...)._validate_line_tag_sizeskipped validation if no size prefix was present (if not re.match(r'^[\d/]', p0): return True, None), allowing single-letter and rating tokens to pass as lines._compile_linesaccepted single-letter services (^[A-Z]{1,4}$) and pure numeric specs (2500,300), valve specs (26BL9073), and alarms (HH).
- Correction:
- Require that line tags without size prefixes have a standard multi-letter service code (
\ge 2characters, e.g.PV,VA,WF,FG,IA,DR,FL,PL,BD,VD), rejecting single letters (A,B,G). - Reject pressure units (
PSI,BAR,KPA) and equipment codes (CX,KA,HA,TK,FA,PU,PA,KO,CK,ST) as line service codes. - Reject numeric specs (
2500,300,150), valve codes (BL,GB,GT,CB,CK,NV), and alarm indicators (HH,LL,SD) from being line specification classes.
- Require that line tags without size prefixes have a standard multi-letter service code (
E. Cross-Type Duplicate Entity Resolution
- Problem:
26-CK-921(Suction Strainer) appeared as bothEQUIPMENTandVALVE. - Runtime Path:
compiler.py\rightarrow_compile_valves. - Root Cause: Line 873 in
_compile_valveshad a hardcoded check forCK-911(if tag_upper in ('CK-911', '26-CK-911')), failing to rejectCK-921or any other 3-digit suction strainer. - Correction:
- In
_compile_valves, checkre.match(r'^(?:26-)?CK-\d{3}\b', tag_upper)to reject all suction strainers from the valve registry. - Maintain a cross-type registration check: any tag already registered in
equipmentis excluded fromvalves.
- In
F. Generic Component Residual Leakage
- Problem: Residual duplicate entries in generic components.
- Runtime Path:
compiler.py\rightarrow_compile_generic. - Root Cause: Previously ingested
EQUIPMENT_TAGand lacked full alias matching. - Correction: Retain strict restriction to
GENERIC_TAGonly, with lookup againsttag_alias_mapand base tags. Only true unknown candidates with no physical resolution remain generic.
5. File Modification Budget
Files to be Modified:
src/agents/compiler.py:_compile_references: Enforce strict target resolution (engineering tag, boundary sink/source, or drawing number); demote non-engineering phrases to annotations/notes._compile_lines: Enforce line grammar (multi-letter service if no size, reject equipment/pressure-unit services, reject numeric/valve/alarm specs)._compile_valves: Reject all suction strainers (CK-\d{3}) and check against compiled equipment tags._compile_instruments: Clean suffixes before reference check; preserve local graphical instruments.
src/utils/tag_classifier.py:_validate_line_tag_size/ line candidate filtering: Reject single-letter non-sized tokens, pressure units, and equipment codes fromLINE_TAG.
Files Explicitly Protected (DO NOT MODIFY):
- EasyOCR & PaddleOCR configuration (
src/utils/paddle_ocr.py) - YOLO model & weights
- Ray-casting line tracing algorithm (
src/utils/line_tracer.py) - Relationship topology engine (
CONNECTED_TO,INSTALLED_ON,MEASURES) - Core workflow state graph (
src/graph.py,src/state.py) - All deliverable exporter formats (
src/agents/output_generator.py) - Streamlit UI (
app.py)