Fix bd ready excluding ephemeral issues, add --include-ephemeral flag

GetReadyWork hardcoded (ephemeral = 0 OR ephemeral IS NULL) which excluded
all ephemeral issues from bd ready results. This broke gastown refinery
merge queue since merge-request beads are created as ephemeral=true.

Add IncludeEphemeral field to WorkFilter and --include-ephemeral CLI flag
so callers can opt in to ephemeral results when needed.

Fixes: bd-i5k5x

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Executed-By: beads/crew/emma
Rig: beads
Role: crew
This commit is contained in:
emma 2026-02-16 15:33:08 -08:00 • committed by Steve Yegge
commit 7eaea49b82
4 changed files with 52 additions and 3 deletions

View file

@ -55,6 +55,7 @@ This is useful for agents executing molecules to see which steps can run next.`,
molTypeStr, _ := cmd.Flags().GetString("mol-type")
prettyFormat, _ := cmd.Flags().GetBool("pretty")
includeDeferred, _ := cmd.Flags().GetBool("include-deferred")
includeEphemeral, _ := cmd.Flags().GetBool("include-ephemeral")
rigOverride, _ := cmd.Flags().GetString("rig")
var molType *types.MolType
if molTypeStr != "" {
@ -86,7 +87,8 @@ This is useful for agents executing molecules to see which steps can run next.`,
SortPolicy: types.SortPolicy(sortPolicy),
Labels: labels,
LabelsAny: labelsAny,
IncludeDeferred: includeDeferred, // GH#820: respect --include-deferred flag
IncludeDeferred: includeDeferred, // GH#820: respect --include-deferred flag
IncludeEphemeral: includeEphemeral, // bd-i5k5x: allow ephemeral issues (e.g., merge-requests)
}
// Use Changed() to properly handle P0 (priority=0)
if cmd.Flags().Changed("priority") {
@ -378,6 +380,7 @@ func init() {
readyCmd.Flags().String("mol-type", "", "Filter by molecule type: swarm, patrol, or work")
readyCmd.Flags().Bool("pretty", false, "Display issues in a tree format with status/priority symbols")
readyCmd.Flags().Bool("include-deferred", false, "Include issues with future defer_until timestamps")
readyCmd.Flags().Bool("include-ephemeral", false, "Include ephemeral issues (wisps) in results")
readyCmd.Flags().Bool("gated", false, "Find molecules ready for gate-resume dispatch")
readyCmd.Flags().String("rig", "", "Query a different rig's database (e.g., --rig gastown, --rig gt-, --rig gt)")
rootCmd.AddCommand(readyCmd)

View file

@ -1417,6 +1417,45 @@ func TestDoltStoreGetReadyWork(t *testing.T) {
if !foundReady {
t.Error("expected ready issue to be in ready work")
}
// Test ephemeral filtering: create an ephemeral issue
ephemeral := &types.Issue{
ID: "test-ephemeral",
Title: "Ephemeral Task",
Status: types.StatusOpen,
Priority: 1,
IssueType: types.TypeTask,
Ephemeral: true,
}
if err := store.CreateIssue(ctx, ephemeral, "tester"); err != nil {
t.Fatalf("failed to create ephemeral issue: %v", err)
}
// Default filter should exclude ephemeral
readyDefault, err := store.GetReadyWork(ctx, types.WorkFilter{})
if err != nil {
t.Fatalf("failed to get ready work (default): %v", err)
}
for _, issue := range readyDefault {
if issue.ID == ephemeral.ID {
t.Error("expected ephemeral issue to be excluded by default")
}
}
// IncludeEphemeral should include it
readyWithEph, err := store.GetReadyWork(ctx, types.WorkFilter{IncludeEphemeral: true})
if err != nil {
t.Fatalf("failed to get ready work (include-ephemeral): %v", err)
}
foundEphemeral := false
for _, issue := range readyWithEph {
if issue.ID == ephemeral.ID {
foundEphemeral = true
}
}
if !foundEphemeral {
t.Error("expected ephemeral issue to be included when IncludeEphemeral=true")
}
}
// TestCloseWithTimeout tests the close timeout helper function

View file

@ -290,8 +290,10 @@ func (s *DoltStore) GetReadyWork(ctx context.Context, filter types.WorkFilter) (
}
whereClauses := []string{
statusClause,
"(ephemeral = 0 OR ephemeral IS NULL)", // Exclude wisps by ephemeral flag
"(pinned = 0 OR pinned IS NULL)", // Exclude pinned issues (context markers, not work)
"(pinned = 0 OR pinned IS NULL)", // Exclude pinned issues (context markers, not work)
}
if !filter.IncludeEphemeral {
whereClauses = append(whereClauses, "(ephemeral = 0 OR ephemeral IS NULL)")
}
args := []interface{}{}
if filter.Status != "" {

View file

@ -1012,6 +1012,11 @@ type WorkFilter struct {
// Time-based deferral filtering (GH#820)
IncludeDeferred bool // If true, include issues with future defer_until timestamps
// Ephemeral issue filtering
// By default, GetReadyWork excludes ephemeral issues (wisps).
// Set to true to include them (e.g., for merge-request processing).
IncludeEphemeral bool
// Molecule step filtering
// By default, GetReadyWork excludes mol/wisp steps (IDs containing -mol- or -wisp-)
// Set to true for internal callers that need to see mol steps (e.g., findGateReadyMolecules)