From 9892f94fbe44505c8767ea5c4a558cbe6d35dcc6 Mon Sep 17 00:00:00 2001 From: taylorlynn Date: Fri, 20 Feb 2026 11:22:18 -0500 Subject: [PATCH 1/3] changed the stream update logic --- .../implementations/analysis_repository.py | 13 +++++++++++++ app/services/analysis_orchestrator.py | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/repositories/implementations/analysis_repository.py b/app/repositories/implementations/analysis_repository.py index ecd7a46..b944c1a 100644 --- a/app/repositories/implementations/analysis_repository.py +++ b/app/repositories/implementations/analysis_repository.py @@ -33,6 +33,19 @@ async def create(self, analysis: Analysis) -> Analysis: self._session.expunge(model) 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) + + # 2. Merge the state into the current session + merged_obj = await self._session.merge(db_obj) + + # 3. Commit the transaction to release the locks and clear the 'idle in transaction' + 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.""" 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", From d07e2865eee2bca4e36aaee2bf5e409b8746057b Mon Sep 17 00:00:00 2001 From: taylorlynn Date: Fri, 20 Feb 2026 11:23:02 -0500 Subject: [PATCH 2/3] code cleanup --- app/repositories/implementations/analysis_repository.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/repositories/implementations/analysis_repository.py b/app/repositories/implementations/analysis_repository.py index b944c1a..e502f36 100644 --- a/app/repositories/implementations/analysis_repository.py +++ b/app/repositories/implementations/analysis_repository.py @@ -37,11 +37,7 @@ async def create(self, analysis: Analysis) -> Analysis: async def update_stream_safe(self, analysis: Analysis) -> Analysis: """Update with proper async handling.""" db_obj = self._to_model(analysis) - - # 2. Merge the state into the current session merged_obj = await self._session.merge(db_obj) - - # 3. Commit the transaction to release the locks and clear the 'idle in transaction' await self._session.commit() self._session.expunge(merged_obj) From bac8d09fc3d89488f69bae86d2c8ca4514be94b5 Mon Sep 17 00:00:00 2001 From: taylorlynn Date: Fri, 20 Feb 2026 11:25:24 -0500 Subject: [PATCH 3/3] formating --- app/repositories/implementations/analysis_repository.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/repositories/implementations/analysis_repository.py b/app/repositories/implementations/analysis_repository.py index e502f36..29fea4a 100644 --- a/app/repositories/implementations/analysis_repository.py +++ b/app/repositories/implementations/analysis_repository.py @@ -33,14 +33,14 @@ async def create(self, analysis: Analysis) -> Analysis: self._session.expunge(model) 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]: