Skip to content

Commit d59f7a1

Browse files
committed
fix(opencode): narrow stale session retries
1 parent 8ec0c5a commit d59f7a1

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

apps/sim/lib/opencode/service.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,13 @@ describe('shouldRetryWithFreshOpenCodeSession', () => {
4040
it('returns true for stale-session errors', () => {
4141
expect(shouldRetryWithFreshOpenCodeSession(new Error('404 session not found'))).toBe(true)
4242
expect(shouldRetryWithFreshOpenCodeSession('session does not exist')).toBe(true)
43+
expect(shouldRetryWithFreshOpenCodeSession('unknown session')).toBe(true)
4344
})
4445

4546
it('returns false for unrelated session errors', () => {
4647
expect(shouldRetryWithFreshOpenCodeSession(new Error('session limit exceeded'))).toBe(false)
4748
expect(shouldRetryWithFreshOpenCodeSession('invalid session format')).toBe(false)
49+
expect(shouldRetryWithFreshOpenCodeSession('model not found')).toBe(false)
50+
expect(shouldRetryWithFreshOpenCodeSession('provider does not exist')).toBe(false)
4851
})
4952
})

apps/sim/lib/opencode/service.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -504,13 +504,20 @@ export function shouldRetryWithFreshOpenCodeSession(error: unknown): boolean {
504504
: JSON.stringify(error)
505505

506506
const normalized = message.toLowerCase()
507-
return (
508-
normalized.includes('404') ||
509-
normalized.includes('not found') ||
510-
normalized.includes('session not found') ||
511-
normalized.includes('session does not exist') ||
512-
normalized.includes('does not exist')
513-
)
507+
const staleSessionPatterns = [
508+
'session not found',
509+
'session does not exist',
510+
'session was not found',
511+
'session no longer exists',
512+
'unknown session',
513+
'invalid session id',
514+
]
515+
516+
if (staleSessionPatterns.some((pattern) => normalized.includes(pattern))) {
517+
return true
518+
}
519+
520+
return normalized.includes('404') && normalized.includes('session')
514521
}
515522

516523
export async function logOpenCodeFailure(message: string, error: unknown): Promise<void> {

0 commit comments

Comments
 (0)