Spaces:
Running
Running
Pulastya B commited on
Commit Β·
29c9177
1
Parent(s): e2e1cea
ARCHITECTURAL FIX: Use single UUID session identity everywhere - removed http_session_key hack
Browse files- FRRONTEEEND/components/ChatInterface.tsx +7 -0
- src/api/app.py +10 -10
- src/orchestrator.py +18 -46
FRRONTEEEND/components/ChatInterface.tsx
CHANGED
|
@@ -210,6 +210,13 @@ export const ChatInterface: React.FC<{ onBack: () => void }> = ({ onBack }) => {
|
|
| 210 |
|
| 211 |
const data = await response.json();
|
| 212 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 213 |
let assistantContent = '';
|
| 214 |
let reports: Array<{name: string, path: string}> = [];
|
| 215 |
let plots: Array<{title: string, url: string, type?: 'image' | 'html'}> = [];
|
|
|
|
| 210 |
|
| 211 |
const data = await response.json();
|
| 212 |
|
| 213 |
+
// CRITICAL: Store the actual session UUID returned from backend for SSE routing
|
| 214 |
+
if (data.session_id) {
|
| 215 |
+
console.log(`π Session UUID from backend: ${data.session_id}`);
|
| 216 |
+
// Update the active session to use this UUID for SSE connection
|
| 217 |
+
setActiveSessionId(data.session_id);
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
let assistantContent = '';
|
| 221 |
let reports: Array<{name: string, path: string}> = [];
|
| 222 |
let plots: Array<{title: string, url: string, type?: 'image' | 'html'}> = [];
|
src/api/app.py
CHANGED
|
@@ -349,9 +349,9 @@ async def run_analysis(
|
|
| 349 |
# Set progress callback on existing agent
|
| 350 |
agent.progress_callback = progress_callback
|
| 351 |
|
| 352 |
-
#
|
| 353 |
-
agent.
|
| 354 |
-
print(f"[SSE]
|
| 355 |
|
| 356 |
try:
|
| 357 |
# Agent's session memory should resolve file_path from context
|
|
@@ -468,9 +468,9 @@ async def run_analysis(
|
|
| 468 |
# Set progress callback on existing agent
|
| 469 |
agent.progress_callback = progress_callback
|
| 470 |
|
| 471 |
-
#
|
| 472 |
-
agent.
|
| 473 |
-
print(f"[SSE]
|
| 474 |
|
| 475 |
# Call existing agent logic
|
| 476 |
logger.info(f"Starting analysis with task: {task_description}")
|
|
@@ -484,8 +484,8 @@ async def run_analysis(
|
|
| 484 |
|
| 485 |
logger.info(f"Analysis completed: {result.get('status')}")
|
| 486 |
|
| 487 |
-
# Send completion event via SSE
|
| 488 |
-
progress_manager.emit(
|
| 489 |
"type": "analysis_complete",
|
| 490 |
"status": result.get("status"),
|
| 491 |
"message": "β
Analysis completed successfully!"
|
|
@@ -512,13 +512,13 @@ async def run_analysis(
|
|
| 512 |
|
| 513 |
serializable_result = make_json_serializable(result)
|
| 514 |
|
| 515 |
-
# Return result with progress tracking
|
| 516 |
return JSONResponse(
|
| 517 |
content={
|
| 518 |
"success": result.get("status") == "success",
|
| 519 |
"result": serializable_result,
|
| 520 |
"progress": progress_store.get(session_key, []),
|
| 521 |
-
"session_id":
|
| 522 |
"metadata": {
|
| 523 |
"filename": file.filename,
|
| 524 |
"task": task_description,
|
|
|
|
| 349 |
# Set progress callback on existing agent
|
| 350 |
agent.progress_callback = progress_callback
|
| 351 |
|
| 352 |
+
# Get the agent's actual session UUID for SSE routing
|
| 353 |
+
actual_session_id = agent.session.session_id if hasattr(agent, 'session') and agent.session else "default"
|
| 354 |
+
print(f"[SSE] Using agent session UUID: {actual_session_id}")
|
| 355 |
|
| 356 |
try:
|
| 357 |
# Agent's session memory should resolve file_path from context
|
|
|
|
| 468 |
# Set progress callback on existing agent
|
| 469 |
agent.progress_callback = progress_callback
|
| 470 |
|
| 471 |
+
# Get the agent's actual session UUID for SSE routing
|
| 472 |
+
actual_session_id = agent.session.session_id if hasattr(agent, 'session') and agent.session else "default"
|
| 473 |
+
print(f"[SSE] Using agent session UUID: {actual_session_id}")
|
| 474 |
|
| 475 |
# Call existing agent logic
|
| 476 |
logger.info(f"Starting analysis with task: {task_description}")
|
|
|
|
| 484 |
|
| 485 |
logger.info(f"Analysis completed: {result.get('status')}")
|
| 486 |
|
| 487 |
+
# Send completion event via SSE using actual session UUID
|
| 488 |
+
progress_manager.emit(actual_session_id, {
|
| 489 |
"type": "analysis_complete",
|
| 490 |
"status": result.get("status"),
|
| 491 |
"message": "β
Analysis completed successfully!"
|
|
|
|
| 512 |
|
| 513 |
serializable_result = make_json_serializable(result)
|
| 514 |
|
| 515 |
+
# Return result with progress tracking and ACTUAL session UUID for SSE
|
| 516 |
return JSONResponse(
|
| 517 |
content={
|
| 518 |
"success": result.get("status") == "success",
|
| 519 |
"result": serializable_result,
|
| 520 |
"progress": progress_store.get(session_key, []),
|
| 521 |
+
"session_id": actual_session_id, # Return UUID for SSE connection
|
| 522 |
"metadata": {
|
| 523 |
"filename": file.filename,
|
| 524 |
"task": task_description,
|
src/orchestrator.py
CHANGED
|
@@ -2239,13 +2239,9 @@ You are a DOER. Complete workflows based on user intent."""
|
|
| 2239 |
self.tokens_this_minute += tokens_used
|
| 2240 |
print(f"π Tokens: {tokens_used} this call | {self.tokens_this_minute}/{self.tpm_limit} this minute")
|
| 2241 |
|
| 2242 |
-
# Emit token update for SSE streaming
|
| 2243 |
-
|
| 2244 |
-
|
| 2245 |
-
session_key_for_emit = self.session.session_id
|
| 2246 |
-
|
| 2247 |
-
if session_key_for_emit:
|
| 2248 |
-
progress_manager.emit(session_key_for_emit, {
|
| 2249 |
'type': 'token_update',
|
| 2250 |
'message': f"π Tokens: {tokens_used} this call | {self.tokens_this_minute}/{self.tpm_limit} this minute",
|
| 2251 |
'tokens_used': tokens_used,
|
|
@@ -2283,13 +2279,9 @@ You are a DOER. Complete workflows based on user intent."""
|
|
| 2283 |
self.tokens_this_minute += tokens_used
|
| 2284 |
print(f"π Tokens: {tokens_used} this call | {self.tokens_this_minute}/{self.tpm_limit} this minute")
|
| 2285 |
|
| 2286 |
-
# Emit token update for SSE streaming
|
| 2287 |
-
|
| 2288 |
-
|
| 2289 |
-
session_key_for_emit = self.session.session_id
|
| 2290 |
-
|
| 2291 |
-
if session_key_for_emit:
|
| 2292 |
-
progress_manager.emit(session_key_for_emit, {
|
| 2293 |
'type': 'token_update',
|
| 2294 |
'message': f"π Tokens: {tokens_used} this call | {self.tokens_this_minute}/{self.tpm_limit} this minute",
|
| 2295 |
'tokens_used': tokens_used,
|
|
@@ -2351,13 +2343,9 @@ You are a DOER. Complete workflows based on user intent."""
|
|
| 2351 |
self.tokens_this_minute += tokens_used
|
| 2352 |
print(f"π Tokens: {tokens_used} this call | {self.tokens_this_minute}/{self.tpm_limit} this minute")
|
| 2353 |
|
| 2354 |
-
# Emit token update for SSE streaming
|
| 2355 |
-
|
| 2356 |
-
|
| 2357 |
-
session_key_for_emit = self.session.session_id
|
| 2358 |
-
|
| 2359 |
-
if session_key_for_emit:
|
| 2360 |
-
progress_manager.emit(session_key_for_emit, {
|
| 2361 |
'type': 'token_update',
|
| 2362 |
'message': f"π Tokens: {tokens_used} this call | {self.tokens_this_minute}/{self.tpm_limit} this minute",
|
| 2363 |
'tokens_used': tokens_used,
|
|
@@ -3033,24 +3021,16 @@ You are a DOER. Complete workflows based on user intent."""
|
|
| 3033 |
except:
|
| 3034 |
print(f" Arguments: {tool_args}")
|
| 3035 |
|
| 3036 |
-
# Emit progress event for SSE streaming
|
| 3037 |
-
|
| 3038 |
-
|
| 3039 |
-
|
| 3040 |
-
|
| 3041 |
-
|
| 3042 |
-
print(f"[SSE] DEBUG EMIT: http_session_key={getattr(self, 'http_session_key', 'NOT SET')}, session={hasattr(self, 'session')}, final_key={session_key_for_emit}")
|
| 3043 |
-
|
| 3044 |
-
if session_key_for_emit:
|
| 3045 |
-
print(f"[SSE] EMITTING tool_executing for session: {session_key_for_emit}, tool: {tool_name}")
|
| 3046 |
-
progress_manager.emit(session_key_for_emit, {
|
| 3047 |
'type': 'tool_executing',
|
| 3048 |
'tool': tool_name,
|
| 3049 |
'message': f"π§ Executing: {tool_name}",
|
| 3050 |
'arguments': tool_args
|
| 3051 |
})
|
| 3052 |
-
else:
|
| 3053 |
-
print(f"[SSE] WARNING: SKIPPING EMIT: No session key available")
|
| 3054 |
|
| 3055 |
# Execute tool
|
| 3056 |
tool_result = self._execute_tool(tool_name, tool_args)
|
|
@@ -3064,12 +3044,8 @@ You are a DOER. Complete workflows based on user intent."""
|
|
| 3064 |
print(f" β οΈ Error Message: {error_msg}")
|
| 3065 |
|
| 3066 |
# Emit failure event for SSE streaming
|
| 3067 |
-
|
| 3068 |
-
|
| 3069 |
-
session_key_for_emit = self.session.session_id
|
| 3070 |
-
|
| 3071 |
-
if session_key_for_emit:
|
| 3072 |
-
progress_manager.emit(session_key_for_emit, {
|
| 3073 |
'type': 'tool_failed',
|
| 3074 |
'tool': tool_name,
|
| 3075 |
'message': f"β FAILED: {tool_name}",
|
|
@@ -3142,12 +3118,8 @@ You are a DOER. Complete workflows based on user intent."""
|
|
| 3142 |
print(f" β Completed: {tool_name}")
|
| 3143 |
|
| 3144 |
# Emit completion event for SSE streaming
|
| 3145 |
-
|
| 3146 |
-
|
| 3147 |
-
session_key_for_emit = self.session.session_id
|
| 3148 |
-
|
| 3149 |
-
if session_key_for_emit:
|
| 3150 |
-
progress_manager.emit(session_key_for_emit, {
|
| 3151 |
'type': 'tool_completed',
|
| 3152 |
'tool': tool_name,
|
| 3153 |
'message': f"β Completed: {tool_name}"
|
|
|
|
| 2239 |
self.tokens_this_minute += tokens_used
|
| 2240 |
print(f"π Tokens: {tokens_used} this call | {self.tokens_this_minute}/{self.tpm_limit} this minute")
|
| 2241 |
|
| 2242 |
+
# Emit token update for SSE streaming using session UUID
|
| 2243 |
+
if hasattr(self, 'session') and self.session:
|
| 2244 |
+
progress_manager.emit(self.session.session_id, {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2245 |
'type': 'token_update',
|
| 2246 |
'message': f"π Tokens: {tokens_used} this call | {self.tokens_this_minute}/{self.tpm_limit} this minute",
|
| 2247 |
'tokens_used': tokens_used,
|
|
|
|
| 2279 |
self.tokens_this_minute += tokens_used
|
| 2280 |
print(f"π Tokens: {tokens_used} this call | {self.tokens_this_minute}/{self.tpm_limit} this minute")
|
| 2281 |
|
| 2282 |
+
# Emit token update for SSE streaming using session UUID
|
| 2283 |
+
if hasattr(self, 'session') and self.session:
|
| 2284 |
+
progress_manager.emit(self.session.session_id, {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2285 |
'type': 'token_update',
|
| 2286 |
'message': f"π Tokens: {tokens_used} this call | {self.tokens_this_minute}/{self.tpm_limit} this minute",
|
| 2287 |
'tokens_used': tokens_used,
|
|
|
|
| 2343 |
self.tokens_this_minute += tokens_used
|
| 2344 |
print(f"π Tokens: {tokens_used} this call | {self.tokens_this_minute}/{self.tpm_limit} this minute")
|
| 2345 |
|
| 2346 |
+
# Emit token update for SSE streaming using session UUID
|
| 2347 |
+
if hasattr(self, 'session') and self.session:
|
| 2348 |
+
progress_manager.emit(self.session.session_id, {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2349 |
'type': 'token_update',
|
| 2350 |
'message': f"π Tokens: {tokens_used} this call | {self.tokens_this_minute}/{self.tpm_limit} this minute",
|
| 2351 |
'tokens_used': tokens_used,
|
|
|
|
| 3021 |
except:
|
| 3022 |
print(f" Arguments: {tool_args}")
|
| 3023 |
|
| 3024 |
+
# Emit progress event for SSE streaming using session UUID
|
| 3025 |
+
if hasattr(self, 'session') and self.session:
|
| 3026 |
+
session_id = self.session.session_id
|
| 3027 |
+
print(f"[SSE] EMIT tool_executing: session={session_id}, tool={tool_name}")
|
| 3028 |
+
progress_manager.emit(session_id, {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3029 |
'type': 'tool_executing',
|
| 3030 |
'tool': tool_name,
|
| 3031 |
'message': f"π§ Executing: {tool_name}",
|
| 3032 |
'arguments': tool_args
|
| 3033 |
})
|
|
|
|
|
|
|
| 3034 |
|
| 3035 |
# Execute tool
|
| 3036 |
tool_result = self._execute_tool(tool_name, tool_args)
|
|
|
|
| 3044 |
print(f" β οΈ Error Message: {error_msg}")
|
| 3045 |
|
| 3046 |
# Emit failure event for SSE streaming
|
| 3047 |
+
if hasattr(self, 'session') and self.session:
|
| 3048 |
+
progress_manager.emit(self.session.session_id, {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3049 |
'type': 'tool_failed',
|
| 3050 |
'tool': tool_name,
|
| 3051 |
'message': f"β FAILED: {tool_name}",
|
|
|
|
| 3118 |
print(f" β Completed: {tool_name}")
|
| 3119 |
|
| 3120 |
# Emit completion event for SSE streaming
|
| 3121 |
+
if hasattr(self, 'session') and self.session:
|
| 3122 |
+
progress_manager.emit(self.session.session_id, {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3123 |
'type': 'tool_completed',
|
| 3124 |
'tool': tool_name,
|
| 3125 |
'message': f"β Completed: {tool_name}"
|