Skip to main content

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

· 10 min read
Jaybee
AI & Robotics Engineer

National Budget Inspector Web Portal v3.0 & 20/20 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.

[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:

  1. Episode #1: High-precision Text-to-SQL & GraphRAG hybrid retrieval baseline.
  2. Episode #2: 400+ empirical audit cases verified against 10-year Board of Audit and Inspection (BAI) precedents.
  3. Episode #3: 3D Sector Partitioning filtering out 85% noise across 4 million public procurement records.
  4. Episode #4: Unmasking borrowed-name paper cartels via DART corporate disclosures and registries.
  5. 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​

  1. Executive Command Center (/api/stats, /api/alerts):
    • Real-time anomaly counters, high-priority flash alerts, audit throughput metrics, and integrated AI assistant chat.
  2. 6-Sector Partitioning Matrix (/api/sectors):
    • Multi-dimensional filtering and live data grid querying across high-risk Sectors 1 through 6.
  3. Automated Audit Summons Synthesizer (/api/summons):
    • Instant generation of formal investigative summons citing specific statutory violations and matching BAI precedents.
  4. e-Naradoum Subsidy Fraud Tracker (/api/subsidy_fraud):
    • Detection of duplicate subsidy receipts, off-purpose embezzlement, and indirect kickbacks to family accounts.
  5. 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.
  6. Parliamentary Budget Cut Analyzer (/api/budget_cuts):
    • Automated calculation of recommended budget reductions based on historical disuse and poor fiscal execution rates.
  7. 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.

📌 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.
  • 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 stabilizationIterationsDone event, the system immediately executes network.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).
  • 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.
  • 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.

🐛 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.py intermittently caused test failures with sqlite3.OperationalError: database is locked.
  • Root Cause:
    • Successive test scripts (verify_prototype.py, verify_pipeline.py, verify_case_matcher.py) opened simultaneous write transactions against the shared budget_audit.db. On Windows, file handle release latency prevented sequential processes from acquiring clean write locks.
  • 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.

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 ScriptScope of VerificationStatus
1verify_prototype.pyNatural language Text-to-SQL generation & query accuracyPASS
2verify_pipeline.pyIngestion pipeline, data cleansing & database loadingPASS
3verify_graph_and_rag.pyKnowledge graph entity mapping & hybrid RAG retrievalPASS
4verify_interactive_rag.pyMulti-turn conversational audit agent context maintenancePASS
5verify_streaming_monitor.pyReal-time procurement data streaming & threshold alertingPASS
6verify_web_api.pyCompliance verification across 12 core RESTful DTO endpointsPASS
7verify_live_api.pyLive mock data synchronization & payload integrityPASS
8verify_batch_hwp.pyBatch parsing of official HWP/HWPX documents & cost tablesPASS
9verify_case_matcher.pySemantic matching against 10-year BAI precedent databasePASS
10verify_e2e_orchestrator.pyFull multi-agent workflow orchestration end-to-endPASS
11verify_web_portal_v2.pyWeb Portal v3.0 frontend rendering & 7-tab data synchronizationPASS
12verify_live_sync_and_discovery.pyBackground synchronization & automated anomaly discoveryPASS
13verify_sector_partition.py3D sector partitioning engine filtering accuracyPASS
14verify_web_sectors.pySector-specific UI data transfer & grid consistencyPASS
15verify_daily_monitor.pyMidnight automated batch audit & daily dossier generationPASS
16verify_sectors_5_6.py$40K smurfing & December fiscal year-end dump detectionPASS
17verify_corporate_and_summons.pyDART registry cartel unmasking & summons draft generationPASS
18verify_subsidy_fraud.pye-Naradoum subsidy embezzlement & relative transactionsPASS
19verify_bidding_rings.pySOC bidding ring identification & co-bidding ratio calculationPASS
20verify_budget_cuts.pyDisused fund tracking & legislative budget cut formulationPASS
$ 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.

ADVERTISEMENT