Skip to content

Fix #40 keep detached exit-summary secrets off disk - #46

Open
jayzeng wants to merge 7 commits into
mainfrom
review/fix-pr40
Open

jayzeng wants to merge 7 commits into
mainfrom
review/fix-pr40

Conversation

@jayzeng

@jayzeng jayzeng commented Sep 21, 2026

Copy link
Copy Markdown
Owner

Follow-up to #40. Replaces the temporary JSON payload file with a one-shot stdin pipe, so API keys, conversation prompts, and model metadata are never persisted to disk. Adds fallback behavior when pipe setup is unavailable and tests for no temp-file leakage.

tbontb-iaq and others added 5 commits September 18, 2026 20:56
Pi core awaits session_shutdown handlers with no timeout, so real quits
block on the exit-summary LLM round trip (bounded only by the 10s
PI_MEMORY_EXIT_SUMMARY_TIMEOUT_MS from #26/#28). This adds a third way:
PI_MEMORY_EXIT_SUMMARY=detached (alias: background) hands the prepared
summary to a detached worker process and returns immediately, so quitting
is instant and no shutdown timeout is needed.

- shutdown handler: resolve branch/gate/model/key and build the prompt as
  today, then spawn the worker and return; falls back to the inline path
  if spawning fails or the summary cannot be prepared
- worker entry: this same file executed directly with
  --exit-summary-worker <payload.json> (import.meta.main); reads a 0600
  temp-file payload, deletes it, runs the LLM call, appends the daily
  log, and refreshes qmd (honors PI_MEMORY_QMD_UPDATE)
- refactor: extract generateExitSummary pre-flight into
  prepareExitSummaryRequest, shared by both paths; inline behavior and
  its ExitSummaryResult semantics are unchanged
- default remains inline; disable values unchanged

Tests: bun test test/unit.test.ts — 182 pass / 0 fail before, 188 / 0
after (mode parsing, spawn hand-off payload, trivial-session skip,
spawn-failure fallback, worker write/empty-drop).

Signed-off-by: Jin <JinRMoriarty@outlook.com>
@jayzeng
jayzeng changed the base branch from main to review/base-pr40 September 21, 2026 02:06
@jayzeng jayzeng closed this Sep 21, 2026
@jayzeng jayzeng reopened this Sep 21, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

💡 Codex Review

if (outcome !== "fallback") return;

P1 Badge Clear the pending qmd timer before returning

When detached mode successfully spawns or skips a summary, this early return bypasses the finally block that clears updateTimer. If a memory write scheduled scheduleQmdUpdate() shortly before the user quits, the referenced timer—and then its qmd update child—can keep the parent process alive for up to the command timeout, defeating detached mode's instant-exit guarantee. Clear the pending timer before returning from these outcomes.


pi-memory/index.ts

Lines 545 to 546 in 9b7c812

child.stdin.end(JSON.stringify(payload), "utf-8");
(child.stdin as typeof child.stdin & { unref?: () => void }).unref?.();

P2 Badge Handle errors emitted by the worker stdin pipe

If the detached worker exits before consuming the payload—for example because startup or module loading fails—this write can asynchronously emit EPIPE on child.stdin. The surrounding try and the listener on child do not handle errors emitted by the stdin stream, so a large exit-summary payload can produce an unhandled error in the parent during shutdown instead of degrading cleanly. Attach an error handler to the pipe and treat delivery failure as a failed handoff.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@jayzeng
jayzeng changed the base branch from review/base-pr40 to main September 21, 2026 02:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants