Skip to content

fix: set org header for AI Fix #106

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

Merged
merged 5 commits into from
Jul 28, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions llm/api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (d *DeepCodeLLMBindingImpl) runExplain(ctx context.Context, options Explain
}
}

responseBody, err := d.submitRequest(ctx, u, requestBody)
responseBody, err := d.submitRequest(ctx, u, requestBody, "", "")
Copy link
Contributor Author

@ShawkyZ ShawkyZ Jul 28, 2025

Choose a reason for hiding this comment

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

requestId and orgId weren't being set before for explain. I will leave it as is for now.

if err != nil {
return Explanations{}, err
}
Expand All @@ -62,7 +62,7 @@ func (d *DeepCodeLLMBindingImpl) runExplain(ctx context.Context, options Explain
return explains, nil
}

func (d *DeepCodeLLMBindingImpl) submitRequest(ctx context.Context, url *url.URL, requestBody []byte) ([]byte, error) {
func (d *DeepCodeLLMBindingImpl) submitRequest(ctx context.Context, url *url.URL, requestBody []byte, requestId string, orgId string) ([]byte, error) {
logger := d.logger.With().Str("method", "submitRequest").Logger()
logger.Trace().Str("payload body: %s\n", string(requestBody)).Msg("Marshaled payload")

Expand All @@ -72,7 +72,7 @@ func (d *DeepCodeLLMBindingImpl) submitRequest(ctx context.Context, url *url.URL
return nil, err
}

d.addDefaultHeaders(req)
d.addDefaultHeaders(req, requestId, orgId)

resp, err := d.httpClientFunc().Do(req) //nolint:bodyclose // this seems to be a false positive
if err != nil {
Expand Down Expand Up @@ -142,7 +142,7 @@ func (d *DeepCodeLLMBindingImpl) runAutofix(ctx context.Context, requestId strin
}

logger.Info().Msg("Started obtaining autofix Response")
responseBody, err := d.submitRequest(ctx, endpoint, requestBody)
responseBody, err := d.submitRequest(ctx, endpoint, requestBody, requestId, options.CodeRequestContext.Org.PublicId)
logger.Info().Msg("Finished obtaining autofix Response")

if err != nil {
Expand Down Expand Up @@ -199,11 +199,11 @@ func (d *DeepCodeLLMBindingImpl) autofixRequestBody(options *AutofixOptions) ([]
return requestBody, err
}

func (d *DeepCodeLLMBindingImpl) submitAutofixFeedback(ctx context.Context, requestId string, options AutofixFeedbackOptions) error {
func (d *DeepCodeLLMBindingImpl) submitAutofixFeedback(ctx context.Context, fixId string, options AutofixFeedbackOptions) error {
span := d.instrumentor.StartSpan(ctx, "code.SubmitAutofixFeedback")
defer span.Finish()

logger := d.logger.With().Str("method", "code.SubmitAutofixFeedback").Str("requestId", requestId).Logger()
logger := d.logger.With().Str("method", "code.SubmitAutofixFeedback").Str("fixId", fixId).Logger()

endpoint, err := url.Parse(fmt.Sprintf("%s/autofix/event", options.Host))
if err != nil {
Expand All @@ -218,7 +218,7 @@ func (d *DeepCodeLLMBindingImpl) submitAutofixFeedback(ctx context.Context, requ
}

logger.Info().Msg("Started obtaining autofix Response")
_, err = d.submitRequest(ctx, endpoint, requestBody)
_, err = d.submitRequest(ctx, endpoint, requestBody, "", options.CodeRequestContext.Org.PublicId)
logger.Info().Msg("Finished obtaining autofix Response")

return err
Expand Down Expand Up @@ -257,7 +257,14 @@ func prepareDiffs(diffs []string) []string {
return encodedDiffs
}

func (d *DeepCodeLLMBindingImpl) addDefaultHeaders(req *http.Request) {
func (d *DeepCodeLLMBindingImpl) addDefaultHeaders(req *http.Request, requestId string, orgId string) {
// if requestId is empty it will be enriched from the Gateway
if len(requestId) > 0 {
req.Header.Set("snyk-request-id", requestId)
}
if len(orgId) > 0 {
req.Header.Set("snyk-org-name", orgId)
}
req.Header.Set("Cache-Control", "private, max-age=0, no-cache")
req.Header.Set("Content-Type", "application/json")
}
6 changes: 3 additions & 3 deletions llm/binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ type DeepCodeLLMBindingImpl struct {
instrumentor observability.Instrumentor
}

func (d *DeepCodeLLMBindingImpl) SubmitAutofixFeedback(ctx context.Context, requestId string, options AutofixFeedbackOptions) error {
func (d *DeepCodeLLMBindingImpl) SubmitAutofixFeedback(ctx context.Context, fixId string, options AutofixFeedbackOptions) error {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this wasn't the requestID
LS is sending the fixId here

We will need to refactor this after the planned hotfix.

method := "SubmitAutofixFeedback"
span := d.instrumentor.StartSpan(ctx, method)
defer d.instrumentor.Finish(span)
logger := d.logger.With().Str("method", method).Str("requestId", requestId).Logger()
logger := d.logger.With().Str("method", method).Str("fixId", fixId).Logger()
logger.Info().Msg("Started submitting autofix feedback")
defer logger.Info().Msg("Finished submitting autofix feedback")

err := d.submitAutofixFeedback(ctx, requestId, options)
err := d.submitAutofixFeedback(ctx, fixId, options)
return err
}

Expand Down