Skip to content

fix(ai-prompt-decorator): prevent message accumulation across requests#12582

Merged
nic-6443 merged 2 commits into
apache:masterfrom
oil-oil:fix/ai-prompt-decorator-message-accumulation
Sep 4, 2025
Merged

fix(ai-prompt-decorator): prevent message accumulation across requests#12582
nic-6443 merged 2 commits into
apache:masterfrom
oil-oil:fix/ai-prompt-decorator-message-accumulation

Conversation

@oil-oil

@oil-oil oil-oil commented Sep 3, 2025

Copy link
Copy Markdown
Contributor

Description

The ai-prompt-decorator plugin accumulated user messages across multiple requests due to a Lua table reference issue.

Root Cause:

  local new_messages = conf.prepend or EMPTY  -- Direct reference, not copy
  This caused new_messages to point to the same table as conf.prepend, so modifications accumulated in the original configuration.

Solution:

  local messages = {}
  if conf.prepend then
      for i = 1, #conf.prepend do
          messages[i] = conf.prepend[i]  -- Deep copy instead of reference
      end
  end

Changes: Created new table instead of referencing conf.prepend

Fiexed issue: #12532

Which issue(s) this PR fixes:

Fixes #

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working labels Sep 3, 2025

@ronething ronething left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm

@nic-6443
nic-6443 merged commit 38ea6f8 into apache:master Sep 4, 2025
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants