Skip to content

Evidence-backed use cases, prompts, integrations, evaluations, and safety notes for OpenAI GPT-6 Astra.

fix: resolve render fetch loop, set home view default, and add db keepalives

jaiprasad049428cd864eae
diff --git a/client/src/app/page.js b/client/src/app/page.js
index 5722d40..2a1dce4 100644
--- a/client/src/app/page.js
+++ b/client/src/app/page.js
@@ -6,7 +6,7 @@ import OpenSpacesApp from "../components/OpenSpacesApp";
export default function HomePage() {
return (
<OpenSpacesApp
- initialRailTab="spaces" // Default to pages & spaces on homepage
+ initialRailTab="home"
/>
);
}
diff --git a/client/src/components/OpenSpacesApp.js b/client/src/components/OpenSpacesApp.js
index 9b70764..36c829b 100644
--- a/client/src/components/OpenSpacesApp.js
+++ b/client/src/components/OpenSpacesApp.js
@@ -1,6 +1,6 @@
"use client";
-import React, { useState, useEffect, useCallback, useRef } from "react";
+import React, { useState, useEffect, useCallback, useRef, useMemo } from "react";
import IconRail from "./IconRail";
import OpenSpacesSidebar from "./OpenSpacesSidebar";
import SpaceSidebar from "./SpaceSidebar";
@@ -23,7 +23,7 @@ const generateUUID = () => {
};
export default function OpenSpacesApp({
- initialRailTab = "spaces", // Default to "spaces" so pages/spaces are shown on the homepage
+ initialRailTab = "home", // Default to "home" view on the homepage
initialSpaceId = null,
initialPageId = null,
initialChatId = null,
@@ -56,10 +56,18 @@ export default function OpenSpacesApp({
const [saveStatus, setSaveStatus] = useState("Saved");
const [saveTrigger, setSaveTrigger] = useState(0);
- // Dynamic Auth Headers based strictly on authenticated user
- const authHeaders = currentUser
- ? { "X-User-Id": currentUser.id, "Authorization": `Bearer ${currentUser.id}` }
- : {};
+ // Ref tracking activeSpaceId to avoid recreating callbacks
+ const activeSpaceIdRef = useRef(activeSpaceId);
+ useEffect(() => {
+ activeSpaceIdRef.current = activeSpaceId;
+ }, [activeSpaceId]);
+
+ // Dynamic Auth Headers based strictly on authenticated user (memoized to prevent render loops)
+ const authHeaders = useMemo(() => {
+ return currentUser?.id
+ ? { "X-User-Id": currentUser.id, Authorization: `Bearer ${currentUser.id}` }
+ : {};
+ }, [currentUser?.id]);
// Track initialization
const initializedFromUrlRef = useRef(false);
@@ -177,7 +185,7 @@ export default function OpenSpacesApp({
// If current active space doesn't exist in data, select first space
if (data.length > 0) {
- const match = data.find((s) => s.id === activeSpaceId);
+ const match = data.find((s) => s.id === activeSpaceIdRef.current);
if (!match) {
setActiveSpaceId(data[0].id);
setActivePageId(null);
@@ -224,9 +232,9 @@ export default function OpenSpacesApp({
}
} catch (_) {}
- // Default to first space and pages view on homepage
+ // Default to home tab on homepage root
+ setActiveRailTab("home");
if (data.length > 0) {
- setActiveRailTab("spaces");
setActiveSpaceId(data[0].id);
setActivePageId(null);
}
@@ -236,7 +244,7 @@ export default function OpenSpacesApp({
} catch (err) {
console.warn("Backend connecting on port 8000...", err);
}
- }, [currentUser?.id, activeSpaceId, initialSpaceId, initialPageId, initialChatId, updateRoute]);
+ }, [currentUser?.id, initialSpaceId, initialPageId, initialChatId, updateRoute]);
useEffect(() => {
fetchSpaces();
@@ -294,7 +302,7 @@ export default function OpenSpacesApp({
useEffect(() => {
if (activeSpaceId) {
- fetchSpaceDetails(activeSpaceId, activePageId);
+ fetchSpaceDetails(activeSpaceId);
}
}, [activeSpaceId, fetchSpaceDetails]);
@@ -324,7 +332,7 @@ export default function OpenSpacesApp({
}
} else {
// Root /
- setActiveRailTab("spaces");
+ setActiveRailTab("home");
}
};
diff --git a/server/app/db/session.py b/server/app/db/session.py
index 3d7f7a2..99a58b2 100644
--- a/server/app/db/session.py
+++ b/server/app/db/session.py
@@ -21,13 +21,23 @@ from sqlalchemy.pool import NullPool
is_supabase_pooler = "pooler.supabase.com" in db_url or ":6543" in db_url
+connect_args = {
+ "sslmode": "require",
+ "keepalives": 1,
+ "keepalives_idle": 30,
+ "keepalives_interval": 10,
+ "keepalives_count": 5,
+} if "supabase.com" in db_url else {}
+
if is_supabase_pooler:
# Supabase Transaction Pooler (PgBouncer port 6543) manages connection pooling on the server.
- # NullPool disables SQLAlchemy client-side connection pooling, eliminating QueuePool timeouts.
+ # NullPool disables client-side connection pooling, eliminating QueuePool timeouts.
+ # pool_pre_ping=True automatically tests connections and reconnects if SSL was dropped.
engine = create_engine(
db_url,
poolclass=NullPool,
- connect_args={"sslmode": "require"} if "supabase.com" in db_url else {}
+ pool_pre_ping=True,
+ connect_args=connect_args
)
else:
engine = create_engine(
@@ -36,7 +46,7 @@ else:
pool_size=20,
max_overflow=40,
pool_recycle=300,
- connect_args={"sslmode": "require"} if "supabase.com" in db_url else {}
+ connect_args=connect_args
)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)