fix: prevent inherited BEADS_DIR from causing prefix mismatch (#321)
- Fix beads.run() to always explicitly set BEADS_DIR based on the working directory or explicit override - This prevents inherited environment variables (e.g., from mayor session with BEADS_DIR=/home/erik/gt/.beads) from causing prefix mismatch errors when creating agent beads for rigs - Update polecat manager to use NewWithBeadsDir for explicitness - Add comprehensive test coverage for BEADS_DIR routing and validation - Add SessionLister interface for deterministic orphan session testing Root cause: When BEADS_DIR was set in the parent environment, all bd commands used the town database (hq- prefix) instead of the rig database (gt- prefix), causing "prefix mismatch: database uses 'hq' but you specified 'gt'" errors during polecat spawn. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
committed by
Steve Yegge
parent
ea84079f8b
commit
598a39e708
@@ -133,10 +133,14 @@ func (b *Beads) run(args ...string) ([]byte, error) {
|
||||
cmd := exec.Command("bd", fullArgs...) //nolint:gosec // G204: bd is a trusted internal tool
|
||||
cmd.Dir = b.workDir
|
||||
|
||||
// Set BEADS_DIR if specified (enables cross-database access)
|
||||
if b.beadsDir != "" {
|
||||
cmd.Env = append(os.Environ(), "BEADS_DIR="+b.beadsDir)
|
||||
// Always explicitly set BEADS_DIR to prevent inherited env vars from
|
||||
// causing prefix mismatches. Use explicit beadsDir if set, otherwise
|
||||
// resolve from working directory.
|
||||
beadsDir := b.beadsDir
|
||||
if beadsDir == "" {
|
||||
beadsDir = ResolveBeadsDir(b.workDir)
|
||||
}
|
||||
cmd.Env = append(os.Environ(), "BEADS_DIR="+beadsDir)
|
||||
|
||||
var stdout, stderr bytes.Buffer
|
||||
cmd.Stdout = &stdout
|
||||
|
||||
Reference in New Issue
Block a user