AI Initiative logoAI Initiative
Reading room / GraFOSa

GCA Architecture Decision Records

Records graph-based code-analysis decisions: intra-procedural CFG/DFG, composed code-property graphs, Thompson-sampling model selection, and simplification tradeoffs.

Graph composition decisions
This is the retained source text, not a new validation of its claims. Numerical results and comparative claims require the accompanying source review before public reuse.

Read the connected case study or article →

Not explicitly attributed in document header · Date not established

Provenance, authorship and editorial notes

GCA Architecture Decision Records

Id

grafosa-gca-decisions

Project

GraFOSa

Source path

grafosa/docs/GCA-ARCHITECTURE-DECISIONS.md

Source host

genesis

Source sha256

04565da7ed3afd47fd528134d353260845609ed30b73ca589f5d591811a13853

Repo root

grafosa

Repo head

388b50cfb34decee9d716f7f02d01ccf53305c03

Date
Not recorded
Author

Not explicitly attributed in document header

Document status

Graph composition decisions

Source status statement

Accepted

Summary

Records graph-based code-analysis decisions: intra-procedural CFG/DFG, composed code-property graphs, Thompson-sampling model selection, and simplification tradeoffs.

Topics
  • GraFOSa
  • AI Learning
  • Orchestration
  • Graph composition decisions
Related ids
  • grafosa-vision
  • grafosa-pipeline
  • grafosa-embedded-graph-os
Evidence concerns
  • Intra-procedural scope describes this historical ADR, not the full current scanner surface. Any soundness or complexity claims need algorithm-level validation and current implementation reconciliation.
  • Decision records explain choices but do not certify runtime integration or comparative performance.
  • Private source selection. Source inspection only; no fresh build, deployment or effectiveness certification.
Copy scope

Full original document, byte-identical

Copy status

copied-private-review

Format

markdown

Bytes

10171

Word count

1339

Headings
  • GCA Architecture Decision Records
  • ADR-001: Intra-Procedural Only for CFG/DFG Extraction
  • ADR-002: CPG as a Composed Overlay (Not a Separate Graph)
  • ADR-003: Thompson Sampling Bandit for Vulnerability Detection Model Selection
  • ADR-004: Rule-Based vs ML Vulnerability Detection as Competing Arms
  • ADR-005: Graph Simplification Strategies (Chain Collapse, Hub Bypass)
  • ADR-006: Build-Time Security Analysis Auto-Wiring
Sensitive content review
Automated secret patterns
Email occurrences

0

Customer record terms
Limitation

Pattern scan plus editorial review; not a guarantee of no personal or proprietary material. Private copies retain source code examples, internal locations and attributions.

Attribution note

Source document attribution is preserved. Repository ownership or an agent role is not automatically authorship.

Date basis

Document header or dated filename; source may contain later updates

Source pin note

SHA-256 binds exact copied working-file bytes; repo_head is repository context, not proof that every byte is committed at that head.

Publication recommendation

Private technical reading candidate; editorial selection and claim review required before public use

GCA Architecture Decision Records

Architecture decisions for the Graph-Based Code Analysis (GCA) additions in EPIC MD-8596.


ADR-001: Intra-Procedural Only for CFG/DFG Extraction

Status: Accepted

Context: CFG and DFG extraction can operate at two scopes: intra-procedural (within a single function) or inter-procedural (across function boundaries via call sites). Inter-procedural analysis is more precise for whole-program reasoning but introduces quadratic complexity, requires a complete call graph before extraction begins, and is sensitive to dynamic dispatch and higher-order functions common in Python.

Decision: Both CFGExtractor and DFGExtractor operate strictly intra-procedurally, producing one FunctionCFG / FunctionDFG per function or method definition. Cross-function data flow is handled separately through the existing call graph CALLS edges in the graph kernel and through the CPG layer's taint query, which combines per-function DFG with call graph adjacency.

Consequences:


ADR-002: CPG as a Composed Overlay (Not a Separate Graph)

Status: Accepted

Context: A Code Property Graph merges AST structure, control flow, and data flow into one queryable representation. The standard approach in tools like Joern creates a dedicated CPG data structure. GraFOSa already maintains a GraphKernel with AST-derived Symbol/File/Endpoint nodes and CALLS/IMPORTS/DEFINES edges.

Decision: CodePropertyGraph is implemented as a composed overlay on top of the existing GraphKernel. It stores CFG BasicBlock nodes and DFG Variable nodes directly into the kernel via add_node/add_edge, using the same node ID namespace. CFG and DFG data are also cached in-memory dictionaries (_cfgs, _dfgs) keyed by symbol FQN for fast analytical queries (taint, slicing) that do not need full graph traversal.

Consequences:


ADR-003: Thompson Sampling Bandit for Vulnerability Detection Model Selection

Status: Accepted

Context: We have two fundamentally different approaches to vulnerability detection: a DFG-feature-based heuristic model and a rule-based call-graph security slicer. Each has different precision/recall trade-offs that vary by codebase characteristics. Statically choosing one approach leaves performance on the table; A/B testing requires manual intervention.

Decision: Vulnerability detection model selection uses GraFOSa's existing BanditRegistry with Thompson Sampling (Beta-Bernoulli). The register_in_bandit function creates a vulnerability_detection bandit with two arms: dfg_heuristic and rule_slicer. The rule-based slicer receives a warm-start prior (alpha=2.0) reflecting its proven production track record, while the DFG model starts with the default uninformative prior.

Consequences:


ADR-004: Rule-Based vs ML Vulnerability Detection as Competing Arms

Status: Accepted

Context: The SecuritySlicer uses backward call-graph traversal plus pattern matching against known dangerous/mitigation patterns (e.g., execute + no parameterize = confirmed SQL injection). The VulnerabilityDetector extracts numeric features from DFG structure (taint source/sink counts, reach density, parameter exposure) and applies a weighted scoring model. Both produce vulnerability findings but through fundamentally different mechanisms.

Decision: Both approaches are kept as first-class, independent implementations rather than being merged into a single hybrid detector. The rule-based slicer operates on the call graph and source context patterns (_DANGEROUS_PATTERNS, _MITIGATION_PATTERNS). The DFG heuristic operates on data flow features with a hand-tuned weight vector and threshold (score >= 4.0). They compete as bandit arms (ADR-003), and the CPG layer can optionally combine them: SecuritySlicer.set_cpg() enriches slice results with CPG taint confirmation.

Consequences:


ADR-005: Graph Simplification Strategies (Chain Collapse, Hub Bypass)

Status: Accepted

Context: Code graphs can have long chains of pass-through nodes (e.g., delegation wrappers, middleware layers) and high-degree hub nodes (e.g., utility modules imported everywhere). Both patterns degrade GNN message-passing effectiveness -- research shows AMPLE's graph simplification reduced average node distance by 41.65%. GraFOSa needs to support downstream ML consumers without destroying structural information needed for precise analysis.

Decision: The simplify module provides two composable strategies that return new GraphKernel instances (never mutating the original): (1) Chain collapse identifies nodes with in-degree=1 and out-degree=1, removes them, and adds SHORTCUT edges with weight equal to the collapsed chain length. (2) Hub bypass adds direct HUB_BYPASS edges between all predecessor-successor pairs of high-degree nodes (degree > configurable threshold, default 10), while preserving the hub node itself. A preserve_labels parameter protects semantically important node types from modification. Both strategies can be applied in sequence via strategy="both".

Consequences:


ADR-006: Build-Time Security Analysis Auto-Wiring

Status: Accepted

Context: The security analysis pipeline requires multiple components to be initialized in the correct order: source files must be collected, CPGs must be built from source, the SecuritySlicer must be created and enhanced with CPG data, and the BanditRegistry must have vulnerability detection arms registered. Requiring callers to manually wire this is error-prone and leads to partial initialization.

Decision: The _init_security_analysis function in build.py is called automatically at the end of every build_graph execution, after scanning and dependency wiring are complete. It follows a three-phase pattern: (1) collect Python source files from all configured services, filtering out tests/migrations; (2) create a SecuritySlicer and call enhance_with_cpg(source_map) to build CPGs and attach taint analysis; (3) instantiate BanditRegistry and call register_in_bandit to set up the competing detection arms. All three phases are wrapped in exception handlers with degraded-mode fallbacks -- if CPG enhancement fails, the slicer still works without taint data; if bandit registration fails, detection still works without adaptive selection.

Consequences:

Continue exploring