feat(runtime): sync experience bus and learner stack into main

This commit is contained in:
Apple
2026-03-05 11:30:17 -08:00
parent edd0427c61
commit ef6ebe3583
22 changed files with 2837 additions and 22 deletions

View File

@@ -443,6 +443,9 @@ class Database:
) -> Dict[str, Any]:
"""Create or update a user fact (isolated by agent_id)"""
import json
# Normalize NULL to empty string so ON CONFLICT matches (PostgreSQL: NULL != NULL in unique)
_agent_id = (agent_id or "").strip()
_team_id = team_id or ""
# Convert dict to JSON string for asyncpg JSONB
json_value = json.dumps(fact_value_json) if fact_value_json else None
@@ -457,7 +460,7 @@ class Database:
fact_value_json = EXCLUDED.fact_value_json,
updated_at = NOW()
RETURNING *
""", user_id, team_id, agent_id, fact_key, fact_value, json_value)
""", user_id, _team_id, _agent_id, fact_key, fact_value, json_value)
except asyncpg.exceptions.InvalidColumnReferenceError:
# Backward compatibility for DBs that only have UNIQUE(user_id, team_id, fact_key).
row = await conn.fetchrow("""
@@ -470,7 +473,7 @@ class Database:
fact_value_json = EXCLUDED.fact_value_json,
updated_at = NOW()
RETURNING *
""", user_id, team_id, agent_id, fact_key, fact_value, json_value)
""", user_id, _team_id, _agent_id, fact_key, fact_value, json_value)
return dict(row) if row else {}