Heuristic:20000419 Fauxnix Warm Call Optimization
| Knowledge Sources | |
|---|---|
| Domains | Performance, Optimization, Session_Management |
| Last Updated | 2026-10-26 00:00 GMT |
Overview
Prewarm the resident PowerShell host at session startup so the first command call is already warm, eliminating cold-boot latency (~30s) from the first user-visible operation.
Description
PowerShell 5.1 takes up to 30 seconds to cold-boot on some machines. Fauxnix eliminates this latency by calling `prewarm()` at session startup — before any user command runs. The MCP server prewarms immediately after creating the session (`await session.prewarm()` in `mcp.ts:294`), and the facade entry does the same (`await session.prewarm()` in `facade.ts:146`). Prewarming starts the resident PowerShell process and waits for the ready handshake. By the time the first `bash` or `bash_batch` tool call arrives, the host is already initialized. The prewarm also establishes the host's environment snapshot (cwd, env vars) so the first call sees a complete session state.
Usage
Use this heuristic when initializing any session that wraps a slow-to-start process. Call `prewarm()` before exposing the session to user-facing operations. This is especially important for MCP servers where the first tool call latency directly affects the agent's perceived responsiveness.
The Insight (Rule of Thumb)
- Action: Call `session.prewarm()` at session startup, before accepting the first user command.
- Value: Prewarm starts the host and waits for the ready handshake (up to 30s default; configurable via `FAUXNIX_HOST_READY_TIMEOUT_MS`).
- Trade-off: Adds up to 30s to session startup time, but saves it from the first call. Net zero if the first call would have cold-booted anyway, but the latency moves to a non-user-visible phase.
- Compatibility: `reset()` also re-prewarms after disposing the old host — a reset session is warm again.
Reasoning
The resident PowerShell host takes 5-30 seconds to cold-boot depending on machine load. If the first user command triggers this cold-boot, the agent sees a long pause with no indication of progress. By prewarming during session setup (which the MCP client expects to take time), the first actual tool call returns in milliseconds. The 30-second ready timeout is tuned for dev machines; contended CI runners can widen it via `FAUXNIX_HOST_READY_TIMEOUT_MS` (minimum 1000ms). The prewarm is idempotent — calling `ready()` on an already-started host is a no-op.
Code Evidence
Prewarm in MCP server startup from `src/mcp.ts:293-294`:
try {
await session.prewarm();
server.tool(TOOL_NAME, TOOL_DESCRIPTION, { ... }, ...);
Prewarm in facade from `src/facade.ts:146`:
await session.prewarm();
Prewarm implementation from `src/executor.ts:358-363`:
/** Boot the selected PowerShell now so the first run() is not a cold start. */
prewarm(): Promise<void> {
return this.withLock(async () => {
await this.ensureHost().ready();
});
}
Ready timeout configuration from `src/ps-host.ts:42-45`:
const READY_TIMEOUT_MS = (() => {
const raw = Number(process.env.FAUXNIX_HOST_READY_TIMEOUT_MS);
return Number.isFinite(raw) && raw >= 1000 ? raw : 30_000;
})();