Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

fix(open-knowledge): deflake 4 merge-queue-blocking CI tests (#1588)

Nick Gomezb1fe9c2f4697
diff --git a/.changeset/deflake-merge-queue-tests.md b/.changeset/deflake-merge-queue-tests.md
new file mode 100644
index 000000000..ccb3a2050
--- /dev/null
+++ b/.changeset/deflake-merge-queue-tests.md
@@ -0,0 +1,5 @@
+---
+"@inkeep/open-knowledge-server": patch
+---
+
+Make the local telemetry file sink flush spans on span end (SimpleSpanProcessor) so `ok diagnose bundle` reliably captures spans — previously a batch-timer vs shutdown-timeout race could drop them under load. Also make project template enumeration order deterministic across filesystems by sorting the directory walk, so which templates fall inside the scan cap is stable run to run.
diff --git a/packages/app/package.json b/packages/app/package.json
index 5b25f487c..0a37a91b5 100644
--- a/packages/app/package.json
+++ b/packages/app/package.json
@@ -16,7 +16,7 @@
"test": "bun test --conditions development --path-ignore-patterns='**/*.dom.test.tsx' src/",
"test:dom": "bash scripts/run-test-dom.sh",
"check": "tsc --noEmit && biome check . && bun run test && bun run test:dom && bun run test:integration && bun run test:conversion",
- "test:integration": "bun test tests/integration/ tests/meta/ tests/lint-plugins/ --path-ignore-patterns=per-session-um-perf",
+ "test:integration": "bun test --timeout 30000 tests/integration/ tests/meta/ tests/lint-plugins/ --path-ignore-patterns=per-session-um-perf",
"test:perf:sessions": "bun test tests/integration/per-session-um-perf.test.ts --timeout 60000",
"test:conversion": "bun test tests/conversion/",
"test:fidelity": "bun test --timeout 120000 tests/fidelity/",
diff --git a/packages/app/tests/integration/c11-activity-panel-undo.test.ts b/packages/app/tests/integration/c11-activity-panel-undo.test.ts
index e15cbf956..b56d48eff 100644
--- a/packages/app/tests/integration/c11-activity-panel-undo.test.ts
+++ b/packages/app/tests/integration/c11-activity-panel-undo.test.ts
@@ -147,7 +147,7 @@ describe('C11 — Activity Panel undo isolation + CC1 signal', () => {
await writeAs(agentSuffix, '# CC1 test\n\ncontent\n', docName, ccServer);
- const deadline = Date.now() + 5000;
+ const deadline = Date.now() + 20_000;
while (Date.now() < deadline) {
const called = spy.mock.calls.some((args) => args[0] === 'session-activity');
if (called) break;
@@ -155,11 +155,17 @@ describe('C11 — Activity Panel undo isolation + CC1 signal', () => {
}
const sessionActivityCalls = spy.mock.calls.filter((args) => args[0] === 'session-activity');
+ if (sessionActivityCalls.length === 0) {
+ const channels = spy.mock.calls.map((args) => args[0]);
+ throw new Error(
+ `CC1 'session-activity' never fired within 20s. cc1Broadcaster.signal was called ${spy.mock.calls.length} time(s); channels seen: [${channels.join(', ') || 'none'}]. The persistence-debounce -> git-commit -> CC1-debounce chain likely stalled under load.`,
+ );
+ }
expect(sessionActivityCalls.length).toBeGreaterThan(0);
} finally {
await ccServer.cleanup();
}
- });
+ }, 30_000);
test('listAgentActivity: no sessions → { sessionAlive: false, agent: null, files: [] }', () => {
const sessionManager = server.instance.sessionManager;
diff --git a/packages/app/tests/integration/rename-history.test.ts b/packages/app/tests/integration/rename-history.test.ts
index da8b8a0a6..e6ceb868a 100644
--- a/packages/app/tests/integration/rename-history.test.ts
+++ b/packages/app/tests/integration/rename-history.test.ts
@@ -201,11 +201,13 @@ async function awaitWipCommit(
timeoutMs = 20_000,
): Promise<string> {
const deadline = Date.now() + timeoutMs;
+ const intervals = [100, 250, 500, 1000];
+ let attempt = 0;
while (Date.now() < deadline) {
const h = await getHistory(server.port, docName);
const newWip = h.entries.find((e) => e.type === 'wip' && !beforeShas.has(e.sha));
if (newWip !== undefined) return newWip.sha;
- await wait(50);
+ await wait(intervals[Math.min(attempt++, intervals.length - 1)]);
}
throw new Error(`awaitWipCommit: no NEW WIP commit for ${docName} within ${timeoutMs}ms`);
}
diff --git a/packages/server/src/content/templates-resolver.ts b/packages/server/src/content/templates-resolver.ts
index ae00008dc..e58b52a4f 100644
--- a/packages/server/src/content/templates-resolver.ts
+++ b/packages/server/src/content/templates-resolver.ts
@@ -82,7 +82,7 @@ export function resolveProjectTemplates(projectDir: string): ProjectTemplatesRes
const absDir = folderRel ? join(projectDir, folderRel) : projectDir;
let entries: string[];
try {
- entries = readdirSync(absDir);
+ entries = readdirSync(absDir).sort();
} catch (err) {
const code = (err as NodeJS.ErrnoException | undefined)?.code;
if (code !== 'ENOENT' && !templateMetaWarnedPaths.has(absDir)) {
diff --git a/packages/server/src/telemetry-file-sink.ts b/packages/server/src/telemetry-file-sink.ts
index 6ae200c2f..0314dbd61 100644
--- a/packages/server/src/telemetry-file-sink.ts
+++ b/packages/server/src/telemetry-file-sink.ts
@@ -1,4 +1,5 @@
import { statSync } from 'node:fs';
+import { mkdir, rename, writeFile } from 'node:fs/promises';
import { dirname, join } from 'node:path';
import { Writable } from 'node:stream';
import type { Context } from '@opentelemetry/api';
@@ -11,7 +12,6 @@ import type {
SpanExporter,
SpanProcessor,
} from '@opentelemetry/sdk-trace-base';
-import { tracedMkdir, tracedRename, tracedWriteFile } from './fs-traced.ts';
export interface RotatingAppenderOpts {
currentPath: string;
@@ -44,10 +44,10 @@ export class RotatingAppender {
async #doAppend(data: string | Uint8Array): Promise<void> {
if (!this.#parentDirEnsured) {
- await tracedMkdir(dirname(this.#currentPath), { recursive: true });
+ await mkdir(dirname(this.#currentPath), { recursive: true });
this.#parentDirEnsured = true;
}
- await tracedWriteFile(this.#currentPath, data, { flag: 'a' });
+ await writeFile(this.#currentPath, data, { flag: 'a' });
let size: number;
try {
size = statSync(this.#currentPath).size;
@@ -56,7 +56,7 @@ export class RotatingAppender {
return;
}
if (size > this.#maxBytes) {
- await tracedRename(this.#currentPath, this.#previousPath);
+ await rename(this.#currentPath, this.#previousPath);
}
}
}
diff --git a/packages/server/src/telemetry.ts b/packages/server/src/telemetry.ts
index 70faf292a..f4115e1eb 100644
--- a/packages/server/src/telemetry.ts
+++ b/packages/server/src/telemetry.ts
@@ -10,6 +10,7 @@ import { MeterProvider, PeriodicExportingMetricReader } from '@opentelemetry/sdk
import {
BasicTracerProvider,
BatchSpanProcessor,
+ SimpleSpanProcessor,
type SpanProcessor,
} from '@opentelemetry/sdk-trace-base';
import { ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION } from '@opentelemetry/semantic-conventions';
@@ -65,7 +66,7 @@ export function initTelemetry(opts: InitTelemetryOptions = {}): { tracer: Tracer
spanProcessors.push(new ScrubbingSpanProcessor({ attributeDenylist }));
if (fileSinkEnabled && opts.localSink !== undefined) {
spanProcessors.push(
- new BatchSpanProcessor(
+ new SimpleSpanProcessor(
new FileSpanExporter({
contentDir: opts.localSink.contentDir,
maxBytes: opts.localSink.spansMaxBytes,