Skip to content

feat(kap-server): enable multi-server shared home by default#1826

Open
sailist wants to merge 1 commit into
MoonshotAI:mainfrom
sailist:feat/multi-server-shared-home
Open

feat(kap-server): enable multi-server shared home by default#1826
sailist wants to merge 1 commit into
MoonshotAI:mainfrom
sailist:feat/multi-server-shared-home

Conversation

@sailist

@sailist sailist commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

No linked issue — the problem is explained below.

Problem

Multi-server shared-home support in kap-server shipped behind the experimental env var KIMI_CODE_EXPERIMENTAL_MULTI_SERVER. With the flag off (the default), every server takes the single-instance home-dir lock, so a second server on the same home directory fails fast with ServerLockedError; meanwhile CLI and desktop consumers (kimi web daemon reuse, kimi server ps/kill) still only knew how to read that legacy lock file. The feature is ready to become the default, so the flag gate — and the legacy lock it was protecting — need to go away, and all server-discovery consumers must learn the instance registry.

What changed

  • kap-server: startServer now always registers itself under <home>/server/instances/; the KIMI_CODE_EXPERIMENTAL_MULTI_SERVER env check is gone. The legacy single-instance lock (acquireLock / getLiveLock / ServerLockedError and the lockPath option) is removed from the package surface; port-conflict handling stays the port + 1 walk, which doubles as the multi-instance coexistence mechanism. An instancesDir option replaces lockPath for test isolation.
  • agent-core-v2: the multi_server experimental flag domain is deleted (definition, barrel contribution, domain-layer map entry, docs example now points at another flag).
  • CLI: kimi web daemon reuse and kimi server ps / kill / rotate-token discover running servers through the instance registry (longest-running live instance), matching the server's new registration-only behavior.
  • Desktop: ensure-server reads <home>/server/instances/*.json (live pid, longest-running) instead of the lock file. kimi-inspect's dev discovery keeps reading the legacy lock as a fallback for pre-registry builds only.
  • Dev tooling: dev:kap-server:multi (root dev:v2) no longer needs the env var; related comments/docs updated.
  • Also removes the four pending minidb changesets (per maintainer request).

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works. (kap-server instance-registry wiring tests for shared-home boot/release; updated CLI server command and boot/port-retry suites — 649 kap-server tests and 477 CLI tests pass locally.)
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update. (The env var was never documented in user docs; no user-facing doc change needed.)

- always register kap-server instances under server/instances and drop the
  legacy single-instance lock (acquireLock/getLiveLock/ServerLockedError)
- remove the multi_server experimental flag and its
  KIMI_CODE_EXPERIMENTAL_MULTI_SERVER env var from agent-core-v2
- discover running servers via the instance registry in server
  ps/kill/rotate-token, kimi web daemon reuse, and the desktop app
- remove the pending minidb changesets
@changeset-bot

changeset-bot Bot commented Jul 17, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 04762f1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Jul 17, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@04762f1
npx https://pkg.pr.new/@moonshot-ai/kimi-code@04762f1

commit: 04762f1

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 04762f1fb4

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

const deadline = Date.now() + SPAWN_TIMEOUT_MS;
while (Date.now() < deadline) {
const live = getLiveLock();
const live = await getLiveServerInstance();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Probe every registered daemon before timing out

When an older registry entry has a live pid but is not answering /healthz, this loop keeps selecting only that oldest entry because getLiveServerInstance() returns live[0]. After spawning a replacement, the new healthy daemon has a later startedAt, so kimi web/server run will ignore it until the 20s timeout and leave the user with a failed startup despite a usable server being registered. In this fallback path, iterate listLiveServerInstances() and return the first healthy origin instead of polling only the oldest entry.

Useful? React with 👍 / 👎.

@@ -1,6 +0,0 @@
---
"@moonshot-ai/minidb": minor

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Restore the dropped minidb changesets

This commit deletes the pending minidb changesets while only adding the multi-server changeset, and there is no release-version update in the diff that would have consumed them. On the next Changesets release, the minidb durability/perf/reader-catchup/review hardening changes will no longer bump @moonshot-ai/minidb or appear in the changelog, so these unrelated changeset files should be restored unless they were already released in this same commit.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant