Add health-driven automation decisions - #27
Conversation
Co-Authored-By: Codex <noreply@openai.com>
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
🤖 Codex PR Review✅ Merge allowed: No issues found Review by Codex PR Review bot • PR |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6936e970fa
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| return suggest_control_action(get_health_monitor().status, quota_status, org_health) | ||
| control = suggest_control_action(get_health_monitor().status, quota_status, org_health) | ||
| try: | ||
| recent_runs = get_automation_run_ledger().snapshot(limit=20)["runs"] |
There was a problem hiding this comment.
Do not truncate ledger before counting repo failures
In a shared service, if the target repo has already hit max_consecutive_failures but more than 20 newer runs from other repositories exist, this snapshot contains none of the target repo's failed runs. consecutive_failure_count() skips non-matching repos, so the execution decision sees consecutive_failures=0 and can return auto_fix_allowed=true, bypassing the new failure-streak safety gate; fetch enough history or filter by repo/task before applying the limit.
Useful? React with 👍 / 👎.
| _assert_source_repository_owner_or_operator(claims, source_repo) | ||
| repo = source_repo or str(claims.get("repository") or "unknown") | ||
| control = _automation_control_snapshot(repo) | ||
| control = _automation_control_snapshot(repo, task_name=str(payload.get("task") or payload.get("task_name") or "")) |
There was a problem hiding this comment.
Preserve the recorded run mode in control decisions
When an external workflow records a run with mode: "review_only" or omits mode, this call still uses _automation_control_snapshot's new default review_and_fix. Under healthy signals the returned control.execution can therefore report requested_mode=review_and_fix and auto_fix_allowed=true for a review-only run, which gives schedulers the wrong safety signal; pass the payload mode through here or default the snapshot to the service contract's review-only mode.
Useful? React with 👍 / 👎.
| """Produce a safe execution decision from health, quota, failures, and repo policy.""" | ||
| repo_policy = repo_execution_policy(repo, policy) | ||
| max_autonomy = _normalize_autonomy(repo_policy.get("max_autonomy"), AUTONOMY_AUTO_PR) | ||
| max_failures = int(repo_policy.get("max_consecutive_failures") or DEFAULT_MAX_CONSECUTIVE_FAILURES) |
There was a problem hiding this comment.
Guard malformed failure thresholds in the policy
If the service-owned execution_policy.json contains a non-integer max_consecutive_failures value (for example after a manual policy edit), this int(...) raises before the control snapshot can be returned. That makes /v1/ai/automation/control and any path that records automation runs fail instead of falling back to the default threshold, so parse this value defensively like the rest of the optional policy file.
Useful? React with 👍 / 👎.
| run_id: str = "", | ||
| ) -> dict[str, Any]: | ||
| control = _automation_control_snapshot(repo) | ||
| control = _automation_control_snapshot(repo, task_name=task) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Co-Authored-By: Codex <noreply@openai.com>
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
Co-Authored-By: Codex <noreply@openai.com>
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f5fe332b59
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if state in TERMINAL_STATES: | ||
| break |
There was a problem hiding this comment.
Treat reviewed runs as streak-clearing
For service jobs, job_task_state({"status": "succeeded"}) records the run as reviewed, but reviewed is not in TERMINAL_STATES, so this loop skips a newer successful run the same way it skips an in-flight run. In a sequence like newest-first reviewed, failed, failed, the repo still reaches max_consecutive_failures and forces human review even though the latest run succeeded; clear the streak for completed non-failure states such as reviewed.
Useful? React with 👍 / 👎.
| run_id: str = "", | ||
| ) -> dict[str, Any]: | ||
| control = _automation_control_snapshot(repo) | ||
| control = _automation_control_snapshot(repo, task_name=task) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| control = _automation_control_snapshot( | ||
| repo, | ||
| task_name=str(payload.get("task") or payload.get("task_name") or ""), | ||
| requested_mode=str(payload.get("mode") or MODE_REVIEW_ONLY), | ||
| ) |
There was a problem hiding this comment.
Include the just-recorded failure in returned control
When POST /v1/ai/automation/runs records a terminal failed state that reaches max_consecutive_failures, this snapshot is computed before the payload is written to the ledger. The response therefore reports the pre-update streak (for example 1/2 after posting the second failure) and can still allow review_and_fix to a scheduler that uses the returned control; compute the control after recording or include the incoming run in the decision inputs.
Useful? React with 👍 / 👎.
| else: | ||
| reasons.append(f"quota status is {quota}; recommending low-cost model") | ||
| elif quota in {"exhausted", "blocked"}: | ||
| action = EXECUTION_DEFER |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Co-Authored-By: Codex <noreply@openai.com>
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
Co-Authored-By: Codex <noreply@openai.com>
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
Co-Authored-By: Codex <noreply@openai.com>
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
Co-Authored-By: Codex <noreply@openai.com>
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
Co-Authored-By: Codex <noreply@openai.com>
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
Co-Authored-By: Codex <noreply@openai.com>
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
Co-Authored-By: Codex <noreply@openai.com>
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
Co-Authored-By: Codex <noreply@openai.com>
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
Co-Authored-By: Codex <noreply@openai.com>
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
Co-Authored-By: Codex <noreply@openai.com>
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
Co-Authored-By: Codex <noreply@openai.com>
Co-Authored-By: Codex <noreply@openai.com>
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
Co-Authored-By: Codex <noreply@openai.com>
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
Co-Authored-By: Codex <noreply@openai.com>
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
Co-Authored-By: Codex <noreply@openai.com>
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
Co-Authored-By: Codex <noreply@openai.com>
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
Co-Authored-By: Codex <noreply@openai.com>
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
Co-Authored-By: Codex <noreply@openai.com>
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
Co-Authored-By: Codex <noreply@openai.com>
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
Co-Authored-By: Codex <noreply@openai.com>
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
Co-Authored-By: Codex <noreply@openai.com>
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
Co-Authored-By: Codex <noreply@openai.com>
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
Co-Authored-By: Codex <noreply@openai.com>
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
Co-Authored-By: Codex <noreply@openai.com>
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
Co-Authored-By: Codex <noreply@openai.com>
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
Summary
control.executionfrom/v1/ai/automation/controlusing health, quota, consecutive failure, and service-owned repo policy inputs.Test Plan
bash -n scripts/deploy_codex_audit_service.shactionlint .github/workflows/*.ymlpython3 -m ruff check service scripts testspython3 -m compileall -q service scripts testspython3 -m unittest discover testsnode --test cloudflare/codex-audit-proxy/tests/index.test.mjsnode --test cloudflare/ai-gateway-dash/tests/index.test.mjsSafety