Repository navigation
fix(cron): use non-blocking delivery for bot-chat to avoid session lock conflicts - #102659
itsflownium wants to merge 1 commit into
Conversation
a576fff to
04c07f7
Compare
Related: competing fixes for #99956 — #100319 (durable delivery queue drained once the live owner releases) and #70406 (exact-session inject). Note the diff here is a bounded blocking retry (5 attempts, 2s→16s backoff) rather than a non-blocking path, so it only clears transient contention; a Bot Chat held open indefinitely on another surface still fails after the retries. Maintainer should pick one mechanism. |
crazyief
left a comment
There was a problem hiding this comment.
Lab: tests/cron/test_cron_bot_chat_delivery.py → 26 passed. Bounded retry on session-lock refusal plus per-profile turn lock is the right bot-chat delivery fix. Not an approval.
|
Thanks @itsflownium for separating lease/cap contention from other delivery failures and coordinating cron with relay turns. #105442 is merged at Leaving this PR open because its legacy-lane turn-lock coordination and bounded recovery from machine active-session-cap or unsupported-owner refusals are not covered by that change. Main still makes a single subprocess attempt in the unowned/unsupported-consumer fallback. The remaining scope is contention handling on that fallback, not non-blocking delivery to a permanently open Desktop chat. |
|
Thanks @itsflownium — the session-lock conflict this PR worked around is resolved on main by a different mechanism: 5280fe9 routes a cron bot-chat delivery into a Desktop/TUI-held Bot Chat through the durable live-owner ingress, and 5d8390d defers the payload for a CLI-only owner instead of racing the lease ( |
Fixes #99956
Problem
When a scheduled cron job uses
deliver: bot-chat(orbot-chat:<profile>),_deliver_to_bot_chatincron/scheduler.pyspawnshermes chat --in ~ -c "Bot Chat" ...as a synchronous subprocess. Hermes enforces a single-owner session lease — only one surface (CLI/TUI/Desktop) may run a session at a time. If the target profile already has an active interactive session, the subprocess exits with code 1 and the delivery is permanently dropped:Root Cause
_deliver_to_bot_chatfired thehermes chatsubprocess with no fallback. Unliketools/bot_mode_dm.py(which coordinates delivery through per-profile turn locks), the cron path had no lock coordination and no retry — a transient in-flight turn or a concurrently open surface caused a hard drop.Fix
In
cron/scheduler.py:_bot_chat_delivery_lock, mirroringtools.bot_mode_dm._delivery_lock), so the scheduled subprocess is not an uncoordinated writer. Degrades to a no-op if the relay lock machinery is unavailable._is_session_lock_refusal:"already has a live owner"/"active session limit") and retry them with exponential backoff — delays double 2s → 4s → 8s → 16s, ~30s total — before giving up.Verification
tests/cron/test_cron_bot_chat_delivery.pycovers token parsing, target resolution, the delivery lane, and the fix(cron): bot-chat delivery fails when target profile has active session lock #99956 paths: retry-then-succeed, give-up-after-retries, active-session-limit message, non-lock failures not retried, exponential backoff within 30s, and turn-lock key resolution.uv run pytest tests/cron/test_cron_bot_chat_delivery.py→ 26 passed.