Spaces:
Sleeping
Sleeping
Commit
·
fd9d0f9
1
Parent(s):
0f8c838
fix: V3 migration issues - Auto-migrate old sessions and use Mistral for chat names
Browse files- Fix integrity check to auto-migrate old MongoDB messages to S3
- Clear MongoDB messages array after successful migration
- Initialize S3 for new empty sessions
- Change chat name model from Claude to Mistral (V3 compliance)
- Resolves session integrity failure on second message
- Resolves Bedrock ResourceNotFoundException for chat names
- api_routes_v2.py +14 -5
api_routes_v2.py
CHANGED
|
@@ -142,12 +142,20 @@ def _validate_conversation_integrity(session_id: str) -> Dict[str, Any]:
|
|
| 142 |
session_manager.update_session(session_id, {"conversation_s3_key": default_key})
|
| 143 |
return {"valid": True, "note": "Fixed missing s3_key metadata"}
|
| 144 |
except ClientError:
|
| 145 |
-
# S3 missing.
|
| 146 |
-
# For strict V3, we error if S3 missing, unless session is empty.
|
| 147 |
msgs = session.get("messages", [])
|
| 148 |
if msgs:
|
| 149 |
-
|
| 150 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
|
| 152 |
try:
|
| 153 |
s3.head_object(Bucket=S3_BUCKET, Key=key)
|
|
@@ -357,7 +365,8 @@ def _resolve_bedrock_model_for_titles(session: Dict[str, Any]) -> str:
|
|
| 357 |
except Exception:
|
| 358 |
model = None
|
| 359 |
if not model:
|
| 360 |
-
|
|
|
|
| 361 |
return model
|
| 362 |
|
| 363 |
|
|
|
|
| 142 |
session_manager.update_session(session_id, {"conversation_s3_key": default_key})
|
| 143 |
return {"valid": True, "note": "Fixed missing s3_key metadata"}
|
| 144 |
except ClientError:
|
| 145 |
+
# S3 missing. Migrate old MongoDB messages to S3 (V3 migration path)
|
|
|
|
| 146 |
msgs = session.get("messages", [])
|
| 147 |
if msgs:
|
| 148 |
+
# Auto-migrate old session to V3
|
| 149 |
+
try:
|
| 150 |
+
_save_conversation_to_s3(session_id, msgs)
|
| 151 |
+
# Clear old MongoDB messages after successful migration
|
| 152 |
+
session_manager.update_session(session_id, {"messages": []})
|
| 153 |
+
return {"valid": True, "note": "Migrated old MongoDB messages to S3"}
|
| 154 |
+
except Exception as e:
|
| 155 |
+
return {"valid": False, "error": f"Migration failed: {str(e)}"}
|
| 156 |
+
# New empty session - initialize S3
|
| 157 |
+
_save_conversation_to_s3(session_id, [])
|
| 158 |
+
return {"valid": True, "note": "Initialized new session"}
|
| 159 |
|
| 160 |
try:
|
| 161 |
s3.head_object(Bucket=S3_BUCKET, Key=key)
|
|
|
|
| 365 |
except Exception:
|
| 366 |
model = None
|
| 367 |
if not model:
|
| 368 |
+
# V3 RULE: NO CLAUDE - Use Mistral or Titan only
|
| 369 |
+
model = os.getenv("BEDROCK_MODEL_ID") or os.getenv("BEDROCK_DEFAULT_MODEL") or "mistral.mistral-large-2402-v1:0"
|
| 370 |
return model
|
| 371 |
|
| 372 |
|