cloudflare / cloudflare/workers-sdk

[Vite plugin] Inline auxiliary Workers recreate remote-binding sessions during Miniflare updates

Open
#15,418 1 comment 0 reactions 0 assignees View on GitHub
package:vite-plugin
Dominant language
TypeScript
Stars
4.5k
Forks
1.5k
Avg merge
3d 8h
Merged PRs (30d)
187

Description

### What version of Wrangler / Vite plugin?

- `@cloudflare/vite-plugin@1.54.1`
- `wrangler@4.127.0`
- `vite@8.2.2`

### Reproduction

Configure one file-backed entry Worker and three inline auxiliary Workers (`auxiliaryWorkers: [{ config: ... }, ...]`). Give every Worker an AI or other `remote: true` binding, then run Vite dev.

The first `getDevMiniflareOptions()` call opens four expected proxy sessions. After export discovery changes the wrapper export map, the plugin regenerates Miniflare options. The entry Worker reuses its session, but all three inline auxiliaries open replacements, so the four-Worker graph logs seven `Establishing remote connection...` messages and retains three extra workerd process trees.

Observed on a full TanStack Start multi-Worker app:

- remote sessions: 7 instead of 4
- process count after idle: 11 instead of 8
- warm PSS: 2.55 GiB instead of 2.39 GiB
- warm ready/first HTTP: 45.3s/66.1s instead of 38.6s/59.5s

### Root cause

`packages/vite-plugin-cloudflare/src/miniflare-options.ts` caches `RemoteProxySessionData` only when `worker.config.configPath` exists:

```ts
const preExisting = worker.config.configPath
? remoteProxySessionsDataMap.get(worker.config.configPath)
: undefined;

if (worker.config.configPath && remoteProxySessionData) {
remoteProxySessionsDataMap.set(worker.config.configPath, remoteProxySessionData);
}
```

Inline auxiliary Worker configuration is a documented public API and has no `configPath`, so it can never participate in reuse. The same pattern exists in preview options.

### Suggested fix

Use the required unique Worker name as the fallback identity for inline configs (with a prefix to avoid colliding with paths):

```ts
const key = worker.config.configPath ?? `inline:${worker.config.name}`;
const preExisting = remoteProxySessionsDataMap.get(key);
// ...
if (remoteProxySessionData) remoteProxySessionsDataMap.set(key, remoteProxySessionData);
```

I verified this locally in both dev and preview code paths. It reduces the connection count from seven to four and removes the three retained process trees without changing remote binding behavior.

Contributor guide

Open the contributing guide

Research direction

Start in packages/vite-plugin-cloudflare/src/miniflare-options.ts and reproduce the inline auxiliary Worker setup with Vite dev, watching remote-connection logs and retained process counts. Inspect the corresponding preview-options path for the same session-cache behavior; done means four connections for four Workers in both dev and preview, with no extra process trees.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript, vite
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
76/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.