|
| 1 | +# Autonomy Health Auto-Merge Hardening Implementation Plan |
| 2 | + |
| 3 | +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. |
| 4 | +
|
| 5 | +**Goal:** Make AIAuditBridge safer for mostly-AI-operated monitoring, remediation PR creation, and guarded auto-merge while keeping high-risk changes auditable by humans. |
| 6 | + |
| 7 | +**Architecture:** Keep the current layered model: AI proposes/fixes, deterministic policy gates decide autonomy, CI and GitHub branch protections own final merge, health/feedback observe outcomes. This plan avoids a rewrite and tightens risk boundaries, persistence, and dashboard explainability. |
| 8 | + |
| 9 | +**Tech Stack:** Python stdlib service/scripts, GitHub Actions, pytest, ruff, actionlint, Cloudflare Worker dashboard. |
| 10 | + |
| 11 | +--- |
| 12 | + |
| 13 | +## File/Module Map |
| 14 | + |
| 15 | +- `service/autonomy.py`: single autonomy decision envelope, safer default matrix, policy loading/normalization helpers. |
| 16 | +- `.github/codex_auto_merge_policy.json`: repo-level default policy and review-failure behavior. |
| 17 | +- `scripts/run_monthly_codex_audit.py`: guarded auto-merge classification alignment and feedback registration metadata. |
| 18 | +- `scripts/run_codex_pr_review.py`: risk-aware fail-open/fail-closed behavior. |
| 19 | +- `scripts/gate_codex_app_review.py`: risk-aware Codex App timeout behavior. |
| 20 | +- `service/feedback.py`: durable effectiveness records and rollback-issue intent metadata. |
| 21 | +- `service/health.py`: keep online health separate from background job latency; expose decision-friendly health reasons. |
| 22 | +- Dashboard worker/static files: add Autonomy Decisions, Pending Human Audit, Effectiveness presentation if this repo owns dashboard UI; otherwise document target repo handoff. |
| 23 | +- `tests/`: cover autonomy matrix, policy alignment, review-failure behavior, feedback persistence, health status. |
| 24 | +- `docs/architecture.md` / README: document tiers and human-audit boundary. |
| 25 | + |
| 26 | +--- |
| 27 | + |
| 28 | +### Task 1: Policy Inventory and Branch Protection Baseline |
| 29 | + |
| 30 | +**Files:** |
| 31 | +- Modify: `docs/superpowers/plans/2026-07-04-autonomy-health-auto-merge-hardening.md` |
| 32 | +- No production code change. |
| 33 | + |
| 34 | +- [ ] Confirm current PR/check/protection state for `QuantStrategyLab/AIAuditBridge`. |
| 35 | +- [ ] Record whether branch protection/rulesets are missing. |
| 36 | +- [ ] Produce exact branch protection recommendation; do not mutate GitHub settings without explicit user confirmation if tool requires admin-side irreversible policy change. |
| 37 | + |
| 38 | +Commands: |
| 39 | +```bash |
| 40 | +gh pr view 11 --json mergeStateStatus,statusCheckRollup,reviewDecision |
| 41 | +gh api repos/QuantStrategyLab/AIAuditBridge/branches/main/protection || true |
| 42 | +gh api repos/QuantStrategyLab/AIAuditBridge/rulesets || true |
| 43 | +``` |
| 44 | + |
| 45 | +Expected: |
| 46 | +- PR checks green or pending identified. |
| 47 | +- Current protection gaps documented. |
| 48 | + |
| 49 | +--- |
| 50 | + |
| 51 | +### Task 2: Safer Autonomy Policy Defaults |
| 52 | + |
| 53 | +**Files:** |
| 54 | +- Modify: `service/autonomy.py` |
| 55 | +- Modify: `.github/codex_auto_merge_policy.json` |
| 56 | +- Test: `tests/test_autonomy.py` or extend existing tests if present. |
| 57 | + |
| 58 | +- [ ] Add tests proving high/critical risk never returns `auto_merge` by default. |
| 59 | +- [ ] Add tests proving low-risk high-confidence can return `auto_merge`. |
| 60 | +- [ ] Add tests proving medium-risk defaults to `auto_pr` or `escalate` unless explicit policy override says otherwise. |
| 61 | +- [ ] Adjust `DEFAULT_DECISION_MATRIX` to remove high-risk auto-merge. |
| 62 | +- [ ] Ensure critical/secrets always escalate. |
| 63 | +- [ ] Document reason strings accurately. |
| 64 | + |
| 65 | +Validation: |
| 66 | +```bash |
| 67 | +python -m pytest tests/test_autonomy.py -q |
| 68 | +``` |
| 69 | + |
| 70 | +--- |
| 71 | + |
| 72 | +### Task 3: Risk-Aware Review Failure Behavior |
| 73 | + |
| 74 | +**Files:** |
| 75 | +- Modify: `scripts/run_codex_pr_review.py` |
| 76 | +- Modify: `scripts/gate_codex_app_review.py` |
| 77 | +- Test: `tests/test_run_codex_pr_review.py` |
| 78 | +- Test: `tests/test_gate_codex_app_review.py` |
| 79 | + |
| 80 | +- [ ] Add/adjust tests: docs/tests-only PR may pass if AI review unavailable. |
| 81 | +- [ ] Add/adjust tests: source/workflow/policy PR must not silently pass when AI review unavailable; should request human review or fail check depending current workflow contract. |
| 82 | +- [ ] Keep developer velocity for low-risk surfaces. |
| 83 | +- [ ] Avoid API/secret logging. |
| 84 | + |
| 85 | +Validation: |
| 86 | +```bash |
| 87 | +python -m pytest tests/test_run_codex_pr_review.py tests/test_gate_codex_app_review.py -q |
| 88 | +``` |
| 89 | + |
| 90 | +--- |
| 91 | + |
| 92 | +### Task 4: Feedback Loop Durability and Action Envelope |
| 93 | + |
| 94 | +**Files:** |
| 95 | +- Modify: `service/feedback.py` |
| 96 | +- Modify: `service/ai_gateway_service.py` if API response shape needs envelope fields. |
| 97 | +- Test: existing feedback tests or create `tests/test_feedback.py`. |
| 98 | + |
| 99 | +- [ ] Make shadow disagreement persistence durable under the same job dir pattern, or document why not possible in this pass. |
| 100 | +- [ ] Ensure every registered autonomous change includes action, risk, confidence, changed paths, policy version, source PR/issue URL when available. |
| 101 | +- [ ] When effect is degraded, store rollback-required metadata or issue intent; do not directly roll back. |
| 102 | +- [ ] Expose aggregated stats for dashboard without secrets. |
| 103 | + |
| 104 | +Validation: |
| 105 | +```bash |
| 106 | +python -m pytest tests/test_ai_gateway_service_get_routes.py tests/test_health.py -q |
| 107 | +``` |
| 108 | + |
| 109 | +--- |
| 110 | + |
| 111 | +### Task 5: Dashboard Information Architecture |
| 112 | + |
| 113 | +**Files:** |
| 114 | +- Modify dashboard-owned files if present in this repo. |
| 115 | +- If dashboard UI is generated/deployed from another repo, create a handoff note in `docs/architecture.md` instead of guessing. |
| 116 | + |
| 117 | +- [ ] Locate dashboard source ownership. |
| 118 | +- [ ] Add sections or data mapping for: |
| 119 | + - Autonomy Decisions |
| 120 | + - Pending Human Audit |
| 121 | + - Effectiveness / Recent Auto Actions |
| 122 | +- [ ] Keep mobile header distributed and card empty states centered. |
| 123 | +- [ ] Verify in browser if dashboard source is editable here. |
| 124 | + |
| 125 | +Validation: |
| 126 | +```bash |
| 127 | +python -m pytest tests/test_ai_gateway_service_get_routes.py -q |
| 128 | +``` |
| 129 | +Browser smoke test on dashboard URL if deploy is performed. |
| 130 | + |
| 131 | +--- |
| 132 | + |
| 133 | +### Task 6: Final Validation and Delivery |
| 134 | + |
| 135 | +**Files:** |
| 136 | +- No new production changes unless fixing validation failures. |
| 137 | + |
| 138 | +- [ ] Run targeted tests. |
| 139 | +- [ ] Run full test suite if targeted tests pass. |
| 140 | +- [ ] Run lint/actionlint if available. |
| 141 | +- [ ] Inspect git diff for accidental secrets or unrelated changes. |
| 142 | +- [ ] Report changed files, validation results, risks, and any manual actions required. |
| 143 | + |
| 144 | +Commands: |
| 145 | +```bash |
| 146 | +python -m pytest -q |
| 147 | +ruff check . |
| 148 | +actionlint |
| 149 | +python -m compileall service scripts |
| 150 | +``` |
0 commit comments