Repository navigation
fix(heartbeat): pause, resume and terminate record the verified principal (#21136) - #21148
Conversation
|
Warning Review limit reachedYou'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 24 minutes. View limit details
Walkthrough
Severity of issue fixed: Medium Merge Risk:
|
|
Verdict: CHANGES (reviewed head 537bc8b) Actor resolution, spoof closure and ACs are sound. One blocking finding (non-durable audit) and two non-blocking ones. Blocking
Non-blocking Checks
#21136 ACs
State: unresolved review threads 0. CI at head: 0 real failures; 11 success, 10 in progress, 9 queued, 26 cancelled (superseded runs), 2 skipped, 1 neutral. Milestone: M2 - Company OS workflow-ready. Labels: bug, backend, area: company-os, phase:M2.6. |
… display name; stop sending paused_by (#21136)
✅ SSOT Configuration Compliance: Passing🎉 No new hardcoded values of either class — Known backlog in |
|
Code review (code-reviewer pass) at 5dd5967 (delta from 537bc8b; 63dec16 is the api.ts regeneration)
Answers
CodeRabbit threads: 0 review threads (only the summary comment). |
…503 if it cannot be written; one display-name helper (#21136)
|
Delta review → adf4fdb (fix 27938ad, plus a main merge): APPROVE.
Queued for the next merge train. |
mrveiss
left a comment
There was a problem hiding this comment.
Verdict: CHANGES @ 3321184
Scope: delta 46de677..3321184 (2 files: schemas_heartbeat.py description, new route test). The earlier locale finding is withdrawn: locale-parity.test.ts only forbids keys in non-English locales that en.json lacks, and i18n_untranslated_ratchet_test.py only fails when an existing translation is lost against base; an en-only agent.systemActor passes both (fallbackLocale en).
G1 ok: schema text equals the api.ts JSDoc at 80017 character for character. _paused_by_name (heartbeat.py:~527) returns None for no actor, system:*, legacy free text and unknown user, so the sentence covers every null case. Dispatch Generated Types Autofix run 43185053629: success at 3321184 ("already fresh"), which covers the other schema hunks too.
G2 ok: the PR adds no hardcoded UI string (the only new template text goes through $t; "Paused By" and 'Manual pause from UI' are pre-existing).
(a) non-blocking: the fallback matches budget_policies.py:244 and admin_orphan_repair.py:66, and #21136's ACs do not forbid it. But resolve_principal_id returns None for service keys and dev-header auth, so "unknown" or a username can be stored for an authenticated caller. Not forgeable, but not a principal id. Filed #21368 (sub-issue of #21137), covering all sites.
(b) BLOCKING: autobot-backend/tests/api/test_heartbeat_pause_route_actor_21136.py is a real route test (router mounted, real get_current_user via real_auth_middleware, same override pattern as the 21119 test), but it will error. Line 40 patches _state_response to return {}, and the route declares response_model=HeartbeatConfigResponse (heartbeat.py:~303), which has required fields (agent_id, heartbeat_enabled, status, heartbeat_interval_seconds, max_run_duration_seconds, current_task_id, last_heartbeat_at, session_params, extra, created_at, updated_at). FastAPI raises ResponseValidationError and the TestClient re-raises it, so the 200 assertion is never reached. Fix: patch _paused_by_name (AsyncMock, None) and give the state SimpleNamespace every field _state_to_response reads (agent_id, heartbeat_enabled, error_*, max_run_duration_seconds, current_task_id, last_heartbeat_at, session_params, extra, created_at, updated_at), or return a valid HeartbeatConfigResponse. The rest walks clean: the forged body is ignored (AgentPauseRequest.paused_by is unused), the assertions would fail if the route used it, and there is no Redis or DB. Unverified: no other test imports api.heartbeat at module scope under the stub conftest. The existing api/heartbeat_actor_21136_test.py does, which is some evidence.
(b2) non-blocking: no unauthenticated-request test. Auth is per-route Depends(get_current_user) on pause/resume/terminate (heartbeat.py:312, 399, 440), the same dependency the 21119 test exercises. A 401 assertion on pause would be cheap; add it in the same fix.
(c) non-blocking: HeartbeatPanel.vue is 721 lines on main and on head, and the ceiling is 721 in scripts/frontend_file_size_known_large.py:26. No import-order or blank-line rule is configured (oxlintrc has overrides only; prettier does not touch blank lines), so the current form should not fail lint.
Guards: new test is 61 lines; the *_21136 name matches the 21119 sibling; no non-py/md registry references the neighbouring non-route modules, so no reach entry is evident.
Own CI: the suite shows cancelled runs (coordinator), not failures; the cheap gates (PR structure, issue link, conflict gate, typecheck, types dispatch) pass.
Blocking fix: (b) only. Static review; not run.
… heartbeat controls (#21136)
|
Addressed the CHANGES verdict (B1, B2) in 11b2e0d. Test file only; no product change. Not run locally; needs CI. B1: the test no longer patches B2: parametrized over pause, resume and terminate. With no identity the route returns 401 (get_current_user ends in raise_auth_error("AUTH_0002"), catalogued as 401; the captcha/diagnostics/metrics auth test asserts 401 for the same fixture). The test also asserts no audit write, no state fetch, no commit, and no scheduler call. Import under the conftest stubs: |
mrveiss
left a comment
There was a problem hiding this comment.
Verdict: APPROVE @ 11b2e0d
Scope: delta 3321184..11b2e0d only (one file, the route test); the rest of the PR was settled by the previous review. Static review; not run.
Import: same imports as the previous revision plus HeartbeatConfigResponse and HeartbeatStatus (real modules); api.heartbeat is already imported by heartbeat_actor_21136_test.py. real_auth_middleware comes from tests/conftest.py, as in the mirrored 21119 test.
App: router has no prefix, mounted at /api/heartbeat, so /api/heartbeat/a1/{pause,resume,terminate} match. All Depends are overridden: get_db_session and _get_scheduler (identity with the names api.heartbeat binds), get_current_user (stub key to real function, same pattern as the 21119 and captcha tests). The fake middleware's identity.user is read at call time, so the harness can flip it to None.
Pause walk: body {"reason","paused_by"}; AgentPauseRequest declares both fields, so it parses. State "active" is neither "terminated" nor "paused" (HeartbeatStatus is a str Enum compared via .value). _actor_id on the dict gives "principal-7" ("id" is first in _CLAIM_ORDER). _audit_control builds a real AuditEvent (AGENT_PAUSE exists), the async fake _record returns True and appends event.actor_id. State is a SimpleNamespace; every attribute _state_to_response reads is present. commit and refresh are AsyncMock, disable_agent is AsyncMock and awaited. _state_response awaits the patched _paused_by_name(session, "principal-7") and gets None. Response validates (status str, ISO strings, session_params {}, extra None). Expected: 200, status "paused", paused_reason "r", paused_by "principal-7", paused_by_name null, paused_at set.
Assertions: all hold, and the state and audit assertions would fail if the handler used the body's "system:forged".
Unauthenticated, all three routes: bodies are valid for their models ({} for resume, reason for terminate), so no 422. get_current_user finds no service opt-in and no user or run/device token, then raises raise_auth_error("AUTH_0002"), a plain HTTPException 401 (AUTH_0002 maps to 401 in error_catalog), so no extra exception handler is needed (same as the captcha precedent). The dependency raises before the handler, so with_error_handling is never reached. All "nothing called" assertions reference the right fakes.
Style: no line over 120 columns; param ids are valid; monkeypatch only.
No blocking findings. Non-blocking: the resume 202 and 409 branches are not covered (out of scope for this delta).
|
Landing on its own (a single PR does not get a merge train): approved at |
|
Correction to the previous comment: this PR cannot land on its own from its current head. The head is an automatic sync merge of |
|
Boarded merge train #21382 (T117) at |
Thinking Path
Heartbeat pause, resume and terminate each recorded their actor differently (body field, nothing, username). Route them through one helper that takes the principal id from the verified caller and writes it to the row and an audit event.
Single-issue rationale
Only #21136: one defect (inconsistent actor recording) across three routes in one file, plus the audit actions it needs.
What Changed
autobot-backend/api/heartbeat.py:_actor_id/_audit_control; pause, resume and terminate useresolve_principal_idand emitagent.pause|resume|terminate. The bodypaused_byis ignored (description updated).autobot-backend/services/audit/taxonomy.py: three newAuditActionmembers.autobot-frontend/src/types/generated/api.ts(field description only).Verification
autobot-backend/api/heartbeat_actor_21136_test.py(4 tests: principal id per route, resume audit names caller, forged body actor ignored). Ran with the audit vocabulary, one-admin-gate, docstring-restatement and fast-guard tests: 2133 passed. api.ts regenerated via the verify-generated-types recipe.Model Used
Claude Sonnet 5.5
Closes #21136
Refs #21137
🤖 Generated with Claude Code
Summary by CodeRabbit