diff --git a/maskinrommet/src/agent.rs b/maskinrommet/src/agent.rs index dad6a8c..b395b9c 100644 --- a/maskinrommet/src/agent.rs +++ b/maskinrommet/src/agent.rs @@ -63,7 +63,13 @@ pub async fn handle_agent_respond( ).bind(agent_node_id).fetch_optional(db).await .map_err(|e| format!("DB-feil: {e}"))?.unwrap_or(false); if !is_active { - return Ok(serde_json::json!({"status": "skipped", "reason": "agent_inactive"})); + // La jobben ligge for ekstern handler (Claude Code polling) + sqlx::query("UPDATE job_queue SET status = 'pending', started_at = NULL WHERE id = $1") + .bind(job.id) + .execute(db) + .await + .map_err(|e| format!("DB-feil ved tilbakestilling: {e}"))?; + return Ok(serde_json::json!({"status": "deferred", "reason": "agent_inactive_external_handler"})); } // Rate limiting @@ -164,7 +170,9 @@ async fn load_agent_config(db: &PgPool, agent_node_id: Uuid) -> Result Result, sqlx::Error> { + // Finn agent-deltaker uansett is_active — kill switch sjekkes i handleren. + // Dette sikrer at jobben opprettes slik at eksterne handlers (Claude Code) kan plukke den. sqlx::query_scalar( - "SELECT n.id FROM nodes n JOIN edges e ON e.source_id = n.id JOIN agent_identities ai ON ai.node_id = n.id WHERE e.target_id = $1 AND e.edge_type IN ('owner', 'member_of') AND n.node_kind = 'agent' AND ai.is_active = true LIMIT 1", + "SELECT n.id FROM nodes n JOIN edges e ON e.source_id = n.id JOIN agent_identities ai ON ai.node_id = n.id WHERE e.target_id = $1 AND e.edge_type IN ('owner', 'member_of') AND n.node_kind = 'agent' LIMIT 1", ).bind(communication_id).fetch_optional(db).await }