fix: add 8s timeout to NeoInstituteContext school node fetch

Races the SchoolNeoDBService.getSchoolNode() call against an 8-second
timeout. If Neo4j is slow or unavailable the workspace now loads within
seconds rather than waiting for the full axios 120s timeout. The context
degrades gracefully — workspace opens without institute data, error is
logged as a warning not an exception.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
kcar 2026-05-21 17:28:57 +00:00
parent d3c2a9bdff
commit ab1f8111f6

View File

@ -5,6 +5,8 @@ import { SchoolNeoDBService } from '../services/graph/schoolNeoDBService';
import { CCSchoolNodeProps } from '../utils/tldraw/cc-base/cc-graph/cc-graph-types';
import { logger } from '../debugConfig';
const NEO_INSTITUTE_TIMEOUT_MS = 8000;
export interface NeoInstituteContextType {
schoolNode: CCSchoolNodeProps | null;
isLoading: boolean;
@ -58,7 +60,17 @@ export const NeoInstituteProvider: React.FC<{ children: ReactNode }> = ({ childr
userEmail: user?.email
});
const node = await SchoolNeoDBService.getSchoolNode(profile.school_db_name);
// Race the Neo4j call against a timeout so a slow/unavailable Neo4j
// never blocks the workspace from loading for more than 8 seconds.
const timeoutPromise = new Promise<null>((_, reject) =>
setTimeout(() => reject(new Error(`Neo4j timed out after ${NEO_INSTITUTE_TIMEOUT_MS}ms`)), NEO_INSTITUTE_TIMEOUT_MS)
);
const node = await Promise.race([
SchoolNeoDBService.getSchoolNode(profile.school_db_name),
timeoutPromise
]);
if (node) {
setSchoolNode(node);
logger.debug('neo-institute-context', '✅ School node loaded', {
@ -71,7 +83,7 @@ export const NeoInstituteProvider: React.FC<{ children: ReactNode }> = ({ childr
} catch (error) {
const errorMessage = error instanceof Error ? error.message : 'Failed to load school node';
logger.error('neo-institute-context', '❌ Failed to load school node', {
logger.warn('neo-institute-context', '⚠️ School node unavailable — workspace will load without institute data', {
error: errorMessage,
schoolDbName: profile.school_db_name
});