Debug a wrong lesson from the failure hook by replaying the failure payload
When to use#
A PostToolUseFailure hook injected a lesson that has nothing to do with the error, or none when one should match, and you want to see why and check a fix.
Steps#
Save the failure as a hook payload, with the exact command and error text (a Python
json.dumpskeeps quotes and newlines right):Replay it with a throwaway state folder, so the "once per session" rule and your real session log do not interfere:
; XDG_STATE_HOME=/stateOutput with
<rkb-lesson id=...>means it injected; no output means it did not.Add
RKB_NO_MODEL=1to test the word-coverage fallback that runs when the model is cold or times out; without it you test the model path.To see the search query the hook built, print
rkb_core::hooks::error_query(command, error)from a scratch test, then runrkb search "<query>" --format jsonand look atranked_byand eachrelevance.After a fix, build and replay the same payload; it must give the expected result.
Evidence#
rkb, 2026-09-29: a sed syntax error injected an unrelated pi lesson. The replay reproduced it; the printed query showed a line of plain grep output taken as an error line (the error words lacked invalid) and a 3-word line counted as a strong match. After the fix (rkb commit 4b129d3), the same replay injected nothing, with rkb 0.0.6 in 0.56 s.
Also found by searching
- PostToolUseFailure hook injected <rkb-lesson id=...> about pi for a sed syntax error
- the failure hook keeps suggesting an unrelated lesson for my error, I want to reproduce why
- how do I replay a tool failure payload through rkb hook tool-failed to debug which lesson it picks?
- XDG_STATE_HOME throwaway state, RKB_NO_MODEL=1 fallback, print error_query to see the search terms
- PostToolUseFailure hook injected an irrelevant rkb lesson for my error, how do I debug
- how do I replay a failed tool call through the rkb hook to see which lesson matches?
- rkb hook shows no lesson when one should match, test with a payload json
- simulate hook payload session_id cwd tool_name error with throwaway state folder