Skip to content

Conversation

@codefromthecrypt
Copy link
Collaborator

Improves error handling reliability for OpenAI-compatible providers and adds comprehensive test coverage.

I tried using Goose through a gateway which had an incorrect max payload size. The gateway returned a plain text error.

Before, the underlying error was obfuscated by a JSON failure: Error: Request failed: error decoding response body

$ goose run --debug -t 'should I install goose?'
starting session | provider: openai model: qwen3
    logging to /Users/codefromthecrypt/.local/share/goose/sessions/20250819_090611.jsonl
    working directory: /Users/codefromthecrypt/oss/goose
Error: Request failed: error decoding response body
Interrupted before the model replied and removed the last message.
  error: The error above was an exception we were not able to handle.
These errors are often related to connection or authentication
We've removed the conversation up to the most recent user message
- depending on the error you may be able to continue

Now, the error is easier to see:
Error: Request failed: Request failed with status: 413 Payload Too Large

$  ./target/debug/goose run --debug -t 'should I install goose?'
starting session | provider: openai model: qwen3
    logging to /Users/codefromthecrypt/.local/share/goose/sessions/20250819_090540.jsonl
    working directory: /Users/codefromthecrypt/oss/goose
  2025-08-19T02:05:53.160383Z  WARN goose::providers::utils: Provider request failed with status: 413 Payload Too Large. Payload: None. Returning error: RequestFailed("Request failed with status: 413 Payload Too Large")
    at crates/goose/src/providers/utils.rs:113

Error: Request failed: Request failed with status: 413 Payload Too Large
Interrupted before the model replied and removed the last message.
  error: The error above was an exception we were not able to handle.
These errors are often related to connection or authentication
We've removed the conversation up to the most recent user message
- depending on the error you may be able to continue

Changes:

  • Add PartialEq derive to ProviderError enum to enable testing
  • Refactor handle_status_openai_compat to improve error parsing and reduce complexity
  • Enhance authentication error message formatting with cleaner conditional logic
  • Add comprehensive test suite covering various error scenarios and edge cases
  • Improve function documentation with clear references to OpenAI error codes

Impact:

  • More reliable error handling when provider APIs return malformed responses
  • Better error messages for authentication failures
  • Increased test coverage prevents regressions in error handling logic
  • Cleaner code structure improves maintainability

@michaelneale
Copy link
Collaborator

michaelneale commented Aug 19, 2025

thanks Adrian tagging @DOsinga as I know he had designs on making openai and providers more declarative and configurable

will need a good old cargo fmt run of course

Improves error handling reliability for OpenAI-compatible providers and adds comprehensive test coverage.

I tried using Goose through a gateway which had an incorrect max payload size. The gateway returned a plain text error.

Before, the underlying error was obfuscated by a JSON failure:
`Error: Request failed: error decoding response body`
```bash
$ goose run --debug -t 'should I install goose?'
starting session | provider: openai model: qwen3
    logging to /Users/codefromthecrypt/.local/share/goose/sessions/20250819_090611.jsonl
    working directory: /Users/codefromthecrypt/oss/goose
Error: Request failed: error decoding response body
Interrupted before the model replied and removed the last message.
  error: The error above was an exception we were not able to handle.
These errors are often related to connection or authentication
We've removed the conversation up to the most recent user message
- depending on the error you may be able to continue
```

Now, the error is easier to see:
`Error: Request failed: Request failed with status: 413 Payload Too Large`
```bash
$  ./target/debug/goose run --debug -t 'should I install goose?'
starting session | provider: openai model: qwen3
    logging to /Users/codefromthecrypt/.local/share/goose/sessions/20250819_090540.jsonl
    working directory: /Users/codefromthecrypt/oss/goose
  2025-08-19T02:05:53.160383Z  WARN goose::providers::utils: Provider request failed with status: 413 Payload Too Large. Payload: None. Returning error: RequestFailed("Request failed with status: 413 Payload Too Large")
    at crates/goose/src/providers/utils.rs:113

Error: Request failed: Request failed with status: 413 Payload Too Large
Interrupted before the model replied and removed the last message.
  error: The error above was an exception we were not able to handle.
These errors are often related to connection or authentication
We've removed the conversation up to the most recent user message
- depending on the error you may be able to continue
```

**Changes:**
- Add `PartialEq` derive to `ProviderError` enum to enable testing
- Refactor `handle_status_openai_compat` to improve error parsing and reduce complexity
- Enhance authentication error message formatting with cleaner conditional logic
- Add comprehensive test suite covering various error scenarios and edge cases
- Improve function documentation with clear references to OpenAI error codes

**Impact:**
- More reliable error handling when provider APIs return malformed responses
- Better error messages for authentication failures
- Increased test coverage prevents regressions in error handling logic
- Cleaner code structure improves maintainability

Signed-off-by: Adrian Cole <[email protected]>
Signed-off-by: Adrian Cole <[email protected]>
@codefromthecrypt
Copy link
Collaborator Author

rebased!

@michaelneale
Copy link
Collaborator

running now...

Signed-off-by: Adrian Cole <[email protected]>
Signed-off-by: Adrian Cole <[email protected]>
@michaelneale
Copy link
Collaborator

get it in when the lights are green!

@codefromthecrypt
Copy link
Collaborator Author

I see 💚

@DOsinga DOsinga merged commit 9d9fb06 into block:main Aug 22, 2025
10 checks passed
@codefromthecrypt codefromthecrypt deleted the non-json-error branch August 23, 2025 01:11
michaelneale added a commit that referenced this pull request Aug 24, 2025
* main:
  docs: Plan tutorial (#4309)
  Extensions Modal Improvements (#4293)
  docs: fixed cicd tutorial pipeline in docs (#4223)
  Read oltp config from config and env (#4292)
  release/1.6.0 (#4280)
  docs: fix broken links in Docker tutorial (#4285)
  Remove half-second wait, rework auto submit (#4282)
  Block send until extensions are ready (#4271)
  fix: improve OpenAI-compatible error handling and add test coverage (#4175)
  Move To-Do Tool to Session Scope from Agent Scope (#4157)
  fix: recipe params not being replaced all the time (#4207)
  chore: removing little-used session sharing feature (#4249)
  Stop auto scrolling when agent responds and let scroll area handle scrolling to bottom (#4257)
  restore cli projects from accidental removal during cleanup (#4266)
  Fix: deep link extension installation to show dialog for headers configuration (#4150)
michaelneale added a commit that referenced this pull request Aug 25, 2025
* main: (24 commits)
  feat: autovisualiser of structured data with mcp-ui (#4153)
  docs: Plan tutorial (#4309)
  Extensions Modal Improvements (#4293)
  docs: fixed cicd tutorial pipeline in docs (#4223)
  Read oltp config from config and env (#4292)
  release/1.6.0 (#4280)
  docs: fix broken links in Docker tutorial (#4285)
  Remove half-second wait, rework auto submit (#4282)
  Block send until extensions are ready (#4271)
  fix: improve OpenAI-compatible error handling and add test coverage (#4175)
  Move To-Do Tool to Session Scope from Agent Scope (#4157)
  fix: recipe params not being replaced all the time (#4207)
  chore: removing little-used session sharing feature (#4249)
  Stop auto scrolling when agent responds and let scroll area handle scrolling to bottom (#4257)
  restore cli projects from accidental removal during cleanup (#4266)
  Fix: deep link extension installation to show dialog for headers configuration (#4150)
  feat: Add message queue system with interruption handling (#4179)
  Start extensions concurrently  (#4234)
  Add X-Title and referer headers on exchange to tetrate (#4250)
  docs: update View/Edit Recipe menu item name (#4267)
  ...
shellz-n-stuff pushed a commit to shellz-n-stuff/goose that referenced this pull request Aug 27, 2025
dorien-koelemeijer pushed a commit to dorien-koelemeijer/goose that referenced this pull request Sep 2, 2025
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.

4 participants