Repository navigation
Improve timeout errors on the llm command
#915
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -777,7 +777,24 @@ auto sourcemeta::jsonschema::llm(const sourcemeta::core::Options &options) | |
|
|
||
| // Sent once and never retried. A completion is not idempotent and it costs | ||
| // money, so a request that fails is reported rather than repeated | ||
| const auto response{request.send()}; | ||
| const auto started{std::chrono::steady_clock::now()}; | ||
| sourcemeta::core::HTTPResponse response; | ||
| try { | ||
| response = request.send(); | ||
| } catch (const sourcemeta::core::HTTPError &) { | ||
| // What the backend says about a failure is its own business, so whether the | ||
| // time ran out is read off the clock rather than off the message | ||
| // TODO: Have Core raise an exception of its own for a request that ran out | ||
| // of time, so that this is detected from the failure rather than inferred | ||
| // from how long it took | ||
| if (std::chrono::steady_clock::now() - started >= timeout) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you check the silent-endpoint case on macOS at Severity: medium 🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage. |
||
| throw LLMTimeoutError{"The completion request did not answer within " + | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: (Based on your team's feedback about structured exception data.) Prompt for AI agentsThere was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you check the late response-size failure case on Windows at Severity: medium 🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage. |
||
| std::to_string(timeout.count()) + " seconds", | ||
| std::string{url}}; | ||
| } | ||
|
|
||
| throw; | ||
| } | ||
|
|
||
| LOG_VERBOSE(options) << "Received HTTP " << response.status.code << "\n"; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| #!/bin/sh | ||
|
|
||
| set -o errexit | ||
| set -o nounset | ||
|
|
||
| TMP="$(mktemp -d)" | ||
| PORT=5899 | ||
|
|
||
| # A server that accepts the connection and never answers, which is the one | ||
| # failure the caller can do something about by waiting longer | ||
| cat << 'EOF' > "$TMP/server.js" | ||
| const http = require('http'); | ||
| const server = http.createServer(() => {}); | ||
| server.listen(parseInt(process.argv[2], 10)); | ||
| EOF | ||
|
|
||
| node "$TMP/server.js" "$PORT" & | ||
| SERVER_PID="$!" | ||
|
|
||
| clean() { | ||
| kill "$SERVER_PID" 2>/dev/null || true | ||
| rm -rf "$TMP" | ||
| } | ||
| trap clean EXIT | ||
|
|
||
| sleep 2 | ||
|
|
||
| cat << 'EOF' > "$TMP/schema.json" | ||
| { | ||
| "$schema": "https://json-schema.org/draft/2020-12/schema", | ||
| "type": "string" | ||
| } | ||
| EOF | ||
|
|
||
| "$1" llm "$TMP/schema.json" --ask hello \ | ||
| --url "http://localhost:${PORT}/v1/chat/completions" --model my-model \ | ||
| --timeout 2 \ | ||
| > "$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" | ||
| # Unexpected error | ||
| test "$EXIT_CODE" = "1" | ||
|
|
||
| cat << EOF > "$TMP/expected.txt" | ||
| error: The completion request did not answer within 2 seconds | ||
| at url http://localhost:${PORT}/v1/chat/completions | ||
|
|
||
| Pass --timeout/-T with a larger number of seconds to wait longer | ||
| EOF | ||
|
|
||
| diff "$TMP/output.txt" "$TMP/expected.txt" | ||
|
|
||
| "$1" llm "$TMP/schema.json" --ask hello \ | ||
| --url "http://localhost:${PORT}/v1/chat/completions" --model my-model \ | ||
| --timeout 2 --json \ | ||
| > "$TMP/output_json.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" | ||
| # Unexpected error | ||
| test "$EXIT_CODE" = "1" | ||
|
|
||
| cat << EOF > "$TMP/expected_json.txt" | ||
| { | ||
| "error": "The completion request did not answer within 2 seconds", | ||
| "url": "http://localhost:${PORT}/v1/chat/completions" | ||
| } | ||
| EOF | ||
|
|
||
| diff "$TMP/output_json.txt" "$TMP/expected_json.txt" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: We probably need a better upstream error for this...