Commit Graph

2 Commits

Author SHA1 Message Date
joakimp f590a3ac5b feat(pi): print and JSON mode skip the feed by default (MEMPALACE_FEED_PRINT=1 to keep it)
After 2f0edf5 a `pi -p` still waited for one full catch-up feed. lastFeedAt
starts at 0, so the first settled turn feeds, and session_shutdown waits for
that feed. On tor-ms22 this took 45 s (prepare 11 s + mine 31 s) for a 3 s
answer. That feed almost never files the run's own transcript, because a
one-shot run rarely passes the exporter's gate (4 messages, 1000 assistant
chars). What it files is the device's other sessions, and the next interactive
feed re-offers those without duplicates. The source_file is the staged path,
fixed per session UUID. An unchanged file is skipped. For a grown file, its
drawers are purged and then refiled.

Now, when ctx.mode is "print" or "json", neither agent_settled nor
session_shutdown feeds. Without ctx.mode, the bridge falls back to
hasUI === false. A stale ctx keeps the old behaviour. RPC mode is long-lived
and feeds as before. MEMPALACE_FEED_PRINT=1 restores feeding in print and JSON
mode, for a device that only ever runs pi -p.

Measured on tor-ms22 with the workspace copy (-ne -nt --no-session -e):
- pi -p: 2.9 s / 2.8 s
- --mode json: 3.8 s
- -p with MEMPALACE_FEED_PRINT=1: 30.8 s; the probe saw the prepare and race
  timers, so the feed ran.

scripts/test-feed-exit.sh now fires agent_settled and then session_shutdown
with a ctx, and gained cases C (print), D (json), E (print +
MEMPALACE_FEED_PRINT=1) and F (rpc). Against 2f0edf5's source, C and D fail
(mines=1, about 1 s wait). All six scripts/test-*.sh pass.
2026-10-13 14:51:37 +02:00
joakimp 2f0edf51cf fix(pi): clear the feed's mine-race timer, so pi -p exits when the mine returns
feedPalace() raced mempalace_mine against a bare setTimeout(reject,
feedMineTimeoutMs) and never cleared it. When the mine won (the normal case)
the losing 300 000 ms timer stayed referenced. Interactive and RPC mode call
process.exit() and never showed it. Print mode (`pi -p`, `--mode json`) returns
and waits for an empty event loop, so every `pi -p` on a devbox printed its
answer and then idled for the rest of the five minutes.

Measured on tor-ms22 (pi 1.1.0, NODE_OPTIONS=--import probe):
- before: PONG at 4 s, exit at 315.1 s. The 300 000 ms timer from
  mempalace.ts:1144 (created +15.1 s) was the ONLY active resource from +50 s on.
- after:  PONG at 3 s, exit at 45.2 s, the moment the mine's socket closed.
- MEMPALACE_FEED=0: 3.8 s.
pi 1.0.0 behaved the same as 1.1.0, so this is not a pi regression.

The timer is now cleared in a finally once the race settles. It stays
referenced while it runs because it is the liveness guard.

scripts/test-feed-exit.sh loads the type-stripped SHIPPED extension under a
stub pi with a fake palace in a separate process and fires session_shutdown:
- A: the mine answers in 1 s with a 20 s deadline. Node must exit within 3 s
  of the handler resolving. The pre-fix source FAILS here (19 000 ms).
- B: the mine never answers, 2 s deadline. The deadline still ends the wait,
  and the failure is logged.
All five scripts/test-*.sh pass.

README Debugging section: the remaining expected wait (one catch-up feed per
session, ~45 s here) and MEMPALACE_FEED=0 for scripts that want an instant
return.
2026-10-13 13:55:55 +02:00