fix: scope instance-served state to the connected instance
Linear and GitHub logins, quotas, MCP status, skills and agent memory are served by whichever instance is connected, but each was cached globally or by directory alone — which two instances can share. Switching instances left the previous instance's answers on screen and its Linear login usable against a runtime that has no Linear. Reset them all through runtimeEndpointReset, each store guarding its in-flight requests with a generation so a response for the previous instance cannot land in the new one. The Linear team filter is now persisted per instance: a team belongs to one workspace, so carrying it across filtered the new instance's issue list down to nothing. Usage also waits for the instance to report itself initialised before loading. Providers report themselves as configured only once the instance can read their credentials, so a fetch fired at mount answered "nothing configured" for every provider and cached it — which is why Usage stayed missing from the work-status panel until Settings -> Usage forced a fresh fetch.
This commit is contained in:
@@ -12,6 +12,13 @@ type LinearAuthStore = {
|
||||
runtimeLinear?: RuntimeAPIs['linear'],
|
||||
options?: { force?: boolean }
|
||||
) => Promise<LinearAuthStatusWithError | null>;
|
||||
/**
|
||||
* Linear is authenticated on the OpenChamber instance, not in the browser, so
|
||||
* this status belongs to whichever instance is connected. Switching instances
|
||||
* must drop it — otherwise the previous instance's login stays on screen and
|
||||
* its issue surfaces remain usable against a runtime that has no Linear at all.
|
||||
*/
|
||||
resetForRuntimeSwitch: () => void;
|
||||
};
|
||||
|
||||
const fetchStatus = async (
|
||||
@@ -24,6 +31,9 @@ const fetchStatus = async (
|
||||
};
|
||||
|
||||
let inFlightAuthRefresh: Promise<LinearAuthStatusWithError | null> | null = null;
|
||||
// Bumped by every reset so a response already in flight for the previous
|
||||
// instance cannot write itself into the new instance's status.
|
||||
let authGeneration = 0;
|
||||
|
||||
export const useLinearAuthStore = create<LinearAuthStore>((set, get) => ({
|
||||
status: null,
|
||||
@@ -41,13 +51,16 @@ export const useLinearAuthStore = create<LinearAuthStore>((set, get) => ({
|
||||
|
||||
if (inFlightAuthRefresh) return inFlightAuthRefresh;
|
||||
|
||||
const generation = authGeneration;
|
||||
set({ isLoading: true });
|
||||
inFlightAuthRefresh = (async () => {
|
||||
try {
|
||||
const payload = await fetchStatus(runtimeLinear);
|
||||
if (generation !== authGeneration) return null;
|
||||
set({ status: payload, isLoading: false, hasChecked: true });
|
||||
return payload;
|
||||
} catch (error) {
|
||||
if (generation !== authGeneration) return null;
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
// A failed request is not an authoritative disconnect. Keep the last
|
||||
// known status and leave `hasChecked` false so the next caller retries
|
||||
@@ -64,4 +77,9 @@ export const useLinearAuthStore = create<LinearAuthStore>((set, get) => ({
|
||||
|
||||
return inFlightAuthRefresh;
|
||||
},
|
||||
resetForRuntimeSwitch: () => {
|
||||
authGeneration += 1;
|
||||
inFlightAuthRefresh = null;
|
||||
set({ status: null, isLoading: false, hasChecked: false });
|
||||
},
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user