Context
Issue #263 established the required ownership boundary for Codex Desktop delivery: a collector should only detect unread mail, wake the intended visible Codex thread, and let that thread read the official inbox.
The current visible-turn fallback is not proactive. When no app-server bridge is attached, it records waiting_for_chat_turn and waits for the operator to speak. In daily use, messages can remain unread even though monitor mode appears armed. A heartbeat-only pseudo-monitor also lacks a reliable receiver lifecycle and can silently stop checking.
Goal
Provide a near-real-time Codex Desktop receiver only for sessions that explicitly enable agmsg monitoring. The operator should not need to send another message before the target thread notices inbound mail.
Proposed design
- Bind a monitor lease to
(project, team, role, Codex thread id) when actas or mode monitor is explicitly used.
- Use unread-only detection (
inbox-peek.sh / watch-once.sh) and never consume message bodies in the collector.
- Wake the selected visible Codex thread through the app-internal
send_message_to_thread capability.
- Keep the app-server bridge as the low-latency path when available.
- Add a thread-attached heartbeat or scheduled watchdog that verifies receiver liveness, rebinds after restart, and wakes the target thread for missed unread messages.
- Tear down the lease, bridge, watchdog, and role metadata on
mode off, drop, SessionEnd, thread loss, or lease expiry.
- Prevent duplicate monitors and duplicate wakes with a stable monitor identity, a single-owner lock, and the unread high-water mark.
- Do not start hidden
codex exec resume workers by default.
- Do not poll Codex sessions that never opted into agmsg monitoring.
Acceptance criteria
- A message sent to an explicitly monitored Codex Desktop role starts a visible turn without additional operator input.
- The target thread reads and handles the official inbox; the collector does not mark messages read.
- Multiple Codex threads cannot claim the same role concurrently.
- Repeated watchdog runs do not create duplicate turns for the same unread high-water mark.
mode off, drop, and SessionEnd stop further wakes and remove receiver artifacts.
- A stopped or stale low-latency receiver is detected and recovered by the watchdog.
- Existing
turn and off modes remain unchanged.
- Tests cover opt-in scope, target selection, duplicate suppression, restart recovery, teardown, and unread ownership.
Relationship to existing work
This is a focused lifecycle and reliability follow-up to #263. Existing branch work under fix/263-codex-visible-monitor can be reused only after these acceptance criteria are independently verified.
Context
Issue #263 established the required ownership boundary for Codex Desktop delivery: a collector should only detect unread mail, wake the intended visible Codex thread, and let that thread read the official inbox.
The current visible-turn fallback is not proactive. When no app-server bridge is attached, it records
waiting_for_chat_turnand waits for the operator to speak. In daily use, messages can remain unread even though monitor mode appears armed. A heartbeat-only pseudo-monitor also lacks a reliable receiver lifecycle and can silently stop checking.Goal
Provide a near-real-time Codex Desktop receiver only for sessions that explicitly enable agmsg monitoring. The operator should not need to send another message before the target thread notices inbound mail.
Proposed design
(project, team, role, Codex thread id)whenactasormode monitoris explicitly used.inbox-peek.sh/watch-once.sh) and never consume message bodies in the collector.send_message_to_threadcapability.mode off,drop, SessionEnd, thread loss, or lease expiry.codex exec resumeworkers by default.Acceptance criteria
mode off,drop, and SessionEnd stop further wakes and remove receiver artifacts.turnandoffmodes remain unchanged.Relationship to existing work
This is a focused lifecycle and reliability follow-up to #263. Existing branch work under
fix/263-codex-visible-monitorcan be reused only after these acceptance criteria are independently verified.