Skip to content
This repository was archived by the owner on Sep 11, 2025. It is now read-only.

Conversation

mattjohnsonpint
Copy link
Member

This PR does the following:

  • Changes how HTTP 4xx errors are handled by the Runtime when invoking models. Previously, any body content on such an error was logged but not returned to user code, so it was not possible to take specific action or return the error response to the end-user. Going forward, the body of error responses will not be in the logs, but will be returned to user code.
  • Introduces an optional Validator function that can be set on any model in the models interface. If provided, the validator can be used to determine if the response is the expected model output, or a well-known error response.
  • Implements the validator for the OpenAI Chat Completions model interface.
  • Ensures that top-level error messages returned from a user's function are returned in the GraphQL response.

The net result is that when a model returns a structured error object, we can now show the message from that error in the API output.

This affects the Runtime and the Go SDK. A similar PR is forthcoming for AssemblyScript in #864, but is waiting on some json-as fixes before it's ready.

@Copilot Copilot AI review requested due to automatic review settings May 28, 2025 20:03
@mattjohnsonpint mattjohnsonpint requested a review from a team as a code owner May 28, 2025 20:03
Copy link

linear bot commented May 28, 2025

Copy link

trunk-io bot commented May 28, 2025

Running Code Quality on PRs by uploading data to Trunk will soon be removed. You can still run checks on your PRs using trunk-action - see the migration guide for more information.

Copy link
Contributor

@Copilot 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 changes error handling so that structured error responses from models and host functions are returned to caller code rather than swallowed, and introduces an optional validator mechanism for model outputs.

  • Adds a Validator hook on ModelBase to detect and bubble up model‐returned errors, with an implementation for the OpenAI chat API.
  • Updates HTTP utilities (sendHttp, PostHttp) to return both the response body and an error for non-200 status codes.
  • Adjusts WASM host logic to propagate guest function errors and ensures error bodies make it into GraphQL responses.

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
sdk/go/tools/modus-go-build/codegen/preprocess.go Generates os.Exit(1) in wrappers to terminate on error.
sdk/go/pkg/models/openai/chat.go Adds validateChatModelResponse (uses gjson) and validator hook.
sdk/go/pkg/models/models.go Introduces Validator to ModelBase and plugs it into Invoke.
runtime/utils/http.go Modifies sendHttp / PostHttp to return body + error; retains commented legacy code.
runtime/models/models.go Propagates both data and error from PostToModelEndpoint.
runtime/wasmhost/hostfns.go Reorders error checks and removes early exit on host function failures.
runtime/wasmhost/fncall.go Updates log message for non-zero exit code.
runtime/graphql/datasource/source.go Parses and clears WASM exit errors to include user-visible errors.
CHANGELOG.md Adds entry for this feature in Go SDK changelog.
Comments suppressed due to low confidence (1)

sdk/go/pkg/models/openai/chat.go:329

  • The gjson package is used here but not imported. Add import "github.com/tidwall/gjson" to the top of the file to resolve the reference.
result := gjson.GetBytes(data, "error")

@mattjohnsonpint mattjohnsonpint merged commit 9566a5c into main May 28, 2025
50 checks passed
@mattjohnsonpint mattjohnsonpint deleted the mjp/hyp-3400-forward-model-invocation-errors branch May 28, 2025 21:24
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants