---
created: 2026-03-29T18:40:00.000Z
title: Revise stash to delegate Psyche teardown to Psyche itself
area: tooling
files:
  - owl.sh:443-496
  - live.sh:297-359
  - psyche.md
---

## Problem

`$OWL stash` currently tears down the Psyche wrapper process and perch (lines 455-486 of owl.sh) before the stash sleep loop. This means the Psyche never receives or processes any final COMMUNE sent just before stash. The teardown kills the wrapper before the Psyche can save context from that last message.

The current sequence is:
1. Self sends a COMMUNE (manually, before stash)
2. Self runs `$OWL stash doyle true`
3. Stash kills Psyche wrapper → Psyche's poll dies → COMMUNE may be lost
4. Stash tears down Psyche perch
5. Stash tears down Self perch
6. Stash enters sleep loop

The COMMUNE at step 1 races with the teardown at step 3. If the Psyche hasn't consumed it yet, it's deleted with the perch.

## Solution

Make the stash protocol include a final COMMUNE as part of its sequence, and delegate Psyche teardown to the Psyche itself:

1. `$OWL stash` sends a special `COMMUNE (STASH_FINAL): <context>` to the Psyche
2. Stash does NOT tear down the Psyche wrapper or perch — it only tears down Self's perch
3. The Psyche receives the STASH_FINAL COMMUNE, saves context via `$LIVE context-save`, then self-terminates (tears down its own perch and exits the wrapper loop)
4. Psyche's self-teardown: remove ready file, clean inbox, exit wrapper

This ensures the Psyche always processes the final context update before dying. Add a `STASH_FINAL` message type to psyche.md that triggers: absorb context → save → self-teardown.

Fallback: If the Psyche doesn't self-terminate within N seconds, stash force-kills it (timeout safety net).
