commit babdd4d2b8a85b16001e26430738ef37618ebc3b from: Isaac Meerleo date: Fri Jul 17 23:53:15 2026 UTC Classify code-only context overflows commit - 4150f8458ba83e3fd4eb3a9523584218c33c84d6 commit + babdd4d2b8a85b16001e26430738ef37618ebc3b blob - 6bb5f30365904a29172c625e2f2822b92cfc77cd blob + 4be5d03efeeaefac58d7d88f06598e9e031de60b --- regress/openai/openai_test.c +++ regress/openai/openai_test.c @@ -611,6 +611,10 @@ test_error_body(void) "{\"error\":{\"message\":\"too many tokens\"," "\"type\":\"invalid_request_error\"," "\"code\":\"context_length_exceeded\"}}"; + static const char code_only[] = + "{\"error\":{\"code\":\"context_length_exceeded\"}}"; + static const char wrong_code_only[] = + "{\"error\":{\"code\":400}}"; static const char near[] = "{\"error\":{\"message\":\"context_length_exceeded\"," "\"type\":\"invalid_request_error\"," @@ -634,6 +638,18 @@ test_error_body(void) CHECK(openai_error_body(overflow, sizeof(overflow) - 1, 413, out, sizeof(out), &category) == 0); CHECK(category == PROVIDER_ERROR_OTHER); + CHECK(openai_error_body(code_only, sizeof(code_only) - 1, 400, out, + sizeof(out), &category) == 0); + CHECK(strcmp(out, "error") == 0); + CHECK(category == PROVIDER_ERROR_CONTEXT_OVERFLOW); + CHECK(openai_error_body(code_only, sizeof(code_only) - 1, 413, out, + sizeof(out), &category) == 0); + CHECK(strcmp(out, "error") == 0); + CHECK(category == PROVIDER_ERROR_OTHER); + CHECK(openai_error_body(wrong_code_only, + sizeof(wrong_code_only) - 1, 400, out, sizeof(out), &category) == + -1); + CHECK(category == PROVIDER_ERROR_OTHER); CHECK(openai_error_body(near, sizeof(near) - 1, 400, out, sizeof(out), &category) == 0); CHECK(category == PROVIDER_ERROR_OTHER); blob - b302cf0dda281f2c4069498406b0bdd470b64406 blob + 6783ec441207111db3d0f960a5412732d238a81f --- src/common/openai_stream.c +++ src/common/openai_stream.c @@ -584,7 +584,8 @@ openai_error_body(const void *data, size_t len, int st free(code); code = NULL; } - if (rt < 0 || rm < 0 || (type == NULL && message == NULL)) { + if (rt < 0 || rm < 0 || + (type == NULL && message == NULL && code == NULL)) { free(type); free(message); free(code);