Repository navigation
fix(agent): enforce PreToolUse on schema-parsed args and UserPromptSubmit on structured messages - #47
Open
alexb-openrouter wants to merge 1 commit into
Open
alexb-openrouter wants to merge 1 commit into
alexb-openrouter wants to merge 1 commit into
Conversation
…bmit on structured messages
Contributor
|
I'll fix CI failures and address comments from users with write access that start with 'Devin'.
|
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.
Summary
Fixes two lifecycle-hook enforcement gaps in
ModelResult:PreToolUsenow receives schema-parsed arguments and re-validates mutations:PreToolUsereceived rawcall.argumentsbeforeinput_schemadefaults and coercions were applied byexecute_tool. A blocking hook inspectingtool_inputcould miss defaulted or coerced fields (for example,dangerous: bool = Trueomitted from{})._emit_pre_tool_use,_tool_input_for_hooks, and_revalidate_mutated_argumentsinsrc/openrouter_agent/model_result.py(used by both_run_tool_with_hooksand_prepare_tool_calls_for_approval), plus an optionalnormalize_payloadcallback onHooksManager.emit/execute_handler_chainso mutations piped between chainedPreToolUsehandlers are also re-parsed throughinput_schema.PermissionRequest,PostToolUse, andPostToolUseFailurealso receive schema-parsedtool_input.UserPromptSubmitnow fires on SDK typed messages and structured content arrays:_maybe_run_user_prompt_submit/_find_latest_user_string_indexonly matched plaindictitems withisinstance(content, str), skipping typed SDK objects (such asEasyInputMessage) and messages whosecontentis a structured array (such as[{"type": "input_text", "text": "..."}])._extract_user_message_prompt,_find_latest_user_prompt_index, and_replace_user_message_promptto extract text from both plain dicts and typed SDK objects (string content or structured content arrays, including single non-list user message inputs) and applymutated_promptback without mutating caller objects or dropping non-text parts (such asinput_image).Testing
tests/unit/test_lifecycle_hook_enforcement.pycovering both fixes (schema defaults, coercions, chained mutation re-validation, invalid mutation rejection, approval-pathPreToolUse, andUserPromptSubmitrejection/mutation acrossEasyInputMessage, structured content arrays with non-text parts, and single-message inputs).uv run --extra dev ruff check .,uv run --extra dev ruff format --check .,uv run --extra dev pytest tests/unit -q --cov --cov-fail-under=83(189 passed, 85.71% coverage), anduv run --extra dev mypy src tests.