@@ -119,6 +119,10 @@ async def record_request(self, prompt_params: Optional[Prompt] = None) -> Option
119119 """
120120 INSERT INTO prompts (id, timestamp, provider, request, type, workspace_id)
121121 VALUES (:id, :timestamp, :provider, :request, :type, :workspace_id)
122+ ON CONFLICT(id) DO UPDATE SET
123+ timestamp = excluded.timestamp, provider = excluded.provider,
124+ request = excluded.request, type = excluded.type,
125+ workspace_id = excluded.workspace_id
122126 RETURNING *
123127 """
124128 )
@@ -173,6 +177,9 @@ async def record_outputs(
173177 """
174178 INSERT INTO outputs (id, prompt_id, timestamp, output)
175179 VALUES (:id, :prompt_id, :timestamp, :output)
180+ ON CONFLICT (id) DO UPDATE SET
181+ timestamp = excluded.timestamp, output = excluded.output,
182+ prompt_id = excluded.prompt_id
176183 RETURNING *
177184 """
178185 )
@@ -192,6 +199,10 @@ async def record_alerts(self, alerts: List[Alert], initial_id: Optional[str]) ->
192199 )
193200 VALUES (:id, :prompt_id, :code_snippet, :trigger_string, :trigger_type,
194201 :trigger_category, :timestamp)
202+ ON CONFLICT (id) DO UPDATE SET
203+ code_snippet = excluded.code_snippet, trigger_string = excluded.trigger_string,
204+ trigger_type = excluded.trigger_type, trigger_category = excluded.trigger_category,
205+ timestamp = excluded.timestamp, prompt_id = excluded.prompt_id
195206 RETURNING *
196207 """
197208 )
@@ -219,9 +230,6 @@ async def record_alerts(self, alerts: List[Alert], initial_id: Optional[str]) ->
219230
220231 def _should_record_context (self , context : Optional [PipelineContext ]) -> tuple :
221232 """Check if the context should be recorded in DB and determine the action."""
222- if context is None or context .metadata .get ("stored_in_db" , False ):
223- return False , None , None
224-
225233 if not context .input_request :
226234 logger .warning ("No input request found. Skipping recording context." )
227235 return False , None , None
@@ -245,7 +253,6 @@ async def record_context(self, context: Optional[PipelineContext]) -> None:
245253 await self .record_request (context .input_request )
246254 await self .record_outputs (context .output_responses , None )
247255 await self .record_alerts (context .alerts_raised , None )
248- context .metadata ["stored_in_db" ] = True
249256 logger .info (
250257 f"Recorded context in DB. Output chunks: { len (context .output_responses )} . "
251258 f"Alerts: { len (context .alerts_raised )} ."
@@ -255,7 +262,6 @@ async def record_context(self, context: Optional[PipelineContext]) -> None:
255262 await self .update_request (initial_id , context .input_request )
256263 await self .record_outputs (context .output_responses , initial_id )
257264 await self .record_alerts (context .alerts_raised , initial_id )
258- context .metadata ["stored_in_db" ] = True
259265 logger .info (
260266 f"Recorded context in DB. Output chunks: { len (context .output_responses )} . "
261267 f"Alerts: { len (context .alerts_raised )} ."
0 commit comments