pi-memory icon indicating copy to clipboard operation
pi-memory copied to clipboard

Windows: automatic consolidation silently fails with spawn pi ENOENT

Open edision opened this issue 2 months ago • 1 comments

Bug description

Automatic session-end consolidation silently fails on Windows when Pi is installed with pi.ps1 / pi.cmd launchers. Pi itself works, and pi-memory opens its SQLite store, but no facts or lessons are learned. A fresh session cannot recall an explicitly stated lasting preference.

The configured consolidation model was independently verified through a direct Node + Pi CLI invocation, so this is not a missing model or authentication failure.

Environment

  • Windows
  • Node.js 24.21.0
  • @earendil-works/pi-coding-agent 1.0.2, managed Windows installation
  • @samfp/pi-memory 1.6.0, unmodified npm package for the failing runs

The same launch code is still present on the default branch: src/index.ts, lines 714–746.

Steps to reproduce

  1. Start Pi on Windows, with the normal script-based launcher and a known-working memory.consolidationModel.
  2. Use an empty, project-local memory store, e.g. "pi-memory": { "localPath": ".pi/memory" } in the project's .pi/settings.json.
  3. Send at least three real user messages establishing a lasting preference and a correction. For example: a permanent release codename, followed by a rule never to abbreviate or lowercase it.
  4. Exit normally, letting session_shutdown run. Do not call memory_remember or /memory-consolidate.
  5. Inspect the isolated store, then start a fresh session with no original conversation and ask for the preference.

Actual behavior

In two independent failing runs, shutdown exited successfully but the isolated store remained at 0 facts, 0 lessons, 0 write audit events. Fresh-session recall returned UNKNOWN. There was no consolidation failure warning.

Expected behavior

With enough eligible conversation and a working model, normal shutdown should be able to launch consolidation and persist the extracted memory. Launch/model failures should be observable rather than silently ignored.

Minimal launch reproduction and root cause

Run this as probe.mjs with the same PATH as Pi:

import { spawn } from "node:child_process";

const child = spawn("pi", ["--version"], { shell: false });
console.log({ pid: child.pid ?? null });
child.on("error", (error) => {
  console.error({ message: error.message, code: error.code });
});

Observed:

{ pid: null }
{ message: 'spawn pi ENOENT', code: 'ENOENT' }

consolidateSession() calls pi.exec("pi", ...). In this Pi version, the exec helper uses spawn(..., { shell: false }); the Windows script launchers cannot be launched this way. The helper normalizes the spawn error to:

{ "stdout": "", "stderr": "", "code": 1, "killed": false }

pi-memory only handles code === 0 && stdout, so the failure is silently skipped. Node documents the Windows script-launching limitation here.

Verified local fix direction

For the Node CLI installation, invoking the actual running Pi CLI through the current Node executable works without a shell:

await pi.exec(process.execPath, [resolvedPiCli, ...consolidationArgs], {
  timeout: 45_000,
  cwd: sessionCwd,
});

Resolve the active host CLI, not merely a PATH shim or an arbitrary installed SDK copy. In a local development checkout, resolving the SDK from compiled ESM can select the physical 0.87.1 development dependency instead of the running 1.0.2 host; a launch-path regression test caught this distinction. SDK-hosted or compiled-binary installations may need their own resolution strategy; my real end-to-end testing covered Windows/Node CLI installations.

Also report nonzero exit, timeout, empty output and launch exceptions while avoiding raw provider output that could contain credentials. Keep consolidation isolated from tools/extensions and unrelated context resources.

Validation

With the local launch/diagnostic fix:

  • Seven new launch/error-path regression tests were first observed failing, then passing. The full suite passed 135/135 under an isolated HOME; typecheck and build passed.
  • Four fresh, isolated end-to-end runs, including two after restarting Pi, passed: automatic learning → SQLite persistence → new-process, empty-history recall → embedding backfill.
  • Learning and automatic recall used zero tool calls; no manual memory writes or manual consolidation were used.
  • Real 1024-dimensional Ollama backfill and hybrid retrieval passed. A query with zero keyword hits still retrieved the automatically learned preference through vector matching.
  • The global memory store was unchanged. Asynchronous backfill was allowed to finish before closing the recall process.

This report concerns the subprocess launch failure, separately from the session:unknown provenance issue in #35.

edision avatar Oct 04 '26 23:10 edision

This is a spawn-boundary failure: pi.exec builds its child process with shell: false, which Node explicitly can't use to launch Windows .ps1/.cmd script shims, so the exec call never reaches a real Pi process — it dies at OS dispatch, before the model or auth layer is even touched. The reporter's own phrase nails it: "the Windows script launchers cannot be launched this way," paired with the normalized failure shape "pi-memory only handles code === 0 && stdout, so the failure is silently skipped." That's a swallowed-error class, not a missing-model class — the exec wrapper collapses ENOENT, non-zero exit, and empty stdout into one indistinguishable "no output" bucket, so consolidation has no way to tell "model declined" from "process never started."

The deterministic check that catches this before it ships: a contract-level assertion at the pi.exec boundary that a spawn attempting to launch pi must either return a real PID or raise a typed LaunchError — never both a non-null exit object and a child.on('error') event. Concretely: assert child.pid != null immediately after spawn, and if a child.on('error') fires, that must be the only signal propagated upward (never silently coerced into {code:1, stdout:''}). A second regression test should run the resolved CLI path through fs.existsSync plus a --version smoke spawn on actual Windows script shims (.ps1/.cmd), not just POSIX binaries, since "resolving the SDK from compiled ESM can select the physical 0.87.1 development dependency instead of the running 1.0.2 host" shows path resolution itself needs its own fixture-backed test, separate from the exec-shell test.

Open question I can't resolve from the issue alone: whether the same ENOENT-swallowing happens for SDK-hosted or compiled-binary Pi installations, since the reporter explicitly scoped validation to "Windows/Node CLI installations" only — that's the evidence that would confirm or narrow this fix's blast radius.

Advisory SFA-2026-C2FE38593C · Full redacted write-up: https://impartshadow.github.io/echo-site/failure-cases/windows-automatic-consolidation-silently-fails-with-c2fe38593c.html If this diagnosis is useful, react 👍 to this comment; if it is wrong, react 👎 — I use the verdict to choose what I investigate next.

impartshadow avatar Oct 09 '26 06:10 impartshadow