From 6d5465523982e737eeb07e8cd7770e1cd42d2dea Mon Sep 17 00:00:00 2001 From: "Molecule AI Dev Engineer A (Kimi)" Date: Mon, 1 Jun 2026 18:59:14 +0000 Subject: [PATCH] fix(broadcast): port corrected org-root CTE from org_scope.go (#1959) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit workspace_broadcast.go used the OLD org-root CTE shape that carried `id AS root_id` from the recursive seed. For a non-root sender, this resolved the org root to the sender's own ID instead of the topmost ancestor, causing broadcast under-delivery (missed the rest of the org subtree). Replace the inline CTE with the shared `orgRootID` helper from org_scope.go (commit from #1954), which selects `id AS root_id` only from the parentless row — the actual org root. Fixes #1959 Co-Authored-By: Claude Opus 4.7 --- .../internal/handlers/workspace_broadcast.go | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/workspace-server/internal/handlers/workspace_broadcast.go b/workspace-server/internal/handlers/workspace_broadcast.go index 27ce7a8ea..60155038f 100644 --- a/workspace-server/internal/handlers/workspace_broadcast.go +++ b/workspace-server/internal/handlers/workspace_broadcast.go @@ -82,19 +82,7 @@ func (h *BroadcastHandler) Broadcast(c *gin.Context) { // Find the sender's org root by walking the parent_id chain. // Workspaces with parent_id = NULL are org roots; every other workspace // belongs to the org identified by its topmost ancestor. - var orgRootID string - err = db.DB.QueryRowContext(ctx, ` - WITH RECURSIVE org_chain AS ( - SELECT id, parent_id, id AS root_id - FROM workspaces - WHERE id = $1 - UNION ALL - SELECT w.id, w.parent_id, c.root_id - FROM workspaces w - JOIN org_chain c ON w.id = c.parent_id - ) - SELECT root_id FROM org_chain WHERE parent_id IS NULL LIMIT 1 - `, senderID).Scan(&orgRootID) + rootID, err := orgRootID(ctx, db.DB, senderID) if err != nil { log.Printf("Broadcast: org root lookup for %s: %v", senderID, err) c.JSON(http.StatusInternalServerError, gin.H{"error": "internal error"}) @@ -121,7 +109,7 @@ func (h *BroadcastHandler) Broadcast(c *gin.Context) { SELECT 1 FROM workspaces w WHERE w.id = c.id AND w.status != 'removed' ) - `, orgRootID, senderID) + `, rootID, senderID) if err != nil { log.Printf("Broadcast: recipient query failed for %s: %v", senderID, err) c.JSON(http.StatusInternalServerError, gin.H{"error": "internal error"}) -- 2.52.0