GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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
Filter options
  • packages/opencode
    • src/session
      • retry.ts
    • test/session
      • retry.test.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/opencode/src/session/retry.ts‎

Copy file name to clipboardExpand all lines: packages/opencode/src/session/retry.ts
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ function parseJSON(value: unknown) {
173173
})
174174
}
175175

176+
export const MAX_SESSION_RETRIES = 5
177+
176178
export function policy(opts: {
177179
provider: string
178180
parse: (error: unknown) => Err
@@ -182,7 +184,7 @@ export function policy(opts: {
182184
Effect.succeed((meta: Schedule.InputMetadata<unknown>) => {
183185
const error = opts.parse(meta.input)
184186
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)
186188
return Effect.gen(function* () {
187189
const wait = delay(meta.attempt, SessionV1.APIError.isInstance(error) ? error : undefined)
188190
const now = yield* Clock.currentTimeMillis
Collapse file

‎packages/opencode/test/session/retry.test.ts‎

Copy file name to clipboardExpand all lines: packages/opencode/test/session/retry.test.ts
+29Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,35 @@ describe("session.retry.delay", () => {
8585
expect(SessionRetry.delay(1, error)).toBe(SessionRetry.RETRY_MAX_DELAY)
8686
})
8787

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+
88117
it.instance("policy updates retry status and increments attempts", () =>
89118
Effect.gen(function* () {
90119
const sessionID = SessionID.make("session-retry-test")

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.