Skip to content

fix(budget-policies): resume records the acting admin as approver (#21119) - #21135

Closed
mrveiss wants to merge 3 commits into
mainfrom
issue-21119
Closed

mrveiss wants to merge 3 commits into
mainfrom
issue-21119

Conversation

@mrveiss

@mrveiss mrveiss commented Nov 8, 2026

Copy link
Copy Markdown
Owner

Thinking Path

The budget policy resume route is admin-gated but recorded the literal admin as the approver in the agent state and the agent.budget_resumed audit event, so the audit trail could not name who resumed an agent.

Single-issue rationale

One defect, one route: the placeholder actor on resume. The pause path writes genuinely system-initiated actors (budget_policy), which stay as they are.

What Changed

  • resume_paused_agent takes the verified caller via get_current_user and passes resolve_principal_id(current_user), falling back to the username, as approved_by. Nothing comes from the request body.
  • New test_budget_policy_resume_approver_21119.py asserts resume_agent receives the calling admin's id, the username fallback, and never a placeholder.
  • api.ts regenerated; the only change is the route description.

Verification

Budget policy tests, the one-admin-gate, audit action vocabulary and docstring restatement guards, and the fast guard list: 2153 passed. api.ts regenerated with the verify-generated-types recipe.

Model Used

Claude Sonnet 5.5

Closes #21119

🤖 Generated with Claude Code

@mrveiss mrveiss added this to the M2 - Company OS workflow-ready milestone Nov 8, 2026
@mrveiss mrveiss added bug Something isn't working backend phase:M2.6 Budgets enforced and costs recorded labels Nov 8, 2026
@coderabbitai

coderabbitai Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 18 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 250ddc4 and 8e851de.

Files ignored due to path filters: 1

  • autobot-frontend/src/types/generated/api.ts is excluded by !**/generated/**
Files selected for processing: 2

  • autobot-backend/api/budget_policies.py
  • autobot-backend/tests/api/test_budget_policy_resume_approver_21119.py
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Notice: 29 open PRs — past the runaway threshold (25)

This is not a request to defer this PR. There is no cap on open PRs (#19397) -- nothing blocks opening or pushing a PR.

This notice only means the count is high enough to be worth a glance for a runaway — something opening PRs in a loop, or a merge pipeline that has stalled so nothing is draining.

Currently open:

If the queue is draining normally, ignore this. Otherwise:

  1. Check whether CI is dispatching at all — see the ci-dispatch-watchdog status on these PRs
  2. Approved PRs land through the merge train the coordinator sequences (merge commits, never squash) -- check the open chore(merge-train) PR is moving, not each PR on its own
  3. Look for a loop opening near-identical PRs

Warn-only runaway detector — .github/workflows/pr-queue-gate.yml. It never blocks a merge.

@mrveiss

mrveiss commented Nov 8, 2026

Copy link
Copy Markdown
Owner Author

Verdict: APPROVE (head c1e91de; review is read-only, from the diff and base)

CI at head is still running, so merge on green.

Check Result
Spoofing resume_paused_agent (autobot-backend/api/budget_policies.py:238-245) has only agent_id (path) and two Depends. There is no body or query model, so nothing client-supplied reaches approved_by. The caller comes from get_current_user. Without the change approved_by is the literal "admin", so test_resume_records_calling_admin_id (forged body mallory, expects u-42) fails on base.
Canonical helper resolve_principal_id is autobot_shared/principal.py:27, the only definition. The line resolve_principal_id(u) or str(u.get("username") or "unknown") is identical to admin_orphan_repair.py:66. A collision between a username and another principal's id is theoretically possible, but it matches the accepted pattern and applies only to id-less principals (service key or dev header).
Sibling routes A grep of approved_by across the backend found no other route that takes an approver from a request body. Related routes: api/heartbeat.py:324 resume_agent records no resumer and emits no audit event. api/heartbeat.py:401 terminate_agent stores the username in paused_by, not the id. Neither is a body-supplied approver, and both are outside #21119. The heartbeat usernames-vs-ids inconsistency is worth a separate issue if the owner wants one actor convention.
api.ts The only diff is one description line at api.ts:42822, matching the new docstring. This is generator output.
Hygiene The route is about 13 lines. The test file is 64 lines. No print calls, nothing hardcoded, and no swallowed errors.

Acceptance criteria of #21119:

  1. Real identity from the verified caller: met. budget_policies.py:244 sets approver = resolve_principal_id(current_user) or str(current_user.get("username") or "unknown") and line 245 passes approved_by=approver. services/budget_policy.py:442-445 writes it to the audit actor_id and metadata.approved_by. The audit schema has no display-name field on this path, so the id-or-username value is all that is recorded.
  2. Test asserts the caller, not a literal: met. test_budget_policy_resume_approver_21119.py has three tests: id u-42 with a forged body, the username fallback, and a never-placeholder check.
  3. Other placeholder actors in the same flow: met. The remaining actors are paused_by="budget_policy" (services/budget_policy.py:341) and actor_id="budget_policy_service" (:317). Both are genuinely system-initiated, so no change is needed there.

Non-blocking: the placeholder test (test_resume_never_records_placeholder) is weaker than the first, since it only excludes three strings. It is acceptable, because the first test pins the exact value.

Review threads unresolved: 0. Milestone: M2 - Company OS workflow-ready. Labels: bug, backend, phase:M2.6.

@mrveiss

mrveiss commented Nov 8, 2026

Copy link
Copy Markdown
Owner Author

Landed via merge train #21184, merge commit 209d547 (frozen head c1e91de is an ancestor of it).

@mrveiss mrveiss closed this Nov 8, 2026
timothybrush pushed a commit to timothybrush/AutoBot-AI that referenced this pull request Nov 9, 2026
@mrveiss mrveiss reopened this Nov 18, 2026
@mrveiss

mrveiss commented Nov 18, 2026

Copy link
Copy Markdown
Owner Author

Branch audit (zero-change deletion). This PR shows 0 changed files against main (head ad964492fa): every change it carried is already in main. Closing and deleting the branch through this PR; it can be restored with the Restore branch button below.

@mrveiss mrveiss closed this Nov 18, 2026
@mrveiss
mrveiss deleted the issue-21119 branch November 18, 2026 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend bug Something isn't working phase:M2.6 Budgets enforced and costs recorded

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(budget-policies): resume records a placeholder approver instead of the acting admin

1 participant