Skip to content

Commit e0db88f

Browse files
Altruistusclaude
andauthored
CM-72541: Report the model on every AI guardrails hook event (#544)
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 64d84c5 commit e0db88f

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

cycode/cyclient/ai_security_manager_client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def create_event(
7979
'event_type': event_type,
8080
'outcome': outcome,
8181
'generation_id': payload.generation_id,
82+
'model': payload.model,
8283
'block_reason': block_reason,
8384
'cli_scan_id': scan_id,
8485
'mcp_server_name': payload.mcp_server_name,

tests/cyclient/test_ai_security_manager_client.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,32 @@ def test_create_event_reports_a_distinct_id_per_hook_event() -> None:
4242
assert len(set(reported_ids)) == 2
4343

4444

45+
def test_create_event_reports_the_model_of_that_event() -> None:
46+
"""A model switch starts no new conversation, so the conversation's model goes stale."""
47+
client, http_client = _build_client()
48+
conversation_id = 'conv-1'
49+
# The same conversation before and after the user switched models.
50+
first = AIHookPayload(event_name='Prompt', conversation_id=conversation_id, model='grok-4.6')
51+
second = AIHookPayload(event_name='Prompt', conversation_id=conversation_id, model='gpt-5.6-sol')
52+
53+
client.create_event(first, AiHookEventType.PROMPT, AIHookOutcome.ALLOWED)
54+
client.create_event(second, AiHookEventType.PROMPT, AIHookOutcome.ALLOWED)
55+
56+
reported_models = [call.kwargs['body']['model'] for call in http_client.post.call_args_list]
57+
assert reported_models == ['grok-4.6', 'gpt-5.6-sol']
58+
59+
60+
def test_create_event_without_a_model_reports_none() -> None:
61+
"""Not every IDE dialect resolves a model (e.g. a Claude Code transcript with no assistant turn yet)."""
62+
client, http_client = _build_client()
63+
64+
client.create_event(
65+
AIHookPayload(event_name='Prompt', conversation_id='conv-1'), AiHookEventType.PROMPT, AIHookOutcome.ALLOWED
66+
)
67+
68+
assert _posted_body(http_client)['model'] is None
69+
70+
4571
def test_create_event_without_a_conversation_posts_nothing() -> None:
4672
client, http_client = _build_client()
4773

0 commit comments

Comments
 (0)