Skip to content

fix(heartbeat): scope routes to the owning company, audit attempt and outcome, send reason codes (#21376, #21375, #21377) - #21979

Merged
mrveiss merged 12 commits into
mainfrom
issue-21376
Nov 22, 2026
Merged

mrveiss merged 12 commits into
mainfrom
issue-21376

Conversation

@mrveiss

@mrveiss mrveiss commented Nov 21, 2026 •

Copy link
Copy Markdown
Owner

Thinking Path

The three issues all land in the heartbeat routes and their panel. #21376: every route only required a signed-in user, so any user could read, pause or terminate any agent. The owning company is resolvable through the agent record (AgentOrgNode.agent_id is the slug the heartbeat keyspace uses, AgentOrgNode.company_id names the company), so no migration is needed. #21375: the success audit row was committed before the state change, so a failed change left a row claiming it happened; the repo's secret routes already use an attempted row followed by a success or failed outcome row, so the same shape is applied here. #21377: the panel sent English literals as the reason; a stable code rendered through i18n keeps the stored value locale-neutral.

What Changed

  • autobot-backend/api/heartbeat_scope.py (new): read_scope / manage_scope dependencies built on the existing is_company_member, require_company_admin_unless_platform and _is_platform_admin_claim. Reads need membership, writes need owner/admin, a platform admin is exempt. Another company's agent, an unknown agent and a platform agent (no company, or a soft-deleted or missing one, via live_company_agents_clause()) answer 404 for everyone but a platform admin; a member who is not an owner/admin answers 403. may_see_user gates paused_by_name to a platform admin or a user of the same company.
  • autobot-backend/api/heartbeat.py: every route takes a scope dependency; pause, resume and terminate lock the runtime-state row (_get_or_create_state(..., for_update=True)) and go through apply_control. The file is 518 lines (origin/main: 545).
  • autobot-backend/api/heartbeat_controls.py (new): apply_control writes the attempted row (a failed write is a 503 and nothing changes), commits the state, calls the scheduler, then writes the linked success row. A failed commit leaves a failed row; a scheduler failure restores the row under a re-taken row lock (leaving a row a newer control changed alone, recorded as superseded), leaves a failed row and answers 503.
  • autobot-backend/services/audit/outcome.py (new): record_attempt / record_outcome over record_committed.
  • autobot-backend/services/heartbeat_scheduler.py: _get_or_create_state takes for_update.
  • autobot-frontend/src/composables/useHeartbeatReasons.ts (new), HeartbeatPanel.vue, i18n/locales/en.json: the panel sends manual_pause_ui / manual_wakeup_ui, renders known codes through agent.heartbeatReasons.* and any other value unchanged. The panel is 717 lines (origin/main: 721).
  • Tests: llc/tests/test_heartbeat_company_scope_21376.py, tests/api/test_heartbeat_control_outcome_21375.py, __tests__/HeartbeatPanel.test.ts; the two existing bug(company-os): heartbeat resume/terminate routes record the acting user inconsistently #21136 test files are updated for the new signature and rows.

Verification

Not run locally (CI gates). Run locally: ruff check and black --check --line-length=120 --target-version py310 on every changed Python file, eslint on the changed frontend files, and vue-tsc --noEmit -p tsconfig.app.json; all clean.

Risks

Model Used

Claude Sonnet 5.5 (claude-sonnet-5-5)

Issue Link

Closes #21376
Closes #21377
Refs #21375 (state-commit and scheduler failure are delivered; AC3, the shared helper across heartbeat and secrets, remains, blocked by #21970)

Changelog fragment

  • Added changelog/unreleased/21376-heartbeat-company-scope-and-outcome-rows.md

Checklist

  • Code follows AutoBot patterns from CLAUDE.md
  • Tests added or updated (or N/A with reason)
  • Documentation updated if behavior changed
  • Pre-commit hooks pass (git commit runs them automatically)
  • PR targets main (not release)
  • No secrets or credentials in the diff

Pre-handover (docs/developer/CLAUDE_REVIEW.md, #19285)

  • Every guard or test this body claims exists and ran
  • Size ceilings met by splitting, not by trimming text
  • Every cited owner decision is quoted on its issue
  • Pre-push green: it runs the whole-tree guards (symbol forks, isolated-git, file size, reach)

Summary by CodeRabbit

  • New Features
    • Heartbeat access is now scoped by company: members can view their company’s agents, while pause, resume and terminate controls require administrator privileges.
    • Heartbeat control actions are audited, with state restored where possible if scheduling fails.
    • Pause and wakeup reasons display translated labels for recognised reasons; existing free-text reasons remain visible.
  • Bug Fixes
    • User names associated with paused agents are shown only to callers with permission to view them.

@mrveiss mrveiss added bug Something isn't working priority: medium backend area: company-os Wave 4 · cluster A — Company OS & LLC canvas phase:M2.6 Budgets enforced and costs recorded labels Nov 21, 2026
@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

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 13 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 ccbb51e and de692cc.

Files ignored due to path filters: 1

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

  • autobot-backend/api/heartbeat.py
  • autobot-backend/api/heartbeat_actor_21136_test.py
  • autobot-backend/api/heartbeat_controls.py
  • autobot-backend/api/heartbeat_scope.py
  • autobot-backend/llc/tests/test_heartbeat_company_scope_21376.py
  • autobot-backend/migrations/versions/20261122_121_agent_runtime_state_control_id.py
  • autobot-backend/models/heartbeat.py
  • autobot-backend/services/audit/outcome.py
  • autobot-backend/services/budget_policy.py
  • autobot-backend/services/heartbeat_scheduler.py
  • autobot-backend/tests/api/test_heartbeat_control_outcome_21375.py
  • autobot-backend/tests/api/test_heartbeat_pause_route_actor_21136.py
  • autobot-frontend/src/components/agents/HeartbeatPanel.vue
  • autobot-frontend/src/components/agents/__tests__/HeartbeatPanel.test.ts
  • autobot-frontend/src/composables/useHeartbeatReasons.ts
  • autobot-frontend/src/i18n/locales/en.json
  • autobot-frontend/src/views/BudgetPolicies.vue
  • changelog/unreleased/21376-heartbeat-company-scope-and-outcome-rows.md
Walkthrough

Heartbeat routes now apply company-scoped access and audited state controls. The panel sends stable pause and wakeup reason codes, translates known codes, and preserves legacy free-text reasons.

Changes: Heartbeat Access and State Controls

Layer / File(s) Summary
Company scope and name visibility
autobot-backend/api/heartbeat_scope.py, autobot-backend/api/heartbeat.py, autobot-backend/llc/tests/test_heartbeat_company_scope_21376.py
Routes use read or management scopes. Scope checks resolve live owning companies, apply membership and manager rules, and limit paused-user name visibility. Tests cover access, control permissions, and name visibility.
Audited state transitions
autobot-backend/services/audit/outcome.py, autobot-backend/api/heartbeat_controls.py, autobot-backend/services/heartbeat_scheduler.py, autobot-backend/api/heartbeat.py, autobot-backend/api/heartbeat_actor_21136_test.py, autobot-backend/tests/api/test_heartbeat_control_outcome_21375.py, autobot-backend/tests/api/test_heartbeat_pause_route_actor_21136.py, changelog/unreleased/21376-heartbeat-company-scope-and-outcome-rows.md
Pause, resume, and termination use locked state transitions with linked audit attempts and outcomes. Scheduler failures trigger conditional restoration and a 503 response. Tests cover commit and scheduler failures, restoration, superseded controls, and audit outcomes.

Heartbeat Panel Reason Codes

Layer / File(s) Summary
Reason codes and panel rendering
autobot-frontend/src/composables/useHeartbeatReasons.ts, autobot-frontend/src/i18n/locales/en.json, autobot-frontend/src/components/agents/HeartbeatPanel.vue, autobot-frontend/src/components/agents/__tests__/HeartbeatPanel.test.ts
Manual pause and wakeup requests use stable reason codes. Known codes use translated labels, and unknown text remains unchanged.

Severity of issue fixed: High

Merge Risk: Moderate · previous review ccbb5

The change scopes heartbeat access by company and audits pause, resume and terminate. Under concurrent controls plus a scheduler failure, a failed restore can overwrite a newer pause, and a database error during restoration can skip the audit outcome and the 503. A test also needs updating. These should be fixed before merge.

Pre-merge checks: Passed 3 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Out of Scope Changes check Inconclusive The scope-related changes (heartbeat_scope.py, the route scope dependencies, the panel reason codes, and the i18n entries) connect directly to #21376 and #21377. The audit and outcome work is differen… Confirm whether #21375 is a linked issue of this pull request. If it is not linked, either link it or move the audit and outcome changes (heartbeat_controls.py, services/audit/outcome.py, the for_update change in heartbeat_scheduler.py, and…
Passed Passed checks: 3 passed

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the heartbeat fix and lists three changes: company-scoped routes, audit attempt and outcome rows, and reason codes. The changeset implements all three, so the title relates to the main…
Linked Issues check Passed [#21376] Requirement: runtime state linked to, or resolvable to, the owning company; all heartbeat routes need company membership or role, with a platform-admin exception; paused_by_name visible only …
Full details: Title check

Explanation

The title names the heartbeat fix and lists three changes: company-scoped routes, audit attempt and outcome rows, and reason codes. The changeset implements all three, so the title relates to the main change. However, the title is 121 characters and carries issue numbers, which is longer and noisier than the guidance prefers. The main change is clear, so the check passes.

Full details: Linked Issues check

Explanation

[#21376] Requirement: runtime state linked to, or resolvable to, the owning company; all heartbeat routes need company membership or role, with a platform-admin exception; paused_by_name visible only to permitted callers; cross-company read, pause, resume and terminate return 403 or 404. The PR resolves the company through AgentOrgNode in heartbeat_scope.py, which avoids a migration. read_scope and manage_scope reuse is_company_member and require_company_admin_unless_platform. Other-company, unknown and platform agents return 404 to non-platform-admins. Members who are not owner/admin get 403 on writes. may_see_user gates paused_by_name. Tests in test_heartbeat_company_scope_21376.py cover these cases. [#21377] Requirement: no free-text English reason; stable code rendered through i18n; legacy values unchanged; wakeup handled the same way. HeartbeatPanel.vue sends manual_pause_ui and manual_wakeup_ui through useHeartbeatReasons.ts. Known codes render via agent.heartbeatReasons.*, and unknown values render unchanged. HeartbeatPanel.test.ts covers these cases. Test results were not run locally, so the verdict rests on the described code and test content.

Full details: Out of Scope Changes check

Explanation

The scope-related changes (heartbeat_scope.py, the route scope dependencies, the panel reason codes, and the i18n entries) connect directly to #21376 and #21377. The audit and outcome work is different. It covers heartbeat_controls.py, services/audit/outcome.py, the for_update flag in heartbeat_scheduler.py, the 503 and restore behaviour, and test_heartbeat_control_outcome_21375.py. The PR body refers to #21375 as 'Refs', but #21375 is not in the linked issues for this assessment. Its linkage therefore cannot be confirmed from the supplied issue set. The change also alters observable audit behaviour: one attempted row and one linked outcome row replace the single pre-commit success row. The change is related to a referenced issue, so it is not shown to be unrelated. Whether it is in scope depends on whether #21375 is a linked issue of this pull request.

Resolution

Confirm whether #21375 is a linked issue of this pull request. If it is not linked, either link it or move the audit and outcome changes (heartbeat_controls.py, services/audit/outcome.py, the for_update change in heartbeat_scheduler.py, and the #21375 test file) to a separate pull request. Then reassess the out-of-scope check.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • 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

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.

@github-actions

Copy link
Copy Markdown
Contributor

✅ SSOT Configuration Compliance: Passing

🎉 No new hardcoded values of either class — ssot and other both block.

Known backlog in pipeline-scripts/hardcoded_values_baseline.txt is suppressed and tracked in #14371.

@mrveiss mrveiss removed the land-next Landing set: CI capacity goes to these PRs first (owner direction 2026-09-18, #15397) label Nov 22, 2026
@mrveiss mrveiss added the land-next Landing set: CI capacity goes to these PRs first (owner direction 2026-09-18, #15397) label Nov 22, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 6

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 4071d97 and ccbb51e.

Files ignored due to path filters: 1

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

  • autobot-backend/api/heartbeat.py
  • autobot-backend/api/heartbeat_actor_21136_test.py
  • autobot-backend/api/heartbeat_controls.py
  • autobot-backend/api/heartbeat_scope.py
  • autobot-backend/llc/tests/test_heartbeat_company_scope_21376.py
  • autobot-backend/services/audit/outcome.py
  • autobot-backend/services/heartbeat_scheduler.py
  • autobot-backend/tests/api/test_heartbeat_control_outcome_21375.py
  • autobot-backend/tests/api/test_heartbeat_pause_route_actor_21136.py
  • autobot-frontend/src/components/agents/HeartbeatPanel.vue
  • autobot-frontend/src/components/agents/__tests__/HeartbeatPanel.test.ts
  • autobot-frontend/src/composables/useHeartbeatReasons.ts
  • autobot-frontend/src/i18n/locales/en.json
  • changelog/unreleased/21376-heartbeat-company-scope-and-outcome-rows.md

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@mrveiss mrveiss removed the land-next Landing set: CI capacity goes to these PRs first (owner direction 2026-09-18, #15397) label Nov 22, 2026
@mrveiss mrveiss added land-next Landing set: CI capacity goes to these PRs first (owner direction 2026-09-18, #15397) and removed land-next Landing set: CI capacity goes to these PRs first (owner direction 2026-09-18, #15397) labels Nov 22, 2026
@mrveiss mrveiss added land-next Landing set: CI capacity goes to these PRs first (owner direction 2026-09-18, #15397) and removed land-next Landing set: CI capacity goes to these PRs first (owner direction 2026-09-18, #15397) labels Nov 22, 2026
@mrveiss mrveiss added the land-next Landing set: CI capacity goes to these PRs first (owner direction 2026-09-18, #15397) label Nov 22, 2026
@mrveiss
mrveiss merged commit 2fcaa9a into main Nov 22, 2026
73 checks passed
@mrveiss
mrveiss deleted the issue-21376 branch November 22, 2026 18:19
@mrveiss mrveiss removed the land-next Landing set: CI capacity goes to these PRs first (owner direction 2026-09-18, #15397) label Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: company-os Wave 4 · cluster A — Company OS & LLC canvas backend bug Something isn't working phase:M2.6 Budgets enforced and costs recorded priority: medium

Projects

None yet

1 participant