Skip to content

fix(audit): log() not log_event() in proactive messages (#374) - #416

Merged
vybe merged 3 commits into
mainfrom
fix/374-audit-log-event-method
Apr 21, 2026
Merged

vybe merged 3 commits into
mainfrom
fix/374-audit-log-event-method

Conversation

@dolho

@dolho dolho commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #374.

proactive_message_service._audit_send called platform_audit_service.log_event(...) — a method that does not exist on PlatformAuditService (the real method is log()). The call was wrapped in try/except so the AttributeError surfaced only as a WARNING: Failed to audit proactive message: 'PlatformAuditService' object has no attribute 'log_event', and no audit row was ever written for a proactive message — a silent coverage hole in the SEC-001 audit trail.

Fix

  • _audit_send is now async and awaits platform_audit_service.log(...).
  • Kwargs updated to match the real signature: actor_agent_name="..." replaces the non-existent actor_type="agent" + actor_id=... pair (actor resolution is now delegated to log()'s internal _resolve_actor).
  • All four call sites in send_message now await self._audit_send(...).

Test plan

  • New regression unit test tests/test_proactive_audit_unit.py with 3 cases:
    • log() invoked with correct kwargs (actor_agent_name, target_type, target_id, details, no legacy actor_type/actor_id)
    • Audit failures never propagate to caller (best-effort contract)
    • message_preview truncated to 100 chars
  • All 3 pass locally.
  • Live smoke: send a proactive message via Telegram, verify a row appears in audit_log with event_type=proactive_message (deferred — requires rebuilt backend).

🤖 Generated with Claude Code

dolho and others added 2 commits April 20, 2026 11:20
…sages (#374)

_audit_send called platform_audit_service.log_event(...) which never existed
— the try/except swallowed the AttributeError so every proactive message
silently failed to write an audit row. Fixed by awaiting platform_audit_service.log()
with the correct kwargs (actor_agent_name replaces actor_type/actor_id).
_audit_send is now async; all four call sites in send_message awaited.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
can_agent_message_email crashed with AttributeError when the agent owner's
users.email column was NULL — dict.get's default only applies when the key
is absent, not when the value is None. Broke every proactive messaging call
for admin-owned agents (admin has NULL email on fresh installs), returning
generic HTTP 500 and swallowing the audit row as collateral damage.

Discovered while live-verifying #374 fix in the same PR.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@dolho
dolho force-pushed the fix/374-audit-log-event-method branch from 4b01e80 to 319e2b6 Compare April 20, 2026 08:21
Adds a regression test that stubs db.can_agent_message_email, rate limit, and
_deliver_via_channel to return success, then calls send_message and asserts
platform_audit_service.log received the success=True audit. Guards against
regressions where the success-branch await at the end of send_message silently
drops (sync regression, forgotten await).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@dolho
dolho requested a review from vybe April 20, 2026 08:30
@vybe
vybe merged commit aa25fc6 into main Apr 21, 2026
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.

bug: PlatformAuditService missing 'log_event' method

2 participants