Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions packages/cli/src/serve/run-qwen-serve.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16281,6 +16281,14 @@ describe('runQwenServe startup observability', () => {
preheat: vi.fn().mockResolvedValue(undefined),
getDaemonStatusSnapshot: vi.fn().mockReturnValue(BASE_BRIDGE_SNAPSHOT),
isChannelLive: vi.fn().mockReturnValue(true),
getWorkspaceRuntimeLifecycleSnapshot: vi.fn().mockReturnValue({
state: 'idle',
runtimeLive: true,
runtimeEpoch: 1,
activeWork: false,
}),
reloadWorkspaceMcp: vi.fn().mockResolvedValue({ accepted: true }),
initializeWorkspaceMcp: vi.fn().mockResolvedValue({ accepted: true }),
} as unknown as HttpAcpBridge;
}

Expand Down Expand Up @@ -16524,6 +16532,36 @@ describe('runQwenServe startup observability', () => {
}
});

it('loads persisted MCP configuration after ACP preheat succeeds', async () => {
tmpDir = fs.realpathSync(
fs.mkdtempSync(path.join(os.tmpdir(), 'qws-startup-mcp-config-')),
);
const bridge = installInternalBridge(() => Promise.resolve());

const handle = await runQwenServe(
{
port: 0,
hostname: '127.0.0.1',
mode: 'http-bridge',
workspace: tmpDir,
maxSessions: 1,
serveWebShell: false,
},
{ preheatBridge: true },
);

try {
expect(await waitForPreheatStatus(handle, 'succeeded')).toMatchObject({
status: 'succeeded',
});
await vi.waitFor(() =>
expect(bridge.reloadWorkspaceMcp).toHaveBeenCalledOnce(),
);
} finally {
await handle.close();
}
});

it('tracks preheat running and succeeded states for an internally-created bridge', async () => {
tmpDir = fs.realpathSync(
fs.mkdtempSync(path.join(os.tmpdir(), 'qws-startup-preheat-')),
Expand Down
22 changes: 19 additions & 3 deletions packages/cli/src/serve/run-qwen-serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8928,7 +8928,22 @@ async function runQwenServeImpl(
clearRuntimeStartupTimer();
markRuntimeReady();
};
const startBridgePreheat = (bridge: AcpSessionBridge): void => {
const schedulePersistedMcpConfigurationAfterPreheat = (
app: Application,
): void => {
const registry = app.locals?.['workspaceRegistry'] as
| WorkspaceRegistry
| undefined;
const primary = registry?.primary;
if (!primary?.trusted) return;
getWorkspaceRuntimeCoordinatorIfSupported?.(
primary,
)?.reconcileMcpConfiguration();
};
const startBridgePreheat = (
bridge: AcpSessionBridge,
app: Application,
): void => {
startup.preheat.status = 'running';
const preheatStartedAt = performance.now();
bridge
Expand All @@ -8938,6 +8953,7 @@ async function runQwenServeImpl(
startup.preheat.durationMs = Math.round(
performance.now() - preheatStartedAt,
);
schedulePersistedMcpConfigurationAfterPreheat(app);
})
.catch((err) => {
const message = err instanceof Error ? err.message : String(err);
Expand Down Expand Up @@ -8973,7 +8989,7 @@ async function runQwenServeImpl(
return;
}
if (shouldPreheat && runtime.bridge) {
startBridgePreheat(runtime.bridge);
startBridgePreheat(runtime.bridge, runtime.app);
}
await completeRuntimeStartup(runtime.app);
})
Expand Down Expand Up @@ -9510,7 +9526,7 @@ async function runQwenServeImpl(
if (preparedRuntimeApp && bridgeRef && deps.bridge) {
attachLiveDiscoveryControl(preparedRuntimeApp);
if (shouldPreheat) {
startBridgePreheat(bridgeRef);
startBridgePreheat(bridgeRef, preparedRuntimeApp);
}
if (opts.channelSelection && !runtimeStartupSettled) {
armRuntimeStartupTimer();
Expand Down
Loading