From 74a6b6bb187cec98338ea0c4190c74efaeec798e Mon Sep 17 00:00:00 2001 From: dtoro Date: Tue, 7 Jul 2026 16:45:28 +0200 Subject: [PATCH] =?UTF-8?q?phase=204:=20fix=20execution=20FK=20violation?= =?UTF-8?q?=20=E2=80=94=20create=20entity=20row=20before=20insert?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - phase3.go: RequestExecution now calls InsertEntity before InsertExecution (executions.entity_id references entities.id via FK constraint). - mcp/server.go: request_execution MCP tool same fix — inserts entities row with slug 'exec::' before executions insert. - docker-compose.yml: fix seed OIKOS_SEEDS_DIR from /app/seeds to /seeds (distroless image COPY destination). --- docker-compose.yml | 2 +- internal/httpapi/phase3.go | 12 ++++++++++++ internal/mcp/server.go | 10 ++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index bdb1abb..2c152b4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -42,7 +42,7 @@ services: condition: service_completed_successfully environment: OIKOS_DATABASE_URL: postgres://oikos:${OIKOS_DB_PASSWORD:-oikos_dev}@postgres:5432/oikos?sslmode=disable - OIKOS_SEEDS_DIR: /app/seeds + OIKOS_SEEDS_DIR: /seeds command: ["seed"] restart: "no" diff --git a/internal/httpapi/phase3.go b/internal/httpapi/phase3.go index 1fac1d3..8703547 100644 --- a/internal/httpapi/phase3.go +++ b/internal/httpapi/phase3.go @@ -504,6 +504,18 @@ func (s *Server) RequestExecution(ctx context.Context, req gen.RequestExecutionR defer tx.Rollback(ctx) q := sqlcgen.New(tx) + + execSlug := "exec:" + id.String()[:8] + if _, err := q.InsertEntity(ctx, sqlcgen.InsertEntityParams{ + ID: id, + Slug: execSlug, + Type: "execution", + Name: req.Body.Action + " on " + req.Body.Target, + Attributes: []byte("{}"), + }); err != nil { + return nil, err + } + if err := q.InsertExecution(ctx, sqlcgen.InsertExecutionParams{ EntityID: id, TargetEntityID: &targetID, diff --git a/internal/mcp/server.go b/internal/mcp/server.go index e7aa1bd..e92b440 100644 --- a/internal/mcp/server.go +++ b/internal/mcp/server.go @@ -243,6 +243,16 @@ func newServer(pool *db.Pool, agentID uuid.UUID) *mcp.Server { } correlationID := uuid.New().String() + execSlug := "exec:" + targetSlug + ":" + id.String()[:8] + + _, err = pool.Exec(ctx, ` + INSERT INTO entities (id, slug, type, name, attributes) + VALUES ($1, $2, 'execution', $3, '{}')`, + id, execSlug, action+" on "+targetSlug) + if err != nil { + return textResult(fmt.Sprintf("insert entity: %v", err)), nil + } + _, err = pool.Exec(ctx, ` INSERT INTO executions (entity_id, target_entity_id, action, risk_class, status, correlation_id, agent_id)