Fix boot state sharing across Next.js module boundaries
All checks were successful
CI / lint-and-test (push) Successful in 29s
Deploy Production / deploy (push) Successful in 47s
CI / build (push) Successful in 1m16s

Use globalThis for all in-memory stores (credentials, models, agents,
tasks) so the instrumentation hook and API route handlers share the
same data. Next.js bundles these as separate chunks with independent
module instances, causing boot-populated state to be invisible to
API routes.
This commit is contained in:
Julia McGhee
2026-03-21 19:59:34 +00:00
parent a079225367
commit a60754d5a2
5 changed files with 22 additions and 12 deletions

View File

@@ -13,8 +13,10 @@ export interface Credential {
baseUrl?: string; // for self-hosted GitLab or custom endpoints
}
// In-memory store. Will be replaced with encrypted persistent storage.
const credentials: Map<string, Credential> = new Map();
// In-memory store shared via globalThis to survive Next.js module re-bundling.
const g = globalThis as unknown as { __harnessCredentials?: Map<string, Credential> };
g.__harnessCredentials ??= new Map();
const credentials = g.__harnessCredentials;
export function getAllCredentials(): Credential[] {
return Array.from(credentials.values()).map(c => ({