Fix root cause: naive vs aware datetime crash + stuck AI mode indicator
The autonomous loop was crashing on every decision with: TypeError: can't subtract offset-naive and offset-aware datetimes because MongoDB stores created_at without timezone info but the code compared it against datetime.now(timezone.utc). - conversation_context_service: make created_at timezone-aware before subtraction (replace tzinfo=utc when naive) - DiscussionPanel: fix sync effect — when server reports AI mode is inactive, always clear localAiModeActive regardless of its value, so the "AI is generating..." spinner doesn't get stuck when the backend fails/stops before the frontend has confirmed AI mode started Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
7e72d07329
commit
2e85fc1acc
2 changed files with 7 additions and 3 deletions
|
|
@ -50,6 +50,9 @@ class ConversationContextService:
|
|||
# Calculate elapsed time
|
||||
created_at = focus_group.get('created_at')
|
||||
if created_at:
|
||||
# MongoDB may return naive datetimes — make timezone-aware before subtracting
|
||||
if created_at.tzinfo is None:
|
||||
created_at = created_at.replace(tzinfo=timezone.utc)
|
||||
elapsed_minutes = (datetime.now(timezone.utc) - created_at).total_seconds() / 60
|
||||
else:
|
||||
elapsed_minutes = 0
|
||||
|
|
|
|||
|
|
@ -77,12 +77,13 @@ const DiscussionPanel = ({
|
|||
// Calculate reasoning panel visibility - only show when user explicitly expands it
|
||||
const reasoningPanelVisible = reasoningPanelExpanded;
|
||||
|
||||
// Sync localAiModeActive back to null once parent prop has caught up
|
||||
// When server reports AI is NOT active, clear any optimistic local override immediately.
|
||||
// This handles the case where AI mode fails/stops before the frontend confirms it started.
|
||||
useEffect(() => {
|
||||
if (localAiModeActive !== null && localAiModeActive === isAiModeActive) {
|
||||
if (!isAiModeActive && localAiModeActive !== null) {
|
||||
setLocalAiModeActive(null);
|
||||
}
|
||||
}, [isAiModeActive, localAiModeActive]);
|
||||
}, [isAiModeActive]);
|
||||
|
||||
// Fetch reasoning history when in AI mode
|
||||
useEffect(() => {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue