Skip to content

Commit eaaa718

Browse files
drfarrellclaude
andcommitted
fix: detect 502 errors on initial project load
- Add mount time tracking to detect initial 502s - If no provider exists after 5 seconds from mount, show amber - Works even when sandbox isn't in "connecting" state - Handles immediate 502 failures on project load The key fix: Check for missing provider after grace period, not just when actively connecting 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent cb0293e commit eaaa718

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

apps/web/client/src/app/project/[id]/_components/bottom-bar/terminal-area.tsx

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export const TerminalArea = observer(({ children }: { children: React.ReactNode
5555
// Ultra-lightweight error detection using a single timer
5656
const timeoutIdRef = useRef<NodeJS.Timeout | null>(null);
5757
const [hasSandboxError, setHasSandboxError] = useState(false);
58+
const mountTimeRef = useRef<number>(Date.now());
5859

5960
// Single effect that only sets/clears one timer - extremely efficient
6061
useEffect(() => {
@@ -85,25 +86,23 @@ export const TerminalArea = observer(({ children }: { children: React.ReactNode
8586
return;
8687
}
8788

88-
// Only set timer if actually connecting (not just idle)
89-
const isConnecting = sandbox.session.isConnecting || sandbox.isIndexing;
90-
if (!isConnecting) {
91-
setHasSandboxError(false);
92-
return;
89+
// Check if enough time has passed since mount (avoid false positives on initial load)
90+
const timeSinceMount = Date.now() - mountTimeRef.current;
91+
if (timeSinceMount < 5000) {
92+
// Set timer to check after 5 seconds from mount
93+
const delay = 5000 - timeSinceMount;
94+
timeoutIdRef.current = setTimeout(() => {
95+
// Check if still no provider (indicates 502 or failure)
96+
const stillNoProvider = !branches.getBranchDataById(activeBranch.id)?.sandbox?.session?.provider;
97+
if (stillNoProvider) {
98+
setHasSandboxError(true);
99+
}
100+
}, delay);
101+
} else {
102+
// We're past the grace period - if no provider, it's an error
103+
setHasSandboxError(true);
93104
}
94105

95-
// Set a single 5-second timer - that's it, ultra simple
96-
timeoutIdRef.current = setTimeout(() => {
97-
// Final check after 5 seconds
98-
const stillConnecting = branches.getBranchDataById(activeBranch.id)?.sandbox?.session?.isConnecting ||
99-
branches.getBranchDataById(activeBranch.id)?.sandbox?.isIndexing;
100-
const stillNoProvider = !branches.getBranchDataById(activeBranch.id)?.sandbox?.session?.provider;
101-
102-
if (stillConnecting && stillNoProvider) {
103-
setHasSandboxError(true);
104-
}
105-
}, 5000);
106-
107106
// Cleanup on unmount or deps change
108107
return () => {
109108
if (timeoutIdRef.current) {

0 commit comments

Comments
 (0)