# Postmortem: Notify-pull dogfood regression cluster

**Date:** 2026-08-02  
**Severity:** Medium — lifecycle actions failed or UX was misleading; no message loss observed  
**Status:** Resolved; follow-up process adopted

## Summary

Real peer testing found three implementation defects and one e2e harness defect that passed the original automated suite:

1. AMQ read JSON placed identity under `header`.
2. Handshake discovery could grant implicit primary targeting.
3. Restored partial mailboxes failed before watcher startup.
4. Terminal output caused e2e waits to miss valid results.

A separate usability gap showed that peer connection housekeeping did not refresh the status bar or notify the user.

## Impact

- Resolve rejected valid message IDs.
- A discovered peer could have become an unintended default send target.
- A restored session released ownership and did not start its watcher.
- E2e harness reported false timeouts.
- Users could see stale peer status after a remote connection.

No evidence of message-body injection, duplicate ownership, data loss, or unauthorized primary promotion after fixes.

## Detection

Detection sequence:

1. Independent ADR review identified the handshake target issue.
2. `bi-boss` performed real send/read/reply/resolve testing.
3. Peer reported resolve failure with a valid message ID.
4. User restarted a new session with a partial mailbox and reported migration failure.
5. User observed stale status after connecting a new peer.

## Root causes

### Contract assumption

Tests modeled a simplified read object. They did not fixture the exact live `amq read --json` shape.

### Restore precondition gap

Attach explicitly initialized mailboxes. Restore assumed prior initialization and went directly into migration.

### UX side-effect omission

Housekeeping messages were intentionally filtered from agent turns, but no separate UI notification/status refresh was implemented.

### Harness fragility

The e2e wait helper relied on terminal line counts and literal output. Tmux scrollback and terminal control sequences invalidated those assumptions.

## Corrective actions

| Action | Commit | Evidence |
|---|---|---|
| Normalize read header identity | `43b7444` | mailbox regression fixture |
| Block implicit handshake primary | `9f14e93` | peer trust regression |
| Refresh status on peer connection | `f65b804` | UI source regression |
| Repair mailbox before restored migration | `ad37c6b` | restore preflight regression |
| Harden tmux e2e matching | `26ae469` | cross-CWD/real-Pi flow |
| Add durable bug-fix log | current | `docs/bug-fix-log.md` |

## Validation after remediation

- 132/132 automated tests pass.
- TypeScript clean.
- Real peer send/read/reply/resolve passed.
- One complete real peer tic-tac-toe conversation completed and resolved.
- Clean mailbox/state reset verified.

## What went well

- Shared state released ownership safely on failed startup.
- Real peer testing exposed contract and UX gaps quickly.
- Fixes remained small and localized.
- Existing lifecycle invariants prevented duplicate injectors.

## What failed

- Fixture fidelity was insufficient for the CLI read contract.
- Restore path lacked mailbox preflight.
- Static extension tests did not exercise live Pi restart behavior.
- Status UI was not treated as part of connection semantics.

## Prevention policy

Every future defect must add:

1. a reproducible report;
2. a bug-log entry;
3. a regression test reproducing the failure;
4. a fix commit referencing the test;
5. validation evidence;
6. a postmortem when discovered by dogfood or user report.

ADR-0003 owns the longer-term hardening work: deterministic provider-independent validation, startup reconciliation, lifecycle invariants, and operational diagnostics.

## Follow-up: graceful disconnect visibility

A user review identified that graceful peer shutdown released local ownership but did not notify the remote peer. The roster therefore stayed visually connected.

Resolution: add `detached` housekeeping notices on owner detach/session shutdown, classify them as housekeeping, mark the peer offline, refresh the status bar, and show a non-turn warning notification. Primary/trust promotion remains unchanged. Abrupt process kill still requires presence reconciliation and is explicitly tracked as follow-up risk.
