Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ai-proxy): prevent shared state #13028

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

fix(ai-proxy): prevent shared state #13028

wants to merge 4 commits into from

Conversation

Tieske
Copy link
Member

@Tieske Tieske commented May 14, 2024

The object initializer (new) would set properties on class instead of on the instance. Also cleans up some code.

I have added comments on the actual bug, everything else is cosmetic/cleanup. Please review with whitespace changes disabled in the github UI.

Summary

Checklist

  • The Pull Request has tests
  • A changelog file has been created under changelog/unreleased/kong or skip-changelog label added on PR if changelog is unnecessary. README.md
  • There is a user-facing docs PR against https://github.com/Kong/docs.konghq.com - PUT DOCS PR HERE

Issue reference

Internal ticket: AG-44

The object initializer (new) would set properties on the
parent instead of on the instance.
-- @treturn[2] nil
-- @treturn[2] string An error message if instantiation failed
function _M.new_driver(conf, http_opts)
local self = {
Copy link
Member Author

Choose a reason for hiding this comment

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

Comment to reviewers: self was pointing to _M in the old code. So setting self.conf, self.http_opts, and self.driver would actually modify the class, and not the instance.

if not ai_driver then
return internal_server_error(err)
end

-- if asked, introspect the request before proxying
kong.log.debug("introspecting request with LLM")
local new_request_body, err = llm:ai_introspect_body(
local new_request_body, err = ai_driver:ai_introspect_body(
Copy link
Member Author

Choose a reason for hiding this comment

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

Comment to reviewers: The old code would call on llm (the class) instead of on ai_driver (the instance).

@@ -123,7 +129,7 @@ function _M:access(conf)
-- if asked, introspect the request before proxying
kong.log.debug("introspecting response with LLM")

local new_response_body, err = llm:ai_introspect_body(
local new_response_body, err = ai_driver:ai_introspect_body(
Copy link
Member Author

Choose a reason for hiding this comment

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

Comment to reviewers: The old code would call on llm (the class) instead of on ai_driver (the instance).

@Tieske Tieske marked this pull request as ready for review May 15, 2024 12:57
@Tieske Tieske requested a review from tysoekong May 15, 2024 13:11
return internal_server_error(err)
kong_ctx_shared.skip_response_transformer = true
kong.log.err("failed to configure request for AI service: ", err)
return kong.response.exit(500)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we response with the error message?

Suggested change
return kong.response.exit(500)
return kong.response.exit(500, { error = { message = err } })

Copy link
Member Author

Choose a reason for hiding this comment

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

No, this is an internal server error. Targeted at the admin of the system (hence the log line), it is of no concern for the end user.

@@ -0,0 +1,3 @@
message: "**AI-Proxy**: object constructor would set data on the class instead of the instance"
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's not necessary to have a changelog for an internal refracting PR

Copy link
Member Author

Choose a reason for hiding this comment

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

It is a bugfix, so the changelog should be here imho

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.

None yet

3 participants