# Queue Completion Postmortem

## Summary

AMQ Bridge could reactivate completed answer messages during queue advancement and receive planning.

## Detection

Live peer dogfood: after resolving a request, `Next active` pointed at an old answer. Repeated peer turns followed.

## Root cause

`processedIds` represented injection dedupe, not completion. Messages retained in `inbox/new` remained actionable to both `dequeueNext()` and `planBatch()`. No state distinguished processed from completed.

## Fix

Add bounded `completedIds` to shared state. Reply and resolve lifecycles mark completion only after successful read. Queue advancement excludes completed IDs, and receive planning merges completed IDs with processed IDs. Existing stale active IDs are cleared when completed.

## Evidence

- `tests/queue-lifecycle.test.mjs`: completed old answer skipped.
- `tests/receive-loop.test.mjs`: completed answer not re-injected and next question activates.
- `npm test`: 140/140 passing.
- Lifecycle E2E: attach, blocked detach, reattach, and quit cleanup pass.

## Residual risk

Completion history is bounded to 500 IDs. Retained messages older than that may re-enter and need explicit history/retention cleanup.
