Spaces:
Sleeping
Sleeping
event response
Browse files- app/api/run.py +18 -4
app/api/run.py
CHANGED
|
@@ -39,6 +39,14 @@ async def run_verification(
|
|
| 39 |
):
|
| 40 |
async def event_generator() -> AsyncGenerator[Dict[str, Any], None]:
|
| 41 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
start_time = time.time()
|
| 43 |
print(f"--- STREAM STARTED FOR: {payload.question[:30]}... ---")
|
| 44 |
|
|
@@ -95,9 +103,6 @@ async def run_verification(
|
|
| 95 |
if kind == "on_chain_start" and name in ui_node_map:
|
| 96 |
current_active_node = ui_node_map[name]
|
| 97 |
|
| 98 |
-
# STRIKE 3 FIX: The State Accumulation Patch
|
| 99 |
-
# If the Architect fires again, it means the Prosecutor triggered a retry.
|
| 100 |
-
# We must wipe the previous failed draft from memory and tell the UI to clear.
|
| 101 |
if current_active_node in ["Architect", "Strategist"] and full_generation:
|
| 102 |
full_generation = ""
|
| 103 |
yield {"event": "clear", "data": json.dumps({"message": "retry_triggered"})}
|
|
@@ -157,4 +162,13 @@ async def run_verification(
|
|
| 157 |
print(f"❌ MASTER STREAM CRASH: {error_msg}")
|
| 158 |
yield {"event": "error", "data": json.dumps({"detail": f"Backend Engine Disconnected: {error_msg}"})}
|
| 159 |
|
| 160 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
):
|
| 40 |
async def event_generator() -> AsyncGenerator[Dict[str, Any], None]:
|
| 41 |
try:
|
| 42 |
+
# FIX 1: Nginx/Vercel Buffer Flush
|
| 43 |
+
# Cloud proxies trap small SSE events. We send a massive padding payload
|
| 44 |
+
# to instantly overflow the buffer and force the stream to open in real-time.
|
| 45 |
+
yield {
|
| 46 |
+
"event": "connected",
|
| 47 |
+
"data": json.dumps({"status": "established", "padding": " " * 2048})
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
start_time = time.time()
|
| 51 |
print(f"--- STREAM STARTED FOR: {payload.question[:30]}... ---")
|
| 52 |
|
|
|
|
| 103 |
if kind == "on_chain_start" and name in ui_node_map:
|
| 104 |
current_active_node = ui_node_map[name]
|
| 105 |
|
|
|
|
|
|
|
|
|
|
| 106 |
if current_active_node in ["Architect", "Strategist"] and full_generation:
|
| 107 |
full_generation = ""
|
| 108 |
yield {"event": "clear", "data": json.dumps({"message": "retry_triggered"})}
|
|
|
|
| 162 |
print(f"❌ MASTER STREAM CRASH: {error_msg}")
|
| 163 |
yield {"event": "error", "data": json.dumps({"detail": f"Backend Engine Disconnected: {error_msg}"})}
|
| 164 |
|
| 165 |
+
# stream small node_update events instead of holding them in a buffer bucket.
|
| 166 |
+
return EventSourceResponse(
|
| 167 |
+
event_generator(),
|
| 168 |
+
ping=10,
|
| 169 |
+
headers={
|
| 170 |
+
"X-Accel-Buffering": "no",
|
| 171 |
+
"Cache-Control": "no-cache",
|
| 172 |
+
"Connection": "keep-alive"
|
| 173 |
+
}
|
| 174 |
+
)
|