Guard pairing token renewal against concurrent edits and cap pairing names

This commit is contained in:
Chris Scott committed 2026-11-28 20:36:48 -05:00
1 parent 3c7bc80988
commit 12dab07b87
4 files changed
+65 -3

No files matched your search

@@ -321,9 +321,22 @@ export class OpenCodeServerRegistry {
if (expiry === null) return
const remaining = expiry - Date.now()
if (remaining <= 0 || remaining > TOKEN_RENEWAL_WINDOW_MS) return
if (remaining <= 0) {
logger.warn(`The pairing token for OpenCode server ${serverId} has expired; pair the server again`)
return
}
if (remaining > TOKEN_RENEWAL_WINDOW_MS) return
const renewed = await this.pairWithToken(server.baseUrl, token)
const current = this.get(serverId)
if (
current === null ||
current.baseUrl !== server.baseUrl ||
readOpenCodeServerPassword(this.db, serverId) !== token
) {
return
}
updateOpenCodeServer(this.db, serverId, { password: renewed })
this.invalidateClient(serverId)
} catch (error) {