CM-71606: Mint and report a hook event id per guardrail hook - #525
Open
Altruistus wants to merge 1 commit into
Open
CM-71606: Mint and report a hook event id per guardrail hook#525Altruistus wants to merge 1 commit into
Altruistus wants to merge 1 commit into
Conversation
The guardrail scan and the hook event are reported in two separate requests, so neither can learn an id the other assigned. Mint one per AIHookPayload - one payload is one hook event - and send it on both: in the scan metadata, so the detection can name the event it came from, and as the event id itself, the way the conversation id is already sent. A generation id cannot stand in for it: the IDE mints one per prompt, so several hook events share it, and some IDEs supply none at all. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Mint one hook event id per ai-guardrails hook and send it on both requests the hook makes, so a Cycode violation can be resolved back to the exact hook event that produced it.
Changes
AIHookPayload.hook_event_id— a UUID minted per payload viadefault_factory. One payload is one hook event, so no per-IDE parser has to change.build_ai_guardrails_scan_parameters— sends it in the guardrail scan metadata, alongsideconversation_id/generation_id.AISecurityManagerClient.create_event— sends it as the event'sid, the same waycreate_conversationalready sends the conversation id.idis the payload's, and two hooks of one prompt report distinct ids).Why
A guardrail hook makes two independent requests: the scan (which becomes a violation) and the hook event report. Neither can learn an id the other was assigned, and the event is reported in the handler's
finally— after the scan has already gone out. Minting the id here is what lets both name the same event without either waiting on the other.generation_idcannot stand in for it. The IDE mints one per prompt, so every hook of that prompt shares it, and some IDEs supply none at all —codexreadsturn_id,cursorreadsgeneration_id,claude-codedigs it out of the transcript and may come back withNone.Both consumers already tolerate its absence, so this can ship independently:
idas optional and mints one itself when it is missing, and accepts a redelivery of an id it already stored (this hook path retries on network failure).hook_event_iddetection detail entirely when it is not sent.Testing
pytest tests/cyclient/test_ai_security_manager_client.py tests/cli/commands/ai_guardrails/— 302 passed.🤖 Generated with Claude Code