diff --git a/app/repositories/implementations/analysis_repository.py b/app/repositories/implementations/analysis_repository.py index ecd7a46..29fea4a 100644 --- a/app/repositories/implementations/analysis_repository.py +++ b/app/repositories/implementations/analysis_repository.py @@ -34,6 +34,15 @@ async def create(self, analysis: Analysis) -> Analysis: return self._to_domain(model) + async def update_stream_safe(self, analysis: Analysis) -> Analysis: + """Update with proper async handling.""" + db_obj = self._to_model(analysis) + merged_obj = await self._session.merge(db_obj) + await self._session.commit() + self._session.expunge(merged_obj) + + return analysis + async def get_with_relations(self, analysis_id: UUID) -> Optional[Analysis]: """Get analysis with related sources and feedback.""" query = ( diff --git a/app/services/analysis_orchestrator.py b/app/services/analysis_orchestrator.py index 1a9e2f3..2ea3aa4 100644 --- a/app/services/analysis_orchestrator.py +++ b/app/services/analysis_orchestrator.py @@ -251,7 +251,7 @@ async def _generate_analysis( log_data = LogProbsData(tokens=analysis_text, probs=log_probs) current_analysis.log_probs = log_data - updated_analysis = await self._analysis_repo.update(current_analysis) + updated_analysis = await self._analysis_repo.update_stream_safe(current_analysis) yield { "type": "analysis_complete",