From ed19d4872ccd199db4400eae6e1f25997c2fcf00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20=C5=A0=C4=87eki=C4=87?= Date: Thu, 29 Jan 2026 11:12:20 +0100 Subject: [PATCH] fix(share): skip session sync when kilo token is invalid Validate the kilo API token against the user endpoint before syncing and cache auth validity per token to avoid repeated checks. --- packages/opencode/src/share/share-next.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/packages/opencode/src/share/share-next.ts b/packages/opencode/src/share/share-next.ts index 1b87dd1447..3414c74b94 100644 --- a/packages/opencode/src/share/share-next.ts +++ b/packages/opencode/src/share/share-next.ts @@ -16,6 +16,23 @@ import type * as SDK from "@kilocode/sdk/v2" // kilocode_change export namespace ShareNext { const log = Log.create({ service: "share-next" }) + const authCache = new Map() + + async function authValid(token: string) { + const cached = authCache.get(token) + if (cached) return cached.valid + + const response = await fetch("https://app.kilo.ai/api/user", { + headers: { + Authorization: `Bearer ${token}`, + }, + }).catch(() => undefined) + + const valid = response ? response.ok : false + authCache.set(token, { valid: !!response?.ok }) + return valid + } + export async function kilocodeToken() { const auth = await Auth.get("kilo") if (auth?.type === "api" && auth.key.length > 0) return auth.key @@ -34,6 +51,9 @@ export namespace ShareNext { const token = await kilocodeToken() if (!token) return undefined + const valid = await authValid(token) + if (!valid) return undefined + const base = await Config.get().then((x) => x.enterprise?.url ?? "https://ingest.kilosessions.ai") const baseHeaders: Record = { "Content-Type": "application/json",