fix(http): bd gate check over HTTP through issueops.ListGates (#7578)

* fix(http): bd gate check over http through issueops.ListGates

gate check listed its open gates with a raw SearchIssues filter (gate type,
closed excluded, --limit), which the HTTP backend refuses, so the command
failed before reading a gate on a remote scope and gc's core gate-sweep order
(bd gate check --type=timer --escalate) failed every tick there.

The listing now goes through issueops.ListGates over openQuerier on the
direct and proxied routes, the same entry bd gate list took in S20 (#7549):
the same question, served as queryIssues by every deployed server. The close,
the bead-gate target read and sighting, the pure timer arm and the gh/gt execs
are unchanged. The gh:run discovery's await_id persist still refuses on the
wire and counts as that gate's error.

The served corpus gains mc-gate-check-timer, mc-gate-check-gh (gate-sweep's
argv) and gate-check-all. No seeded gate carries an await type, since no wire
create accepts await_*, so these prove the listing is served.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* docs(gate): name both refused gate check writes; close gate's filter hole

Review fixes for #7578 (apply-fixes, iteration 1).

CHANGELOG, minor (taken): the entry said a bead gate's sighting was
already served over HTTP. It is not. evaluateBeadGate records the first
sighting (await_seen) through recordSeen, which calls the raw
store.UpdateIssue (cmd/bd/gate.go:675). The HTTP Store has no UpdateIssue
override, so its embedded unsupportedDoltStorage refuses the call in the
client before any request is sent (internal/httpclient/unsupported_gen.go),
exactly as it refuses the gh:run discovery's await_id persist. "Refuses on
the wire" was wrong for the same reason. The entry now names both writes
and keeps "counts as that gate's error" (applyGateCheckResults counts
r.err). The sighting is written only when the check finds the awaited
bead, not yet closed, in the gate's own store; inspectBeadGate sets
seenHere only there.

CHANGELOG, nit (taken): `bd gate check --limit -1` used to list every
open gate on the direct and proxied routes, because the raw search
emitted no LIMIT clause for a negative limit. The listing now goes
through issueops.ListGates, whose Querier rejects a negative limit as
ErrValidation, and the HTTP server rejects it too
(internal/httpapi/query.go). The entry says so.

.golangci.yml, minor (taken): at this head cmd/bd/gate.go and
gate_proxied_server.go name no filter type (one each at the base), so
their slot in the cmd/bd forbidigo family only kept a hole open. `gate`
leaves the alternation, with a "LEFT this list" note like the ones for
search, status and count. gate_discover keeps its own hole:
findPendingGates still builds the raw filter.

Declined:
- bd gate discover still refuses over HTTP in findPendingGates (minor):
  the synthesis' first remedy is no change in this PR, and the file is
  not in this PR's diff. Finalize files the follow-up to move it onto
  ListGates.
- the proxied listing is not pinned on its own (nit): it calls the same
  listOpenGatesForCheck as the direct route (gate_proxied_server.go:106),
  and the synthesis calls accepting the gap defensible.
- listOpenGatesForCheck/listOpenGatesWith naming (nit): the remedy is
  "leave as is".

Verified:
- git diff --check: clean.
- bazel build --config=nogo -- //cmd/bd:all on the edited config: 16
  targets, exit 0.
- Probe, then reverted: a types.IssueFilter literal in gate.go and a
  types.WorkFilter literal in gate_proxied_server.go each failed nogo
  with forbidigo's "do not write a filter here", so the hole is shut.
- git merge-tree against the heads of all 102 other open PRs that touch
  CHANGELOG.md or .golangci.yml (today's census): this commit changes
  no conflict count in either file. 43 PR/file pairs already conflict
  with or without it.

Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Julian Knutsen 2026-10-16 09:20:24 +00:00 • committed by GitHub
commit b126a7d1d2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 191 additions and 33 deletions

View file

@ -471,7 +471,13 @@ linters:
# `search` LEFT this list when all three of its routes moved onto
# issueops.Reader.List with issueops.SearchListRequest (cmd/bd/search.go);
# it builds no filter any more.
- path: '^cmd/bd/(close|duplicates|find_duplicates|gate|gc|graph|info|label|orphans|purge|todo|wisp|human)(_proxied_server)?\.go$'
#
# `gate` LEFT it when `bd gate check` joined `bd gate list` on
# issueops.ListGates over the route's Querier: cmd/bd/gate.go and
# cmd/bd/gate_proxied_server.go name no filter type any more.
# `gate_discover` keeps its own hole below, since findPendingGates still
# asks SearchIssues for its gates.
- path: '^cmd/bd/(close|duplicates|find_duplicates|gc|graph|info|label|orphans|purge|todo|wisp|human)(_proxied_server)?\.go$'
text: 'do not write a filter here'
linters:
- forbidigo

View file

@ -524,6 +524,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- **`bd gate check` works over a connected HTTP workspace.** Its open-gate
listing built the same raw `SearchIssues` filter `bd gate list` did before
S20, so the HTTP backend refused the command before reading a gate and gc's
core `gate-sweep` order (`bd gate check --type=timer --escalate`) failed on
every remote scope. It now lists through `issueops.ListGates` over the
route's Querier (direct, proxied and remote alike). Closing a resolved gate
was already served. Two writes the check can make still refuse over HTTP,
because the HTTP store has no raw `UpdateIssue` and the client refuses it
before sending a request: a bead gate's first sighting of its awaited bead
(`await_seen`, recorded when the check finds that bead, not yet closed, in
the gate's own store) and the gh:run discovery's `await_id` persist. Each
counts as that gate's error. A negative `--limit` is now an error; the
direct and proxied routes used to read it as no limit. The served corpus
gains `mc-gate-check-timer`, `mc-gate-check-gh` and `gate-check-all`.
- **`bd gate list` works over a connected HTTP workspace** (S20). The
workspace-wide listing built a raw `SearchIssues` filter, which the HTTP
backend refuses, so gc's `renudge-stale-human-gates` order failed on every

View file

@ -441,6 +441,23 @@ shapes:
- id: mc-gate-list-all
source: core pack orders (gate list --all)
args: [gate, list, --all, --json]
# gate check lists the open gates through the same ListGates entry. No
# seeded gate carries an await type (no wire create accepts await_*), so the
# typed sweeps find nothing of their type and the untyped one lists the open
# gates and evaluates none: the listing is what these shapes prove served,
# and nothing resolves, escalates (no gt exec) or writes.
- id: mc-gate-check-timer
source: gc core pack gate-sweep.sh (bd gate check --type=timer --escalate)
args: [gate, check, --type=timer, --escalate]
compare: text
- id: mc-gate-check-gh
source: gc core pack gate-sweep.sh (bd gate check --type=gh --escalate)
args: [gate, check, --type=gh, --escalate]
compare: text
- id: gate-check-all
source: bd gate check (every open gate)
args: [gate, check]
compare: text
- id: gc-export-all
source: gc core pack reaper (gc bd export --all -o F)

View file

@ -797,6 +797,7 @@ go_test(
"formula_help_test.go",
"formula_primitives_test.go",
"formula_schema_test.go",
"gate_check_listing_test.go",
"gate_check_proxied_integration_test.go",
"gate_discover_test.go",
"gate_embedded_test.go",

View file

@ -653,16 +653,9 @@ Examples:
escalateFlag, _ := cmd.Flags().GetBool("escalate")
limit, _ := cmd.Flags().GetInt("limit")
gateType := types.IssueType("gate")
filter := types.IssueFilter{
IssueType: &gateType,
ExcludeStatus: []types.Status{types.StatusClosed},
Limit: limit,
}
ctx := rootCtx
gates, err := store.SearchIssues(ctx, "", filter)
gates, err := listOpenGatesForCheck(ctx, limit)
if err != nil {
return HandleErrorRespectJSON("%v", err)
}
@ -701,6 +694,28 @@ Examples:
},
}
// listOpenGatesForCheck lists the open gates `bd gate check` evaluates through
// the same library entry `bd gate list` uses, issueops.ListGates over the
// route's Querier (openQuerier: the direct store, the proxied server's unit
// of work, or the remote http backend's queryIssues). It is the question the
// raw SearchIssues filter used to ask — the gate type, both planes, closed
// rows excluded, cut at limit — but a remote backend serves it, where the raw
// filter was refused before any gate was read. The per-type selection stays
// with filterCheckableGates.
func listOpenGatesForCheck(ctx context.Context, limit int) ([]*types.Issue, error) {
querier, err := openQuerier()
if err != nil {
return nil, err
}
return listOpenGatesWith(ctx, querier, limit)
}
// listOpenGatesWith is listOpenGatesForCheck over a given Querier: the open
// gates only (gate check never evaluates a closed one), cut at limit.
func listOpenGatesWith(ctx context.Context, querier issueops.Querier, limit int) ([]*types.Issue, error) {
return issueops.ListGates(ctx, querier, issueops.GateListRequest{Limit: limit})
}
type gateCheckResult struct {
gate *types.Issue
resolved bool

View file

@ -0,0 +1,100 @@
package main
import (
"context"
"errors"
"reflect"
"testing"
"time"
"github.com/steveyegge/beads/internal/types"
"github.com/steveyegge/beads/issueops"
)
// recordingGateQuerier records every Query and answers with fixed rows.
type recordingGateQuerier struct {
calls []issueops.QueryRequest
items []*types.IssueWithCounts
err error
}
func (q *recordingGateQuerier) Query(_ context.Context, req issueops.QueryRequest) (issueops.IssuePage, error) {
q.calls = append(q.calls, req)
if q.err != nil {
return issueops.IssuePage{}, q.err
}
return issueops.IssuePage{Items: q.items}, nil
}
// TestGateCheckListsOpenGatesThroughListGates pins the gate check listing to
// the Querier role (queryIssues on a remote backend) instead of the raw
// SearchIssues filter the http store refused before reading a gate: the gate
// type, closed excluded, the --limit carried as given (0 = unlimited).
func TestGateCheckListsOpenGatesThroughListGates(t *testing.T) {
for _, limit := range []int{0, 5, 100} {
q := &recordingGateQuerier{items: []*types.IssueWithCounts{
{Issue: &types.Issue{ID: "g-timer", IssueType: "gate", AwaitType: "timer"}},
{Issue: &types.Issue{ID: "g-pr", IssueType: "gate", AwaitType: "gh:pr"}},
}}
got, err := listOpenGatesWith(context.Background(), q, limit)
if err != nil {
t.Fatalf("limit %d: listOpenGatesWith: %v", limit, err)
}
l := limit
want := issueops.QueryRequest{Expression: "type=gate", IncludeClosed: false, Limit: &l}
if len(q.calls) != 1 || !reflect.DeepEqual(q.calls[0], want) {
t.Fatalf("limit %d: Query calls = %#v, want one %#v", limit, q.calls, want)
}
if len(got) != 2 || got[0].ID != "g-timer" || got[1].ID != "g-pr" {
t.Fatalf("limit %d: gates = %v, want [g-timer g-pr] in the Querier's order", limit, got)
}
// The per-type selection still happens after the listing.
timers := filterCheckableGates(got, "timer")
if len(timers) != 1 || timers[0].ID != "g-timer" {
t.Fatalf("limit %d: timer gates = %v, want [g-timer]", limit, timers)
}
gh := filterCheckableGates(got, "gh")
if len(gh) != 1 || gh[0].ID != "g-pr" {
t.Fatalf("limit %d: gh gates = %v, want [g-pr]", limit, gh)
}
}
}
// TestGateCheckListingFailureIsAnError keeps a refused or failed listing an
// error: gate-sweep must fail loudly, never report "No open gates found."
func TestGateCheckListingFailureIsAnError(t *testing.T) {
refusal := &issueops.ErrUnsupported{Op: "Querier.Query", Backend: "http"}
q := &recordingGateQuerier{err: refusal}
got, err := listOpenGatesWith(context.Background(), q, 0)
if !errors.Is(err, refusal) || got != nil {
t.Fatalf("listOpenGatesWith = (%v, %v), want (nil, the refusal)", got, err)
}
}
// TestGateCheckTimerArmOverListedGates runs the evaluation over the listed
// rows: an expired timer gate resolves, an unexpired one stays pending, and a
// gate with no await type is not evaluated (the corpus seed's case).
func TestGateCheckTimerArmOverListedGates(t *testing.T) {
now := time.Date(2026, 10, 15, 12, 0, 0, 0, time.UTC)
q := &recordingGateQuerier{items: []*types.IssueWithCounts{
{Issue: &types.Issue{ID: "g-expired", IssueType: "gate", AwaitType: "timer", CreatedAt: now.Add(-2 * time.Hour), Timeout: time.Hour}},
{Issue: &types.Issue{ID: "g-pending", IssueType: "gate", AwaitType: "timer", CreatedAt: now.Add(-time.Minute), Timeout: time.Hour}},
{Issue: &types.Issue{ID: "g-untyped", IssueType: "gate"}},
}}
gates, err := listOpenGatesWith(context.Background(), q, 0)
if err != nil {
t.Fatalf("listOpenGatesWith: %v", err)
}
results := evaluateGates(context.Background(), filterCheckableGates(gates, ""), now, nil, nil, nil)
got := map[string]bool{}
for _, r := range results {
if r.err != nil {
t.Fatalf("%s: unexpected error %v", r.gate.ID, r.err)
}
got[r.gate.ID] = r.resolved
}
want := map[string]bool{"g-expired": true, "g-pending": false}
if !reflect.DeepEqual(got, want) {
t.Fatalf("evaluated = %v, want %v (g-untyped skipped)", got, want)
}
}

View file

@ -87,13 +87,6 @@ func runGateCheckProxiedServer(cmd *cobra.Command, ctx context.Context) error {
return HandleErrorRespectJSON("proxied-server UOW provider not initialized")
}
gateType := types.IssueType("gate")
filter := types.IssueFilter{
IssueType: &gateType,
ExcludeStatus: []types.Status{types.StatusClosed},
Limit: limit,
}
discovered := map[string]string{}
var seen []*types.Issue
var persistAwaitID func(gateID, runID string) error
@ -109,17 +102,12 @@ func runGateCheckProxiedServer(cmd *cobra.Command, ctx context.Context) error {
}
}
readUW, err := proxiedOpenReadUOW(ctx)
// The listing is the shared entry's, on this route too (gate list's S20).
gates, err := listOpenGatesForCheck(ctx, limit)
if err != nil {
return err
}
page, err := readUW.IssueUseCase().SearchIssues(ctx, "", filter)
if err != nil {
readUW.Close(ctx)
return HandleErrorRespectJSON("%v", err)
}
filteredGates := filterCheckableGates(page.Items, gateTypeFilter)
readUW.Close(ctx)
filteredGates := filterCheckableGates(gates, gateTypeFilter)
if len(filteredGates) == 0 {
printNoOpenGates(gateTypeFilter)

View file

@ -19,6 +19,7 @@ import (
"github.com/steveyegge/beads/internal/storage"
storageissueops "github.com/steveyegge/beads/internal/storage/issueops"
"github.com/steveyegge/beads/internal/types"
"github.com/steveyegge/beads/issueops"
)
var gateTestStdoutMu sync.Mutex
@ -33,15 +34,29 @@ type gateCloseCall struct {
type fakeGateCheckStore struct {
storage.DoltStorage
issues []*types.Issue
searchFilter types.IssueFilter
queries []issueops.QueryRequest
searchCalled bool
closeCalls []gateCloseCall
}
func (f *fakeGateCheckStore) SearchIssues(_ context.Context, _ string, filter types.IssueFilter) ([]*types.Issue, error) {
f.searchFilter = filter
// SearchIssues records that the raw filter was used: gate check lists through
// the Querier role (ListGates), which a remote backend serves, and must not.
func (f *fakeGateCheckStore) SearchIssues(_ context.Context, _ string, _ types.IssueFilter) ([]*types.Issue, error) {
f.searchCalled = true
return f.issues, nil
}
func (f *fakeGateCheckStore) Querier() (issueops.Querier, error) { return f, nil }
func (f *fakeGateCheckStore) Query(_ context.Context, req issueops.QueryRequest) (issueops.IssuePage, error) {
f.queries = append(f.queries, req)
items := make([]*types.IssueWithCounts, 0, len(f.issues))
for _, issue := range f.issues {
items = append(items, &types.IssueWithCounts{Issue: issue})
}
return issueops.IssuePage{Items: items}, nil
}
func (f *fakeGateCheckStore) CloseIssue(_ context.Context, id, reason, actor, session string) error {
f.closeCalls = append(f.closeCalls, gateCloseCall{
id: id,
@ -1768,14 +1783,15 @@ func TestGateCheck_GHRunWorkflowDiscoveryPersistence(t *testing.T) {
if !gateTestContains(output, "Checked 1 gates: 1 resolved, 0 escalated, 0 errors") {
t.Fatalf("summary output missing expected counts: %q", output)
}
if fakeStore.searchFilter.IssueType == nil || *fakeStore.searchFilter.IssueType != "gate" {
t.Fatalf("expected gate filter, got %+v", fakeStore.searchFilter)
if fakeStore.searchCalled {
t.Fatal("gate check listed through the raw SearchIssues filter; want issueops.ListGates")
}
if len(fakeStore.searchFilter.ExcludeStatus) != 1 || fakeStore.searchFilter.ExcludeStatus[0] != types.StatusClosed {
t.Fatalf("expected closed-status exclusion, got %+v", fakeStore.searchFilter.ExcludeStatus)
if len(fakeStore.queries) != 1 {
t.Fatalf("Querier.Query calls = %d, want 1", len(fakeStore.queries))
}
if fakeStore.searchFilter.Limit != 100 {
t.Fatalf("expected limit 100, got %d", fakeStore.searchFilter.Limit)
q := fakeStore.queries[0]
if q.Expression != "type=gate" || q.IncludeClosed || q.Limit == nil || *q.Limit != 100 {
t.Fatalf("gate check query = %+v, want type=gate, closed excluded, limit 100", q)
}
if tt.wantCloseCalls == 1 {
call := fakeStore.closeCalls[0]