Personal_AI_Infrastructure icon indicating copy to clipboard operation
Personal_AI_Infrastructure copied to clipboard

SessionEnd waits on the detached IntegrityMaintenance child because it inherits stderr

Open corobis opened this issue 2 months ago • 2 comments

hooks/handlers/SystemIntegrity.ts spawns the maintenance script with detached: true and stdio: ['pipe', 'ignore', 'inherit']. The inherited stderr pipe stays open until the child exits, so Claude Code keeps the SessionEnd hook open that long. Here that was about 24 seconds per session end.

Environment: Linux (WSL2), Bun, Claude Code 2.1.278.

Fix that works here: open a log file in append mode and pass its fd for both stdout and stderr:

const logFd = openSync(paiPath('MEMORY', 'OBSERVABILITY', 'integrity-maintenance.log'), 'a');
const child = spawn('bun', [INTEGRITY_SCRIPT], {
  detached: true,
  stdio: ['pipe', logFd, logFd],
  env: { ...process.env },
});

SessionEnd returns right away, and the child's success lines land in the log too.

corobis avatar Sep 21 '26 15:09 corobis

This is Shiva, Eugene's AI Assistant, reporting on Eugene's behalf.

Confirmed and reproduced the exact hang (3.0s vs 0.02s) — the detached IntegrityMaintenance child inherited the stderr pipe, so SessionEnd blocked waiting on a process it wasn't supposed to wait on. Routed the child's stdout/stderr to a log file instead of inheriting.

Environment: ThinkPad, Ubuntu 24.04.4 LTS, Ryzen AI 9 HX PRO 370, Bun 1.3.11.

waveman2020-sudo avatar Sep 23 '26 19:09 waveman2020-sudo

Thanks @corobis. Confirmed: the detached IntegrityMaintenance child inherited the hook's stderr, so SessionEnd waited for it. The child now writes stdout and stderr to a log file descriptor and the hook returns at once (hooks/handlers/SystemIntegrity.ts), with a test. Next release carries it.

danielmiessler avatar Oct 03 '26 04:10 danielmiessler