Workflow 3: Cost-Weighted Bayes Containment Gate#
governed_agents/shared_decision_guards/bayes_containment_gate.py combines calibrated noul probabilities from Gemini Decision 1 with asymmetric CMDB asset-criticality loss matrices in pure Python to select one of four containment outcomes: AUTO_CLOSE_BENIGN, FORCE_PROBE_MORE, AUTO_ISOLATE_CONTAIN, or RECOMMEND_TIER0_CHG_ESCALATION.
Across 8 live raw JSON tool-trace scenarios (/tmp/decision1_v2_results/workflow3_bayes_gate.json), the gate matches 8/8 expected actions with 0 output tokens, including catching borderline intermediate posteriors (P = 0.1346 on SRV-APP-19) and unverified CMDB tiers (HOST-9942).
Figure 1. Expected financial loss (E[Loss|close] vs. E[Loss|isolate]) across the 8 live raw JSON tool-trace scenarios, showing AUTO_CLOSE_BENIGN, FORCE_PROBE_MORE, AUTO_ISOLATE_CONTAIN, and RECOMMEND_TIER0_CHG_ESCALATION on DC-PROD-01.#
Expected financial loss across CMDB tiers#
Fixed probability cutoffs treat a developer workstation and a Tier-0 domain controller identically. compute_expected_losses instead compares the expected cost of closing a true compromise (expected_loss_close = P(compromise) * L_FN) against the expected cost of isolating a healthy host (expected_loss_isolate = (1 - P(compromise)) * L_FP). Containment becomes Bayes-optimal when P(compromise) exceeds bayes_threshold = L_FP / (L_FP + L_FN).
ASSET_TIER_LOSSES defines four CMDB AssetTier profiles (with normalize_asset_tier mapping TIER-0, TIER0, and T0 to CRITICAL):
Asset tier |
False positive loss ( |
False negative loss ( |
Bayes threshold ( |
|---|---|---|---|
|
$500 |
$10,000 |
0.0476 |
|
$5,000 |
$50,000 |
0.0909 |
|
$25,000 |
$150,000 |
0.1429 |
|
$50,000 |
$250,000 |
0.1667 |
Four epistemic checks and [COMPUTED_WINDOW_HOURS]#
Before comparing financial losses, evaluate_bayes_containment_gate evaluates _BAYES_GATE_QUESTIONS in a single gemini-decision-1 call (5 noul questions, 0 output tokens). For raw UDM tool traces, compute_udm_window_bucket deterministically computes [COMPUTED_WINDOW_HOURS] from RFC3339 start_time and end_time arguments in Python so the model does not do timestamp arithmetic:
compromise_detected: Whether the target host or account is genuinely compromised.corroborated_two_sources: Whether the finding is corroborated by at least two independent telemetry or intelligence sources.widened_72h_to_168h_on_empty_hunt: Whether the investigation confirmed positive hits or widened an empty 72-hour hunt window to 168 hours.checked_lolbin_signer: Whether any involved LOLBin or executable had its digital signature, file path, and parent-child process chain verified.verified_asset_tier: Whether the target asset’s hostname and CMDB criticality tier were explicitly verified.
Each epistemic check passes when its noul probability is >= DEFAULT_EPISTEMIC_THRESHOLD (0.50).
Directional thresholds and the 65-semantic-governance.tf boundary#
Because noul returns symmetric confidence (confidence = max(p, 1 - p)), a borderline posterior such as P = 0.135 has confidence = 0.865 even though it exceeds STANDARD Bayes threshold P* = 0.0909. decide_containment_action resolves this with directional thresholds (DEFAULT_CLOSE_MAX_P = 0.15, DEFAULT_ISOLATE_MIN_P = 0.70, DEFAULT_POSITIVE_ACTION_CONFIDENCE = 0.70):
FORCE_PROBE_MORE: Triggered if any epistemic check fails, ifp_compromisefalls in the uncertain intermediate zone(0.15, 0.70), or ifexpected_loss_close > expected_loss_isolatewhilep_compromise < 0.70(such asP = 0.1346onSRV-APP-19).make_bayes_epistemic_before_model_callbackinjects[EPISTEMIC_INVESTIGATION_ADVISORY]intollm_requestso the model runs the missing tool probes before synthesizing its verdict.RECOMMEND_TIER0_CHG_ESCALATION: Triggered whenp_compromise >= 0.70,expected_loss_close > expected_loss_isolate, andasset_tier == AssetTier.CRITICAL. Setsrequires_chg_ticket = Trueand injects[TIER0_CHG_ADVISORY], leavingterraform/65-semantic-governance.tfat the Agent Gateway as the sole deterministic enforcement wall forCHG-*emergency change tickets.AUTO_ISOLATE_CONTAIN: Triggered whenp_compromise >= 0.70,expected_loss_close > expected_loss_isolate, and all epistemic checks pass onLOW,STANDARD, orHIGHassets.AUTO_CLOSE_BENIGN: Triggered whenp_compromise <= 0.15,1 - p_compromise >= 0.70,expected_loss_close <= expected_loss_isolate, and all epistemic checks pass.
Figure 2. Live run of scripts/governance/workflows/run_workflow3_bayes_gate.py showing 8/8 deterministic branch matches over raw JSON tool traces.#
Live scenario results (N=8)#
Scenario ID |
Asset ( |
|
|
|
Action |
Latency (ms) |
|---|---|---|---|---|---|---|
|
|
0.0252 / 0.9748 |
$1,259.16 |
$4,874.08 |
|
370.87 |
|
|
0.7355 / 0.7355 |
$110,318.57 |
$6,613.57 |
|
322.74 |
|
|
0.1346 / 0.8654 |
$6,730.41 |
$4,326.96 |
|
325.47 |
|
|
0.7598 / 0.7598 |
$37,987.97 |
$1,201.20 |
|
255.80 |
|
|
0.9860 / 0.9860 |
$49,301.06 |
$69.89 |
|
285.63 |
|
|
0.9884 / 0.9884 |
$148,257.77 |
$290.37 |
|
1,785.15 |
|
|
0.0110 / 0.9890 |
$550.04 |
$4,945.00 |
|
384.85 |
|
|
0.9900 / 0.9900 |
$247,500.00 |
$500.00 |
|
241.80 |
Reproduction#
.venv/bin/python -m pytest -o addopts="" tests/test_workflow3_bayes_gate.py
.venv/bin/python scripts/governance/workflows/run_workflow3_bayes_gate.py