fix(beads): prevent routes.jsonl corruption and add doctor check for rig-level routes.jsonl (#377)
* fix(beads): prevent routes.jsonl corruption from bd auto-export When issues.jsonl doesn't exist, bd's auto-export mechanism writes issue data to routes.jsonl, corrupting the routing configuration. Changes: - install.go: Create issues.jsonl before routes.jsonl at town level - manager.go: Create issues.jsonl in rig beads; don't create routes.jsonl (rig-level routes.jsonl breaks bd's walk-up routing to town routes) - Add integration tests for routes.jsonl corruption prevention Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(doctor): add check to detect and fix rig-level routes.jsonl Add RigRoutesJSONLCheck to detect routes.jsonl files in rig .beads directories. These files break bd's walk-up routing to town-level routes.jsonl, causing cross-rig routing failures. The fix unconditionally deletes rig-level routes.jsonl files since bd will auto-export to issues.jsonl on next run. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * test(rig): add verification that routes.jsonl does NOT exist in rig .beads Add explicit test assertion and detailed comment explaining why rig-level routes.jsonl files must not exist (breaks bd walk-up routing to town routes). Also verify that issues.jsonl DOES exist (prevents bd auto-export corruption). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(doctor): ensure town root route exists in routes.jsonl The RoutesCheck now detects and fixes missing town root routes (hq- -> .). This can happen when routes.jsonl is corrupted or was created without the town route during initialization. Changes: - Detect missing hq- route in Run() - Add hq- route in Fix() when missing - Handle case where routes.jsonl is corrupted (regenerate with town route) - Add comprehensive unit tests for route detection and fixing Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * test(beads): fix routing integration test for routes.jsonl corruption The TestBeadsRoutingFromTownRoot test was failing because bd's auto-export mechanism writes issue data to routes.jsonl when issues.jsonl doesn't exist. This corrupts the routing configuration. Fix: Create empty issues.jsonl after bd init to prevent corruption. This mirrors what gt install does to prevent the same bug. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: julianknutsen <julianknutsen@users.noreply.github> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -635,19 +635,21 @@ func (m *Manager) initBeads(rigPath, prefix string) error {
|
||||
// Ignore errors - fingerprint is optional for functionality
|
||||
_, _ = migrateCmd.CombinedOutput()
|
||||
|
||||
// Add route from rig beads to town beads for cross-database resolution.
|
||||
// This allows rig beads to resolve hq-* prefixed beads (role beads, etc.)
|
||||
// that are stored in town beads.
|
||||
townRoute := beads.Route{Prefix: "hq-", Path: ".."}
|
||||
if err := beads.AppendRouteToDir(beadsDir, townRoute); err != nil {
|
||||
// Non-fatal: role slot set will fail but agent beads still work
|
||||
fmt.Printf(" ⚠ Could not add route to town beads: %v\n", err)
|
||||
// Ensure issues.jsonl exists to prevent bd auto-export from corrupting other files.
|
||||
// bd init creates beads.db but not issues.jsonl in SQLite mode.
|
||||
// Without issues.jsonl, bd's auto-export might write issues to other .jsonl files.
|
||||
issuesJSONL := filepath.Join(beadsDir, "issues.jsonl")
|
||||
if _, err := os.Stat(issuesJSONL); os.IsNotExist(err) {
|
||||
if err := os.WriteFile(issuesJSONL, []byte{}, 0644); err != nil {
|
||||
// Non-fatal but log it
|
||||
fmt.Printf(" ⚠ Could not create issues.jsonl: %v\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
typesCmd := exec.Command("bd", "config", "set", "types.custom", constants.BeadsCustomTypes)
|
||||
typesCmd.Dir = rigPath
|
||||
typesCmd.Env = filteredEnv
|
||||
_, _ = typesCmd.CombinedOutput()
|
||||
// NOTE: We intentionally do NOT create routes.jsonl in rig beads.
|
||||
// bd's routing walks up to find town root (via mayor/town.json) and uses
|
||||
// town-level routes.jsonl for prefix-based routing. Rig-level routes.jsonl
|
||||
// would prevent this walk-up and break cross-rig routing.
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user