Agent: jobb deferred for ekstern handler når is_active=false

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
vegard 2026-03-20 04:59:54 +00:00
parent d597b45cb6
commit 8e248f4828

View file

@ -63,7 +63,13 @@ pub async fn handle_agent_respond(
).bind(agent_node_id).fetch_optional(db).await ).bind(agent_node_id).fetch_optional(db).await
.map_err(|e| format!("DB-feil: {e}"))?.unwrap_or(false); .map_err(|e| format!("DB-feil: {e}"))?.unwrap_or(false);
if !is_active { 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 // Rate limiting
@ -164,7 +170,9 @@ async fn load_agent_config(db: &PgPool, agent_node_id: Uuid) -> Result<AgentConf
} }
pub async fn find_agent_participant(db: &PgPool, communication_id: Uuid) -> Result<Option<Uuid>, sqlx::Error> { pub async fn find_agent_participant(db: &PgPool, communication_id: Uuid) -> Result<Option<Uuid>, 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( 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 ).bind(communication_id).fetch_optional(db).await
} }