Skip to content

fix(pluginhost): preserve HTTP status codes in host callback errors - #5855

Open
yontani wants to merge 2 commits into
router-for-me:devfrom
yontani:fix/preserve-host-callback-http-status
Open

yontani wants to merge 2 commits into
router-for-me:devfrom
yontani:fix/preserve-host-callback-http-status

Conversation

@yontani

@yontani yontani commented Sep 16, 2026

Copy link
Copy Markdown

Problem

Native host callback errors lose their numeric HTTP status when modelExecutionError returns a plain cause and when the Unix/Windows bridges serialize only err.Error(). A plugin receiving an opaque 503 cannot distinguish it from a terminal request error.

An outer StatusCode accessor can also return 0 while wrapping a valid 429/503. This occurs with the scheduler auth.WithCause/auth_unavailable wrapper, so stopping at the first errors.As match is insufficient.

Change

  • Share a depth-first, pre-order error-tree traversal through Unwrap() error and Unwrap() []error, returning the first valid 400–599 status. Invalid outer accessors do not hide valid causes.
  • Fall back to ErrorMessage.StatusCode, then 500 only when no valid status exists in a model execution error tree.
  • Preserve messages and error identity through Unwrap, including errors.Is and concrete errors.As behavior.
  • Serialize preserved statuses using the existing pluginabi.Error.HTTPStatus field on Unix and Windows. No C ABI/schema change; untyped non-model errors continue to omit status.

Review follow-up

Addressed discussion_r4021543669 in f107e67 with regressions using the real auth.WithCause wrapper and joined error trees.

Validation

Go 1.26.0, Linux ARM64, CGO enabled:

  • Confirmed direct-status regression failure before the original fix.
  • Confirmed zero-status auth_unavailable wrapper regression failure before the review follow-up, then success afterward.
  • go test -p 2 -count=1 ./internal/pluginhost ./sdk/pluginabi ./sdk/api/handlers
  • Server build and targeted race tests for all added test functions.
  • Windows ARM64 test binary cross-compilation (CGO_ENABLED=0); not a Windows runtime test.
  • gofmt and git diff --check.

Tests cover execute/stream-start envelopes, valid/invalid status boundaries, oversized integers, fallback precedence, nested and joined causes, cancellation identity and unchanged messages. The full repository suite was not run.

A release-based equivalent was exercised with the unchanged native fallback plugin and isolated synthetic upstreams: opaque503/429 fallback,400/422 stop,primary success,output-after-failure and cancellation-after-output. The deployment-specific harness is intentionally excluded from this minimal six-file PR.

@github-actions
github-actions Bot changed the base branch from main to dev September 16, 2026 00:49
@github-actions

Copy link
Copy Markdown

This pull request targeted main.

The base branch has been automatically changed to dev.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b557110299

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread internal/pluginhost/host_callbacks.go Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant