From 8de1cceba7f18374af0b67a9aa4414955c019fad Mon Sep 17 00:00:00 2001 From: flaukowski Date: Sun, 26 Jul 2026 02:01:40 -0500 Subject: [PATCH] fix(workflow): honor definition 'enabled' flag on upsert MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit upsert_workflow's ON CONFLICT DO UPDATE set name/definition/hash but never enabled, so re-publishing a kind:30620 definition with enabled: false changed the stored JSON while leaving the row enabled=TRUE — a disabled workflow kept firing on its schedule. Parse enabled from the definition and apply it on both insert and update. Co-Authored-By: Claude Fable 5 Signed-off-by: flaukowski (cherry picked from commit 96e16889b140bd71eed57bdac420d5e054f56ede) --- crates/buzz-db/src/workflow.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/crates/buzz-db/src/workflow.rs b/crates/buzz-db/src/workflow.rs index 7a2396c1fd..b33e609b4c 100644 --- a/crates/buzz-db/src/workflow.rs +++ b/crates/buzz-db/src/workflow.rs @@ -320,15 +320,24 @@ pub async fn upsert_workflow( definition_json: &str, definition_hash: &[u8], ) -> Result<()> { + // The `enabled` flag lives in the definition (WorkflowDef.enabled, default + // true). Honor it on both insert AND update — otherwise re-publishing a + // definition with `enabled: false` changes the JSON but leaves the row + // enabled, so a disabled workflow keeps firing. + let enabled = serde_json::from_str::(definition_json) + .ok() + .and_then(|v| v.get("enabled").and_then(|e| e.as_bool())) + .unwrap_or(true); let row = sqlx::query( r#" INSERT INTO workflows (community_id, id, name, owner_pubkey, channel_id, definition, definition_hash, status, enabled) - VALUES ($1, $2, $3, $4, $5, $6::jsonb, $7, 'active', TRUE) + VALUES ($1, $2, $3, $4, $5, $6::jsonb, $7, 'active', $8) ON CONFLICT (community_id, id) DO UPDATE SET name = EXCLUDED.name, definition = EXCLUDED.definition, definition_hash = EXCLUDED.definition_hash, + enabled = EXCLUDED.enabled, updated_at = NOW() WHERE workflows.owner_pubkey = EXCLUDED.owner_pubkey AND workflows.channel_id IS NOT DISTINCT FROM EXCLUDED.channel_id @@ -342,6 +351,7 @@ pub async fn upsert_workflow( .bind(channel_id) .bind(definition_json) .bind(definition_hash) + .bind(enabled) .fetch_optional(pool) .await?;