Skip to content

fix: add RouteForBead to bdCmd builder for consistent subprocess routing#3526

Draft
mk-imagine wants to merge 6 commits intogastownhall:mainfrom
mk-imagine:fix/bd-subprocess-routing
Draft

fix: add RouteForBead to bdCmd builder for consistent subprocess routing#3526
mk-imagine wants to merge 6 commits intogastownhall:mainfrom
mk-imagine:fix/bd-subprocess-routing

Conversation

@mk-imagine
Copy link
Copy Markdown
Contributor

@mk-imagine mk-imagine commented Apr 5, 2026

Summary

Add a RouteForBead(beadID string) *bdCmd method to the existing bdCmd builder in internal/cmd/bd_helpers.go. This encapsulates the three-step routing pattern (resolve prefix via routes.jsonl, set cmd.Dir, strip BEADS_DIR) into a single chainable builder call, then migrates 11 call sites that currently lack routing.

Why: ~160 out of ~199 internal bd subprocess calls lack prefix routing. When Go code calls bd show <[rig]-bead> from the town root, it queries the wrong database (hq instead of [rig]). This causes silent failures: beads created by polecats are invisible to the Mayor, convoy completion checks miss rig-level beads, and the merge queue loses MR beads.

Root cause found: The Mayor couldn't see [rig]-* beads created by polecats during a parallel pipeline test run. Investigation traced it to bd subprocess calls in convoy.go and prime.go that set cmd.Dir to the town root instead of routing to the rig database.

Implementation Plan

Phase 1: Implement RouteForBead() method + tests
Phase 2: Migrate 11 call sites across 3 files:

File Sites Pattern
prime.go 1 Raw exec.Command, no Dir
deacon.go 1 Uses townRoot as Dir
convoy.go 9 Uses townBeads as Dir with convoy IDs

Phase 3: Validation sweep

Key Design Decisions

  • Method on existing bdCmd builder (not a standalone function)
  • Always strips BEADS_DIR (defensive — inherited value is never correct for cross-rig)
  • Silent fallback on routing failure (backward compatible)
  • Routes convoy hq-* IDs too (zero-cost when prefix resolves to town-level, future-proofs for rig-level convoys)

Key Files

  • internal/cmd/bd_helpers.go — new RouteForBead() method
  • internal/cmd/bd_helpers_test.go — tests for routing behavior
  • internal/cmd/prime.go — 1 call site
  • internal/cmd/deacon.go — 1 call site
  • internal/cmd/convoy.go — 9 call sites

Test plan

  • go build ./... passes
  • go test -race ./internal/cmd/... passes
  • golangci-lint run clean
  • Existing bd_helpers_test.go tests still pass
  • New RouteForBead tests verify Dir and env stripping behavior

…WIP)

Placeholder for draft PR. Adds 5 routed bd command wrappers under gt bead.
@github-actions github-actions bot added the status/needs-triage Inbox — we haven't looked at it yet label Apr 5, 2026
namuroh and others added 5 commits April 5, 2026 04:05
…x6o)

Replace repeated Dir(resolveBeadDir(id)).StripBeadsDir() pattern with
a single RouteForBead(id) builder method on bdCmd. This prepares for
adding 5 new gt bead subcommands that reuse the same routing logic.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…hq-x6o)

Add 5 new gt bead subcommands that proxy bd commands with automatic
prefix-based routing to the correct rig database:

- create: routes by --rig flag to target rig
- update: routes by bead ID prefix
- dep: routes by first bead ID prefix
- list: routes by --rig flag to target rig
- search: routes by --rig flag to target rig

Also adds RouteForPrefix() builder method on bdCmd for commands
that accept a prefix rather than a bead ID. Fixes variable shadowing
in cat.go and close.go from the RouteForBead refactoring, and adds
missing io import to convoy_stage.go.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
feat: add gt bead subcommands with prefix routing
…ing (WIP)

Placeholder for draft PR. Adds RouteForBead() method and migrates 11 call sites.
Add RouteForBead(beadID) method to the bdCmd builder that encapsulates
the Dir(resolveBeadDir(id)).StripBeadsDir() pattern into a single call.
Also adds RouteForPrefix(prefix) for commands that take a prefix.

Migrated call sites:
- sling_helpers.go: verifyBeadExists, getBeadInfo, storeFieldsInBead (x2)
- bead.go: moveBead source lookup
- hook.go: hookBead retry loop
- cat.go: bd show passthrough (converted from raw exec.Command)
- close.go: bd close passthrough, closeChildren query + close (converted)
- convoy_stage.go: bdShow, bdDepList helpers (converted)

Also fixes pre-existing compact_report_test.go build failure.
@mk-imagine mk-imagine force-pushed the fix/bd-subprocess-routing branch from f562074 to 75e96f7 Compare April 5, 2026 06:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status/needs-triage Inbox — we haven't looked at it yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants