Skip to content

Conversation

@nathaliellenaa
Copy link
Contributor

Description

There's an issue when executing ReadFromScratchPadTool or WriteToScratchPadTool with empty parameters through the execute tool API. While these tools should support empty parameter execution, they currently throw an exception:

POST /_plugins/_ml/tools/_execute/ReadFromScratchPadTool
{
  "parameters": {}
}

// Exception thrown
{
    "status": 500,
    "error": {
        "type": "NotSerializableExceptionWrapper",
        "reason": "System Error",
        "details": "unsupported_operation_exception: null"
    }
}

The issue is due to the immutable map implementations being passed to these tools. These tools expect to modify the parameters map during execution (reference). When they attempt to call parameters.put() on an immutable map, an UnsupportedOperationException is thrown.

To fix this issue, we need to ensure these tools always receive a mutable map by creating a mutable copy of the parameters before passing them to the tools. This will allow the tools to modify the parameters as needed during execution, even when starting with empty parameters.

Test with current fix:

POST /_plugins/_ml/tools/_execute/ReadFromScratchPadTool
{
  "parameters": {}
}


// Successful response
{
    "inference_results": [
        {
            "output": [
                {
                    "name": "response",
                    "result": "Scratchpad is empty."
                }
            ]
        }
    ]
}

Related Issues

Resolves #[Issue number to be closed when this PR is merged]

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff.
  • Public documentation issue/PR created.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@nathaliellenaa nathaliellenaa temporarily deployed to ml-commons-cicd-env-require-approval October 17, 2025 22:16 — with GitHub Actions Inactive
@nathaliellenaa nathaliellenaa had a problem deploying to ml-commons-cicd-env-require-approval October 17, 2025 22:16 — with GitHub Actions Failure
@nathaliellenaa nathaliellenaa temporarily deployed to ml-commons-cicd-env-require-approval October 17, 2025 22:16 — with GitHub Actions Inactive
@nathaliellenaa nathaliellenaa had a problem deploying to ml-commons-cicd-env-require-approval October 17, 2025 22:16 — with GitHub Actions Error
Copy link
Collaborator

@mingshl mingshl left a comment

Choose a reason for hiding this comment

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

the fix makes sense, because scratch pad string is updated through multiple tool use in one agent execution, so it should be mutable parameters in toolExecution.

@nathaliellenaa nathaliellenaa had a problem deploying to ml-commons-cicd-env-require-approval October 21, 2025 00:08 — with GitHub Actions Failure
@nathaliellenaa nathaliellenaa temporarily deployed to ml-commons-cicd-env-require-approval October 21, 2025 00:08 — with GitHub Actions Inactive
@codecov
Copy link

codecov bot commented Oct 21, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.08%. Comparing base (305cb8e) to head (d9f8644).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #4325      +/-   ##
============================================
- Coverage     80.09%   80.08%   -0.01%     
+ Complexity    10199    10198       -1     
============================================
  Files           855      855              
  Lines         44373    44374       +1     
  Branches       5135     5135              
============================================
  Hits          35539    35539              
  Misses         6670     6670              
- Partials       2164     2165       +1     
Flag Coverage Δ
ml-commons 80.08% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@nathaliellenaa nathaliellenaa temporarily deployed to ml-commons-cicd-env-require-approval October 21, 2025 01:23 — with GitHub Actions Inactive
@nathaliellenaa nathaliellenaa had a problem deploying to ml-commons-cicd-env-require-approval October 21, 2025 02:47 — with GitHub Actions Failure
@nathaliellenaa nathaliellenaa had a problem deploying to ml-commons-cicd-env-require-approval October 21, 2025 02:47 — with GitHub Actions Error
@ylwu-amzn ylwu-amzn temporarily deployed to ml-commons-cicd-env-require-approval October 21, 2025 17:20 — with GitHub Actions Inactive
@ylwu-amzn ylwu-amzn had a problem deploying to ml-commons-cicd-env-require-approval October 21, 2025 17:20 — with GitHub Actions Failure
@ylwu-amzn ylwu-amzn temporarily deployed to ml-commons-cicd-env-require-approval October 21, 2025 17:20 — with GitHub Actions Inactive
@nathaliellenaa nathaliellenaa temporarily deployed to ml-commons-cicd-env-require-approval October 21, 2025 20:09 — with GitHub Actions Inactive
@nathaliellenaa nathaliellenaa had a problem deploying to ml-commons-cicd-env-require-approval October 21, 2025 20:09 — with GitHub Actions Failure
@nathaliellenaa nathaliellenaa had a problem deploying to ml-commons-cicd-env-require-approval October 21, 2025 20:09 — with GitHub Actions Failure
@nathaliellenaa nathaliellenaa temporarily deployed to ml-commons-cicd-env-require-approval October 21, 2025 20:09 — with GitHub Actions Inactive
@nathaliellenaa nathaliellenaa had a problem deploying to ml-commons-cicd-env-require-approval October 23, 2025 22:00 — with GitHub Actions Error
@nathaliellenaa nathaliellenaa had a problem deploying to ml-commons-cicd-env-require-approval October 23, 2025 22:00 — with GitHub Actions Error
@nathaliellenaa nathaliellenaa had a problem deploying to ml-commons-cicd-env-require-approval October 23, 2025 22:00 — with GitHub Actions Failure
@nathaliellenaa nathaliellenaa had a problem deploying to ml-commons-cicd-env-require-approval October 23, 2025 22:00 — with GitHub Actions Failure
@nathaliellenaa nathaliellenaa requested a deployment to ml-commons-cicd-env-require-approval October 24, 2025 16:49 — with GitHub Actions Waiting
@nathaliellenaa nathaliellenaa requested a deployment to ml-commons-cicd-env-require-approval October 24, 2025 16:49 — with GitHub Actions Waiting
@nathaliellenaa nathaliellenaa requested a deployment to ml-commons-cicd-env-require-approval October 24, 2025 16:49 — with GitHub Actions Waiting
@nathaliellenaa nathaliellenaa requested a deployment to ml-commons-cicd-env-require-approval October 24, 2025 16:49 — with GitHub Actions Waiting
Signed-off-by: Nathalie Jonathan <nathhjo@amazon.com>
@nathaliellenaa nathaliellenaa temporarily deployed to ml-commons-cicd-env-require-approval October 26, 2025 01:29 — with GitHub Actions Inactive
@nathaliellenaa nathaliellenaa temporarily deployed to ml-commons-cicd-env-require-approval October 26, 2025 01:29 — with GitHub Actions Inactive
@nathaliellenaa nathaliellenaa temporarily deployed to ml-commons-cicd-env-require-approval October 26, 2025 01:29 — with GitHub Actions Inactive
@nathaliellenaa nathaliellenaa temporarily deployed to ml-commons-cicd-env-require-approval October 26, 2025 01:29 — with GitHub Actions Inactive
@nathaliellenaa nathaliellenaa had a problem deploying to ml-commons-cicd-env-require-approval October 26, 2025 04:15 — with GitHub Actions Error
@nathaliellenaa nathaliellenaa had a problem deploying to ml-commons-cicd-env-require-approval October 26, 2025 04:15 — with GitHub Actions Failure
@ylwu-amzn ylwu-amzn merged commit 7b43d61 into opensearch-project:main Oct 27, 2025
11 of 13 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Oct 27, 2025
Signed-off-by: Nathalie Jonathan <nathhjo@amazon.com>
(cherry picked from commit 7b43d61)
ylwu-amzn pushed a commit that referenced this pull request Oct 28, 2025
(cherry picked from commit 7b43d61)

Signed-off-by: Nathalie Jonathan <nathhjo@amazon.com>
Co-authored-by: Nathalie Jonathan <143617992+nathaliellenaa@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants