Skip to content

Hooks: ErrorFixNudgeRule crashes on string toolArgs ('str' object has no attribute 'get') #965

@magicpro97

Description

@magicpro97

Summary

hooks/rules/error_kb.py ErrorFixNudgeRule.evaluate() does tool_args = data.get('toolArgs', {}) or {} then tool_args.get('command', ''). When the runtime passes toolArgs as a non-empty string (e.g. a JSON string), or {} keeps the string and .get() raises 'str' object has no attribute 'get'.

Impact (Facts)

  • ~/.copilot/markers/audit.jsonl recorded 367 entries: event=postToolUse rule=error-fix-nudge decision=error detail="'str' object has no attribute 'get'".
  • Hooks fail-open, so work is not blocked, but the rule never runs (no error→fix→learn nudge) and the audit log is polluted.

Root cause

toolArgs shape is not normalized; a string value is not coerced/parsed.

Fix

Normalize toolArgs: if it is a JSON string, parse it to a dict; otherwise coerce any non-dict to {}. This also preserves the learn.py marker-clear behavior when args arrive as a JSON string.

Acceptance criteria

  • String toolArgs no longer crashes the rule.
  • JSON-string toolArgs is parsed so the nudge still clears on learn.py.
  • Regression test added.
  • tests/test_hook_rules_more.py passes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions