fix: add involves edge from task to agent:nomos at creation
createTaskEntity creates the task entity but never adds any graph edges. The involves edges are only added by the run handler, so sessions that call set_goal but never make a run call leave orphan task entities with zero relationships. Adds an idempotent involves edge from the new task to agent:nomos at creation time, matching the same pattern used for run's involves edges in server.go.
This commit is contained in:
@@ -179,6 +179,15 @@ func (s *store) createTaskEntity(ctx context.Context, sessionID, title string) s
|
||||
`UPDATE agent_sessions SET entity_id = $1 WHERE id = $2`, entityID, sessionID); err != nil {
|
||||
slog.Warn("nomos: could not link task entity", "session", sessionID, "error", err)
|
||||
}
|
||||
// Graph edge: task —involves→ agent:nomos (gives every task at least one
|
||||
// edge from creation, even if no run calls are ever made).
|
||||
s.pool.Exec(ctx, `INSERT INTO relationships (source_id, target_id, type, attributes, valid_from)
|
||||
SELECT $1, id, 'involves', '{"by":"nomos"}'::jsonb, now()
|
||||
FROM entities WHERE slug = 'agent:nomos'
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM relationships r
|
||||
WHERE r.source_id = $1 AND r.target_id = entities.id AND r.type = 'involves' AND r.valid_to IS NULL)`,
|
||||
entityID)
|
||||
return entityID.String()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user