Skip to content

Commit 2afcb30

Browse files
Pigbibicodex
andcommitted
fix: keep automation control legacy actions compatible
Co-Authored-By: Codex <noreply@openai.com>
1 parent acdd960 commit 2afcb30

4 files changed

Lines changed: 11 additions & 17 deletions

File tree

service/ai_gateway_service.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,13 @@
6767
)
6868
from service.automation_run_ledger import (
6969
CONTROL_CONTINUE,
70-
CONTROL_DEFER,
7170
CONTROL_ESCALATE,
7271
CONTROL_PAUSE_AUTO_FIX,
7372
CONTROL_REVIEW_ONLY,
7473
get_automation_run_ledger,
7574
suggest_control_action,
7675
)
77-
from service.automation_decision import EXECUTION_DEFER, EXECUTION_HUMAN_REVIEW, decide_automation_execution, load_execution_policy
76+
from service.automation_decision import EXECUTION_HUMAN_REVIEW, decide_automation_execution, load_execution_policy
7877
from service.strategy_automation_registry import (
7978
apply_strategy_registry_guard,
8079
summarize_strategy_registry_context,
@@ -514,7 +513,7 @@ def _automation_control_snapshot(
514513
repo: str,
515514
*,
516515
task_name: str = "",
517-
requested_mode: str = MODE_REVIEW_ONLY,
516+
requested_mode: str = MODE_REVIEW_AND_FIX,
518517
pending_run: dict[str, Any] | None = None,
519518
) -> dict[str, Any]:
520519
try:
@@ -560,8 +559,6 @@ def _automation_control_snapshot(
560559
strict_action = original_action
561560
if execution.get("action") == EXECUTION_HUMAN_REVIEW:
562561
strict_action = CONTROL_ESCALATE
563-
elif execution.get("action") == EXECUTION_DEFER:
564-
strict_action = CONTROL_DEFER
565562
elif (
566563
execution.get("requested_mode") == MODE_REVIEW_AND_FIX
567564
and execution.get("effective_mode") == MODE_REVIEW_ONLY
@@ -571,7 +568,7 @@ def _automation_control_snapshot(
571568
if strict_action != original_action:
572569
control["action"] = strict_action
573570
control["auto_fix_allowed"] = False
574-
control["requires_human_review"] = execution.get("action") != EXECUTION_DEFER
571+
control["requires_human_review"] = True
575572
reasons = control.get("reasons") if isinstance(control.get("reasons"), list) else []
576573
reasons.append("capped by execution decision")
577574
control["reasons"] = reasons
@@ -1499,7 +1496,7 @@ def _handle_automation_control(self) -> None:
14991496
else:
15001497
repo = claims_repo
15011498
repo = repo or "unknown"
1502-
mode = str(params.get("mode", [MODE_REVIEW_ONLY])[0] or MODE_REVIEW_ONLY)
1499+
mode = str(params.get("mode", [MODE_REVIEW_AND_FIX])[0] or MODE_REVIEW_AND_FIX)
15031500
_json_response(self, HTTPStatus.OK, {"status": "ok", "control": _automation_control_snapshot(repo, requested_mode=mode)})
15041501

15051502
def _handle_automation_triage(self, claims: dict[str, Any], payload: dict[str, Any]) -> None:
@@ -1604,7 +1601,7 @@ def _handle_record_automation_run(self, claims: dict[str, Any], payload: dict[st
16041601
control = _automation_control_snapshot(
16051602
repo,
16061603
task_name=task_name,
1607-
requested_mode=str(payload.get("mode") or MODE_REVIEW_ONLY),
1604+
requested_mode=str(payload.get("mode") or MODE_REVIEW_AND_FIX),
16081605
pending_run={
16091606
"run_id": run_id,
16101607
"task_name": task_name,

service/automation_run_ledger.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,13 @@
2222
CONTROL_REVIEW_ONLY = "review_only"
2323
CONTROL_PAUSE_AUTO_FIX = "pause_auto_fix"
2424
CONTROL_ESCALATE = "escalate"
25-
CONTROL_DEFER = "defer"
2625

2726
CONTROL_ACTIONS = frozenset(
2827
{
2928
CONTROL_CONTINUE,
3029
CONTROL_REVIEW_ONLY,
3130
CONTROL_PAUSE_AUTO_FIX,
3231
CONTROL_ESCALATE,
33-
CONTROL_DEFER,
3432
}
3533
)
3634

tests/test_ai_gateway_automation_control.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414

1515
class TestAutomationControlSnapshot(unittest.TestCase):
16-
def test_control_snapshot_defaults_to_review_only_for_healthy_repo(self) -> None:
16+
def test_control_snapshot_defaults_to_review_and_fix_for_healthy_repo(self) -> None:
1717
health = type("Health", (), {"status": "healthy"})()
1818
quota = type("Quota", (), {"runtime_status": lambda self, repo: {"status": "ok"}})()
1919
ledger = type("Ledger", (), {"snapshot": lambda self, limit=None: {"runs": []}})()
@@ -28,8 +28,8 @@ def test_control_snapshot_defaults_to_review_only_for_healthy_repo(self) -> None
2828
control = _automation_control_snapshot("QuantStrategyLab/TargetRepo")
2929

3030
self.assertEqual(control["action"], "continue")
31-
self.assertEqual(control["execution"]["effective_mode"], "review_only")
32-
self.assertFalse(control["execution"]["auto_fix_allowed"])
31+
self.assertEqual(control["execution"]["effective_mode"], "review_and_fix")
32+
self.assertTrue(control["execution"]["auto_fix_allowed"])
3333

3434
def test_control_snapshot_preserves_continue_for_explicit_review_and_fix_mode(self) -> None:
3535
health = type("Health", (), {"status": "healthy"})()
@@ -210,7 +210,7 @@ def test_control_snapshot_deduplicates_pending_run_by_run_id(self) -> None:
210210
self.assertEqual(control["action"], "continue")
211211
self.assertEqual(control["execution"]["consecutive_failures"], 1)
212212

213-
def test_control_snapshot_maps_defer_to_legacy_defer(self) -> None:
213+
def test_control_snapshot_keeps_legacy_pause_for_defer(self) -> None:
214214
health = type("Health", (), {"status": "healthy"})()
215215
quota = type("Quota", (), {"runtime_status": lambda self, repo: {"status": "low"}})()
216216
ledger = type("Ledger", (), {"snapshot": lambda self, limit=None: {"runs": []}})()
@@ -227,8 +227,7 @@ def test_control_snapshot_maps_defer_to_legacy_defer(self) -> None:
227227
):
228228
control = _automation_control_snapshot("QuantStrategyLab/TargetRepo", requested_mode="review_and_fix")
229229

230-
self.assertEqual(control["action"], "defer")
231-
self.assertFalse(control["requires_human_review"])
230+
self.assertEqual(control["action"], "pause_auto_fix")
232231
self.assertEqual(control["execution"]["action"], "defer")
233232

234233
def test_control_snapshot_fails_closed_when_ledger_is_unavailable(self) -> None:

tests/test_ai_gateway_service_get_routes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ def test_automation_routes_record_and_return_run_ledger(self) -> None:
580580

581581
with urllib.request.urlopen(f"{base_url}/v1/ai/automation/control?repo=local/repo", timeout=5) as response:
582582
control = json.loads(response.read().decode("utf-8"))["control"]
583-
self.assertIn(control["action"], {"continue", "review_only", "pause_auto_fix", "escalate", "defer"})
583+
self.assertIn(control["action"], {"continue", "review_only", "pause_auto_fix", "escalate"})
584584
self.assertIn("execution", control)
585585
finally:
586586
server.shutdown()

0 commit comments

Comments
 (0)