* Schedule refresh using an explicit TTL (seconds until expiry) rather * than decoding a JWT's exp claim. Used by callers whose JWT is opaque * (e.g. POST /v1/code/sessions/{id}/bridge returns expires_in directly).
(
sessionId: string,
expiresInSeconds: number,
)
| 145 | * (e.g. POST /v1/code/sessions/{id}/bridge returns expires_in directly). |
| 146 | */ |
| 147 | function scheduleFromExpiresIn( |
| 148 | sessionId: string, |
| 149 | expiresInSeconds: number, |
| 150 | ): void { |
| 151 | const existing = timers.get(sessionId) |
| 152 | if (existing) clearTimeout(existing) |
| 153 | const gen = nextGeneration(sessionId) |
| 154 | // Clamp to 30s floor — if refreshBufferMs exceeds the server's expires_in |
| 155 | // (e.g. very large buffer for frequent-refresh testing, or server shortens |
| 156 | // expires_in unexpectedly), unclamped delayMs ≤ 0 would tight-loop. |
| 157 | const delayMs = Math.max(expiresInSeconds * 1000 - refreshBufferMs, 30_000) |
| 158 | logForDebugging( |
| 159 | `[${label}:token] Scheduled token refresh for sessionId=${sessionId} in ${formatDuration(delayMs)} (expires_in=${expiresInSeconds}s, buffer=${refreshBufferMs / 1000}s)`, |
| 160 | ) |
| 161 | const timer = setTimeout(doRefresh, delayMs, sessionId, gen) |
| 162 | timers.set(sessionId, timer) |
| 163 | } |
| 164 | |
| 165 | async function doRefresh(sessionId: string, gen: number): Promise<void> { |
| 166 | let oauthToken: string | undefined |
nothing calls this directly
no test coverage detected