Pi hooks abort on Node 26.11.1: readHookStdin destroys fd 0 before synchronous Git subprocesses
Summary
memorix hook aborts under Node 26.11.1 when stdin is a regular file and the hook subsequently performs synchronous project-detection subprocess work. This affects Pi's pi.agent_end and pi.tool_execution_end hooks: the hook produces no JSON response and Pi reports:
[memorix-pi] hook failed: pi.agent_end node: ../deps/uv/src/unix/core.c:646: int uv__close(int): Assertion `fd > STDERR_FILENO' failed.
[memorix-pi] hook failed: pi.tool_execution_end node: ../deps/uv/src/unix/core.c:646: int uv__close(int): Assertion `fd > STDERR_FILENO' failed.
This is independent of embedding credentials. A credential-free standalone reproduction below produces the same abort.
Environment
- Memorix 1.9.10; upstream HEAD checked:
af2550290ca6d37c524450b4366277b211aa7402. - Linux x86-64, kernel
7.2.5-3-omarchy. - Failing Node 26.11.1, libuv 1.52.1.
- Control Node 24.14.1 does not reproduce this failure.
- Pi 1.1.0, embedded Bun 1.3.14. Its
spawnSyncinput was verified usingfstatSync(0)to be a regular file, despite the extension specifyingstdio: ['pipe', 'pipe', 'pipe'].
The bug is not inherently Pi-specific: ordinary file-redirection stdin reproduces it too. No claim is made about every Node 26 release or other operating systems.
Verified root cause
readHookStdin()callsstdin.destroy()for every non-TTY stream after EOF/error/timeout.- With regular-file stdin on Node 26.11.1, this closes fd 0. Separate descriptor probes confirmed that
fstatSync(0)then fails and the nextopenSync('/dev/null', 'r')returns0. With Node 24.14.1, fd 0 remains open. - Project detection can call synchronous Git subprocesses; for example,
getGitRemote()falls back toexecSync('git -c safe.directory=* remote get-url origin', ...)when the filesystem fast path does not find a remote. - The synchronous subprocess runner's temporary libuv loop reuses fd 0 as its backend descriptor. Its cleanup calls
uv__close(0), violating libuv's standard-descriptor assertion and aborting Node.
GDB confirmed both the crash stack and the descriptor value:
#5 uv__close
#6 uv__loop_close
#7 uv_loop_close
#8 node::CheckedUvLoopClose
#9 node::SyncProcessRunner::CloseHandlesAndDeleteLoop
#10 node::SyncProcessRunner::Run
#11 node::SyncProcessRunner::Spawn
(gdb) frame 6
(gdb) print loop->backend_fd
$1 = 0
Minimal reproduction, without Memorix or credentials
Save as repro.mjs:
import { spawnSync } from 'node:child_process';
process.stdin.resume();
process.stdin.on('end', () => {
process.stdin.destroy();
setTimeout(() => {
spawnSync(process.execPath, ['-e', 'process.exit(0)']);
}, 30);
});
Run with Node 26.11.1:
printf '{}' > payload.json
node repro.mjs < payload.json
Actual: SIGABRT with the same uv__close assertion. Reproduced 3/3 times. In contrast, printf '{}' | node repro.mjs exits 0 3/3 times. Node 24.14.1 exits 0 for both stdin forms, 3/3 each.
Removing the process.stdin.destroy() call prevents the failure. Pipe-only tests therefore miss this regular-file-stdin regression.
Proposed and locally verified Memorix fix
Do not close process stdin's standard descriptor. Pause it and unref it where supported:
stdin.pause?.();
- if (!stdin.isTTY) {
- stdin.destroy?.();
- } else {
- stdin.unref?.();
- }
+ stdin.unref?.();
The existing listener removal, stdin-read timeout, and runHookWithDeadline() forced-exit backstop should remain unchanged. This preserves the reason for the original cleanup: an open producer must not leave a hook process hanging. There is no need to disable capture, change Git data, or configure embeddings to fix this abort.
Runtime verification
The equivalent edit was applied to an isolated copy of the actual 1.9.10 built CLI, not just a mocked stdin object. Tests used temporary Git projects with no origin remote, synthetic hook payloads, a dummy LLM credential, and a loopback-only endpoint. No real credentials or user memory stores were used. The CLI's normal heap-respawn banner remained enabled.
| Actual Pi/Bun transport; three runs per hook | Original CLI | Patched CLI |
|---|---|---|
Node 26.11.1, pi.agent_end |
Assertion, no JSON: 3/3 | Exit 0, {"continue":true}: 3/3 |
Node 26.11.1, pi.tool_execution_end |
Assertion, no JSON: 3/3 | Exit 0, {"continue":true}: 3/3 |
| Node 24.14.1, both hooks | Exit 0: 6/6 |
Exit 0: 6/6 |
Additional checks on both Node versions:
- Real
readHookStdin()source with the proposed edit: regular-file EOF, pipe EOF, and pipe left open all returned the expected input and exited naturally. The open-pipe case exited after the 100 ms read timeout, approximately 215 ms total. - Open stdin plus never-resolving hook work: the unchanged hard deadline emitted
{"continue":true}and exited0on both versions. - Focused contract checks: 8/8 passed per version for EOF/error/timeout, pause/unref without destroy, listener cleanup, optional
unref, single settlement, success/error exit, and deadline exit.
The full repository Vitest suite and cross-platform CI were not run; these are targeted runtime and contract results, not a claim of complete release validation. The installed CLI and user configuration were not modified.
Suggested regression coverage
- Add a real Node 26 child-process test with regular-file stdin, followed by a synchronous subprocess. Keep a pipe-stdin control.
- Update the existing lifecycle timeout test to assert pause/unref and preservation of the standard descriptor rather than requiring
destroy()on aPassThrough. - Retain the open-producer and hard-deadline tests so the fix cannot reintroduce orphan hook processes.
Until fixed upstream, running Memorix's hook CLI under Node 24.14.1 is a verified workaround for this particular abort.
Implemented in PR #331 (commit 82e05b0).
The hook reader now pauses and unrefs stdin without destroying fd 0. The PR adds a real smoke test that passes a regular file as stdin to the built Pi hook, reaches synchronous Git project detection, verifies the JSON response, and confirms the observation is persisted. The Node 26 CI job runs this smoke directly.
Local evidence on Windows/Node 22: focused hook tests 7/7, build, typecheck, regular-file smoke, and the full suite (340 files passed, 2 skipped; 3,197 tests passed, 4 skipped). I could not reproduce Node 26.11.1 locally, so the Node 26 result remains a CI gate. Keeping this issue open until the PR is merged.
Update: PR #331 now has a fully green repository CI run, including the dedicated Node 26 regular-file stdin smoke and all Ubuntu/Windows/macOS suites. The issue will remain open until the PR is merged.