Repository navigation
refactor(session/retry): single-pass classify(); policy() no longer double-calls transportMessage #8
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
Closed
Closed
refactor(session/retry): single-pass classify(); policy() no longer double-calls transportMessage #8
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
packages/opencode/test/session/retry-classification.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import { describe, expect, test } from "bun:test" | ||
| import { MessageV2 } from "../../src/session/message-v2" | ||
| import { SessionRetry } from "../../src/session/retry" | ||
|
|
||
| describe("SessionRetry.classify", () => { | ||
| test("returns undefined for non-retryable context overflow", () => { | ||
| const err = new MessageV2.ContextOverflowError({ message: "too long" }).toObject() | ||
| expect(SessionRetry.classify(err)).toBeUndefined() | ||
| }) | ||
|
|
||
| test("returns transport classification for SSEStallError", () => { | ||
| const err = new MessageV2.SSEStallError({ message: "SSE read timed out after 120000ms" }).toObject() | ||
| const out = SessionRetry.classify(err) | ||
| expect(out).toEqual({ message: "SSE read timed out after 120000ms", isTransport: true }) | ||
| }) | ||
|
|
||
| test("returns non-transport classification for APIError 500", () => { | ||
| const err = new MessageV2.APIError({ | ||
| message: "upstream exploded", | ||
| statusCode: 503, | ||
| isRetryable: false, | ||
| }).toObject() | ||
| const out = SessionRetry.classify(err) | ||
| expect(out?.message).toBe("upstream exploded") | ||
| expect(out?.isTransport).toBeFalsy() | ||
| }) | ||
|
|
||
| test("retryable() still returns a string for transport errors (legacy API)", () => { | ||
| const err = new MessageV2.SSEStallError({ message: "SSE read timed out after 120000ms" }).toObject() | ||
| expect(SessionRetry.retryable(err)).toBe("SSE read timed out after 120000ms") | ||
| }) | ||
|
|
||
| test("classifies plain-text ETIMEDOUT transport error as isTransport", () => { | ||
| const err = { | ||
| _tag: "Error", | ||
| name: "UnknownError", | ||
| data: { message: "connect ETIMEDOUT 1.2.3.4:443" }, | ||
| } as unknown as Parameters<typeof SessionRetry.classify>[0] | ||
| const out = SessionRetry.classify(err) | ||
| expect(out).toEqual({ message: "connect ETIMEDOUT 1.2.3.4:443", isTransport: true }) | ||
| }) | ||
|
|
||
| test("mixed rate-limit + transport message keeps rate-limit message AND transport cap", () => { | ||
| // Regression: legacy policy() treated any message matching a TRANSPORT_PATTERN | ||
| // as transport for cap purposes, even when the rate-limit branch picked the | ||
| // message. Preserve that cap behavior via isTransport. | ||
| const err = { | ||
| _tag: "Error", | ||
| name: "UnknownError", | ||
| data: { message: "rate limit exceeded (ETIMEDOUT during retry)" }, | ||
| } as unknown as Parameters<typeof SessionRetry.classify>[0] | ||
| const out = SessionRetry.classify(err) | ||
| expect(out?.message).toBe("rate limit exceeded (ETIMEDOUT during retry)") | ||
| expect(out?.isTransport).toBe(true) | ||
| }) | ||
|
|
||
| test("APIError with overloaded message returns non-transport", () => { | ||
| const err = new MessageV2.APIError({ | ||
| message: "Overloaded", | ||
| statusCode: 529, | ||
| isRetryable: true, | ||
| }).toObject() | ||
| const out = SessionRetry.classify(err) | ||
| expect(out).toEqual({ message: "Provider is overloaded" }) | ||
| }) | ||
| }) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Test name says "APIError 500" but the constructed error uses statusCode: 503. Rename the test description to match the actual status code (or make it generic like "APIError 5xx") to avoid confusion when debugging failures.