Skip to content

Add health-driven automation decisions - #27

Merged
Pigbibi merged 72 commits into
mainfrom
feat/health-driven-decision-p3
Jul 7, 2026
Merged

Add health-driven automation decisions#27
Pigbibi merged 72 commits into
mainfrom
feat/health-driven-decision-p3

Conversation

@Pigbibi

@Pigbibi Pigbibi commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add a health-driven execution decision layer for automation control.
  • Expose control.execution from /v1/ai/automation/control using health, quota, consecutive failure, and service-owned repo policy inputs.
  • Wire deployment/docs to use a service-owned execution policy path.

Test Plan

  • bash -n scripts/deploy_codex_audit_service.sh
  • actionlint .github/workflows/*.yml
  • python3 -m ruff check service scripts tests
  • python3 -m compileall -q service scripts tests
  • python3 -m unittest discover tests
  • node --test cloudflare/codex-audit-proxy/tests/index.test.mjs
  • node --test cloudflare/ai-gateway-dash/tests/index.test.mjs

Safety

  • Does not grant new merge/deploy permissions.
  • Execution policy is read from a service-owned path, not from the reviewed checkout.
  • Degraded health/quota/failure streaks only reduce autonomy.

Co-Authored-By: Codex <noreply@openai.com>
@cursor

cursor Bot commented Jul 6, 2026

Copy link
Copy Markdown

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.

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown

🤖 Codex PR Review

Merge allowed: No issues found


Review by Codex PR Review bot • PR

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread service/ai_gateway_service.py Outdated
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"]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Comment thread service/ai_gateway_service.py Outdated
_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 ""))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment thread service/automation_decision.py Outdated
"""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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment thread service/ai_gateway_service.py Outdated
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.

Co-Authored-By: Codex <noreply@openai.com>
@cursor

cursor Bot commented Jul 6, 2026

Copy link
Copy Markdown

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>
@cursor

cursor Bot commented Jul 6, 2026

Copy link
Copy Markdown

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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread service/automation_decision.py Outdated
Comment on lines +128 to +129
if state in TERMINAL_STATES:
break

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment thread service/ai_gateway_service.py Outdated
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.

Comment thread service/ai_gateway_service.py Outdated
Comment on lines +1541 to +1545
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),
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment thread service/automation_decision.py Outdated
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.

Co-Authored-By: Codex <noreply@openai.com>
@cursor

cursor Bot commented Jul 6, 2026

Copy link
Copy Markdown

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>
@cursor

cursor Bot commented Jul 6, 2026

Copy link
Copy Markdown

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>
@cursor

cursor Bot commented Jul 6, 2026

Copy link
Copy Markdown

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>
@cursor

cursor Bot commented Jul 6, 2026

Copy link
Copy Markdown

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>
@cursor

cursor Bot commented Jul 6, 2026

Copy link
Copy Markdown

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>
@cursor

cursor Bot commented Jul 6, 2026

Copy link
Copy Markdown

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>
@cursor

cursor Bot commented Jul 6, 2026

Copy link
Copy Markdown

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>
@cursor

cursor Bot commented Jul 6, 2026

Copy link
Copy Markdown

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>
@cursor

cursor Bot commented Jul 6, 2026

Copy link
Copy Markdown

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>
@cursor

cursor Bot commented Jul 6, 2026

Copy link
Copy Markdown

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>
@cursor

cursor Bot commented Jul 7, 2026

Copy link
Copy Markdown

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>
@cursor

cursor Bot commented Jul 7, 2026

Copy link
Copy Markdown

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>
@cursor

cursor Bot commented Jul 7, 2026

Copy link
Copy Markdown

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>
@cursor

cursor Bot commented Jul 7, 2026

Copy link
Copy Markdown

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>
@cursor

cursor Bot commented Jul 7, 2026

Copy link
Copy Markdown

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>
@cursor

cursor Bot commented Jul 7, 2026

Copy link
Copy Markdown

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>
@cursor

cursor Bot commented Jul 7, 2026

Copy link
Copy Markdown

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>
@cursor

cursor Bot commented Jul 7, 2026

Copy link
Copy Markdown

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>
@cursor

cursor Bot commented Jul 7, 2026

Copy link
Copy Markdown

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>
@cursor

cursor Bot commented Jul 7, 2026

Copy link
Copy Markdown

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>
@cursor

cursor Bot commented Jul 7, 2026

Copy link
Copy Markdown

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>
@cursor

cursor Bot commented Jul 7, 2026

Copy link
Copy Markdown

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>
@cursor

cursor Bot commented Jul 7, 2026

Copy link
Copy Markdown

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>
@cursor

cursor Bot commented Jul 7, 2026

Copy link
Copy Markdown

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.

@Pigbibi
Pigbibi merged commit b85a0c3 into main Jul 7, 2026
4 checks passed
@Pigbibi
Pigbibi deleted the feat/health-driven-decision-p3 branch July 7, 2026 03:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant