Repository navigation
Description
Summary
Gateway reply-queue state is not flushed on restart. Queued outbound Matrix replies targeting a specific room persist across a gateway process restart and drain to their destination after the gateway comes back up — even when the originating session was isolated and completed long before the restart.
Version
2026.4.25 — reproduced on two separate Mac mini fleet agents (Charlie and Johnny), both running LaunchAgent-managed gateways.
Observed behavior
2026-06-08, ~07:00–07:56 CDT
Charlie (Mac mini, LaunchAgent):
07:00:02— Morning Briefing cron session starts (sessionf8986989, targeting Glenn's DM room)07:14:46— long-running session warning, age=131s07:15:06—UND_ERR_SOCKETfetch failure mid-model-call (Anthropic provider)07:16— gateway self-restarts (process exits and launchd relaunches)07:34:01— liveness warning: active + queued sessions both keyed to@johnnyDM room (wrong room — Charlie's session was targeting Glenn's DM)07:34:47–07:34:58—ReplyRunAlreadyActiveErrorloop; queued reply drains into Johnny's DM with Charlie's Morning Briefing tool narration as payload (memory searches, Linear issue lookups, CFO briefing reasoning)
Johnny (Mac mini, LaunchAgent):
- Same symptom independently: post-restart boot session narration (
⏰ Cron,🧩 Linear Get Issue,📊 Session Status,🛠️ exec,📖 Read,📝 Edit) leaked into a different agent's DM room through multiple restart cycles between 07:40–07:55 CDT. - Second restart (
launchctl kickstart) at 07:56 CDT finally stabilized after the queued boot session drained.
Key diagnostic finding
After both restarts, sessions.json showed 0 pending sessions. The reply-queue state is stored separately from the sessions index — meaning the standard sessions-store check does not reveal pending outbound message queue entries. The reply queue appears to persist in a separate store that survives process restart.
Why sessionTarget: isolated does NOT mitigate this
All fleet cron jobs use sessionTarget: isolated. Both affected cron sessions were isolated. The reply-queue corruption still occurred because isolated governs per-run context (not outbound message queue state). These are orthogonal.
Impact / severity
- Any agent can have outbound messages queued to a wrong room after a network error or restart
- Content leaking can include tool narration, reasoning, memory search results, Linear data — any assistant output from the corrupted session
- In this incident: CFO briefing context (sensitive business reasoning) delivered to a peer agent's DM
- Blast radius scales with session content: a session with GWS auth, customer PII, or credentials could produce a serious information exposure
Proposed fixes (for upstream evaluation)
- Flush pending outbound queue on gateway startup — discard any queued replies that predate the current boot. Safest default; may lose legitimate in-flight replies during brief restarts, but correct behavior.
- Per-room session lock — enforce that a queued reply can only drain if the room key matches the currently active session key.
sessionScope: per-roompartially addresses this at config level but should be enforced at the transport layer. - TTL on queued replies — expire queued replies after N minutes (e.g., 5 min). Replies surviving a restart are almost certainly stale.
Current workaround
sessionScope: per-room on the matrix channel config prevents wrong-room drain even if the queue survives restart (config-level mitigation, not a transport-layer fix).
Steps to reproduce
- Run a cron/isolated session on an agent with Matrix configured
- Mid-session, trigger a network error (
UND_ERR_SOCKETor similar) that causes the gateway to self-restart - After gateway restart, observe
sessions.jsonshows 0 pending sessions - Wait: queued reply from the pre-restart session drains to its (potentially wrong) destination room
- Check logs:
ReplyRunAlreadyActiveErrorloop confirms the stale reply is retrying
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
clawsweeper commentedon Jun 9, 2026
Thanks for the context here. I did a careful shell check against current
main, and this is already implemented.Current main fixes the reported wrong-room replay path: the merged cron resolver now refuses keyless implicit delivery inherited from the shared agent-main bucket before send/enqueue, and issue-specific tests cover the refusal plus dispatch cleanup. The fix is on main only; the latest listed releases were published before the fix commit.
I found the merged PR that appears to have closed this: #91685: fix(cron): refuse keyless implicit isolated cron delivery inherited from shared agent-main bucket.
So I’m closing this as already implemented rather than keeping a duplicate issue open.
Review details
Best possible solution:
Keep the current-main resolver refusal for ambiguous keyless cron delivery and track any broader queue TTL, boot-generation, or transport room-gate design only through separate evidence-backed follow-ups.
Do we have a high-confidence way to reproduce the issue?
Yes from source and tests for the historical path: a keyless implicit cron could inherit the shared main bucket target, and the generic recovery path replays queued targets verbatim. Current main no longer reproduces that path because the resolver now returns ok:false before delivery can enqueue.
Is this the best way to solve the issue?
Yes. The merged fix is the narrow owner-boundary solution for the observed root cause because the shared resolver refuses the ambiguous target once, and dispatch, failure notification, and preview all consume the existing ok:false contract.
Security review:
Security review cleared: The security-sensitive wrong-room disclosure path reported here is addressed on current main by refusing ambiguous keyless cron delivery before send/enqueue.
AGENTS.md: found and applied where relevant.
What I checked:
src/cron/isolated-agent/delivery-target.ts:303, 0a3e0d081dc4)src/cron/isolated-agent/delivery-dispatch.ts:1220, 0a3e0d081dc4)src/cron/isolated-agent/delivery-target.issue-91613.test.ts:208, 0a3e0d081dc4)src/cron/isolated-agent/run.issue-91613-preflight.test.ts:24, 0a3e0d081dc4)Likely related people:
src/cron/isolated-agent/delivery-target.ts,src/cron/isolated-agent/delivery-dispatch.ts,src/cron/isolated-agent/run.ts)src/cron/isolated-agent/delivery-target.ts,src/infra/outbound/delivery-queue-recovery.ts)src/cron/isolated-agent/delivery-target.ts,src/cron/isolated-agent/delivery-dispatch.ts,src/cron/isolated-agent/run.ts)src/infra/outbound/delivery-queue-recovery.ts)Codex review notes: model internal, reasoning high; reviewed against 0a3e0d081dc4; fix evidence: merged PR #91685, commit d4833e27c775, main fix timestamp 2026-06-19T10:05:07Z.