Files
acdl/acdl_platform/confidence_signal.py
T
Jon Chery f68f85c9fd
acdl-ci / Lint (push) Successful in 7s
acdl-ci / Test (push) Successful in 15s
acdl-ci / Platform check-only (offline) (push) Successful in 9s
review(v1.5): READY TO SHIP — multi-persona code review
---ci---
project: acdl
phase: 20
milestone: v1.5
status: review
verdict: READY TO SHIP
p0: 1 (fixed — contract path resolution in deploy workflow)
p1: 6 (flagged post-hoc)
---/ci---

Multi-persona review of v1.5 phase 20 (docs + reusable deploy workflow).

P0 (blocking) — AUTO-FIXED:
- C1: scripts/run_platform.sh contract path resolution broken in deploy
  workflow. The reusable workflow invokes run_platform.sh from the consumer
  workspace root with a relative contract path (.acdl/contract.yaml), but
  run_platform.sh does `cd "$ROOT"` (platform repo) early, so the relative
  path resolved against the platform repo and the pipeline could never run.
  Fix (commit 75c2274): capture CALLER_CWD before cd "$ROOT"; resolve
  caller-supplied relative paths against CALLER_CWD; default no-arg contract
  stays relative to ROOT (preserves platform-local CI). Reproduced pre-fix;
  verified post-fix.

P1 (important) — FLAGGED FOR POST-HOC REVIEW (do not block ship):
- C2: ref: v1.4 in the deploy workflow platform checkout — no v1.4 tag exists
  (only v1.4.0 / v1.4.1). Operator must create a floating v1.4 tag or change
  the ref to v1.4.1.
- C3: modules/l2/{static-asset,microservice}/README.md still use @v1 in their
  Usage examples; missed by the v1.4 bump.
- S1: static-key override is not wired. ACDL_AWS_* env vars on the OIDC step
  are not read by aws-actions/configure-aws-credentials@v4 (it reads AWS_*
  or its own access-key/secret-key inputs). The README/CONSUMER_GUIDE claim
  a working override that doesn't function as written. Needs a conditional
  step or renamed env vars + input wiring.
- S2: README overstates ABAC repo:org/repo:ref:... scoping. The workflow
  constructs a numeric role name (github.repository_id); the actual claim
  enforcement lives in the IAM trust policy, not in this workflow.
- T1: no deploy-workflow triggers conformance test (CI workflow has one;
  deploy doesn't). Minor — reusable workflows use workflow_call, not push
  triggers, but the contract's triggers field is then unenforced.
- A1: terraform/spike/terraform.tf uploaded as artifact leaks the AWS account
  ID via the state-backend bucket name. Recommend excluding terraform.tf or
  gating artifact upload to non-public repos.

P2 (nits) — listed for awareness: floating-tag terminology imprecision (M1),
  header comment "Gitea Actions" in the GitHub copy (M2, intentional byte-
  identical), pip install split (P1-perf), comment drift in pipelines/deploy.yaml
  header (C4), module README internal inconsistency (C5).

Verdict: READY TO SHIP. The one P0 is fixed. The 6 P1s are post-hoc items —
the deploy workflow is a scaffold whose first real consumer run requires
operator setup (tag, IAM role, secrets) that gates go-live. The P1s should
be addressed before any consumer invokes uses: acdl/.gitea/workflows/
deploy.yml@v1.4 in earnest.

Tests: 154 pass (19 new). run_ci.sh green.
2026-07-22 17:24:28 +00:00

175 lines
5.7 KiB
Python

"""ACDL Confidence Signal (REQ-19).
The platform's certified answer to "is this safe to proceed?" (vision
tenet: "Safety is Computed, Not Assumed"). Every delivery action produces
a measurable, explainable confidence signal; reliance on operator
instinct is not a substitute.
Inputs (weights sum to 1.0, D-040):
1. policy_results (0.30) — list[PolicyCheckResult] (schemas/policy_check_result.schema.json)
2. validation (0.25) — {schema: bool, stack_resolved: bool, tf_validated: bool, tf_planned: bool}
3. freshness (0.10) — {age_days: float, max_age_days: float}
4. source (0.15) — {submitter: str, commit_sha: str, signed: bool}
5. history (0.10) — {prior_rollbacks: int, prior_policy_fails: int}
6. nfrs (0.10) — {declared: list[str], conformance: float|None}
Severity -> penalty (locked, ARCHITECTURE.md §8):
critical -> hard override (score = 0, block)
high -> -0.20
medium -> -0.05
low -> -0.01
info -> 0.00
Per-env thresholds (locked, ARCHITECTURE.md §8): dev 0.50, qa 0.75, prod 0.90, dr 0.95.
Output: {score, band, perInput, reasonCodes}.
Halt with explicit reason on missing input (§8).
Spike cold-start (A-6.2): inputs 3 (freshness), 5 (history), 6 (nfrs) are
'present + neutral 0.5' because the spike is the first submission with no
history and no declared NFRs. The gate is *presence*, not *conformance* —
the 'all six inputs present' dev gate (§5) is satisfied by non-null
per-input scores.
"""
from dataclasses import dataclass, asdict
from typing import List, Literal, Optional, Dict, Any
import json
import sys
WEIGHTS = {
"policy": 0.30,
"validation": 0.25,
"freshness": 0.10,
"source": 0.15,
"history": 0.10,
"nfrs": 0.10,
}
PENALTY = {
"critical": None,
"high": 0.20,
"medium": 0.05,
"low": 0.01,
"info": 0.0,
}
THRESHOLDS = {"dev": 0.50, "qa": 0.75, "prod": 0.90, "dr": 0.95}
@dataclass
class Signal:
score: float
band: Literal["pass", "warn", "block"]
perInput: Dict[str, float]
reasonCodes: List[str]
def _per_input_score(name: str, raw: Any) -> tuple:
"""Return (score in [0,1], reasons list). Unknown/missing -> 0.5 + INPUT_MISSING."""
reasons: List[str] = []
if raw is None:
return 0.5, [f"INPUT_MISSING:{name}"]
if name == "policy":
pcrs = raw if isinstance(raw, list) else []
if not pcrs:
return 0.5, []
scores = []
for pcr in pcrs:
r = pcr.get("result", "skipped")
if r == "pass" or r == "skipped":
scores.append(1.0)
else:
scores.append(0.0)
return sum(scores) / len(scores), []
if name == "validation":
keys = ("schema", "stack_resolved", "tf_validated", "tf_planned")
if not isinstance(raw, dict):
return 0.5, []
trues = sum(1 for k in keys if raw.get(k))
return trues / 4.0, []
if name == "freshness":
if not isinstance(raw, dict):
return 0.5, []
age = float(raw.get("age_days", 0))
mx = float(raw.get("max_age_days", 1)) or 1
s = 1.0 - (age / mx)
return max(0.0, min(1.0, s)), []
if name == "source":
if not isinstance(raw, dict):
return 0.5, []
if raw.get("submitter") and raw.get("commit_sha"):
return 1.0, []
return 0.5, []
if name == "history":
if not isinstance(raw, dict):
return 0.5, []
rollbacks = int(raw.get("prior_rollbacks", 0))
fails = int(raw.get("prior_policy_fails", 0))
s = 1.0 - (rollbacks * 0.2 + fails * 0.1)
return max(0.0, min(1.0, s)), []
if name == "nfrs":
if not isinstance(raw, dict):
return 0.5, []
conf = raw.get("conformance")
if conf is None:
return 0.5, []
return float(conf), []
return 0.5, []
def compute(contract_id: str, environment: str,
inputs: Dict[str, Any]) -> Signal:
"""Orchestrate the 6-input weighted sum + severity penalty + band."""
missing = sorted(set(WEIGHTS.keys()) - set(inputs.keys()))
if missing:
return Signal(0.0, "block", {},
[f"INPUT_MISSING:{m}" for m in missing])
per_input: Dict[str, float] = {}
reasons: List[str] = []
base = 0.0
for name, weight in WEIGHTS.items():
raw = inputs.get(name)
s, r = _per_input_score(name, raw)
per_input[name] = s
reasons.extend(r)
base += s * weight
penalty = 0.0
policy_input = inputs.get("policy")
pcrs = policy_input if isinstance(policy_input, list) else []
for pcr in pcrs:
if not isinstance(pcr, dict):
continue
if pcr.get("result") != "fail":
continue
sev = pcr.get("severity")
p = PENALTY.get(sev, 0.0)
if p is None:
return Signal(0.0, "block", per_input,
reasons + [f"CRITICAL_OVERRIDE:{pcr.get('ruleId','?')}"])
penalty += p
score = max(0.0, min(1.0, base - penalty))
threshold = THRESHOLDS[environment]
if score >= threshold:
band = "pass"
elif score < threshold - 0.10:
band = "block"
else:
band = "warn"
if environment == "dev" and band == "warn":
band = "block"
return Signal(score, band, per_input, reasons)
if __name__ == "__main__":
if len(sys.argv) < 3:
print("usage: confidence_signal.py <inputs.json> <environment>", file=sys.stderr)
sys.exit(2)
env = sys.argv[2]
with open(sys.argv[1], "r", encoding="utf-8") as fh:
inputs = json.load(fh)
sig = compute("cli", env, inputs)
print(json.dumps(asdict(sig), indent=2))