Commit graph

14 commits

Author SHA1 Message Date
Julian Knutsen
5126de8c1a
perf(bd): no git subprocesses on read-only commands (in-process repo discovery, lazy actor, backup probe) (#7400)
* perf(git): locate the repository in-process instead of running git rev-parse

Every bd invocation resolved the process-wide git context (beads directory
discovery reads it) with `git rev-parse --git-dir --git-common-dir
--show-toplevel`: one git subprocess per bd call before any work. Tools that
call bd hundreds of times (gascity's doctor issues ~250 bd calls per run)
paid it on every call.

On Linux, initGitContext now first runs discoverGitInProcess, which mirrors
Git's discovery walk (physical cwd, .git as directory or gitfile, bare-dir
check, filesystem-boundary stop) and produces byte-for-byte what rev-parse
prints for ordinary repositories (top and subdirectories), linked worktrees
(absolute or relative gitfile, symlinked targets), submodules (core.worktree
pointing back at the gitfile's directory), nested repositories and no
repository. Both answers feed one shared normalization
(gitContextFromRevParse), so downstream values are unchanged.

It declines, and git runs exactly as before, whenever it cannot prove the
answer: GIT_DIR / GIT_WORK_TREE / GIT_COMMON_DIR / GIT_CEILING_DIRECTORIES /
GIT_DISCOVERY_ACROSS_FILESYSTEM / GIT_OBJECT_DIRECTORY / GIT_CONFIG_PARAMETERS
/ GIT_CONFIG_COUNT in the environment; a symlinked .git, an invalid gitfile
or git directory, a cwd inside a git directory; repository config with
core.worktree (other than the submodule shape), core.bare, extensions,
include directives, a format version above 1 or unmodeled syntax; any path
not owned by the effective uid (safe.directory is git's to evaluate), or
root under sudo. darwin and windows keep the subprocess (case folding and
ownership semantics).

Tests compare discoverGitFrom with real `git rev-parse` output across those
layouts, pin every decline case, and check the resulting cached context
equals the subprocess-derived one.

Agent-Signature: claude-code-claude-opus-5-5-medium on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* perf(cli): resolve the git user.name actor fallback only when needed

PersistentPreRunE assigned `actor = getActorWithGit()` for every command,
which, with no --actor / BEADS_ACTOR / BD_ACTOR / config actor, runs
`git config user.name`: the second git subprocess of every bd call, paid
by read-only commands that never consult the actor.

The pre-run now calls deferActorGitFallback, which marks an empty actor as
pending; currentActor (and getActorWithGit, getActor) resolve it on first
use with the unchanged priority order and store it in the global and the
CommandContext copy, as the eager assignment did. Command code reads the
actor through currentActor() instead of the raw global (a mechanical
rewrite of every read site the compiler reported; writes, the flag binding
and the pre-run config binding keep the raw variable). setActor cancels a
pending fallback. The telemetry span's bd.actor attribute is still set, but
only for a recording span, so a noop span does not force the lookup.

With the in-process repository discovery from the previous commit, a
read-only `bd list` / `bd show` now starts no git process at startup, in
the main checkout and in a linked worktree; a write asks git for user.name
once (bd create previously asked once, now still once) and records the same
value. Measured on 50 sequential `bd list` calls: 100 -> 0 git execs
(embedded and proxied-server workspaces, main checkout and worktree).

TestEmbeddedReadOnlyCommandsSpawnNoGit counts git execs through a PATH shim;
TestDeferredActorGitFallback pins the deferral semantics.

Agent-Signature: claude-code-claude-opus-5-5-medium on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(git): decline in-process discovery on any config line git might read differently

Review follow-ups to the in-process repository discovery.

- The repository config scanner was looser than git: a config starting with
  a UTF-8 BOM followed by `[core] worktree = /other` made git report /other
  while discovery returned the cwd repository, and `[ core ]` or `!!! = x`
  (which git refuses) were accepted. scanGitConfig (gitconfig_linux.go) now
  skips a leading BOM exactly as git does and accepts only a narrow grammar:
  blank/comment lines, `[section]` / `[section "sub"]` headers at column 0,
  and `key` / `key = value` lines inside a section, with values free of
  backslashes and unbalanced quotes. Any other line declines to git.
- Walk from getcwd(2) (syscall.Getwd), as git does, instead of os.Getwd,
  which trusts $PWD when it names the same inode (bind-mount aliases).
- Resolve relative gitfile and commondir targets without filepath.Join's
  lexical Clean, so "link/.." resolves physically like git's realpath.
- A mount-boundary stop reports its own reason in the not-a-repository
  error.
- Tests: every decline case (BOM + core.worktree, malformed headers and
  keys, keys before a section, escapes, continuations, bare repositories,
  a commondir inside .git, ...) now also checks that what startup derives
  equals git's answer; BOM and CRLF/comment configs are equivalence cases;
  the no-repository case must be answered in-process instead of skipping;
  a $PWD alias test pins the getcwd walk.
- The exec-count test drops every GIT_* variable except the config-file
  selectors, so a runner exporting GIT_CONFIG_PARAMETERS & co. cannot make
  it fail spuriously.
- Comment the two places that touch the raw actor before the deferral.

Agent-Signature: claude-code-claude-opus-5-5-medium on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* perf(backup): decide embedded auto-backup's git-remote probe without git

In an embedded workspace whose backup.enabled is unset, maybeAutoBackup
asks isBackupAutoEnabled -> primeHasGitRemote after every command, reads
included. That built a RepoContext (`git -C .beads rev-parse
--git-common-dir`) and ran `git remote`: two git processes per read even
after the startup calls were gone. The throttle cannot short-circuit it:
without a remote no backup ever runs, so there is no backup state to
throttle on.

Both probes are now answered in-process when provable, and the subprocess
remains the fallback, so the decision and every warning/notice downstream
of it are unchanged:

- internal/beads getGitCommonDirForPath uses git.CommonDirInProcess (the
  discovery walk from the given directory, git's spelling).
- primeHasGitRemote uses git.HasRemoteInProcess in the same directory
  primeGitCmd would run git in (primeGitDir, factored out). It answers only
  when every config file `git remote` reads -- system (GIT_CONFIG_SYSTEM, or
  /etc/gitconfig and <prefix>/etc/gitconfig of the git on PATH), global
  (GIT_CONFIG_GLOBAL, or XDG and ~/.gitconfig) and the repository's own --
  is absent or within scanGitConfig's grammar and include-free, no
  GIT_CONFIG_PARAMETERS/COUNT/GIT_CONFIG or discovery override is set, and
  no legacy .git/remotes or .git/branches entries exist. A remote seen only
  in a system-config candidate declines. Remote names outside
  [A-Za-z0-9._-] decline.

Tests compare HasRemoteInProcess with `git remote` (no remote, local,
worktree, submodule, remote.pushDefault only, global remote, no repo) and
pin the declines (global include, malformed global, command-line config);
CommonDirInProcess is compared with `git -C dir rev-parse
--git-common-dir`. TestEmbeddedReadOnlyCommandsSpawnNoGit now runs with
backup.enabled at its default, with and without a git remote, and still
expects zero git processes for list/show.

Agent-Signature: claude-code-claude-opus-5-5-medium on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-08 20:08:24 +00:00
Sam
bcf4da3c65
feat(github): sync epic/child and blocks relationships to GitHub (#5971)
* feat(github): sync epic/child and blocks relationships to GitHub

bd github sync only ever pushed issue content (title/body/labels/state);
Epic-child links and beads "blocks" dependencies never reached GitHub's
relationships panel. Adds a GitHub relationship-sync pass, mirroring the
existing GitLab dependency-link push, using GitHub's sub-issues and issue
dependencies REST APIs:

- internal/github/client.go: AddSubIssue/ListSubIssues and
  AddBlockedBy/ListBlockedBy against GitHub's sub_issues and
  dependencies/blocked_by endpoints.
- internal/github/links.go: DependencyLink + LinkResolver, converting beads
  epic/child parent-child dependencies into GitHub sub-issues and beads
  "blocks" dependencies into GitHub blocked_by relationships. Idempotent
  (lists current relationships before creating) and additive (stale remote
  relationships are left untouched).
- cmd/bd/github.go, cmd/bd/sync_push_pull.go: wires the push pass into both
  `bd github sync` and `bd github push`.

Verified against a live GitHub repo (create, list, and idempotent re-push
all confirmed via the real API), in addition to httptest-mocked unit tests.

Fixes gastownhall/beads#5970

* fix(github): update last_sync after relationship push to prevent sync churn

When AddSubIssue or AddBlockedBy is called, GitHub updates the issue's
updated_at timestamp as a side effect. Without updating last_sync after
the relationship push completes, the next sync would see those issues as
'changed' and pull/push them again, causing unnecessary churn.

This fix updates last_sync to the current time after a successful
relationship push (only if links were created), accounting for any
timestamp changes GitHub made during relationship creation.

Fixes continuous sync churn observed when running bd github sync
multiple times with no local changes.

* fix(github): use relationship reader for link sync

* fix(bazel): enumerate links.go and its tests in internal/github BUILD.bazel

The base advance added internal/github/BUILD.bazel with explicitly
enumerated srcs (gazelle-generated). This PR adds links.go,
links_test.go and review_fixes_test.go, which the base-generated
enumeration cannot know about, so //internal/github:github failed to
build:

  internal/github/tracker.go:41:35: undefined: LinkResolver
  internal/github/tracker.go:244:30: undefined: RefScope

Regenerated with `bazel run //:gazelle` (not hand-edited). Purely
additive; no deps change is needed because links.go only imports
//internal/types, already declared.

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

* fix(github): scope the relationship pass to --parent and report skipped links

Maintainer review fixup for PR #5971, adopt-pr review iterations 1 and 3.

filterGitHubLinkScopedIssues reimplemented four of the SyncOptions
selectors and dropped ParentID, so `bd github sync --push --parent X`
narrowed the content push to the subtree and then created GitHub
sub-issue and blocked-by links for every GitHub-linked issue in the
workspace -- outward API writes on issues the user had excluded. It now
resolves the subtree and requires membership in it. The traversal moves
from gitlab.go to sync_flags.go as buildSyncDescendantSet, beside the
--parent flag that populates the field, and the GitLab and GitHub link
passes share the one copy. The doc comments that claimed parity with the
engine's push loop now enumerate the selectors this path actually
applies, and name the three it does not (State, ExcludeIDPrefix,
ExcludeIDPatterns -- no GitHub command sets them today).

PushLinkResult.UnsupportedSkipped had no reader anywhere in the repo, so
a host without the sub-issue/dependency APIs reported nothing at all.
pushGitHubDependencyLinks now emits one curated line for it, and a 404
on the source issue is classified apart from a 404 on the relationship
endpoint: collapsing the two reported a deleted, renumbered or
permission-hidden issue as an unsupported host. The classifying probe is
memoized per issue number, so a source carrying both link types costs
one extra read.

`bd github push --dry-run` printed "Synced N relationship links" for
links it had only planned, because PushLinks counts planned links in
Created. The `bd github sync` twin already gated that line on its
dry-run flag; the push side now does too.

Tests: a table test over filterGitHubLinkScopedIssues with a row per
selector -- its three ParentID rows fail without the scope fix -- plus a
direct pin that a blocks-edge dependent is not a descendant, and
httptest cases driving 404 through the list call, the create call and
the source-issue probe.

Not fixed here: the PR body still describes a `lastSync` advance that
commit ee6d65692 removed from this PR. That is a PR-surface edit, not a
code change, and is left to the finalize step.

Also not fixed here, and named in buildSyncDescendantSet's doc comment
so the shared helper does not read as covering every tracker: the ADO
link pass has the same scope hole this commit closes for GitHub.
pushADOLinks takes no sync options, so `bd ado sync --push --parent X`
still writes ADO relations for the whole workspace. That predates this
PR, and ADO is outside its diff.

Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Gas City Adopt-PR
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Julian Knutsen <julian@gastownhall.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
2026-10-01 01:22:00 -07:00
Julian Knutsen
24a9da6cc7
test(proxy): topology-parameterized history and remote front-door matrix (#6269)
* feat(ga-p9iuv.22): add shared tracker proxy storage seam

* fix(ga-p9iuv.22): preserve tracker storage capabilities safely

* test(ga-p9iuv.22): cover tracker adapter label semantics

* test(ga-p9iuv.22): harden tracker adapter contracts

* fix(ga-p9iuv.22): reject invalid proxied tracker stores

* feat(ga-p9iuv.1): route Linear and Jira front doors through proxy store

* test(ga-p9iuv.1): exercise tracker mutations through UOW store

* fix(ga-p9iuv.1): preserve proxied Linear endpoint config

* test(ga-p9iuv.1): cover proxied Linear endpoint and direct config

* feat(ga-p9iuv.19): add typed proxied capability matrix

* feat(proxy): enforce typed capability matrix before provider

* test(proxy): cover command capability rows and claim caps

* test(proxy): check capability rows across topologies

* fix(proxy): validate capabilities before workspace side effects

* fix(proxy): refuse ready claim max rows caps

* feat(proxy): add shared maintenance capability policy

* fix(proxy): key maintenance refusals by command path

* test(proxy): cover nested maintenance refusals

* fix(proxy): enumerate nested maintenance command paths

* fix(proxy): refine compact and nested maintenance policy

* test(proxy): prove maintenance refusals preserve files

* fix(proxy): cover admin and remote maintenance refusals

* fix(proxy): refuse doctor before store initialization

* test(proxy): define history capability command matrix

* fix(proxy): wire history capability refusals to front door

* fix(proxy): refuse top-level sync history path

* fix(proxy): preserve maintenance refusal codes

* feat(proxy): classify history as supported UOW API

* feat(proxy): classify transform capability paths

* test(proxy): harden transform capability matrix

* fix(proxy): drive transform validation from exact rows

* fix(proxy): drive transform matrix from normalized flags

* fix(proxy): bound external backend dials per attempt

* test(proxy): cover bounded blocked backend dial

* fix(proxy): make transform capability policy row-driven

* fix(proxy): make transform capability policy row-driven

* fix(proxy): classify formula swarm and merge-slot refusals

* test(proxy): enforce workflow refusal contract

* fix(proxy): classify Dolt remote history boundaries

* test(proxy): enforce history refusal contract

* test(proxy): cover canceled backend dial cleanup

* test(proxy): cover real TCP blackhole cancellation

* test(proxy): cover external transport lifecycle matrix

* test(proxy): assert stable dial failure diagnostics

* test(proxy): add outage reconnect acceptance matrix

* test(proxy): make unix outage bridge restartable

* test(proxy): bound outage subprocess cleanup

* test(proxy): cover upstream restart with retained endpoint bridge

* test(proxy): stabilize managed-local outage contract

* fix(proxy): retire managed proxy when backend exits

* test(proxy): accept managed child retirement restart

* test(proxy): cover workflow refusals at bd front door

* test(proxy): cover history VC front doors

* test(proxy): pass valid workflow refusal arguments

* test(proxy): assert text and json refusal contracts

* test(proxy): assert exact workflow refusal codes

* test(proxy): guard refusal issue-row stability

* fix(proxy): expose non-mutating capability refusals

* test(proxy): match stable refusal text

* test(proxy): compare refusal artifact snapshots

* test(proxy): assert exact refusal messages

* test(proxy): retain direct workflow behavior

* test(proxy): match nested refusal messages

* test(proxy): cover direct-only front-door refusals

* test(proxy): provide valid direct-only command args

* fix(migrate): repair missing proxied sidecar on reentry

* fix: checkpoint Dolt mode migrations for safe retry

* fix: harden migration journal topology and retries

* fix: fsync migration journal removal

* fix: fail on migration journal directory sync errors

* fix: reject external ownership in every migration phase

* fix: enforce canonical shared migration topology

* fix: enforce live migration topology

* test: add migration front-door and topology regressions

* fix: require physical Dolt roots for migration

* test: strengthen migration front-door contracts

* fix: reject missing or invalid Dolt migration roots

* fix: keep shared migration dry-runs side-effect free

* fix: require Dolt repository identity for migrations

* fix: validate Dolt repository identity metadata

* fix: require typed Dolt repo state identity

* test: expand migration front-door CRUD assertions

* test: make migration JSON dry-run front-door safe

* test: sanitize Dolt environment for migration front door

* test: use cgo binary for migration front door

* test: omit empty Dolt overrides in migration front door

* test: isolate migration front door from test mode

* test: isolate home for migration front door

* test: stop supervised Dolt before reverse migration

* fix: reject empty Dolt head refs

* test: harden migration topology invariants

* test: harden external and shared topology refusals

* test: snapshot migration refusal artifacts

* test: cover external migration refusal phases

* fix: refuse stale proxied sidecars during migration

* test: strengthen migration artifact and external front door checks

* feat: type external migration refusals

* test: assert external refusal starts no proxy

* fix: validate migration journal sidecar topology

* fix: make sidecar recovery phase aware

* fix: honor persisted shared topology during migration

* test: exercise external journal migration front door matrix

* test(tracker): add shared conformance harness

* test: harden external migration matrix fixtures

* test: preserve durable dolt gate lock in matrix

* test: preseed gate lock for refusal matrix

* test: cover malformed migration state front door

* fix: type malformed migration config refusals

* fix: type migration preflight state errors

* test: separate migration JSON stdout from warnings

* test: reach typed malformed journal refusal

* test: assert migration retry phase and idempotence

* test: cover shared migration checkpoint retries

* fix: make reverse migration idempotent without sidecar

* test: cover proxied to shared retries

* fix: derive shared topology from persisted YAML

* fix: validate shared migration no-op state

* fix: allow completed proxied shared no-op

* fix: validate forward proxied no-op sidecar

* test: reject bad already-proxied sidecars

* fix: reject stale proxy controls on no-op

* fix: fail closed on malformed migration workspace yaml

* test: pin migration yaml topology precedence

* Cover forward migration no-op ownership refusals (ga-p9iuv.26.5.2)

Agent-Signature: unknown-model/unknown-reasoning

* Strengthen migration retry sentinel coverage (ga-p9iuv.26.1)

Agent-Signature: unknown-model/unknown-reasoning

* Expand migration fault retry artifact coverage (ga-p9iuv.26.1)

Agent-Signature: unknown-model/unknown-reasoning

* Add reverse migration frontdoor fault matrix (ga-p9iuv.26.1.1)

Agent-Signature: unknown-model/unknown-reasoning

* test: cover shared migration frontdoor fault matrices

* test: strengthen direct migration matrix assertions

* test: preserve migration dependency edges

* test: assert exact migration dependency edges

* test: parse migration dependency edges from batch list

* test: fix shared migration matrix compile

* test: verify shared dependencies before shutdown

* test(proxy): cover history remote front-door topology matrix

* docs: define direct-local ownership handoff contract

* fix(ci): repair pre-review CI failures on proxy parity branch

Five PR-introduced failures across the docs, PR Core, and Proxied Dolt Cmd
lanes. Each fix is scoped to the evidenced defect.

- test/docsync: TestEveryDocsPageIsPublished flagged
  docs/architecture/ownership-handoff-contract.md as unpublished. It is an
  internal Beads/Gas City handoff contract with no Mintlify frontmatter and
  no inbound links, so move it to engdocs/design/ beside its peers rather
  than publishing it.

- cmd/bd: TestProxyWorkflowRefusalContractAndNoMutation asserted on
  commandDidWrite, a process-wide atomic latch set by 71 non-test sites and
  never reset, so it reported an earlier test's write. Baseline and restore
  it around the assertion, matching the save/reset/restore idiom already
  used in proxied_lookup_failure_test.go and readonly_policy_test.go.

- cmd/bd: the new pre-provider gate short-circuited compact.go's refusal
  with new wording, breaking TestProxiedServerCompactDolt/non_dolt_mode_-
  rejected in an unchanged test. Restore the long-standing message; the
  proxy.compact.unsupported code is unchanged.

- internal/storage/dbproxy/proxy: the unix subtests bound sockets under
  t.TempDir(), whose embedded test name overflows macOS's ~104-byte
  sun_path limit ("bind: invalid argument"). Add unixSocketPath() to place
  them in a short temp dir.

- cmd/bd: migration topology compared recorded and canonical Dolt roots
  lexically, so macOS's /var -> /private/var symlink made equivalent paths
  compare unequal. Add sameMigrationRoot(), mirroring the existing
  resolveExistingPrefix idiom in cmd/bd/doctor/git.go.

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

* fix(review): address blocker and major findings from adopt-pr review

Maintainer review fixup for the proxy parity branch, iterations 1-2.
Blockers and majors from the review synthesis and quality scorecard.

Blockers:

- cmd/bd/migrate_dolt_mode.go: resuming from migratePrepared rebuilt the
  migration plan from the current argv instead of replaying the recorded
  one. A resume that omitted or changed --idle-timeout wrote a sidecar the
  target_configured check then rejected, and because that check runs only
  after the phase advances past migratePrepared, the block never ran again
  — the workspace stayed wedged in proxied-server mode with no in-tool
  recovery. Replay j.Sidecar and warn when the supplied value is ignored.

- internal/tracker/store.go: NewStore double-wrapped already-adapted values.
  directStore embeds the storage.Storage interface, so *directStore also
  satisfies storage.Storage and was re-wrapped as
  &directStore{Storage: &directStore{...}}; the inner value can never
  satisfy storage.IssueLifecycleStore, which silently degraded
  ApplyIssueUpdate to a bare UpdateIssue — no labels, no lifecycle
  transaction. Match the tracker's own adapters by concrete type first.
  Testing value.(Store) first, as the review suggested, does not work:
  storage.Storage is a strict superset of Store, so a raw direct store
  satisfies Store too and would be returned un-adapted, relocating the same
  bug. The branch order is documented at the call site.

Majors:

- internal/tracker/store.go: directStore.ApplyIssueUpdate now calls
  syncIssueLabels, which normalizes both label sets (trim, drop empty) and
  restores the semantics the pull path had before this seam moved behind
  ApplyIssueUpdate. The un-normalized local copy churned remove+add on
  whitespace-only differences and let an empty label reach AddLabel; it is
  deleted rather than left as a second, divergent implementation.

- Both regressions were invisible to the suite. Adds
  TestNewEngineKeepsDirectStoreAdaptationIntact, TestNewStoreIsIdempotent,
  TestDirectStoreApplyIssueUpdateNormalizesLabels, and
  TestMigrateToProxiedServer_ResumeReplaysRecordedIdleTimeout (changed /
  omitted / never subtests, each also asserting the reverse-migration escape
  hatch still recovers). All four were verified to fail against the
  pre-fix production code with the predicted symptoms.

Non-gating follow-ups from the scorecard, fixed while nearby:

- cmd/bd/proxy_capability.go: treat ProxyOutcomeNA as "this command has no
  such flag" rather than a refusal, so an assert on an N/A row cannot return
  a non-nil error carrying an empty message.

- cmd/bd/errors.go: emit the rule's real Mutates value in the JSON refusal
  envelope instead of a hardcoded false.

- cmd/bd/main.go: the doctor pre-provider check returned unconditionally,
  so a nil result (every doctor subcommand) skipped the legacy-store guard
  and autocommit-mode resolution that other skipsStoreInit commands run.
  Return only on a real refusal.

- internal/tracker/engine.go: type NewEngine's store parameter as Store so
  the seam names its contract, and drop the now-dead applyPullIssueUpdate.

- CHANGELOG.md: record the proxied `bd ready --claim` row-cap refusal, which
  was a behavior change shipped without a release note.

Iteration 2 -- gating major (uowStore/directStore external_ref divergence):

- internal/tracker/uow_store.go: GetIssueByExternalRef resolved through a
  single merged search over both storage planes, which has no plane
  preference: it is a UNION ALL ordered by content and terminating in
  `id ASC`, so one external_ref present on both planes resolved to whichever
  row's id sorted first. The direct backend is explicitly issues-first --
  issueops.GetIssueByExternalRefInTx queries `issues` and falls through to
  `wisps` only on sql.ErrNoRows, and says why ("so that pushed ephemeral
  beads are found during pull dedup"). The consumer is the pull dedup, which
  updates whatever row comes back, so the divergence was a silent write to
  the wrong local bead under --proxied-server only. Query the issues plane
  first via SkipWisps, then fall back.

  The fallback is the merged search rather than the review's literal
  Ephemeral=true: that filter contributes an `ephemeral = 1` predicate the
  direct backend's `SELECT id FROM wisps WHERE external_ref = ?` does not
  have, and wisp-plane rows legitimately carry ephemeral=0 (NoHistory beads;
  see types.IssueFilter.EphemeralTier). Taking it literally would have traded
  one divergence for a narrower one. Verified: implementing the prescription
  fails the ephemeral_flag_clear subtest below.

- internal/tracker/uow_store_engine_test.go: the engine fake now models plane
  routing (SkipWisps / Ephemeral / merged) instead of one flat map, so the
  contract is expressible at all. Adds
  TestUOWStoreGetIssueByExternalRefPrefersIssuePlane, whose wisp id sorts
  first so "first merged hit" fails it, and
  TestUOWStoreGetIssueByExternalRefFallsBackToWispPlane over both ephemeral
  values. Verified to fail against the pre-fix uow_store.go.

- internal/tracker/conformance: the shared suite gains a Wisps plane and
  external_ref_resolution_prefers_issue_plane, so this is a contract both
  backends are held to rather than one adapter's unit test.

Iteration 2 -- non-gating follow-ups from the scorecard:

- cmd/bd/migrate_dolt_mode.go: scope the migratePrepared sidecar-equivalence
  check in runMigrateFromProxiedServer to reverse journals. A forward journal
  at that phase records the sidecar it is about to write, so a crash in the
  pre-write window leaves none on disk -- the correct state -- and the
  unscoped check refused the documented escape hatch by naming a missing
  file, stranding the workspace. Tested against TargetMode's forward value so
  the guard stays live for both reverse targets, "server" and
  "shared-server". Adds
  TestMigrateFromProxiedServer_ForwardJournalAtPreparedIsNotSidecarRefused,
  verified to fail against the unscoped guard.

- cmd/bd/linear.go: buildLinearClientAPIOnly returned the OAuth client inline
  and never reached the WithEndpoint block, so a configured
  linear.api_endpoint was honored for an API key and ignored for OAuth. Hoist
  the endpoint application after the branch, as Tracker.Init does, and add
  the OAuth mirror of the existing endpoint test.

- cmd/bd/ready_max_rows_proxied_test.go: pin the proxied --max-rows refusal
  on `bd ready --claim`. It lives in RunE above the dispatch and nothing
  below it can enforce a cap, but the existing coverage all sits below it.
  Covers both cap sources (--max-rows and BEADS_MAX_ROWS) and the negative
  case that the refusal is conditioned on a live cap, not on --claim.

- engdocs/design/ownership-handoff-contract.md: trim the trailing blank line
  at EOF flagged by `git diff --check`.

Iteration 3 -- non-gating residual on the iteration-2 fix:

- internal/tracker/uow_store.go: the issues-first fix above split one logical
  lookup across two read transactions. uow.RunTxRead opens a fresh unit of
  work per call, so calling s.SearchIssues twice left the wisp fallback's
  premise -- "the issues plane is already known empty" -- without a shared
  snapshot: a concurrent same-ref insert into the issues plane landing between
  the two reads could let the merged fallback return the wisp, re-creating the
  wrong-row write that ordering exists to prevent. The consumer is the pull
  dedup loop, so it runs per imported issue. Both plane reads now share a
  single RunTxRead, which is also the shape the direct backend uses (both
  planes inside one withReadTx). Plane ordering is unchanged.

- internal/tracker/uow_store_engine_test.go: the engine fake counts the units
  of work it hands out, and
  TestUOWStoreGetIssueByExternalRefUsesOneReadTransaction pins that count at 1
  across the two paths that actually perform both reads -- the wisp fallback
  and the miss. An issues-plane hit short-circuits after one read and would
  pass either way, so it is not a case. Verified to fail against the
  two-transaction version with "opened 2, want 1".

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

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-09-05 08:25:49 -07:00
Kevin Glynn
9827c66319
fix(github): content-based dedup on push to stop re-PATCHing every issue (#4214) (#4329)
* fix(github): content-based dedup on push to stop re-PATCHing every issue

GitHub sync never wired engine.PushHooks, so `doPush` fell back to
timestamp-only dedup. Because linking and any local write bump a beads
issue's updated_at past GitHub's second-granularity updated_at, every
`github sync --push-only` / `github push` reconciled and PATCHed the
entire backlog on every run — O(N) REST calls that drain the shared
installation's primary rate limit even when nothing changed.

Add github.PushFieldsEqual, comparing only the fields a push mutates
(title, body, state, and the label set BeadsIssueToGitHubFields sends,
order-insensitive). Wire a ContentEqual push hook (buildGitHubPushHooks)
into both runGitHubSync and runGitHubPush so the engine skips issues
already in sync — mirroring the existing Linear/Jira push hooks.

Dry-run still makes 0 REST calls (unchanged); this targets the live
re-PATCH storm. A push-side incremental cursor to also avoid the
per-issue fetch is a noted follow-up.

Fixes #4214

Co-authored-by: Cursor <cursoragent@cursor.com>

* perf(sync): skip per-issue fetch on no-op push via persisted content hash

The ContentEqual hook added for #4214 stops the redundant PATCH but still
fetches every linked issue (one GET each), so a no-op `github sync --push-only`
still drains the REST rate limit. Add a ContentHash push hook: the engine
persists each issue's pushed content hash in the dolt-ignored local_metadata
table and consults it before FetchIssue. When the local content is unchanged
since the last push, the fetch and update are skipped entirely.

Also record the hash when ContentEqual reports a match (so the first
post-restart pass repopulates hashes) and consult it in dry-run, so an
unchanged issue previews as a skip instead of always reporting "Would update".

Refs gastownhall/beads#4214

Co-authored-by: Cursor <cursoragent@cursor.com>

* shrink(github): simplify PushContentHash framing and labelSetsEqual

Replace length-prefix binary framing in PushContentHash with NUL-separated
fields — the hash is only self-compared, so the simpler scheme is sufficient.
Replace hand-rolled counting map in labelSetsEqual with slices.Sort +
slices.Equal. Drop unused encoding/binary, strconv, sort imports in favor
of slices.

Agent-Signature: cursor-opus-4.6-unknown-reasoning on behalf of kevglynn
Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(sync): bind push cache to remote target

Agent-Signature: codex-gpt-5.6-sol-medium on behalf of matt wilkie

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: matt wilkie <maphew@gmail.com>
2026-08-02 22:53:06 -07:00
maxinflection
16b1dd0a71
feat(gitlab): sync issue dependency links on push (#4294)
* feat(gitlab): sync issue dependency links on push

After issue content syncs, mirror local beads dependency edges as GitLab
issue links: blocks -> GitLab blocks/is_blocked_by (direction-normalized),
related/relates-to -> a single relates_to link per unordered pair (deduped).
Children of synced epics also keep the epic's milestone during a
dependency-only sync. Reports links_pushed in --json.

Additive only (never deletes remote links). License-aware: blocks/
is_blocked_by needs GitLab Premium/Ultimate; on instances without it the
link is reported as a single curated, non-fatal message (links_license_skipped
in JSON) while relates_to and milestones still apply. Genuine (non-license)
link failures remain real warnings, kept distinct from the license case.

Feature: max-efe

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

* refactor(gitlab): address review — drop dead RelationMap, add push link parity

Follow-up to maphew's review on #4294.

- Delete the dead GitLab RelationMap: issueLinksToDependencies maps link
  types via hardcoded constants and ignores MappingConfig, so the field, its
  default, and the test assertion were dead config surface implying a
  configurability that does not exist. (Linear's RelationMap is untouched.)

- Give `bd gitlab push` dependency-link + epic-milestone parity with
  `bd gitlab sync`: extract the shared pushGitLabDependencyLinks helper from
  runGitLabSync's inline block and call it from runGitLabPush, scoped to the
  requested IssueIDs. Render push output natively so the link pass runs
  before the summary, dry-run ordering is correct, and the --json payload
  carries links_pushed / links_license_skipped / milestones_updated, matching
  sync in all output modes; also guard OnMessage under !jsonOutput.

Reviewed with /code-review + /codex (dry-run "Synced" line, output ordering,
and --json link-stat omission all caught and fixed here).

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

* fix(gitlab): check outputJSON error in runGitLabSync (errcheck)

CI lint (first run on this branch, only-new-issues=false) flagged the
unchecked outputJSON return in the sync --json path. Return it, matching
runGitLabPush. Fixes the Lint / Build Artifacts / PR Lint failures.

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

* fix(gitlab): carry closed state on push; surface failed-close in sync result

GitLab's POST /issues (and milestone/work-item creation) cannot set state,
so closed beads were pushed as opened issues and closed epics as active
milestones — milestone progress read 0/X even when all children were done.

- Close after create on all three paths (CreateIssue, createMilestone,
  createTaskWorkItem) via a best-effort follow-up state_event=close.
- BeadsIssueToGitLabFields emits state_event close/reopen so the update path
  flips both directions (reopening a bead reopens the GitLab issue). deferred
  stays open — only "done" work counts toward milestone completion.
- A failed best-effort close now records a warning on TrackerIssue.Warnings,
  which the engine drains into the sync result (visible in --json) instead of
  a bare stderr print that left --json reporting errors:0 while the issue was
  left open.

On close failure the created issue and its external_ref are still returned so
the next push doesn't create a duplicate (the push skip-guard means it won't
retry the close until the bead is next modified — hence the surfaced warning).

Reviewed via /code-review + Codex.

bd: max-9t6

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

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-08 08:00:41 -07:00
Eddie the Engineer
05b29caf55 fix(metrics): maintainer adoption fixes for usage-metrics + RunE refactor
Maintainer fixups for PR #4419 folded into one commit on top of the
contributor branch.

Security (blocker): metrics consent and endpoint are resolved from the
user-global config only (config.MetricsDisabledByUserConfig /
UserMetricsEndpoint). A project/BEADS_DIR config — highest viper precedence —
can no longer re-enable metrics or redirect the endpoint for a user who ran
`bd metrics off`.

First-run notice (major): the consent notice runs after the config-derived
json/quiet rebind and command classification, and is suppressed in
JSON/quiet/hook-json, BD_GIT_HOOK, hook/codex-hook/completion/shell-init/
version/prime, the metrics command, `init --stealth`, and the root
`bd --version` / `bd -V` probe, so it can never corrupt machine-readable or
hook/protocol output.

One cli_command event per invocation (major): delegating commands no longer
double-count. `bd ready --gated` and `bd mol wisp <proto>` record only their
own event by delegating to non-emitting cores (runMolReadyGatedCore /
runWispCreateCore), matching the existing runTodoListCore/runListCore pattern;
cardinality regression tests cover both aliases.

config get/show honor user-global metrics state (major): `bd config get
metrics.*` and `bd config show` report the user-global value (via
config.GetUserYamlConfig) that actually governs runtime behavior, with the
user-global path as the location, instead of a project value that has no
runtime effect.

Metrics cleanup on os.Exit paths (major): CheckReadonly and the reachable
pre-run gates (no-DB, fresh-clone, schema-skew, remote-migrate-gate, identity
mismatch) call the shared metrics.CloseAndFlush before exiting, so events
queued earlier in the run are still written and scheduled for upload instead
of stranded until the next clean exit. main()'s post-command tail uses the
same helper. `bd q` now creates its event before the readonly guard and labels
the readonly operation "q".

Telemetry coverage (major): recompute-blocked converted to RunE + HandleError
and emits a cli_command event; `metrics on/off/example` and `version` emit
cli_command events.

Consistency / minor cleanups: added SilenceUsage/SilenceErrors to the
ADO/GitHub/GitLab/Notion push/pull commands to match the jira/linear siblings
in the same file; corrected the inverted env-override "saved config" status
text; preserved 0600 when unsetting user-global config keys.

Pre-review CI repair (earlier in this commit): lint, stealth-init
cleanliness, proxied-server error handling, and regenerated CLI docs.

Tests: user-global opt-out vs project override at the config readers, runtime
resolvers, and `config get`; first-run notice suppression across
hook/protocol/json/quiet/stealth/root-version contexts; event cardinality for
the todo/ready-gated/wisp aliases; and CloseAndFlush persistence.

Original contributor commits preserved.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-22 20:44:48 +00:00
coffeegoddd☕️✨
d7d7a34607 : refactor to use RunE, emit usage metrics, skip metrics in CI
(cherry picked from commit 9596c7233d)
2026-06-22 20:44:43 +00:00
Jozef Izso
42064c46fe
Sync Linear milestones as local epics (#3528) 2026-05-05 07:45:30 -07:00
maphew
cb1a0700b0 fix(linear): clean sync lock lint 2026-05-02 18:38:36 -07:00
kev
989d0f9496 feat(linear): add per-workspace concurrency lock on sync
Acquires .beads/.linear-sync.lock at start of bd linear sync to
serialize concurrent invocations. Stale lock detection via PID
check. Clean release on SIGTERM via defer. Prevents duplicate
creates and conflict thrash from overlapping sync runs.
2026-05-02 01:02:55 -04:00
matt wilkie
3e56f0b214
Document Linear external_ref pre-linking (#3517)
* Document Linear external ref prelinking (bd-ly3)
* Fix Linear sync dependency graph handling
* Fix init remote clone routing
* Fix stale gate help text
* Fix init remote cherry-pick integration
* Fix init remote flag handling
* Fix Linear prelink hydration blockers
* Fix Linear relation dependency gating
* Fix ready list parent filtering
* Deduplicate dry-run dependency previews by stored identity
2026-04-27 06:05:30 -07:00
matt wilkie
2f60a10fc5
Import Linear relations as dependencies (#3519)
* Fix gate and cook regressions (bd-r2l)

* Import Linear relations as dependencies (bd-ly3)
2026-04-26 20:30:02 -07:00
matt wilkie
c446a2ef09
fix(linear): harden push against data clobbering (#3328)
Closes #3289, #3309, #3252, #3253 — hardens Linear push: requires explicit linear.state_map.* config, rejects ambiguous state resolution, narrows push dedup to pushable fields, blocks unscoped project-filtered push from creating unlinked beads, and adds regression test for the orphan-ownership rule (parent-filtered push must not update external issues Beads hasn't claimed via external_ref).
2026-04-18 08:36:13 -07:00
Harry Miller
d802687869
feat: add --issues flag, push pull subcommands, and --parent port (#2975)
Adds CLI layer for selective sync on top of #2957:
- --issues flag registered on all 6 tracker sync commands via shared helpers
- New push/pull subcommands with --dry-run support
- --parent flag ported from Linear-only to ADO, Jira, GitHub, GitLab

Co-authored-by: Harry <harry_miller@trimble.com>
2026-04-05 22:27:46 -07:00