Repository navigation
fix(s04, s05): register log_hook before permission_hook so denied calls get logged - #660
Open
shuhuNB515 wants to merge 1 commit into
Open
shuhuNB515 wants to merge 1 commit into
shuhuNB515 wants to merge 1 commit into
Conversation
log_hook's docstring promises 'log every tool call', but it was registered after permission_hook, and trigger_hooks short-circuits on the first non-None result. Every denied call therefore produced no [HOOK] line -- the calls most worth logging left no trace. Register log_hook first: it returns None so it never blocks, the permission outcome is unchanged, and denied calls now get logged too. A short comment records the ordering intent. Same change in s04 and s05 (s05 inherits the hooks chapter's setup), plus the matching embedded sources in the web registry. Fixes shareAI-lab#654
This branch has not been deployed
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.
Fixes #654
Problem
s04_hooks/code.py(and the inherited copy ins05_todo_write/code.py) registers:trigger_hooksruns callbacks in registration order and returns on the first non-None result (code.py:142-147). So for any call thatpermission_hookdenies,log_hook— whose docstring says "log every tool call" — never runs. The denied calls, exactly the ones you want in a log when debugging permission behavior, produced no[HOOK]output at all.Fix
Swap the registration order in both chapters and add a two-line comment recording why:
log_hookreturnsNone, so it can't influence the permission decision — only the log coverage changes. This also doubles as a small illustration of the hook-ordering semantics the chapter teaches. (The alternative — rewording the docstring to "every allowed call" — is fine too; I picked the reorder since the log is most useful when it sees denials.)Verification
bashcall now prints[HOOK] bash(...)before being denied, the denial verdict is byte-identical, an allowed call still passes through withNone, and the registration order is["log_hook", "permission_hook"]in both s04 and s05.python3 -m pytest tests/— 503 passed, 118 subtests passed.web/src/data/generated/versions.json(s04 + s05) synced, as asserted bytests/test_web_scenarios.py.Disclosed AI assistance: found and fixed during an AI-assisted review; I verified the behavior before/after and stand behind the change.