Repository navigation
fix: accept Grok hook payloads that carry both key spellings - #337
Merged
Merged
Conversation
Every `atomic agent hooks grok` call from a real Grok Build session failed with "duplicate field `hook_event_name`", so no turn was recorded and nothing was attested. Grok sends its own camelCase key and Claude's snake_case key side by side for most top-level fields: `sessionId` and `session_id`, `toolResult` and `tool_response`, and so on. The adapter accepted both spellings through serde `alias`, which rejects two spellings in one payload as a duplicate field. The adapter now folds the spellings of each field into one before deserializing. The camelCase value wins when they differ. The payload passed downstream is unchanged.
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.
Problem
With the
atomic-grokintegration, every hook call from a real Grok Build session fails:atomic agent statusreports all six hooks as failing, no turn is recorded, andatomic agent attest -sstays atAI-authored: 0%. Reported in #290. It reproduces on the released 0.22.1 with Grok Build 1.0.60 (the version in #290) and 1.0.77.Cause
Grok sends its own camelCase key and Claude's snake_case key side by side for most top-level fields, so one payload carries
sessionIdandsession_id,toolNameandtool_name,toolResultandtool_response, and so on.hookEventNameandhook_event_nameeven carry different values (stopandStop). Grok's hooks guide documents this as intended.The adapter accepted both spellings through serde
alias. An alias means either spelling, not both: two spellings in one payload are rejected as a duplicate field. The error nameshook_event_nameonly because it is the first such pair; removing that field alone moves the failure tolast_assistant_message,session_idand the rest.Fix
grok.rsnow lists the spellings of each field in one table (FIELD_SPELLINGS) and folds them into the field name before deserializing. The camelCase value wins when spellings differ, and anullspelling is skipped. The serde aliases are gone, so the table is the only place spellings are defined. The payload passed downstream is unchanged.Tests
tests/grok_real_payloads.rs, using seven payloads captured from a real Grok Build 1.0.77 session as fixtures (all six events; only machine-specific paths rewritten). All seven fail to parse before the fix. Grok Build 1.0.60 sends the same set of fields for every event.nullspelling, every spellingnull, and a tool result under all three spellings.atomic git import,atomic agent enable --agent grok --from … --from-skills …, onegrok -psession that edits a file). With both Grok versions, released 0.22.1 reports all six hooks failing andAI-authored: 0%; with this fix every hook succeeds, the turn is recorded and attest reportsAI-authored: 100%(xAI / Grok Build).cargo test --workspace: 11,400 passed. The 2 failures are the failpoint tests that needadoption-test-injection; both pass with that feature enabled.cargo fmt --all -- --checkclean;cargo clippy -p atomic-agent --all-targetsclean.Not covered
copilot.rsandcline.rsaccept spellings through serdealiasin the same way. Nothing shows those agents sending both spellings, so they are left alone here.