fix(sync): allow routed prefixes in import validation

When importing issues in a multi-rig setup (Gas Town), the prefix
validation was failing for issues with prefixes from other rigs
(e.g., hq-* prefixes from town-level beads).

This fix extends buildAllowedPrefixSet to also load prefixes from
routes.jsonl, allowing issues from any routed rig to pass validation.

Fixes: gt-2maz79

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
dennis
2026-01-17 03:44:47 -08:00
committed by Steve Yegge
parent feed888b57
commit 828fc11b57

View File

@@ -4,12 +4,14 @@ import (
"context"
"fmt"
"os"
"path/filepath"
"sort"
"strings"
"time"
"github.com/steveyegge/beads/internal/config"
"github.com/steveyegge/beads/internal/linear"
"github.com/steveyegge/beads/internal/routing"
"github.com/steveyegge/beads/internal/storage"
"github.com/steveyegge/beads/internal/storage/sqlite"
"github.com/steveyegge/beads/internal/types"
@@ -228,8 +230,12 @@ func handlePrefixMismatch(ctx context.Context, sqliteStore *sqlite.SQLiteStorage
// Read allowed_prefixes config for additional valid prefixes (e.g., mol-*)
allowedPrefixesConfig, _ := sqliteStore.GetConfig(ctx, "allowed_prefixes")
// Get beads directory from database path for route lookup
beadsDir := filepath.Dir(sqliteStore.Path())
// GH#686: In multi-repo mode, allow all prefixes (nil = allow all)
allowedPrefixes := buildAllowedPrefixSet(configuredPrefix, allowedPrefixesConfig)
// Also include prefixes from routes.jsonl for multi-rig setups (Gas Town)
allowedPrefixes := buildAllowedPrefixSet(configuredPrefix, allowedPrefixesConfig, beadsDir)
if allowedPrefixes == nil {
return issues, nil
}
@@ -1029,7 +1035,8 @@ func validateNoDuplicateExternalRefs(issues []*types.Issue, clearDuplicates bool
// buildAllowedPrefixSet returns allowed prefixes, or nil to allow all (GH#686).
// In multi-repo mode, additional repos have their own prefixes - allow all.
// Also accepts allowedPrefixesConfig (comma-separated list like "gt-,mol-").
func buildAllowedPrefixSet(primaryPrefix string, allowedPrefixesConfig string) map[string]bool {
// Also loads prefixes from routes.jsonl for multi-rig setups (Gas Town).
func buildAllowedPrefixSet(primaryPrefix string, allowedPrefixesConfig string, beadsDir string) map[string]bool {
if config.GetMultiRepoConfig() != nil {
return nil // Multi-repo: allow all prefixes
}
@@ -1049,5 +1056,20 @@ func buildAllowedPrefixSet(primaryPrefix string, allowedPrefixesConfig string) m
}
}
// Load prefixes from routes.jsonl for multi-rig setups (Gas Town)
// This allows issues from other rigs to coexist in the same JSONL
if beadsDir != "" {
routes, err := routing.LoadRoutes(beadsDir)
if err == nil && len(routes) > 0 {
for _, route := range routes {
// Normalize: remove trailing - if present
prefix := strings.TrimSuffix(route.Prefix, "-")
if prefix != "" {
allowed[prefix] = true
}
}
}
}
return allowed
}