Add ServerSocket config field and BEADS_DOLT_SERVER_SOCKET env var to
connect to Dolt via unix sockets instead of TCP. This eliminates port
conflicts between concurrent projects and simplifies sandbox integration.
- Wire --server-socket CLI flag through bd init and bd dolt set (dolt.socket)
- Add GetDoltServerSocket() to configfile with env var precedence
- Socket mode disables auto-start with socket-specific error hints
- TLS settings honored regardless of transport
- Integration test: starts dolt sql-server --socket, verifies end-to-end SQL
- Document in README.md server mode table
Closes#2939
Adds a project-agnostic beads_global database to shared-server mode so
clients can track issues globally across all projects on the server.
- Add EnsureGlobalDatabase() to create the DB during shared server init
- Add --global persistent flag to switch CLI commands to the global DB
- Add global_dolt_database field to metadata.json for connection info
- Seed global DB with issue_prefix="global" and sentinel project ID
- Export/import default to global-issues.jsonl with --global flag
- --global errors when not in shared-server mode (additive, no breakage)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
On slow hardware, Dolt's first-run SQL engine bootstrap takes ~60s before
the MySQL listener accepts connections, exceeding the hardcoded 10-second
waitForReady budget and causing bd init --shared-server to kill dolt
mid-bootstrap with "server started but not accepting connections."
Default behavior is unchanged; the fix is opt-in.
- Add readyTimeout() helper reading BEADS_DOLT_READY_TIMEOUT (positive
integer seconds, default 10) with stderr warning on invalid input
- Use readyTimeout() at the Start() call site
- Add TestReadyTimeout covering parsing, fallback, and edge cases
- Add TestWaitForReady: direct test of waitForReady's timeout behavior
using a delayed-bind fake listener; closes a pre-existing coverage gap
- Update CHANGELOG.md
Maintainer polish: fix warning casing to match project convention,
correct comment (TCP connections, not queries), fix env var cleanup
in unset test case, add subtest ordering comment.
Fixes#3142
Co-authored-by: David Hite <14855188+ghbaud@users.noreply.github.com>
* fix: respect dolt.auto-start=false config, prevent rogue server spawns
resolveAutoStart checked the caller's `current=true` before the config
file's explicit opt-out, so dolt.auto-start=false was never honored.
Reorder priority so config.yaml opt-out wins over caller defaults.
Add defense-in-depth guard in EnsureRunningDetailed and clearer error
messages when auto-start is disabled.
Fixes#3057
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* fix: make config opt-out comparison case-insensitive
Use strings.EqualFold for "false" and "off" checks in resolveAutoStart,
consistent with isFalsyBool in doltserver. Handles quoted YAML strings
like "FALSE" or "Off" that bypass YAML boolean normalization.
Addresses review yellow flag on case sensitivity.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: matt wilkie <maphew@gmail.com>
* fix: use strconv.ParseBool for env var parsing in IsAutoStartDisabled
Replace manual strings.ToLower + equality checks with strconv.ParseBool
for standardized truthy/falsy handling. Retains "off" as a recognized
disable value for backward compatibility.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* style: fix gofmt formatting in doltserver_test.go
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add strings.TrimSpace() before comparison in IsAutoStartDisabled to
handle env var values with surrounding whitespace like ' 0 ' or
' false '. Consistent with TrimSpace usage elsewhere in the file.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* fix: prevent silent fallback to embedded mode when shared-server is active (GH#2949)
Root cause: ResolveServerMode() and IsDoltServerMode() checked
metadata.json dolt_mode=embedded BEFORE runtime env vars, so stale
persisted metadata silently overrode active shared-server config.
Fixes:
- ResolveServerMode: env vars (BEADS_DOLT_SERVER_MODE, BEADS_DOLT_SHARED_SERVER)
now checked before metadata.json, preventing stale embedded override
- IsDoltServerMode: now checks BEADS_DOLT_SHARED_SERVER env var (shared-server
implies server-backed storage)
- warnSharedServerEmbeddedMismatch -> repairSharedServerEmbeddedMismatch:
auto-repairs stale dolt_mode=embedded in metadata.json instead of just warning
- Added 6 regression tests covering the upgrade path
Closes#2949
Amp-Thread-ID: https://ampcode.com/threads/T-019d4b84-cddd-725a-a3c6-ee7e3631f2aa
Co-authored-by: Amp <amp@ampcode.com>
* fix: treat --shared-server as server mode for metadata.json DoltMode (#2946)
--shared-server sets BEADS_DOLT_SHARED_SERVER for directory resolution but
never set initServerMode, so metadata.json recorded DoltMode as "embedded"
and all subsequent commands used embedded Dolt despite config.yaml having
dolt.shared-server: true.
Also override metadata.json at runtime when dolt.shared-server is set,
so existing installs with stale metadata.json are handled without re-init.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* fix: ensure shared server runs during init and fix isEmbeddedMode check
Two additional fixes for GH#2946:
1. Init auto-starts the shared Dolt server if not already running,
since ResolveServerMode classifies shared-server as External
which suppresses the normal auto-start path.
2. isEmbeddedMode() now checks doltserver.IsSharedServerMode() as a
fallback. Dolt subcommands (status, start, stop) skip DB init in
PersistentPreRun, so serverMode is never set from metadata.json.
Without this, "bd dolt status" would still report embedded mode
even with dolt.shared-server: true in config.yaml.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* fix: apply shared-server override to loadServerModeFromConfig()
Closes the gap flagged in PR review: no-db commands (bd dolt start,
bd dolt status, bd doctor, etc.) go through loadServerModeFromConfig()
which didn't have the shared-server override for stale metadata.json.
This ensures isEmbeddedMode() returns false for all command paths when
dolt.shared-server is true in config.yaml, not just commands that pass
the no-db guard in PersistentPreRun.
GH#2946
Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019d4f6f-01f8-72d4-b474-f75d7909b8b9
---------
Co-authored-by: Amp <amp@ampcode.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add config.BeadsDirPerm (0700) and config.BeadsFilePerm (0600) constants
- Add config.CheckBeadsDirPermissions() for startup warning if permissions
are too permissive (non-fatal, checks group/world bits)
- Add config.EnsureBeadsDir() helper for consistent directory creation
- Tighten all MkdirAll calls for .beads/ paths from 0750/0755 to 0700:
init.go, doltserver.go, credentials.go, audit.go, recipes.go,
embeddeddolt store.go and flock.go
- Add startup check in loadEnvironment() (cmd/bd/main.go)
- Windows build tag with no-op implementation (ACL-based permissions)
- 6 tests: constants, dir creation perms, warning on permissive, no
warning on secure, no error on nonexistent
Fixes: bd-kl6
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
When bd dolt start spawns dolt-sql-server as a detached process,
environment variables are not inherited. This breaks cloud storage
remotes (Azure, AWS) that rely on env vars for credentials.
Explicitly set cmd.Env = os.Environ() to ensure the child process
inherits the parent environment regardless of process group detachment.
Fixes#2812
Introduces withRetryTx — a transaction-level retry wrapper for Dolt
serialization errors (1213 deadlock / 1205 lock wait timeout). Migrates
all withWriteTx call sites to use it. Removes advisory lock from schema
init (DDL is now idempotent via IF NOT EXISTS). Stripped debug log level
flag that was left in doltserver.go.
Co-Authored-By: Dustin Brown <dustin@dolthub.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add category-aware custom statuses that control behavior in bd ready
and bd list. New config format: bd config set status.custom
"in_review:active,qa_testing:wip,archived:done,on_hold:frozen".
Backward compatible with old flat format. New bd statuses command
lists all statuses with --json support.
Also fix TestKillStaleServersPreservesOtherRepoServers to clear
BEADS_DOLT_AUTO_START env var, since the new IsAutoStartDisabled guard
in killStaleServersForDir short-circuits when set.
PR: #2665
Co-Authored-By: Harry Miller <harry-miller-trimble@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Introduce ErrServerNotRunning sentinel so callers can distinguish "already
stopped" from real failures. Stop now cleans up leftover PID/port files even
when the server is not running, preventing bd dolt status from reporting stale
state. Consolidate IsAutoStartDisabled into a single exported function covering
both env var and config sources.
PR: #2740
Co-Authored-By: Harry Miller <harry-miller-trimble@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace gastown-specific references with generic alternatives throughout
the codebase:
- Rename --gastown flag to --orchestrator in bd doctor
- Rename gastownMode/gastownThreshold params to orchestratorMode/orchestratorThreshold
- Rename isGasTownTownRoot() to isOrchestratorRoot()
- Replace "gastown" in CLI examples with generic rig names (my-project, other-project)
- Update comments replacing "Gas Town" with "orchestrator" or "multi-agent workspace"
- Update active docs (DOLT.md, CONFIG.md, ADVANCED.md, etc.)
- Update test data to use generic names instead of "gastown"
- Update role templates (deacon, witness, refinery) to use generic language
Preserved as historical (not changed):
- CHANGELOG.md entries (historical record)
- ARTICLES.md (links to real published articles)
- info.go version notes (historical release notes)
- gastown/ file path references in dolt-concurrency.md (point to actual repo)
Replace ad-hoc mode checks (hasExplicitPort(), explicitPort bool parameter,
BEADS_DOLT_SERVER_MODE env var checks) with a single ServerMode enum and
ResolveServerMode() function. This gives one canonical place to determine
whether beads owns/manages the server (Owned), the user manages it (External),
or the legacy embedded path is used (Embedded).
- Add ServerMode type with Owned/External/Embedded constants
- Add ResolveServerMode() as single source of truth for mode inference
- Thread Mode through doltserver.Config (populated by DefaultConfig)
- Replace hasExplicitPort() in EnsureRunningDetailed with ServerMode check
- Update resolveAutoStart() to take ServerMode instead of explicitPort bool
- Re-export ServerMode constants in storage/dolt for downstream callers
- Update all tests to use ServerMode instead of bool parameters
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
KillStaleServers previously killed ANY dolt sql-server process whose CWD
matched the repo's dolt data directory. This could kill systemd-managed
shared servers or other repos' servers using the same shared data dir.
Now killStaleServersForDir checks ownership before killing:
- Skip entirely when hasExplicitPort() is true (externally managed)
- Skip entirely when BEADS_DOLT_AUTO_START=0 (externally managed)
- Skip entirely when no PID file exists (no beads-started server to
compare against, so nothing is "stale" from our perspective)
- Only kill orphan processes when a valid PID file proves beads owns
a server in this directory
Fixes bd-a36.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
When dolt.auto-start is false (via BEADS_DOLT_AUTO_START=0 env var or
config.yaml), bd now skips all server kill logic in KillStaleServers and
refuses to auto-start servers in EnsureRunning. This prevents bd from
killing systemd-managed or other externally-managed dolt processes.
Also fixes initCredentialKey to create the .beads/ directory if it
doesn't exist, allowing connections to external servers without
requiring bd init first.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When metadata.json has an explicit dolt_server_port, the server is
externally managed (e.g. systemd). Do not auto-start a per-project
server — it would conflict with the shared server.
Also adds EnsureRunningDetailed() returning startedByUs for cleanup.
PR: https://github.com/steveyegge/beads/pull/2561
PR: https://github.com/steveyegge/beads/pull/2562
Co-authored-by: matt wilkie <maphew@users.noreply.github.com>
During bd init, port resolution via DefaultConfig falls through to
config.yaml / global config when no port file exists yet for the new
project. This can resolve to another project's server, causing the new
database to be created on the wrong server (cross-project data leakage).
Fix: bd init now uses only project-local port sources (env var, port
file) instead of DefaultConfig. For fresh inits with no port file,
port 0 forces auto-start to allocate an ephemeral port for THIS project.
Shared server mode is handled explicitly.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When auto-start allocates a new ephemeral port because the configured port
is unreachable, bd now warns with the old and new port numbers and suggests
pinning via dolt.port in config.yaml. Also logs when port file is updated
to a different value.
This makes endpoint drift visible instead of silent, addressing the split-brain
scenario where other tools/agents still expect the old port.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
KillStaleServers was called outside the exclusive file lock in
EnsureRunning(), creating a race where one process could kill a server
that another process was in the middle of starting (PID file not yet
written). This caused concurrent dolt sql-server instances to corrupt
the journal file.
Moving the cleanup inside Start() after the flock is acquired ensures
the kill-and-start sequence is atomic — no other process can interfere
between orphan cleanup and PID file creation.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
In shared-server mode, the DB issue_prefix belongs to whichever project
initialized first. This caused all projects sharing a server to use the
wrong prefix for issue creation, ID generation, and imports.
Fix: YAML config.yaml issue-prefix now takes precedence over the DB value
in create.go, github.go, gitlab.go, linear.go, orphans.go, and merge_slot.go
(which already had the correct pattern).
Also: EnsureRunning() now calls KillStaleServers() before starting a new
server, cleaning up orphaned dolt sql-server processes that accumulate when
parent processes crash without graceful shutdown (GH#2372).
Also: add cross-project data isolation tests (5 tests covering read isolation,
port collision, same-prefix isolation, concurrent writes, and concurrent
read-write mix). Based on tests by @PabloLION (PR #2472).
Co-Authored-By: PabloLION <dev@pablolion.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Introduces BEADS_DOLT_SHARED_SERVER mode where multiple beads projects
share a single Dolt server on a fixed port (3308), avoiding per-project
server sprawl. Includes `bd init --shared-server`, `bd dolt shared-*`
commands, doctor checks, and comprehensive tests.
Co-Authored-By: Shybko <shybko@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace DerivePort() (FNV-32a hash into 1000-port range) with OS-assigned
ephemeral ports via net.Listen(":0"). This eliminates birthday-problem
port collisions that caused cross-project data leakage (GH#2098, GH#2372).
DefaultConfig() returns port 0 when no explicit config exists. Start()
allocates an ephemeral port with retry loop for TOCTOU races. Explicit
port config (env var, config.yaml, metadata.json) is preserved unchanged.
Closes#2098. Partially addresses #2372 (Layer 1 — port isolation).
Co-Authored-By: timvisher-dd <timvisher-dd@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace DerivePort() (FNV-32a hash into 1000-port range) with OS-assigned
ephemeral ports via net.Listen(":0"). This eliminates birthday-problem port
collisions (#2098) and complements Layer 2 identity verification (c6e41803)
for defense-in-depth against cross-project data leakage (#2372).
Start() now allocates ephemeral ports with a retry loop (10 attempts) for
TOCTOU races. Explicit port config (env var, config.yaml, metadata.json)
is preserved with conflict detection via reclaimPort.
Closes#2098. Partially addresses #2372.
Co-Authored-By: Tim Visher <194828183+timvisher-dd@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Remove the idle monitor sidecar process and activity file mechanism.
In Gas Town and external Dolt server setups, the server is managed
externally, making this daemon infrastructure unnecessary. The idle
monitor also contributed to background connection accumulation and
CLOSE_WAIT issues under concurrent polecat load.
Co-Authored-By: athosmartins <noreply@github.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The idle monitor removes the port file when stopping an idle server
(via stopServerProcess). When restarting, Start()/DefaultConfig()
cannot find the port file and falls through to DerivePort(), which
produces a hash-derived port that may differ from the original 3307.
This overwrites dolt-server.port with the wrong value, breaking other
bd/gt commands.
Fix: track the server port while running and restore the port file
before calling Start() on restart, so DefaultConfig() picks up the
correct port.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Fix legacy Dolt port resolution and port-file backfill
* Fix doctor checks to honor repo-local Dolt ports
* Fix doctor health checks for repo-local Dolt ports
TestMaxDoltServers/gastown expected maxDoltServers()=1 under GT_ROOT,
but daemon removal made it always return 3.
TestRunIdleMonitorExitsOnStaleActivityNoServer relied on IsDaemonManaged
early exit to complete within 60s; without it the 60s sleep causes timeout.
TestRunIdleMonitorGasTownExitsImmediately tested the removed Gas Town
early-exit path in RunIdleMonitor; replaced with zero-timeout test.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Executed-By: beads/crew/emma
Rig: beads
Role: crew
The daemon removal (w-bd-001) deleted IsDaemonManaged, GasTownPort,
HasGasTownPathSegment, isGasTownRoot, and walkUpForGasTownRoot but
left tests referencing them, causing CI build failures on all branches.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Executed-By: beads/crew/emma
Rig: beads
Role: crew
Three P1 fixes for the Dolt server stabilization epic (bd-109c):
1. Idle-monitor single-instance enforcement (GH#2367): RunIdleMonitor now
acquires an exclusive file lock at startup. If another monitor is already
running, the new one exits immediately. This prevents the accumulation
bug where Start() called from within the monitor watchdog would fork
additional monitors (one per minute, ~32MB each).
2. Port config isolation (GH#2372): The port file (dolt-server.port, now
gitignored) is elevated to primary source for port resolution, ahead of
metadata.json and config.yaml which are git-tracked and can propagate
to collaborators. metadata.json DoltServerPort emits a deprecation
warning when used.
3. Client-side project identity verification (GH#2372): bd init now generates
a UUID stored in both metadata.json (project_id) and the database metadata
table (_project_id). On every store open, these are compared. A mismatch
means the client is connected to the wrong projects Dolt server and the
connection is refused with a clear diagnostic message.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Remove daemon/RPC subsystem and Gas Town detection heuristics from beads.
The daemon functionality has been superseded by Gas Town's deacon/daemon system.
Removed:
- IsDaemonManaged/IsDaemonManagedFor and Gas Town detection functions
- GasTownPort constant and GT_ROOT-based server directory resolution
- Daemon PID file checks in IsRunning, reclaimPort, KillStaleServers
- Daemon guard in Stop/StopWithForce
- Gas Town bypass in forkIdleMonitor and RunIdleMonitor
- Python bd_daemon_client.py RPC client and test_daemon_health_check.py
- Python test_multi_repo.py daemon integration test
- Daemon socket preference in create_bd_client
- Daemon client cleanup tracking in MCP server
- Daemon-related gitignore patterns and doctor fix ordering
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>