GeezerVison is showing github.com — fix(opencode): cap session-level retries and export MAX_SESSION_RETRIES · anomalyco/opencode@60de35a
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: packages/opencode/src/session/retry.ts +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -173,6 +173,8 @@ function parseJSON(value: unknown) { |
173 | 173 | }) |
174 | 174 | } |
175 | 175 |
|
| 176 | +export const MAX_SESSION_RETRIES = 5 |
| 177 | + |
176 | 178 | export function policy(opts: { |
177 | 179 | provider: string |
178 | 180 | parse: (error: unknown) => Err |
@@ -182,7 +184,7 @@ export function policy(opts: { |
182 | 184 | Effect.succeed((meta: Schedule.InputMetadata<unknown>) => { |
183 | 185 | const error = opts.parse(meta.input) |
184 | 186 | const retry = retryable(error, opts.provider) |
185 | | - if (!retry) return Cause.done(meta.attempt) |
| 187 | + if (!retry || meta.attempt > MAX_SESSION_RETRIES) return Cause.done(meta.attempt) |
186 | 188 | return Effect.gen(function* () { |
187 | 189 | const wait = delay(meta.attempt, SessionV1.APIError.isInstance(error) ? error : undefined) |
188 | 190 | const now = yield* Clock.currentTimeMillis |
|
Collapse file
Copy file name to clipboardExpand all lines: packages/opencode/test/session/retry.test.ts +29Lines changed: 29 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -85,6 +85,35 @@ describe("session.retry.delay", () => { |
85 | 85 | expect(SessionRetry.delay(1, error)).toBe(SessionRetry.RETRY_MAX_DELAY) |
86 | 86 | }) |
87 | 87 |
|
| 88 | + it.instance("policy stops retrying after MAX_SESSION_RETRIES attempts on persistent failure", () => |
| 89 | + Effect.gen(function* () { |
| 90 | + const error = apiError({ "retry-after-ms": "0" }) |
| 91 | + const sessionID = SessionID.make("session-retry-cap-test") |
| 92 | + const status = yield* SessionStatus.Service |
| 93 | + |
| 94 | + const step = yield* Schedule.toStepWithMetadata( |
| 95 | + SessionRetry.policy({ |
| 96 | + provider: "test", |
| 97 | + parse: Schema.decodeUnknownSync(SessionV1.APIError.Schema), |
| 98 | + set: (info) => |
| 99 | + status.set(sessionID, { |
| 100 | + type: "retry", |
| 101 | + attempt: info.attempt, |
| 102 | + message: info.message, |
| 103 | + next: info.next, |
| 104 | + }), |
| 105 | + }), |
| 106 | + ) |
| 107 | + |
| 108 | + for (let i = 0; i < SessionRetry.MAX_SESSION_RETRIES; i++) { |
| 109 | + yield* step(error) |
| 110 | + } |
| 111 | + |
| 112 | + const final = yield* Effect.exit(step(error)) |
| 113 | + expect(final._tag).toBe("Failure") |
| 114 | + }), |
| 115 | + ) |
| 116 | + |
88 | 117 | it.instance("policy updates retry status and increments attempts", () => |
89 | 118 | Effect.gen(function* () { |
90 | 119 | const sessionID = SessionID.make("session-retry-test") |
|