Public Budget AI #6: Inspector Web Portal & Full Verification

💡 Key Takeaways
- Inspector Web Portal v3.0 Completed: Transformed fragmented CLI scripts into a centralized, real-time command center featuring 7 dedicated workspaces (Overview, 6-Sector Partition, Summons Generator, e-Naradoum Subsidies, Bidding Rings Graph, Budget Cut Analyzer, Precedents & HWPX Validator).
- Full Verification Test Harness Passed (20/20 PASS): Achieved a 100% pass rate across all 20 end-to-end automated test suites, covering Text-to-SQL, GraphRAG, streaming anomaly monitors, DART registry tracking, bidding cartels, and HWPX cost validation.
- 2 Challenges Prevented in Design: (1) Mitigated server bottlenecks by decoupling heterogeneous audit engines behind 12 normalized RESTful DTO endpoints, (2) Prevented browser DOM bloat during continuous streaming via a Circular DOM Ring Buffer.
- 3 Unexpected Production Bugs Resolved: (1) Solved Vis.js infinite physics oscillation and UI freezing via stabilization-triggered physics freezing, (2) Resolved 50-page HWPX XML parsing event-loop blocking via ThreadPoolExecutor async worker queues, (3) Eliminated SQLite file lock contention during parallel test runs via process-isolated in-memory DB mounts.
- Series Grand Finale: Reflecting on the engineering evolution from a simple Text-to-SQL prototype to an enterprise-grade public procurement audit intelligence platform.
⚖️ Legal Notice & Anonymization
[Notice] All data contained herein has been rigorously pseudonymized to prevent legal disputes.
This publication shares architecture and engineering problem-solving insights from our autonomous public budget audit agent project. To protect corporate trade secrets and institutional integrity, all issuing agency names (Agency A,Institution B,Public Corp C,District D), contractor names (Company Alpha IT,Beta Consulting,Gamma Networks), individual names (Mr. K,Ms. P,Mr. L), contract IDs (CNTR-2026-○○○○), and dates have been 100% pseudonymized or masked (0000).
Introduction: From Fragmented Scripts to an Inspector Command Center
Over the past 5 episodes, our engineering team has methodically conquered critical obstacles in public finance auditing:
- Episode #1: High-precision Text-to-SQL & GraphRAG hybrid retrieval baseline.
- Episode #2: 400+ empirical audit cases verified against 10-year Board of Audit and Inspection (BAI) precedents.
- Episode #3: 3D Sector Partitioning filtering out 85% noise across 4 million public procurement records.
- Episode #4: Unmasking borrowed-name paper cartels via DART corporate disclosures and registries.
- Episode #5: Piercing affirmative action $40K smurfing (Sector 5) and year-end budget dumps (Sector 6).
Yet, regardless of how robust the backend pipelines are, requiring field auditors to manually invoke individual Python CLI scripts and inspect raw markdown outputs severely limits rapid deployment.
"Auditors don't need raw Python scripts. They need an integrated mission portal where anomaly alerts flash in real time, corporate syndicates unfold in interactive knowledge graphs, and dragging-and-dropping an HWPX government contract instantly synthesizes an actionable summons with matched case law."
To answer this demand, we built Inspector Web Portal v3.0 and developed an exhaustive 20-test automated verification suite (20/20 PASS). In this final episode, we document the portal architecture, design mitigations, and the resolution of three critical engineering bugs encountered during system completion.
1. Inspector Web Portal v3.0 Architecture & 7 Dedicated Workspaces
The portal is designed as a unified responsive Single Page Application (SPA) driven by an asynchronous Python RESTful routing layer.
flowchart TD
subgraph Browser Frontend [Inspector Web Portal UI - Tailwind & Vis.js]
Tab1[1. Executive Command Center & AI Chat]
Tab2[2. 6-Sector Partitioning Matrix]
Tab3[3. Summons Generation Engine]
Tab4[4. e-Naradoum Subsidy Fraud Tracker]
Tab5[5. Bidding Ring & Co-bidding Graph]
Tab6[6. Parliamentary Budget Cut Analyzer]
Tab7[7. 10-Yr Precedents & Live HWPX Parser]
end
subgraph REST API Routing Layer [dashboard_server.py - 12 Normalized Endpoints]
R1["/api/stats & /api/alerts"]
R2["/api/sectors & /api/graph"]
R3["/api/summons & /api/subsidy_fraud"]
R4["/api/bidding_rings & /api/budget_cuts"]
R5["/api/precedents & /api/hwpx_analysis"]
R6["/api/evaluate & /api/export_report"]
end
subgraph Core Audit Engines [Public Budget AI Engine Cluster]
E1[Sector Partition Manager]
E2[Corporate Registry Client - DART]
E3[GraphRAG & Precedent Database]
E4[HWPX Overbilling Validator]
E5[Bidding Ring Detector]
E6[Budget Cut Analyzer]
end
Tab1 & Tab2 & Tab3 & Tab4 & Tab5 & Tab6 & Tab7 <-->|RESTful JSON / SSE Streams| REST API Routing Layer
REST API Routing Layer <--> Core Audit Engines
Detailed Capabilities Across 7 Dedicated Workspaces
- Executive Command Center (
/api/stats,/api/alerts):- Real-time anomaly counters, high-priority flash alerts, audit throughput metrics, and integrated AI assistant chat.
- 6-Sector Partitioning Matrix (
/api/sectors):- Multi-dimensional filtering and live data grid querying across high-risk Sectors 1 through 6.
- Automated Audit Summons Synthesizer (
/api/summons):- Instant generation of formal investigative summons citing specific statutory violations and matching BAI precedents.
- e-Naradoum Subsidy Fraud Tracker (
/api/subsidy_fraud):- Detection of duplicate subsidy receipts, off-purpose embezzlement, and indirect kickbacks to family accounts.
- Bidding Ring & Co-bidding Graph Explorer (
/api/bidding_rings,/api/graph):- Interactive Vis.js physics graph displaying rotating bid-rigging rings and interlocked executive director networks.
- Parliamentary Budget Cut Analyzer (
/api/budget_cuts):- Automated calculation of recommended budget reductions based on historical disuse and poor fiscal execution rates.
- 10-Year Precedent DB & Live HWPX Parser (
/api/precedents,/api/hwpx_analysis):- Drag-and-drop parsing of raw HWPX XML procurement contracts to detect labor overbilling and match top 5 precedents.
2. Two Challenges Anticipated & Prevented During Design
During architecture planning, we identified two severe bottlenecks that arise when consolidating heterogeneous audit modules into a single web portal.
📌 Challenge 1: Web Server Bottlenecks from Heterogeneous Module Coupling
- Anticipated Problem:
- GraphRAG traversal, HWPX binary parsing, vector searches, and DART corporate registry queries have wildly disparate CPU and memory profiles. Executing them within a tightly coupled monolithic server could cause a heavy HWPX parse to block real-time alert dispatching, inducing 10-second delays or OOM crashes.
- Preventative Architecture: Decoupled RESTful DTO Layer:
- We decoupled the HTTP presentation server (
dashboard_server.py) from analytical engines (AuditPipelineOrchestrator,PrecedentDatabase,CorporateRegistryClient). - Twelve normalized Data Transfer Object (DTO) endpoints isolate engine payloads. If an external service encounters transient latency, fallback caches and standardized error DTOs keep the other 6 tabs completely operational.
- We decoupled the HTTP presentation server (
📌 Challenge 2: Browser DOM Bloat and Memory Leaks from Live Streams
- Anticipated Problem:
- When continuously streaming anomaly logs (via Server-Sent Events) across hundreds of thousands of transactions, continually invoking
appendChild()on the DOM will cause browser memory to climb past 1.5 GB, triggering tab crashes.
- When continuously streaming anomaly logs (via Server-Sent Events) across hundreds of thousands of transactions, continually invoking
- Preventative Architecture: Circular DOM Ring Buffer:
- Implemented a circular ring buffer capping active live log rows at 100 in the UI.
- When a new event arrives, it prepends to the table, and any row beyond index 100 is immediately detached from the DOM tree, enabling immediate garbage collection. This caps frontend memory consumption under 120 MB indefinitely.
3. Three Unexpected Production Bugs & Troubleshooting
Despite robust advance designs, full-scale integration across browsers, parsers, and test runners exposed three challenging bugs.
🐛 Unexpected Bug 1: Vis.js Infinite Physics Oscillation & Browser UI Freezing
- Symptom:
- In rendering Sector 4 bidding rings and Episode #4 cartel networks with 50+ interconnected nodes, the Vis.js Barnes-Hut repulsion and spring physics failed to reach equilibrium. Nodes oscillated wildly, pinning the browser main thread at 100% CPU and completely freezing drag, zoom, and tab switching.
- Root Cause:
- In complex cyclical cartel subgraphs, the default damping factor (0.09) caused harmonic resonance where repulsive forces continually overshot equilibrium points.
- Resolution:
- Bound the physics simulation lifecycle directly to frontend state transitions.
- Capped initial stabilization iterations to 150. Upon receiving the
stabilizationIterationsDoneevent, the system immediately executesnetwork.setOptions({ physics: { enabled: false } })to freeze node coordinates. - Re-enabled physics only locally for 1-hop neighbor nodes during interactive dragging, dropping browser CPU consumption under 1%.
// Preventing Vis.js UI oscillation via immediate stabilization freeze
const networkOptions = {
physics: {
enabled: true,
solver: 'barnesHut',
barnesHut: { gravitationalConstant: -3000, centralGravity: 0.3, springLength: 95 },
stabilization: { enabled: true, iterations: 150, updateInterval: 25 }
}
};
const network = new vis.Network(container, data, networkOptions);
network.on("stabilizationIterationsDone", function () {
network.setOptions({ physics: { enabled: false } });
console.log("[Portal] Vis.js physics stabilized and frozen.");
});
🐛 Unexpected Bug 2: 50-Page HWPX XML Parsing Blocking HTTP Event Loop
- Symptom:
- Uploading a 50-page complex procurement specification (
Scope_of_Work_and_Costing.hwpx) caused the HTTP server to block for over 8 seconds. During this window, concurrent dashboard requests from other auditors timed out (HTTP 504 Gateway Timeout).
- Uploading a 50-page complex procurement specification (
- Root Cause:
- HWPX packages contain zipped XML streams (
Contents/section0.xml, etc.). Synchronously unzipping, parsing large DOM trees, and evaluating XPath expressions monopolized Python's single-threaded HTTP server.
- HWPX packages contain zipped XML streams (
- Resolution:
- Converted the upload endpoint to assign an immediate Job UUID, delegating heavy XML parsing and precedent scoring to a background
concurrent.futures.ThreadPoolExecutor. - The client UI transitions to polling
GET /api/hwpx_analysis?job_id=...for progress updates (0% to 100%). Average HTTP response times for surrounding endpoints remained under 15 ms.
- Converted the upload endpoint to assign an immediate Job UUID, delegating heavy XML parsing and precedent scoring to a background
🐛 Unexpected Bug 3: SQLite File Lock Contention in 20-Test Automated Runner
- Symptom:
- Running all 20 verification tests in automated batches via
run_all_tests.pyintermittently caused test failures withsqlite3.OperationalError: database is locked.
- Running all 20 verification tests in automated batches via
- Root Cause:
- Successive test scripts (
verify_prototype.py,verify_pipeline.py,verify_case_matcher.py) opened simultaneous write transactions against the sharedbudget_audit.db. On Windows, file handle release latency prevented sequential processes from acquiring clean write locks.
- Successive test scripts (
- Resolution:
- Introduced a test isolation provider (
test_isolation_db_provider). - Each verification test binds to a process-isolated temporary file (
budget_test_{pid}_{timestamp}.db) or a pure:memory:SQLite instance. - Added clean teardown hooks to release connections and unmount temporary files, ensuring 100% deterministic, flake-free test execution.
- Introduced a test isolation provider (
4. Full Verification Summary: 20/20 Test Harnesses Passed
The 20 verification suites ensure end-to-end reliability from low-level query generation up to the web dashboard presentation layer.
| # | Verification Test Script | Scope of Verification | Status |
|---|---|---|---|
| 1 | verify_prototype.py | Natural language Text-to-SQL generation & query accuracy | PASS |
| 2 | verify_pipeline.py | Ingestion pipeline, data cleansing & database loading | PASS |
| 3 | verify_graph_and_rag.py | Knowledge graph entity mapping & hybrid RAG retrieval | PASS |
| 4 | verify_interactive_rag.py | Multi-turn conversational audit agent context maintenance | PASS |
| 5 | verify_streaming_monitor.py | Real-time procurement data streaming & threshold alerting | PASS |
| 6 | verify_web_api.py | Compliance verification across 12 core RESTful DTO endpoints | PASS |
| 7 | verify_live_api.py | Live mock data synchronization & payload integrity | PASS |
| 8 | verify_batch_hwp.py | Batch parsing of official HWP/HWPX documents & cost tables | PASS |
| 9 | verify_case_matcher.py | Semantic matching against 10-year BAI precedent database | PASS |
| 10 | verify_e2e_orchestrator.py | Full multi-agent workflow orchestration end-to-end | PASS |
| 11 | verify_web_portal_v2.py | Web Portal v3.0 frontend rendering & 7-tab data synchronization | PASS |
| 12 | verify_live_sync_and_discovery.py | Background synchronization & automated anomaly discovery | PASS |
| 13 | verify_sector_partition.py | 3D sector partitioning engine filtering accuracy | PASS |
| 14 | verify_web_sectors.py | Sector-specific UI data transfer & grid consistency | PASS |
| 15 | verify_daily_monitor.py | Midnight automated batch audit & daily dossier generation | PASS |
| 16 | verify_sectors_5_6.py | $40K smurfing & December fiscal year-end dump detection | PASS |
| 17 | verify_corporate_and_summons.py | DART registry cartel unmasking & summons draft generation | PASS |
| 18 | verify_subsidy_fraud.py | e-Naradoum subsidy embezzlement & relative transactions | PASS |
| 19 | verify_bidding_rings.py | SOC bidding ring identification & co-bidding ratio calculation | PASS |
| 20 | verify_budget_cuts.py | Disused fund tracking & legislative budget cut formulation | PASS |
$ python -X utf8 tools/run_all_tests.py
====================
TEST SUMMARY
====================
verify_prototype.py: PASS
verify_pipeline.py: PASS
verify_graph_and_rag.py: PASS
verify_interactive_rag.py: PASS
verify_streaming_monitor.py: PASS
verify_web_api.py: PASS
verify_live_api.py: PASS
verify_batch_hwp.py: PASS
verify_case_matcher.py: PASS
verify_e2e_orchestrator.py: PASS
verify_web_portal_v2.py: PASS
verify_live_sync_and_discovery.py: PASS
verify_sector_partition.py: PASS
verify_web_sectors.py: PASS
verify_daily_monitor.py: PASS
verify_sectors_5_6.py: PASS
verify_corporate_and_summons.py: PASS
verify_subsidy_fraud.py: PASS
verify_bidding_rings.py: PASS
verify_budget_cuts.py: PASS
All 20 verification tests passed successfully!
5. Series Conclusion: The Future of Autonomous Audit Engineering
Across this 6-part series, our core engineering objective was clear:
"Can modern LLMs and knowledge graphs deliver verified, production-grade value in public finance auditing?"
Demonstrating real impact required moving far beyond simple prompt engineering:
- 3D Sector Partitioning to eliminate 85% background noise across millions of records,
- DART Registry Knowledge Graphs to expose hidden borrowed-name syndicates,
- Automated Summons Pipelines synthesizing legally grounded audit briefs,
- Inspector Web Portal v3.0 delivering intuitive 7-tab command interfaces,
- And 20 end-to-end verification tests proving continuous system integrity.
This journey confirms that when anchored by rigorous software engineering and domain-specific safety checks, autonomous AI agents can evolve from experimental novelties into indispensable guardians of fiscal integrity.
Thank you for following the [Public Budget AI Engineering Series]. We look forward to sharing more production-tested agentic engineering architectures in our upcoming projects.
