Skip to content

feat: guard autonomy decisions with shared policy - #14

Merged
Pigbibi merged 4 commits into
mainfrom
codex/autonomy-policy-control
Jul 4, 2026
Merged

feat: guard autonomy decisions with shared policy#14
Pigbibi merged 4 commits into
mainfrom
codex/autonomy-policy-control

Conversation

@Pigbibi

@Pigbibi Pigbibi commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Summary

  • load the shared codex_auto_merge_policy.json for autonomy risk classification
  • expose initial_action, policy_version, runtime_guards, and human/auto flags in recommended_action
  • cap auto-merge when service health is degraded and force human review when unhealthy

Validation

  • python3 -m pytest -q
  • python3 -m ruff check service/autonomy.py service/ai_gateway_service.py tests/test_autonomy.py

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

cursor Bot commented Jul 4, 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 4, 2026

Copy link
Copy Markdown

🤖 Codex PR Review

Merge allowed: No issues found


Review by Codex PR Review bot • PR

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

cursor Bot commented Jul 4, 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: d7434126d5

ℹ️ 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/autonomy.py Outdated
"LICENSE",
".gitignore",
})
DEFAULT_POLICY_PATH = Path(".github/codex_auto_merge_policy.json")

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 Package the shared policy with the deployed service

In the normal VPS deployment, scripts/deploy_codex_audit_service.sh sets the systemd WorkingDirectory to DEPLOY_DIR and only copies service/ into that directory, so .github/codex_auto_merge_policy.json is absent there. Because this default path is relative to the service cwd, load_autonomy_policy() returns {} in production and the new policy_version/risk_policy behavior is silently bypassed. Please either install the policy with the service package or resolve it from a path that is actually deployed.

Useful? React with 👍 / 👎.

Comment thread service/autonomy.py
Comment on lines +206 to +209
for tier in (RISK_CRITICAL, RISK_HIGH, RISK_MEDIUM, RISK_LOW):
rule = risk_policy.get(tier)
if isinstance(rule, dict) and _policy_matches(path, rule):
return tier

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 Enforce high as the policy fallback

The checked-in shared policy's risk_policy.high section has only a reason (source code changes require review), and existing policy consumers treat any non-low/non-medium path as high. Here that high rule is ignored unless it also has exact or prefixes, after which built-in fallback classifies paths such as service/ai_gateway_service.py or arbitrary scripts as medium, allowing auto_pr at 70–84% confidence instead of escalating under the shared policy. Please make the high policy section the catch-all after low/medium checks, or require explicit high patterns in the policy.

Useful? React with 👍 / 👎.

Comment thread service/autonomy.py
risk = classify_changes_risk(changed_paths or [])
action = decide_action(confidence, risk, config=config, repo=repo)
active_policy = policy if policy is not None else load_autonomy_policy()
risk = classify_changes_risk(changed_paths or [], policy=active_policy)

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 Apply policy file-count limits before auto-merge

When a review request includes many low-risk changed_paths, this only classifies the paths and ignores max_changed_files from the active shared policy. The checked-in policy caps auto-merge at 30 files, but 31 docs/test files still classify as low here and can return auto_merge at 60%+ confidence, bypassing the limit enforced by the existing guarded auto-merge policy consumers. Please treat file-count limit violations as requiring human review before deciding.

Useful? React with 👍 / 👎.

changed_paths,
repo=repo if repo else None,
policy=load_autonomy_policy(),
health_status=get_health_monitor().status,

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 Record review health before trusting runtime guard

In deployments where /v1/ai/review is the slow or failing endpoint, this status remains healthy because _handle_review never records its latency or failures in HealthMonitor (repo search only found records for analyze/execute/job paths). The new runtime guard therefore cannot cap auto_merge recommendations for review-specific degradation; record the review endpoint health before using it to gate the action.

Useful? React with 👍 / 👎.

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

cursor Bot commented Jul 4, 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 4, 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 b092fc5 into main Jul 4, 2026
4 checks passed
@Pigbibi
Pigbibi deleted the codex/autonomy-policy-control branch July 4, 2026 22:36

@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: d150e220f8

ℹ️ 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/autonomy.py
Comment on lines +110 to +111
if not env_path:
return {}

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 Wire the autonomy policy path into deployment

Fresh evidence for the earlier deployment concern: this revision now requires CODEX_AUDIT_SERVICE_AUTONOMY_POLICY_PATH, but the VPS installer still only copies service/ (scripts/deploy_codex_audit_service.sh:186-190) and the generated systemd environment block does not set this variable (scripts/deploy_codex_audit_service.sh:242-262). In the normal deployed service, load_autonomy_policy() therefore returns {} here, so /v1/ai/review silently drops the shared risk_policy and policy_version; install the policy and set this env var, or pass a deployed policy path.

Useful? React with 👍 / 👎.

changed_paths,
repo=repo if repo else None,
policy=load_autonomy_policy(),
health_status=get_health_monitor().status,

This comment was marked as off-topic.

Comment thread service/autonomy.py
Comment on lines +205 to +206
except re.error:
continue

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 Fail closed on invalid blocked-path regexes

When an operator adds a malformed custom blocked_path_patterns regex to the deployed policy, this path silently ignores it and continues classifying files, so a path that the policy intended to block can still be treated as low risk and return auto_merge. The existing guarded auto-merge policy parser fails closed on the same condition (scripts/run_monthly_codex_audit.py:2271-2275), so this service-side policy path should also force human review instead of continuing.

Useful? React with 👍 / 👎.

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