You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(heartbeat): scope routes to the owning company, audit attempt and outcome, send reason codes (#21376, #21375, #21377) - #21979
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-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).
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.
Behaviour change: a non-admin who is not an owner/admin of the agent's company can no longer pause, resume, terminate or reconfigure it, and a platform agent (no company) is no longer reachable by non-admins. Service principals are not platform admins in _is_platform_admin_claim, so an internal caller using the service key now gets 404; I found no such caller in this tree but did not exhaustively search other services.
The success audit row now follows the change instead of preceding it; a reader that expected one agent.pause row with outcome success per control now sees an attempted row and a success row.
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)
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.
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.
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: 3 · 1
Failed checks: 1 inconclusive
Check name
Status
Explanation
Resolution
Out of Scope Changes check
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 checks: 3 passed
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
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
[#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.
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.
If the queue is draining normally, ignore this. Otherwise:
Check whether CI is dispatching at all — see the ci-dispatch-watchdog status on these PRs
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
Look for a loop opening near-identical PRs
Warn-only runaway detector — .github/workflows/pr-queue-gate.yml. It never blocks a merge.
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
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
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_idis the slug the heartbeat keyspace uses,AgentOrgNode.company_idnames 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 anattemptedrow followed by asuccessorfailedoutcome 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_scopedependencies built on the existingis_company_member,require_company_admin_unless_platformand_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, vialive_company_agents_clause()) answer 404 for everyone but a platform admin; a member who is not an owner/admin answers 403.may_see_usergatespaused_by_nameto 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 throughapply_control. The file is 518 lines (origin/main: 545).autobot-backend/api/heartbeat_controls.py(new):apply_controlwrites theattemptedrow (a failed write is a 503 and nothing changes), commits the state, calls the scheduler, then writes the linkedsuccessrow. A failed commit leaves afailedrow; a scheduler failure restores the row under a re-taken row lock (leaving a row a newer control changed alone, recorded assuperseded), leaves afailedrow and answers 503.autobot-backend/services/audit/outcome.py(new):record_attempt/record_outcomeoverrecord_committed.autobot-backend/services/heartbeat_scheduler.py:_get_or_create_statetakesfor_update.autobot-frontend/src/composables/useHeartbeatReasons.ts(new),HeartbeatPanel.vue,i18n/locales/en.json: the panel sendsmanual_pause_ui/manual_wakeup_ui, renders known codes throughagent.heartbeatReasons.*and any other value unchanged. The panel is 717 lines (origin/main: 721).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 checkandblack --check --line-length=120 --target-version py310on every changed Python file, eslint on the changed frontend files, andvue-tsc --noEmit -p tsconfig.app.json; all clean.paused_by_namerule.failedrow; scheduler failure returns 503 and restores the row; a failed restore is recorded asreconcile_failed; a second request for the same transition writes no audit row;FOR UPDATEis in the compiled statement.Risks
_is_platform_admin_claim, so an internal caller using the service key now gets 404; I found no such caller in this tree but did not exhaustively search other services.agent.pauserow with outcomesuccessper control now sees anattemptedrow and asuccessrow.audit_secret_op, which this PR does not touch (held by fix(secrets): connector credential mirror rotates a same-name row instead of conflicting (#17850) #21970).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
changelog/unreleased/21376-heartbeat-company-scope-and-outcome-rows.mdChecklist
CLAUDE.mdgit commitruns them automatically)main(notrelease)Pre-handover (docs/developer/CLAUDE_REVIEW.md, #19285)
Summary by CodeRabbit