Commit graph

2 commits

Author SHA1 Message Date
matt wilkie
baa9d02457
fix: treat --shared-server as server mode for DoltMode (#2947)
* 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>
2026-04-02 11:52:20 -07:00
matt wilkie
9e17dbfaa0 refactor(doltserver): introduce ServerMode enum to consolidate server ownership inference
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>
2026-03-20 17:46:16 -07:00