Skip to content

Add PropagateMessages option to WolframLanguageToolEvaluate#1401

Merged
rhennigan merged 2 commits intomainfrom
feature/propagate-messages
Feb 21, 2026
Merged

Add PropagateMessages option to WolframLanguageToolEvaluate#1401
rhennigan merged 2 commits intomainfrom
feature/propagate-messages

Conversation

@rhennigan
Copy link
Member

Summary

  • Adds a PropagateMessages option to WolframLanguageToolEvaluate that controls whether messages from sandboxed evaluation are propagated to the calling kernel or silenced with Quiet
  • When suppressed kernel messages accumulate and hit the General::messages limit, they can corrupt tool output; propagating them avoids this issue
  • Defaults to automatic resolution based on $EvaluationEnvironment: off in "Session" (existing behavior), on in other environments (e.g. scripts, MCP servers)
  • Adds .mcp.json to .gitignore

Test plan

  • Run PropagateMessages test: verify that WolframLanguageToolEvaluate["1/0", Method -> "Session", "PropagateMessages" -> True] issues Power::infy externally and includes it in the result string
  • Run PropagateMessages-Session test: verify that with $EvaluationEnvironment = "Session" and Automatic, no external messages are issued
  • Run PropagateMessages-OtherEnvironment test: verify that with $EvaluationEnvironment = "Script" and Automatic, messages propagate externally
  • Run PropagateMessages-Workaround test: verify that a complex FullSimplify/Integrate expression with PropagateMessages -> True does not produce General::messages in the output
  • Verify existing tests still pass (message formatting, print handling, regression tests)

🤖 Generated with Claude Code

rhennigan and others added 2 commits February 20, 2026 18:43
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>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 PropagateMessages option 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.json to .gitignore for 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;
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. Add Automatic to the accepted pattern on line 263: propagate: True|False|Automatic
  2. Or change the tests to omit the option entirely (relying on $$unspecified to trigger automatic resolution)
Suggested change
getOption[ "PropagateMessages", propagate: True|False ] := propagate;
getOption[ "PropagateMessages", propagate: True|False|Automatic ] := propagate;

Copilot uses AI. Check for mistakes.
(*Automatic Resolution*)
VerificationTest[
Block[ { $EvaluationEnvironment = "Session" },
WolframLanguageToolEvaluate[ "First[]", Method -> "Session","PropagateMessages" -> Automatic ]
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space after comma. Should be Method -> "Session", "PropagateMessages" instead of Method -> "Session","PropagateMessages".

Suggested change
WolframLanguageToolEvaluate[ "First[]", Method -> "Session","PropagateMessages" -> Automatic ]
WolframLanguageToolEvaluate[ "First[]", Method -> "Session", "PropagateMessages" -> Automatic ]

Copilot uses AI. Check for mistakes.
@rhennigan rhennigan merged commit 536c90d into main Feb 21, 2026
5 checks passed
@rhennigan rhennigan deleted the feature/propagate-messages branch February 21, 2026 00:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants