Skip to content

Commit 77e213b

Browse files
committed
fix(search): back off durable permission recovery
1 parent 1b2eb2b commit 77e213b

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

‎apps/sim/lib/mothership/persistence/tool-permission/index.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import type { CopilotToolPermissionDecision } from '@sim/db/schema'
22
import { createLogger } from '@sim/logger'
33
import { toError } from '@sim/utils/errors'
4+
import { backoffWithJitter } from '@sim/utils/retry'
45
import { createPubSubChannel, type PubSubChannel } from '@/lib/events/pubsub'
56
import { isExecutableToolPermissionDecision } from '@/lib/mothership/async-runs/lifecycle'
67
import { getAsyncToolCall } from '@/lib/mothership/async-runs/repository'
78

89
const logger = createLogger('CopilotToolPermission')
9-
const DECISION_RECHECK_INTERVAL_MS = 1_000
10+
const DECISION_RECHECK_BACKOFF = { baseMs: 1_000, maxMs: 10_000 } as const
1011

1112
export const TOOL_PERMISSION_DECISION = {
1213
allow: 'allow',
@@ -113,6 +114,7 @@ export async function waitForToolPermissionDecision(
113114
let settled = false
114115
let timeoutId: ReturnType<typeof setTimeout> | null = null
115116
let recheckId: ReturnType<typeof setTimeout> | null = null
117+
let recheckAttempt = 0
116118
let unsubscribe: (() => void) | null = null
117119

118120
const cleanup = () => {
@@ -160,7 +162,11 @@ export async function waitForToolPermissionDecision(
160162
settle(existing)
161163
return
162164
}
163-
recheckId = setTimeout(() => void readDecision(), DECISION_RECHECK_INTERVAL_MS)
165+
recheckAttempt += 1
166+
recheckId = setTimeout(
167+
() => void readDecision(),
168+
backoffWithJitter(recheckAttempt, null, DECISION_RECHECK_BACKOFF)
169+
)
164170
}
165171
void readDecision()
166172
})

‎apps/sim/scripts/test-assistant-actions-e2e.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const databaseUrl = assertDisposableTestDatabaseUrl(
4646
requiredEnvironment('ASSISTANT_ACTIONS_E2E_DATABASE_URL')
4747
)
4848
const redisUrl = new URL(requiredEnvironment('REDIS_URL'))
49-
assert.equal(redisUrl.protocol, 'redis:')
49+
assert(['redis:', 'rediss:'].includes(redisUrl.protocol), 'Use a Redis URL')
5050
assert(['localhost', '127.0.0.1', '[::1]'].includes(redisUrl.hostname), 'Use local Redis')
5151
assert(!redisUrl.username && !redisUrl.password && !redisUrl.search, 'Use credential-free Redis')
5252
const authSecret = requiredEnvironment('ASSISTANT_ACTIONS_E2E_AUTH_SECRET')

0 commit comments

Comments
 (0)