fix background validator#241
Merged
whotwagner merged 1 commit intoJun 11, 2026
Merged
Conversation
whotwagner
approved these changes
Jun 11, 2026
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 #242
Fix MsfSessionCommand background validator unconditionally rejecting all commands (API or MCP)
The bg_not_implemented_yet field validator on MsfSessionCommand raised ValueError on every instantiation, regardless of whether background was actually set to True. Since Pydantic runs all validators when building a model including for default values every msf-session command failed validation with a 422 Unprocessable Entity before reaching the executor.
Direct playbooks: AttackMate parses YAML and calls model_validate() with only the fields present in the YAML. Since background is not in the YAML, Pydantic treats it as "not provided" and by default in Pydantic v2 (validate_default=False) does not run validators on fields that use their default value. The validator never fires.
Via API/MCP: FastAPI validates the JSON request body against RemotelyExecutableCommand, which is a Pydantic discriminated union. When resolving which subtype to use, Pydantic explicitly constructs the full model including all fields, causing the background validator to run even on the default False value. triggers the unconditional raise → 422.
Fixed by adding a if v: guard so the error is only raised when background=True is explicitly requested, and returning the value otherwise.
Description
Checklist