Skip to content

test(sdk-next): make embedded host isolation test deterministic - #14161

Merged
marius-kilocode merged 1 commit into
mainfrom
fix/sdk-next-embedded-hosts-flake
Sep 15, 2026
Merged

marius-kilocode merged 1 commit into
mainfrom
fix/sdk-next-embedded-hosts-flake

Conversation

@marius-kilocode

Copy link
Copy Markdown
Collaborator

What Problem This Solves

independent embedded hosts do not share live notifications in packages/sdk-next/test/embedded.test.ts can hang until its hardcoded 10 second budget and fail. The test creates two OpenCode.create() hosts against one temporary SQLite database, subscribes to both event streams, and waits for both server.connected latches.

Root Cause

OpenCode.create() builds its server layer lazily on the first request. Subscribing both hosts at the same time therefore triggers two concurrent lazy layer builds against the same database.

Building Credential.node runs legacyImportLayer (packages/core/src/credential.ts:110). When a legacy account.json exists, it reads the data_migration journal, finds no row for credential.kilo-account-json-v3, and inserts one inside a transaction (credential.ts:159). That insert has no conflict handling. Both hosts pass the existence check before either inserts, so the second insert violates the data_migration.name primary key. That host's request fails, its server.connected never arrives, and the test waits on Effect.all([firstReady.await, secondReady.await]), which has no timeout, until the 10 second test budget expires.

Local reproduction before the fix (macOS, developer profile with account.json):

$ bun test test/embedded.test.ts -t "independent embedded hosts"
(fail) independent embedded hosts do not share live notifications [10003.43ms]
  ^ this test timed out after 10000ms.

With a clean XDG_DATA_HOME (no account.json) the same test passes in about 1.2 to 1.8 seconds, which confirms the legacy credential import is the trigger.

Why This Change Was Made

The test's intent, that two independent hosts do not share live notifications, does not require the two hosts to run their first lazy layer build concurrently. Serializing the host startup removes the race without changing the assertion:

  • subscribe to the first host, then await its server.connected;
  • subscribe to the second host, then await its server.connected;
  • only then create the session and switch the agent on the first host.

The second host's subscription is still active before the event is emitted, so the isolation check is unchanged. The fix is test-side only; credential.ts is left untouched.

User Impact

None. Test-only change, so no changeset is needed.

Evidence

  • Before: focused test timed out at 10s (reproduced twice).
  • After: focused test pass 10/10. Full test/embedded.test.ts pass 6/6, about 2.3 to 2.8 seconds.
  • Emulated CI (KILO_EXPERIMENTAL_DISABLE_FILEWATCHER=true, clean XDG_DATA_HOME): full file pass 5/5, about 3.1 to 4.8 seconds.
  • bun run test:ci from packages/sdk-next: 5 pass, 0 fail.
  • bun run typecheck from packages/sdk-next: clean (tsgo --noEmit).
  • bun run lint from the repo root: 0 errors.

Note on the reported CI failure

The macOS job cited when this work started (unit (macos), run 34954357833, job 104332897237) failed Run non-CLI unit tests on @opencode-ai/tui#test:ci (test/cli/tui/diff-viewer-file-tree.test.tsx), not on sdk-next. The unit-macos-1-1 JUnit artifact for that run records independent embedded hosts do not share live notifications as passing in 0.805s. So this sdk-next test was not the blocker in that job. This change fixes a separate deterministic failure that reproduces on developer machines with legacy credential state, and the latent concurrent startup race behind it.

Comment thread packages/sdk-next/test/embedded.test.ts Resolved
@kilo-code-bot

kilo-code-bot Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 1
Issue Details (click to expand)

SUGGESTION

File Line Issue
packages/sdk-next/test/embedded.test.ts 189 Serializing host startup removes the only concurrent multi-host OpenCode.create() coverage; suggest a follow-up (conflict-tolerant migration insert or a timeout-bounded regression test).
Files Reviewed (1 file)
  • packages/sdk-next/test/embedded.test.ts - 1 issue

Fix these issues in Kilo Cloud


Reviewed by deepseek-v4.1-flash · Input: 47.6K · Output: 6.8K · Cached: 303K

Review guidance: REVIEW.md from base branch main

@marius-kilocode
marius-kilocode merged commit 43d13cf into main Sep 15, 2026
30 checks passed
@marius-kilocode
marius-kilocode deleted the fix/sdk-next-embedded-hosts-flake branch September 15, 2026 11:08
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.

2 participants