Skip to content

fix: accept Grok hook payloads that carry both key spellings - #337

Merged
vinceblock99 merged 1 commit into
devfrom
fix/grok-hook-duplicate-aliases
Nov 13, 2026
Merged

vinceblock99 merged 1 commit into
devfrom
fix/grok-hook-duplicate-aliases

Conversation

@vinceblock99

@vinceblock99 vinceblock99 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Problem

With the atomic-grok integration, every hook call from a real Grok Build session fails:

Internal error: Failed to parse hook input for grok stop: Failed to parse hook input for grok (turn_end): duplicate field `hook_event_name`

atomic agent status reports all six hooks as failing, no turn is recorded, and atomic agent attest -s stays at AI-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 sessionId and session_id, toolName and tool_name, toolResult and tool_response, and so on. hookEventName and hook_event_name even carry different values (stop and Stop). 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 names hook_event_name only because it is the first such pair; removing that field alone moves the failure to last_assistant_message, session_id and the rest.

Fix

grok.rs now 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 a null spelling is skipped. The serde aliases are gone, so the table is the only place spellings are defined. The payload passed downstream is unchanged.

Tests

  • New 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.
  • New unit tests for spellings that disagree, a null spelling, every spelling null, and a tool result under all three spellings.
  • End to end with real Grok Build 1.0.60 and 1.0.77, following the steps in atomic agent hooks grok: every hook from a real Grok 1.0.60 session fails with 'duplicate field hook_event_name' #290 (Git repo, atomic git import, atomic agent enable --agent grok --from … --from-skills …, one grok -p session that edits a file). With both Grok versions, released 0.22.1 reports all six hooks failing and AI-authored: 0%; with this fix every hook succeeds, the turn is recorded and attest reports AI-authored: 100% (xAI / Grok Build).
  • cargo test --workspace: 11,400 passed. The 2 failures are the failpoint tests that need adoption-test-injection; both pass with that feature enabled.
  • cargo fmt --all -- --check clean; cargo clippy -p atomic-agent --all-targets clean.

Not covered

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.
@vinceblock99
vinceblock99 merged commit 057c222 into dev Nov 13, 2026
10 checks passed
@vinceblock99
vinceblock99 deleted the fix/grok-hook-duplicate-aliases branch November 13, 2026 16:49
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.

1 participant