mirror of
https://github.com/mksglu/context-mode.git
synced 2026-09-19 03:27:16 +08:00
d66f767936
* fix(pi): await MCP bridge bootstrap in before_agent_start Pi subagents (`pi --mode json -p --no-session`) spawn a fresh process that loads the context-mode extension and immediately fires `before_agent_start` to dispatch the LLM call. The MCP bridge bootstrap (spawn server.bundle.mjs → initialize → tools/list → pi.registerTool × N) was fire-and-forget via `_mcpBridgeReady`, so the LLM call went out with an empty ctx_* tool registry and the routing block (~2.5K tokens) became dead weight — the LLM was told to call `ctx_execute` / `ctx_search` / etc. but Pi had not yet registered them. Awaiting `_mcpBridgeReady` at the top of the `before_agent_start` handler closes the race: by the time the handler resolves, the bridge has settled (success or failure — failures are still logged to stderr but never propagated, matching the original best-effort contract) and the registry contains the ctx_* tools. Reported in mksglu/context-mode#472 (comment 4412197109). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * test: raise hookTimeout to 30s to absorb Windows better-sqlite3 cleanup flake The default 10s vitest hookTimeout is exhausted on Windows runners by files whose afterAll loops over many better-sqlite3 handles — tests/session/session-pipeline.test.ts is the canonical example. Local runs finish in ~500ms but Windows fork-pool contention plus native addon cleanup can stretch past 10s, surfacing as FAIL tests/session/session-pipeline.test.ts Error: Hook timed out in 10000ms. Match the 30s testTimeout already in this config so the cleanup window matches the work window — same envelope better-sqlite3 needs for tests themselves. No change to local-dev wall time (only fires when a hook exceeds 10s, which is a flake-level event). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
35 lines
1.7 KiB
TypeScript
35 lines
1.7 KiB
TypeScript
import { defineConfig } from "vitest/config";
|
|
|
|
const isCI = !!process.env.CI;
|
|
|
|
export default defineConfig({
|
|
test: {
|
|
include: ["tests/**/*.test.ts"],
|
|
testTimeout: 30_000,
|
|
// afterAll cleanup loops over many better-sqlite3 handles on Windows
|
|
// and can exceed vitest's default 10s hookTimeout under fork contention
|
|
// (e.g. tests/session/session-pipeline.test.ts cleans every DB it
|
|
// created). Match testTimeout so the cleanup window matches the work
|
|
// window — same envelope better-sqlite3 already needs for tests.
|
|
hookTimeout: 30_000,
|
|
// Native addons (better-sqlite3) can segfault in worker_threads during
|
|
// process cleanup. Use forks on all platforms for stable isolation.
|
|
pool: "forks",
|
|
// Cap parallel workers to prevent fork exhaustion (#258).
|
|
// Tests that spawnSync + better-sqlite3 cause worker SIGKILL under
|
|
// unlimited parallelism. Benchmarked: 3 workers = 2.8x speedup with
|
|
// near-zero crashes (vs unlimited = 3.7x but 6-7 worker kills/run).
|
|
maxWorkers: isCI ? 2 : 3,
|
|
// Hook subprocess tests (spawnSync + better-sqlite3 native addon) can
|
|
// fail intermittently under parallel load on CI. Retry once to absorb
|
|
// transient resource-contention failures without masking real regressions.
|
|
// Only enable retry on CI to avoid slowing down local dev.
|
|
retry: isCI ? 2 : 0,
|
|
// Force exit after tests complete — prevents CI failure from open handles
|
|
// (better-sqlite3 native addon cleanup races with fork worker teardown).
|
|
// Without this, Ubuntu CI consistently fails with "Worker exited unexpectedly"
|
|
// even though all tests pass.
|
|
teardownTimeout: isCI ? 15_000 : 5_000,
|
|
},
|
|
});
|