-
Notifications
You must be signed in to change notification settings - Fork 0
Developer metrics #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
25e4121
c077844
3b9c43f
359a94d
877d88e
006bd37
7e1454e
21ac3f6
5fb1363
ca048a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -106,6 +106,8 @@ export function useJobStream(jobId: string | null): UseJobStreamResult { | |||||||||||||||||||||||||||||||||||||
| useEffect(() => { | ||||||||||||||||||||||||||||||||||||||
| if (!jobId) return; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // Abort any previous in-flight stream before starting a new one. | ||||||||||||||||||||||||||||||||||||||
| abortRef.current?.abort(); | ||||||||||||||||||||||||||||||||||||||
| const ctrl = new AbortController(); | ||||||||||||||||||||||||||||||||||||||
| abortRef.current = ctrl; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
@@ -117,6 +119,13 @@ export function useJobStream(jobId: string | null): UseJobStreamResult { | |||||||||||||||||||||||||||||||||||||
| (async () => { | ||||||||||||||||||||||||||||||||||||||
| const { data: { session } } = await supabase.auth.getSession(); | ||||||||||||||||||||||||||||||||||||||
| const token = session?.access_token ?? ''; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| if (!token) { | ||||||||||||||||||||||||||||||||||||||
| setError('Session expired — please refresh the page'); | ||||||||||||||||||||||||||||||||||||||
| setStatus('failed'); | ||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
120
to
+128
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟠 Major 🧩 Analysis chain🏁 Script executed: cat -n frontend/src/hooks/use-job-stream.tsRepository: ananthanarayanan431/promptly Length of output: 8307 Correct the race condition in the missing-token branch and replace raw The Additionally, the raw Proposed fix for race condition const { data: { session } } = await supabase.auth.getSession();
+ if (ctrl.signal.aborted) return;
const token = session?.access_token ?? '';
if (!token) {
+ if (ctrl.signal.aborted) return;
setError('Session expired — please refresh the page');
setStatus('failed');
return;
}Refactor HTTP calls: Replace 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||
| const res = await fetch(`${API_URL}/api/v1/chat/jobs/${jobId}/stream`, { | ||||||||||||||||||||||||||||||||||||||
| headers: { Authorization: `Bearer ${token}` }, | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -138,7 +147,7 @@ export function useJobStream(jobId: string | null): UseJobStreamResult { | |||||||||||||||||||||||||||||||||||||
| let buf = ''; | ||||||||||||||||||||||||||||||||||||||
| let terminal = false; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| while (true) { | ||||||||||||||||||||||||||||||||||||||
| outer: while (true) { | ||||||||||||||||||||||||||||||||||||||
| const { done, value } = await reader.read(); | ||||||||||||||||||||||||||||||||||||||
| if (done) break; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
@@ -156,7 +165,8 @@ export function useJobStream(jobId: string | null): UseJobStreamResult { | |||||||||||||||||||||||||||||||||||||
| terminal = true; | ||||||||||||||||||||||||||||||||||||||
| } else if (ev.step === 'failed') { | ||||||||||||||||||||||||||||||||||||||
| if (ev.error === 'Stream timeout') { | ||||||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||||||
| // Server closed the stream; fall through to polling fallback. | ||||||||||||||||||||||||||||||||||||||
| break outer; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| setError(ev.error ?? 'Optimization failed'); | ||||||||||||||||||||||||||||||||||||||
| setStatus('failed'); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.