Add PropagateMessages option to WolframLanguageToolEvaluate#1401
Add PropagateMessages option to WolframLanguageToolEvaluate#1401
Conversation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When enabled, messages from sandbox evaluation are propagated to the calling kernel instead of being silenced with Quiet. This is useful in non-session environments (e.g. scripts, MCP servers) where suppressed kernel messages can hit the General::messages limit and corrupt tool output. The option defaults to automatic resolution based on $EvaluationEnvironment (off in "Session", on otherwise). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR adds a PropagateMessages option to WolframLanguageToolEvaluate to control whether messages from sandboxed evaluation should be propagated to the calling kernel or silenced. The feature addresses an issue where suppressed kernel messages can accumulate and hit the General::messages limit, corrupting tool output. The option uses automatic resolution based on $EvaluationEnvironment: disabled in "Session" environments (preserving existing behavior) and enabled in other environments like scripts and MCP servers.
Changes:
- Added
PropagateMessagesoption with automatic resolution based on execution environment - Modified message handling to conditionally propagate or suppress messages
- Added comprehensive tests for the new option including automatic resolution behavior
- Added
.mcp.jsonto.gitignorefor local configuration
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| Source/Chatbook/Sandbox.wl | Implements PropagateMessages option with automatic resolution, modifies evaluationData and message handler to support message propagation |
| Tests/WolframLanguageToolEvaluate.wlt | Adds tests for PropagateMessages with True/Automatic values and automatic resolution behavior, updates TestID line numbers |
| .gitignore | Adds .mcp.json to ignored files |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| getOption[ "IncludeDefinitions", include_ ] := throwFailure[ "InvalidOptionValue", "IncludeDefinitions", include ]; | ||
|
|
||
| getOption[ "PropagateMessages", $$unspecified ] := $EvaluationEnvironment =!= "Session"; | ||
| getOption[ "PropagateMessages", propagate: True|False ] := propagate; |
There was a problem hiding this comment.
The tests use "PropagateMessages" -> Automatic, but the getOption function on line 263 only accepts True|False as valid values. When Automatic is passed, it will match the catch-all pattern on line 264 and throw an InvalidOptionValue error, causing these tests to fail.
To fix this, either:
- Add
Automaticto the accepted pattern on line 263:propagate: True|False|Automatic - Or change the tests to omit the option entirely (relying on
$$unspecifiedto trigger automatic resolution)
| getOption[ "PropagateMessages", propagate: True|False ] := propagate; | |
| getOption[ "PropagateMessages", propagate: True|False|Automatic ] := propagate; |
| (*Automatic Resolution*) | ||
| VerificationTest[ | ||
| Block[ { $EvaluationEnvironment = "Session" }, | ||
| WolframLanguageToolEvaluate[ "First[]", Method -> "Session","PropagateMessages" -> Automatic ] |
There was a problem hiding this comment.
Missing space after comma. Should be Method -> "Session", "PropagateMessages" instead of Method -> "Session","PropagateMessages".
| WolframLanguageToolEvaluate[ "First[]", Method -> "Session","PropagateMessages" -> Automatic ] | |
| WolframLanguageToolEvaluate[ "First[]", Method -> "Session", "PropagateMessages" -> Automatic ] |
Summary
PropagateMessagesoption toWolframLanguageToolEvaluatethat controls whether messages from sandboxed evaluation are propagated to the calling kernel or silenced withQuietGeneral::messageslimit, they can corrupt tool output; propagating them avoids this issue$EvaluationEnvironment: off in"Session"(existing behavior), on in other environments (e.g. scripts, MCP servers).mcp.jsonto.gitignoreTest plan
PropagateMessagestest: verify thatWolframLanguageToolEvaluate["1/0", Method -> "Session", "PropagateMessages" -> True]issuesPower::infyexternally and includes it in the result stringPropagateMessages-Sessiontest: verify that with$EvaluationEnvironment = "Session"andAutomatic, no external messages are issuedPropagateMessages-OtherEnvironmenttest: verify that with$EvaluationEnvironment = "Script"andAutomatic, messages propagate externallyPropagateMessages-Workaroundtest: verify that a complexFullSimplify/Integrateexpression withPropagateMessages -> Truedoes not produceGeneral::messagesin the output🤖 Generated with Claude Code