Skip to content

fix(bot-mode): DMs to a Desktop-owned Bot Chat land in the live session instead of being dropped (#100523) - #101293

Merged
teknium1 merged 2 commits into
mainfrom
fix/bot-dm-delivers-into-live-bot-chat
Sep 2, 2026
Merged

teknium1 merged 2 commits into
mainfrom
fix/bot-dm-delivers-into-live-bot-chat

Conversation

@teknium1

@teknium1 teknium1 commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes #100523: a Bot Mode DM sent to a teammate whose canonical "Bot Chat" is open on the Desktop was silently dropped. The Desktop-hosted session holds the single-owner lease, so the one-turn hermes -p <bot> chat -c "Bot Chat" subprocess that bot_relay.deliver spawns refused with already has a live owner, exited 1, and the payload was gone — while the sender had already been acked "sent".

Reworks #100544 (@fangliquanflq — routing-into-the-live-session insight) and #100542 (@686f6c61 — first claimant) down to the minimal in-process fix. Both authors carry Co-authored-by: trailers on the commit.

Changes

  • tui_gateway/methods_bot_relay.py — bot_relay.deliver: before spawning the subprocess, look up a live in-process session for the target profile whose title resolves to Bot Chat (same profile_home string compare as session.resume's _find_live_unpersisted; pending_title for lazy sessions, db title otherwise via _session_live_title). If found, submit the message through the existing prompt.submit handler — the composer's choke point — so it lands as a normal user turn (role alternation preserved, no synthetic injection, streams to the open window) and return ok. No live owner → the subprocess path runs exactly as before. Helper is nested in the handler per the method_ctx rebinding rule. (+32)
  • tools/bot_mode_dm.py — local message_agent subprocess path: when the CLI's stderr carries the lease refusal, emit a structured {"error": "... NOT delivered ...", "reason": "target_busy"} payload so the sender learns the message did not land, instead of a raw exit-1 with the text buried in stderr. (+11)
  • 2 tests (+61): test_deliver_lands_in_live_bot_chat_instead_of_subprocess (live Bot Chat → prompt.submit used, subprocess never spawned; a live session with another title → subprocess as before) and test_delivery_runner_surfaces_live_owner_refusal.

Validation

  • pytest tests/tui_gateway/test_bot_relay_methods.py tests/tools/test_bot_mode_dm.py → 49 passed, 1 skipped. Sabotage run (fix stashed, tests kept): exactly the two new tests fail.
  • ruff check clean on all four files.
  • Live repro: real dashboard WebSocket harness (uvicorn + /api/ws, isolated HERMES_HOME, real provider creds, profile beta). A WS client did session.create {profile: beta, title: "Bot Chat"} + one real turn (holding the session live), then bot_relay.deliver {profile: beta, message: "[relay from @alpha] ping-100523: reply with the word PONG only."} was called over the same socket. — before (origin/main): {"code": 5092, "message": "delivery turn failed: Session 20260902_051449_f1607d already has a live owner (tui, pid 3424374, running 2m)..."} and beta's transcript stayed at user: Reply with exactly the word OK / assistant: OK — payload dropped; after (this branch): {"reply": "Delivered into @beta's open Bot Chat; the reply will appear there."} and beta's state.db transcript gained user: [relay from @alpha] ping-100523 ... / assistant: PONG — the DM landed as a normal user turn and the agent answered in the live session.

Closes #100523
Supersedes #100544, #100542

Infographic

Bot Chat DMs land in the live session

@alt-glitch alt-glitch added type/bug Something isn't working comp/tools Tool registry, model_tools, toolsets comp/tui Terminal UI (ui-tui/ + tui_gateway/) P2 Medium — degraded but workaround exists area/sessions Session lifecycle, resume, persistence, history area/profiles Multi-profile isolation, HERMES_HOME scoping sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state labels Sep 2, 2026
teknium1 and others added 2 commits September 2, 2026 06:06
…on instead of being dropped (#100523)

When the Desktop has a bot's "Bot Chat" open, that session holds the
single-owner lease, so the `hermes -p <bot> chat -c "Bot Chat"` subprocess
`bot_relay.deliver` spawns refuses with "already has a live owner" and the
DM payload is dropped — the sender was already acked.

bot_relay.deliver now looks up a live in-process session for the target
profile whose title resolves to "Bot Chat" (same profile_home match as
session.resume's _find_live_unpersisted, pending_title for lazy sessions,
otherwise the db title) and, when found, submits the message through the
existing prompt.submit handler — the composer's choke point — so it lands
as a normal user turn (role alternation preserved, streams to the open
window). No live owner → the subprocess path runs exactly as before.

On the local message_agent subprocess path, the lease refusal is surfaced
as a structured `target_busy` delivery failure telling the sender the
message was NOT delivered, instead of a raw exit-1 with the text buried
in stderr.

Closes #100523
Supersedes #100544, #100542

Co-authored-by: fangliquanflq <fangliquan@qq.com>
Co-authored-by: 686f6c61 <github@00b.tech>
@teknium1
teknium1 force-pushed the fix/bot-dm-delivers-into-live-bot-chat branch from 33eb5a1 to 5575ee2 Compare September 2, 2026 13:06
@github-actions

github-actions Bot commented Sep 2, 2026 •

Copy link
Copy Markdown

૮ >ﻌ< ა ci review

ran on 5575ee2 — fix(bot-relay): a DM into a live Bot Chat queues as the next

⚠️ Warnings

OSV vulnerability scan · View job

13 known vulnerabilities found in pinned dependencies.

How to fix:

Review the findings in the Security tab. Update the affected dependencies if a patched version is available.


debug info

CI timings

CI timings · View report · View job

Wall time 5m30s vs 4m34s (+20.4%). 9 job(s) slower, 4 faster, 1 unchanged.

  • OSV scan / Scan lockfiles / osv-scan: +17.0s
  • OS-specific tests / Windows-only tests: +15.0s
  • Python tests / Run tests: -11.0s
  • OSV scan / Emit review status: +10.0s
  • Profile artifact check / Reject profile archives: -8.0s

@teknium1
teknium1 merged commit 0058bde into main Sep 2, 2026
37 checks passed
@teknium1
teknium1 deleted the fix/bot-dm-delivers-into-live-bot-chat branch September 2, 2026 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/profiles Multi-profile isolation, HERMES_HOME scoping area/sessions Session lifecycle, resume, persistence, history comp/tools Tool registry, model_tools, toolsets comp/tui Terminal UI (ui-tui/ + tui_gateway/) P2 Medium — degraded but workaround exists sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Bot Mode DM delivery fails instead of queueing when recipient session has a live desktop owner

2 participants