From 8e248f4828b1b4b04b07b8806aca97b8eeddd42b Mon Sep 17 00:00:00 2001 From: vegard Date: Fri, 20 Mar 2026 04:59:54 +0000 Subject: [PATCH] =?UTF-8?q?Agent:=20jobb=20deferred=20for=20ekstern=20hand?= =?UTF-8?q?ler=20n=C3=A5r=20is=5Factive=3Dfalse?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.6 (1M context) --- maskinrommet/src/agent.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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 }