The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(agent): recreate a delegate child's row when its parent was deleted
kshitijk4poor47022d959aa0
diff --git a/agent/session_persistence.py b/agent/session_persistence.pyindex 42bf18faac3..400d77ae172 100644--- a/agent/session_persistence.py+++ b/agent/session_persistence.py@@ -321,6 +321,15 @@ def _db_flush_failed(agent, e: Exception, batch_rows: List[Dict[str, Any]], adopagent._last_flushed_db_idx = 0agent._session_db_created = Falseagent._ensure_db_session()+ parent_id = agent._parent_session_id+ if not agent._session_db_created and parent_id and agent._session_db.get_session(parent_id) is None:+ # Delegate child whose parent was deleted (cascade): the row's own parent FK would reject every+ # recreate. Create it unparented for this call only; the relay and hooks still use the parent id.+ agent._parent_session_id = None+ try:+ agent._ensure_db_session()+ finally:+ agent._parent_session_id = parent_idif not agent._session_db_created:# Row creation failed too (transient store trouble): don't append into a guaranteed# rollback — keep the batch unmarked so the next flush retries the whole thing.