Skip to content

Commit 3c0acaa

Browse files
authored
πŸ› Bug fix: northbound import error
πŸ› Bug fix: northbound import error
2 parents 5875ebd + 418acd6 commit 3c0acaa

File tree

6 files changed

+649
-29
lines changed

6 files changed

+649
-29
lines changed

β€Ž.dockerignoreβ€Ž

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
# Docker
2020
.dockerignore
21+
make/
2122

2223
# Logs
2324
logs
@@ -40,6 +41,18 @@ build/
4041
backend/assets/*
4142
!backend/assets/test.wav
4243
backend/flower_db.sqlite
44+
uploads/
45+
test/
46+
assets/
47+
48+
# Github
49+
.github/
50+
51+
# Cursor
52+
.cursor/
53+
54+
# Dev Container
55+
.devcontainer/
4356

4457
# OS generated files
4558
.DS_Store

β€Žbackend/apps/northbound_app.pyβ€Ž

Lines changed: 69 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import logging
22
from http import HTTPStatus
3-
from http.client import HTTPException
43
from typing import Optional, Dict
54
import uuid
65

7-
from fastapi import APIRouter, Body, Header, Request
6+
from fastapi import APIRouter, Body, Header, Request, HTTPException
87
from fastapi.responses import JSONResponse
98

109
from consts.exceptions import UnauthorizedError, LimitExceededError, SignatureValidationError
@@ -57,7 +56,8 @@ async def _parse_northbound_context(request: Request) -> NorthboundContext:
5756
validate_aksk_authentication(request.headers, request_body)
5857
except (UnauthorizedError, LimitExceededError, SignatureValidationError) as e:
5958
raise e
60-
except Exception:
59+
except Exception as e:
60+
logging.error(f"Failed to parse northbound context: {str(e)}", exc_info=e)
6161
raise HTTPException(status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
6262
detail="Internal Server Error: cannot parse northbound context")
6363

@@ -78,7 +78,11 @@ async def _parse_northbound_context(request: Request) -> NorthboundContext:
7878
raise HTTPException(status_code=HTTPStatus.UNAUTHORIZED,
7979
detail="Unauthorized: unregistered user_id in JWT token")
8080

81-
except Exception:
81+
except HTTPException as e:
82+
# Preserve explicit HTTP errors raised during JWT parsing
83+
raise e
84+
except Exception as e:
85+
logging.error(f"Failed to parse JWT token: {str(e)}", exc_info=e)
8286
raise HTTPException(status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
8387
detail="Internal Server Error: cannot parse JWT token")
8488

@@ -115,16 +119,23 @@ async def run_chat(
115119
query=query,
116120
idempotency_key=idempotency_key,
117121
)
118-
except UnauthorizedError:
122+
except UnauthorizedError as e:
123+
logging.error(f"Unauthorized: AK/SK authentication failed: {str(e)}", exc_info=e)
119124
raise HTTPException(status_code=HTTPStatus.UNAUTHORIZED,
120125
detail="Unauthorized: AK/SK authentication failed")
121-
except LimitExceededError:
126+
except LimitExceededError as e:
127+
logging.error(f"Too Many Requests: rate limit exceeded: {str(e)}", exc_info=e)
122128
raise HTTPException(status_code=HTTPStatus.TOO_MANY_REQUESTS,
123129
detail="Too Many Requests: rate limit exceeded")
124-
except SignatureValidationError:
130+
except SignatureValidationError as e:
131+
logging.error(f"Unauthorized: invalid signature: {str(e)}", exc_info=e)
125132
raise HTTPException(status_code=HTTPStatus.UNAUTHORIZED,
126133
detail="Unauthorized: invalid signature")
127-
except Exception:
134+
except HTTPException as e:
135+
# Propagate HTTP errors from context parsing without altering status/detail
136+
raise e
137+
except Exception as e:
138+
logging.error(f"Failed to run chat: {str(e)}", exc_info=e)
128139
raise HTTPException(
129140
status_code=HTTPStatus.INTERNAL_SERVER_ERROR, detail="Internal Server Error")
130141

@@ -134,16 +145,22 @@ async def stop_chat_stream(request: Request, conversation_id: str):
134145
try:
135146
ctx: NorthboundContext = await _parse_northbound_context(request)
136147
return await stop_chat(ctx=ctx, external_conversation_id=conversation_id)
137-
except UnauthorizedError:
148+
except UnauthorizedError as e:
149+
logging.error(f"Unauthorized: AK/SK authentication failed: {str(e)}", exc_info=e)
138150
raise HTTPException(status_code=HTTPStatus.UNAUTHORIZED,
139151
detail="Unauthorized: AK/SK authentication failed")
140-
except LimitExceededError:
152+
except LimitExceededError as e:
153+
logging.error(f"Too Many Requests: rate limit exceeded: {str(e)}", exc_info=e)
141154
raise HTTPException(status_code=HTTPStatus.TOO_MANY_REQUESTS,
142155
detail="Too Many Requests: rate limit exceeded")
143-
except SignatureValidationError:
156+
except SignatureValidationError as e:
157+
logging.error(f"Unauthorized: invalid signature: {str(e)}", exc_info=e)
144158
raise HTTPException(status_code=HTTPStatus.UNAUTHORIZED,
145159
detail="Unauthorized: invalid signature")
146-
except Exception:
160+
except HTTPException as e:
161+
raise e
162+
except Exception as e:
163+
logging.error(f"Failed to stop chat: {str(e)}", exc_info=e)
147164
raise HTTPException(
148165
status_code=HTTPStatus.INTERNAL_SERVER_ERROR, detail="Internal Server Error")
149166

@@ -153,16 +170,22 @@ async def get_history(request: Request, conversation_id: str):
153170
try:
154171
ctx: NorthboundContext = await _parse_northbound_context(request)
155172
return await get_conversation_history(ctx=ctx, external_conversation_id=conversation_id)
156-
except UnauthorizedError:
173+
except UnauthorizedError as e:
174+
logging.error(f"Unauthorized: AK/SK authentication failed: {str(e)}", exc_info=e)
157175
raise HTTPException(status_code=HTTPStatus.UNAUTHORIZED,
158176
detail="Unauthorized: AK/SK authentication failed")
159-
except LimitExceededError:
177+
except LimitExceededError as e:
178+
logging.error(f"Too Many Requests: rate limit exceeded: {str(e)}", exc_info=e)
160179
raise HTTPException(status_code=HTTPStatus.TOO_MANY_REQUESTS,
161180
detail="Too Many Requests: rate limit exceeded")
162-
except SignatureValidationError:
181+
except SignatureValidationError as e:
182+
logging.error(f"Unauthorized: invalid signature: {str(e)}", exc_info=e)
163183
raise HTTPException(status_code=HTTPStatus.UNAUTHORIZED,
164184
detail="Unauthorized: invalid signature")
165-
except Exception:
185+
except HTTPException as e:
186+
raise e
187+
except Exception as e:
188+
logging.error(f"Failed to get conversation history: {str(e)}", exc_info=e)
166189
raise HTTPException(
167190
status_code=HTTPStatus.INTERNAL_SERVER_ERROR, detail="Internal Server Error")
168191

@@ -172,16 +195,22 @@ async def list_agents(request: Request):
172195
try:
173196
ctx: NorthboundContext = await _parse_northbound_context(request)
174197
return await get_agent_info_list(ctx=ctx)
175-
except UnauthorizedError:
198+
except UnauthorizedError as e:
199+
logging.error(f"Unauthorized: AK/SK authentication failed: {str(e)}", exc_info=e)
176200
raise HTTPException(status_code=HTTPStatus.UNAUTHORIZED,
177201
detail="Unauthorized: AK/SK authentication failed")
178-
except LimitExceededError:
202+
except LimitExceededError as e:
203+
logging.error(f"Too Many Requests: rate limit exceeded: {str(e)}", exc_info=e)
179204
raise HTTPException(status_code=HTTPStatus.TOO_MANY_REQUESTS,
180205
detail="Too Many Requests: rate limit exceeded")
181-
except SignatureValidationError:
206+
except SignatureValidationError as e:
207+
logging.error(f"Unauthorized: invalid signature: {str(e)}", exc_info=e)
182208
raise HTTPException(status_code=HTTPStatus.UNAUTHORIZED,
183209
detail="Unauthorized: invalid signature")
184-
except Exception:
210+
except HTTPException as e:
211+
raise e
212+
except Exception as e:
213+
logging.error(f"Failed to list agents: {str(e)}", exc_info=e)
185214
raise HTTPException(
186215
status_code=HTTPStatus.INTERNAL_SERVER_ERROR, detail="Internal Server Error")
187216

@@ -191,16 +220,22 @@ async def list_convs(request: Request):
191220
try:
192221
ctx: NorthboundContext = await _parse_northbound_context(request)
193222
return await list_conversations(ctx=ctx)
194-
except UnauthorizedError:
223+
except UnauthorizedError as e:
224+
logging.error(f"Unauthorized: AK/SK authentication failed: {str(e)}", exc_info=e)
195225
raise HTTPException(status_code=HTTPStatus.UNAUTHORIZED,
196226
detail="Unauthorized: AK/SK authentication failed")
197-
except LimitExceededError:
227+
except LimitExceededError as e:
228+
logging.error(f"Too Many Requests: rate limit exceeded: {str(e)}", exc_info=e)
198229
raise HTTPException(status_code=HTTPStatus.TOO_MANY_REQUESTS,
199230
detail="Too Many Requests: rate limit exceeded")
200-
except SignatureValidationError:
231+
except SignatureValidationError as e:
232+
logging.error(f"Unauthorized: invalid signature: {str(e)}", exc_info=e)
201233
raise HTTPException(status_code=HTTPStatus.UNAUTHORIZED,
202234
detail="Unauthorized: invalid signature")
203-
except Exception:
235+
except HTTPException as e:
236+
raise e
237+
except Exception as e:
238+
logging.error(f"Failed to list conversations: {str(e)}", exc_info=e)
204239
raise HTTPException(
205240
status_code=HTTPStatus.INTERNAL_SERVER_ERROR, detail="Internal Server Error")
206241

@@ -224,15 +259,21 @@ async def update_convs_title(
224259
"Idempotency-Key": result.get("idempotency_key", ""), "X-Request-Id": ctx.request_id}
225260
return JSONResponse(content=result, headers=headers_out)
226261

227-
except UnauthorizedError:
262+
except UnauthorizedError as e:
263+
logging.error(f"Unauthorized: AK/SK authentication failed: {str(e)}", exc_info=e)
228264
raise HTTPException(status_code=HTTPStatus.UNAUTHORIZED,
229265
detail="Unauthorized: AK/SK authentication failed")
230-
except LimitExceededError:
266+
except LimitExceededError as e:
267+
logging.error(f"Too Many Requests: rate limit exceeded: {str(e)}", exc_info=e)
231268
raise HTTPException(status_code=HTTPStatus.TOO_MANY_REQUESTS,
232269
detail="Too Many Requests: rate limit exceeded")
233-
except SignatureValidationError:
270+
except SignatureValidationError as e:
271+
logging.error(f"Unauthorized: invalid signature: {str(e)}", exc_info=e)
234272
raise HTTPException(status_code=HTTPStatus.UNAUTHORIZED,
235273
detail="Unauthorized: invalid signature")
236-
except Exception:
274+
except HTTPException as e:
275+
raise e
276+
except Exception as e:
277+
logging.error(f"Failed to update conversation title: {str(e)}", exc_info=e)
237278
raise HTTPException(
238279
status_code=HTTPStatus.INTERNAL_SERVER_ERROR, detail="Internal Server Error")

β€Žbackend/services/memory_config_service.pyβ€Ž

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,16 @@ def build_memory_context(user_id: str, tenant_id: str, agent_id: str | int) -> M
198198
disable_agent_ids=get_disabled_agent_ids(user_id),
199199
disable_user_agent_ids=get_disabled_useragent_ids(user_id),
200200
)
201+
# If user turn off the memory function, return minimum context directly
202+
if not memory_user_config.memory_switch:
203+
return MemoryContext(
204+
user_config=memory_user_config,
205+
memory_config=dict(),
206+
tenant_id=tenant_id,
207+
user_id=user_id,
208+
agent_id=str(agent_id),
209+
)
210+
201211
return MemoryContext(
202212
user_config=memory_user_config,
203213
memory_config=build_memory_config(tenant_id),

β€Žbackend/services/northbound_service.pyβ€Ž

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ async def start_streaming_chat(
150150
query: str,
151151
idempotency_key: Optional[str] = None
152152
) -> StreamingResponse:
153-
composed_key: Optional[str] = None
154153
try:
155154
# Simple rate limit
156155
await check_and_consume_rate_limit(ctx.tenant_id)

0 commit comments

Comments
Β (0)