beads/internal/workapi/BUILD.bazel
mtccressall 652c29b805
fix(show): disclose dependency edges the listing cannot represent (be-lpi) (#6352)
* fix(show): disclose dependency edges the listing cannot represent (be-lpi)

`bd show --json` emitted a self-contradicting payload on any issue with a
cross-repo or `external:` dependency:

    {"id":"hq-cv-ftcra","dependency_count":1,"dependencies":null}

and `bd show` in text mode rendered no dependency section at all, so
`bd dep add x liveop-y` reported success and the `bd show x` a caller ran
straight after was indistinguishable from the edge never having been written.

THE COUNT IS CORRECT. THE ENUMERATION IS THE DEFECT.

`GetDependenciesWithMetadataInTx` reads the edge rows, resolves each far end,
then does a bare `continue` past any id with no local row. An `external:` or
cross-repo target HAS no local row by construction: `IsExternalDepTarget`
routes exactly the ids this database cannot hold into `depends_on_external`,
the one target column with no foreign key into issues. The count queries have
no such join. So the count keeps the edge and every listing drops it, and the
difference is precisely the set of edges that are real, stored, and
unrenderable from here.

Reported as a phantom count on convoy beads. It is neither phantom nor
convoy-specific: `hq-cv-ftcra` carries a real `tracks` edge to
`external:liveop:liveop-kmf`, and convoys are simply the only producer of
external targets in that store (77 external edges, all `tracks`). The
`bd list --json` zero the report also cites is correct by design and unrelated
— that count is blocks-only per `SearchCountsSQL`, and the edge is `tracks`.

Publish the difference instead of leaving the caller to infer it, following
the `comments_omitted` precedent (ga-clgh):

  - `IssueDetails` gains `unresolvable_dependencies` / `unresolvable_dependents`
  - `BuildIssueDetails` sets them, so every frontend — CLI `--json` and the
    HTTP detail view — gets it at once
  - text mode says the same thing on stderr, never stdout, so the rendered
    issue is byte-identical for the common fully-local case; that is the
    choice `warnDroppedDepEdges` already made in dep.go for this same gap
  - the notice helper is shared with the watch-mode render so the two cannot
    drift apart in what they disclose

Set ONLY when the row list was actually read and came back short: the
dependency read's error is now kept rather than discarded, because a FAILED
read and a SHORT read both leave the slice empty and must not collapse into
one signal. `unresolvable_dependents` only under `IncludeDependents`, where
the rows exist — without them the slice is nil by design and a delta would
report every dependent an issue has as unresolvable.

Deliberately NOT done: making the count match the listing. The count is right
and the edge is real, so zeroing it would delete the only signal these edges
exist. Nor does `GetDependenciesWithMetadata` synthesise placeholder issues
for external targets — it has 14 non-test call sites including the Linear,
GitLab, Jira and ADO sync paths, which would then map a fabricated issue onto
a remote tracker.

`bd dep list` needed no change: bd-mtla already warns there and points at
`bd dep list <id> <id>`, which prints the raw edge record. The installed
v1.2.2 predates that fix, which is why the bead's measurements saw a bare `[]`.

Tests. `internal/workapi/detail_unresolvable_test.go` pins the arithmetic
against a source whose counts and rows are set independently, with negative
controls for a fully local store, a failed row read, a failed count read, and
count-only mode. `cmd/bd/show_unresolvable_deps_embedded_test.go` drives the
production path — init, create, `dep add`, `show` — for both target shapes
plus a fully local control, and asserts the notice reaches stderr and not
stdout. Verified the scratch fixture's stored columns are identical to the
production row rather than merely similar. Sabotage control run on both tiers:
removing the guard turns each red, and the negative controls stay green.

`docs/reference/json-schema.md` is intentionally untouched — it is
hand-written and documents the pinned release (`docs/cli-docs.pin` is v1.2.2),
not main. Follow-up filed as be-soj.

Agent-Signature: claude-code-claude-opus-5[1m]-unknown-reasoning on behalf of Marc Cressall
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017B2Z4eQi2a9Cgfumj2RRnR

Executed-By: beadsrig/polecats/toast

* fix(show): do not read a failed dependency listing as unresolvable edges (be-lpi)

Codex review of the previous commit, and it is right.

`bd show` renders dependencies best effort and discarded the listing error:

    depsWithMeta, _ := issueStore.GetDependenciesWithMetadata(ctx, issue.ID)

so when that read FAILED while the count query succeeded, the new notice
reported every counted edge as cross-repo/external. A transient backend error
was rendered as a claim about the data, which is the more expensive of the two
mistakes — the user goes looking for edges that are simply unread.

This is the distinction `BuildIssueDetails` already draws with `depsErr` on
the JSON side, and it is the reason that error is kept there. The text path
did not draw it at all, so the two planes disagreed under failure: `--json`
stayed silent and the human render accused the data.

Carry each direction's rows and error together in a `depListing` and require
BOTH reads to have succeeded before reporting a difference. Rendering stays
best effort; only the diagnosis is gated. A failure in one direction no longer
suppresses the other, which is a case the single-error shape could not express.

`cmd/bd/show_unresolvable_deps_unit_test.go` pins it: 10 cases including the
two the review found, a fully local negative control, a failed count read, and
one direction failing while the other stays reportable. Sabotage control —
relaxing the guard back to `countErr != nil` alone fails exactly the two
listing-read-failed cases and nothing else.

Reuses the existing race-safe `captureStderr` from test_helpers_pure_test.go
rather than a second copy.

Agent-Signature: claude-code-claude-opus-5[1m]-unknown-reasoning on behalf of Marc Cressall
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017B2Z4eQi2a9Cgfumj2RRnR

Executed-By: beadsrig/polecats/toast

* fix(show): read the dependency counts before the row listings (be-lpi)

Second codex finding on this change, and it is real on the path `bd show`
actually uses.

The unresolvable-edge difference is computed from two reads. Where the source
is not snapshot-consistent, a write landing between them skews it — and with
the listing read first the skew was the expensive direction: a freshly added,
perfectly ordinary local edge came back as `unresolvable_dependencies: 1` and
as a stderr notice accusing the data.

Only the store-backed source is exposed. `uow.issueReader.Get` wraps the whole
build in `RunTxRead`, so the UOW path shares one snapshot; `storereader` — what
`EmbeddedDoltStore.IssueReader` returns, and therefore what `bd show` runs on —
issues a connection per call.

Read the counts FIRST. An edge added in the window then leaves the count
stale-LOW, the difference goes negative, and nothing is reported. The text path
gets the same order structurally: the helper is split into `readDepCounts`,
called before the listings, and `warnUnresolvableDepEdges`, called after, so
the ordering is visible at both call sites rather than buried.

THIS IS AN ORDERING MITIGATION, NOT A FIX, and the code says so. A concurrent
DELETE still leaves the count stale-HIGH and produces a spurious notice. Closing
that needs a shared snapshot across the two reads, or a store method that counts
edges whose target has no row directly — either is a new seam across both
backends and the domain path, out of proportion to an advisory field. Filed
separately. Deletion of a dependency edge is also far rarer than addition, which
is why this ordering is strictly better rather than merely different.

The first version of the JSON-side test DID NOT PIN THE ORDER. It used a source
returning fixed values, so reversing the two reads still passed — a test
pinning arithmetic while claiming to pin an order, and the sabotage run is what
caught it. Replaced with `mutatingSource`, where whichever read runs first sees
one edge and the second sees two; swapping the reads in `BuildIssueDetails` now
fails with exactly the false report the review described. The text-side case is
relabelled to say it covers the subtraction only, since the call-site order is
not in its scope.

Agent-Signature: claude-code-claude-opus-5[1m]-unknown-reasoning on behalf of Marc Cressall
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017B2Z4eQi2a9Cgfumj2RRnR

Executed-By: beadsrig/polecats/toast

* fix(show): disclose unrenderable dep edges in proxied render (be-lpi)

`bd show` has three text renders and be-lpi closed two of them.
usesProxiedServer() returns at show.go:45 before any of the fixed code,
and runShowProxiedDefault binds the shared issueops.Reader -- hence
BuildIssueDetails, hence unresolvable_dependencies -- only when
`jsonOutput && !in.shortMode`, so plain text falls through to
proxiedRenderIssue, which rendered both dependency sections from
proxiedListDeps with discarded errors and said nothing. On a
server-backed repo the change`s own symptom survived: a cross-repo or
`external:` dependency still rendered as no dependency at all.

Call warnUnresolvableDepEdges from that route too, counts before the
listings, taking the counts through workapi.NewUOWDetailSource. The
domain use cases behind a proxied UOW are per-table, so proxiedDepCounter
carries the isWisp flag the DetailSource counts take. That flag is
arithmetically inert on this path, and the earlier claim here that the
store seam "resolves" it was the wrong mechanism: the repository read
seam discards it outright -- CountByID forwards only Direction and Types
to CountDependencyEdgesInTx, and ListWithIssueMetadata forwards only the
source id to Get{Dependencies,Dependents}WithMetadataInTx
(dependency.go:888-917) -- so both sides span `dependencies` and
`wisp_dependencies` alike and only the mutating paths pick a table.
The conclusion is unchanged and is what the notice depends on: the
arithmetic is the same on both routes, because
CountDependencyEdgesInTx counts `dependencies` plus `wisp_dependencies`
with no join to `issues`, and proxiedListDeps runs the very
GetDependenciesWithMetadataInTx the direct route runs, so the difference
means here what it means there. --refs and --children stay out of scope:
an alternate query with no count beside it to contradict. The precedent
this design cites, warnDroppedDepEdges, covers both of its own routes
(dep.go:1148, dep_proxied_server.go:457), which is the in-repo standard
applied here.

Pinned by TestProxiedServerShow2/show_discloses_unresolvable_dep_edges
with a fully-local negative control. Measured, not assumed: deleting the
new call reds the first and leaves the control green.

Also from the same review, all non-gating:

- The recovery pointer is outbound-only now. `bd dep list <id> <id>`
  reaches raw edge records through the duplicate-id form, which
  dep.go:1101 selects on `batchMode && direction == "down"`, and
  dep.go:1144 says in the repo`s own words that "up" has the same gap
  with no inbound EdgeReader role to close it. An issue short only on
  dependent edges was handed a command that cannot show them, and now
  gets a line saying so instead.

- The ordering comment no longer advertises a guarantee nothing holds.
  Splitting readDepCounts from warnUnresolvableDepEdges makes the
  counts-first order readable at the call sites; it does not pin it.
  Measured: reversing it at all three sites leaves this package green,
  including the embedded production-path test, because the unit test
  drives warnUnresolvableDepEdges directly and no CLI test can land a
  write inside the window. The only automated pin is one tier down, on
  TestBuildIssueDetails_ConcurrentAddIsNotReportedAsUnresolvable. A CLI
  test that could fail on the order would have to own that window, which
  is out of proportion for an advisory notice, so the comment now states
  its scope rather than overstating it.

- The plane asymmetry is documented rather than changed: text mode reads
  dependents unconditionally and always discloses the inbound direction,
  while unresolvable_dependents needs include_dependents (--json only).
  The per-field restriction is the correct half -- without the rows a
  delta would call every dependent unresolvable -- so the godoc and the
  spec description record the disagreement.

One correction to be-lpi`s own commit message, which cannot be amended
from here: enumerating the edges via issueStore.EdgeReader() is not "a
new seam across both backends and the domain path" on the CLI path.
EdgeReader() sits on the variable that path already holds
(storage.go:235, used at show.go:177). The concurrent-DELETE residual
still stands on the two-reads argument alone, which remains true of
ReadEdges plus a set difference.

Review iteration 2 adds the BUILD-file sync the required Bazel lane
needs, plus one comment correction:

- cmd/bd/BUILD.bazel and internal/workapi/BUILD.bazel now list the three
  test files this change adds. The relevant failure is not a broken
  build: bazel.yml`s "BUILD files in sync" step (:382-406) runs
  `make bazel-sync` and exits 1 on a non-empty `git status --porcelain`,
  and that step`s job is BAZEL_TEST, one of seven Bazel rows in
  pr.yml`s CI_GATE_REQUIRED (:1496-1524, mapped at :1551), so the drift
  reds a required lane rather than merely leaving the files invisible to
  Bazel. The repo`s own fixture agrees: scripts/ci_workflow_test.go`s
  bazelLaneGateIDs holds bazel-test, and bazelAdvisoryLanes retains only
  bazel-integration.

  The rows are gazelle output rather than hand-written. `make bazel-sync`
  on this head proposes five; init_git_bootstrap_routing_test.go and
  init_role_environment_test.go are base staleness that origin/main
  already lists, and a run on the merge target proposes them not at all,
  so only the three this change owns are committed.

  Certificate, run on the merge target rather than argued: merge
  origin/main into this head, resolve, `make bazel-sync`, then
  `git status --porcelain --untracked-files=all` is empty -- which is
  exactly the gate step`s own test, and it also confirms the resolution
  is byte-identical to what gazelle emits. `bazel build //cmd/bd:bd_test
  //internal/workapi:workapi_test` on that tree completes successfully,
  so the widened srcs lists compile.

  These rows do introduce a merge conflict this change did not have
  before: origin/main added show_watch_loop_test.go into the same slot of
  the same sorted srcs list in cmd/bd/BUILD.bazel. It is an add/add with
  an empty base -- neither side edits shared text -- and the resolution
  is the sorted union of all three rows, which is what gazelle emits and
  what the certificate above was run against.

- The ordering comment`s measurement clause named show.go and
  show_display.go while the claim was true of three call sites, the
  third being the show_proxied_server.go site this fixup added. It now
  names all three, re-measured at this head: reversing readDepCounts
  below its listings at every site leaves the selector green -- 35
  subtests across TestWarnUnresolvableDepEdges,
  TestEmbeddedShowUnresolvableDeps and TestProxiedServerShow2.

Maintainer fixup for PR #6352, review iterations 1-2.

---------

Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
2026-10-01 01:29:36 -07:00

75 lines
1.8 KiB
Python

load("@rules_go//go:def.bzl", "go_library", "go_test")
go_library(
name = "workapi",
srcs = [
"bootstrap.go",
"count.go",
"delete.go",
"detail.go",
"doc.go",
"list.go",
"list_comments.go",
"metadata.go",
"page.go",
"query.go",
"ready.go",
"release.go",
"sort.go",
"stats.go",
"sweep.go",
"versionreconcile.go",
"workspaceconfig.go",
],
importpath = "github.com/steveyegge/beads/internal/workapi",
visibility = ["//:__subpackages__"],
deps = [
"//internal/config",
"//internal/query",
"//internal/storage",
"//internal/storage/domain",
"//internal/storage/kvkeys",
"//internal/types",
"//internal/utils",
"//issueops",
],
)
go_test(
name = "workapi_test",
srcs = [
"bootstrap_test.go",
"count_skipwisps_test.go",
"count_test.go",
"delete_test.go",
"detail_test.go",
"detail_unresolvable_test.go",
"list_comments_test.go",
"list_ephemeral_test.go",
"list_golden_test.go",
"list_keyset_test.go",
"list_pinned_test.go",
"list_ready_status_test.go",
"list_status_test.go",
"page_test.go",
"query_test.go",
"race_detector_off_test.go",
"race_detector_on_test.go",
"ready_count_test.go",
"ready_golden_test.go",
"ready_test.go",
"release_test.go",
"stats_test.go",
"sweep_test.go",
"versionreconcile_test.go",
"workspaceconfig_test.go",
],
data = glob(["testdata/**"]),
embed = [":workapi"],
deps = [
"//internal/storage",
"//internal/storage/domain",
"//internal/types",
"//issueops",
],
)