Repository navigation
fix(threads): tag local and linked bots with @ - #2515
Conversation
…age a tagged bot An agent thread's @ list now offers the owner's bots: this computer's and those its other computers share with it, each saying its computer and whether it is offline. A pick leaves the bot's chip and sends the standard tag [@name](mousse://bot/<id>) with the id that names the bot on the thread's computer. A tag alone sends nothing. In the turn a person's message with the tag opens, the thread's agent may message that bot with thread_send to bot:<id>. A bot on this computer gets it through the same way in as message_parent (tagged framing, same replay key and flood guard). A bot of another computer gets it as bots.threadMessage.send there, through that computer's bot access and the bot's Devices, held to this computer's limit; refusals are typed. No other bot, no tag from an earlier turn, and no tag in a message an agent, bot or schedule wrote.
…mputer gets the message there
… turn, and a tag Markdown shows as text grants nothing A turn a person on another computer sent names that computer in its run's own log (run.sent_from, from the authenticated routed send, never the thread's metadata). A tagged bot on the thread's computer is reached only as that computer may: its bot level and the bot's Devices, checked before anything is kept, with bots_off_there or bot_not_shared, and the turn is held to its limit. A bot of a third computer gets the writers in from, and that computer checks each through the same gate and holds the turn to the narrower limit; the bot's own computer still checks the thread's computer as before. A remote device's turn whose run names no computer, or whose log can't be read, sends nothing. Tags are read with remark-parse, as the chat draws the message: a tag in inline, fenced or indented code, an escaped one or one in HTML is text and grants nothing.
…uter's block holds, and side chats and remote transcripts tag bots - A send from another computer records run.sent_from in the transaction that admits its run, from the direct send and a queued item's run alike; the note written after admission adds no second row. - A bot's computer checks a computer a thread message names in from as a bot turn held to it is checked (not blocked there, still on the account, its bot level and the bot's Devices), so a blocked or departed computer is refused as not shared. Calls of the calling computer are gated as before. - A side chat's composer offers the owner's bots with @, by the ids that name them on the side chat's computer. - Read from another computer, a transcript's bot tags that name no computer are qualified with the thread's computer, as its thread links are; tags that name a computer and other bot links stay as written.
…d on the run it keeps before the edit is saved A queued message keeps the run it was queued with when another computer edits it. That computer is now written to the run's log (run.sent_from) inside the queue lock, before the edit is saved, so no drain can start the turn without it. When it can't be written the edit is refused and the message stays as it was. A run that already names that computer gets no second row.
There was a problem hiding this comment.
Walkthrough
The @ picker in threads and side chats now lists this computer's bots and the bots linked computers share, with each tag holding the exact (node-qualified when needed) bot id. A thread's agent can thread_send to bot:<id> only for a bot the person tagged in the message that opened the current turn. Local bots go through BotEngine.threadMessage (tagged), and bots on other computers through the new bots.threadMessage.send routed method. The run's run.sent_from log now records which computer wrote a turn, at admission and on a queued edit, so each writing computer's bot access is checked on the receiving side and the turn is held to the narrowest limit.
Summary by MoussePRBot
- New Features
@in agent threads / side chats offers local and linked-computer bots (with computer name and offline state).thread_sendtobot:<id>for a bot the person tagged in the turn's opening message, locally or on another computer.- New remote method
bots.threadMessage.sendwith param validation,fromnarrowing, and replay byclientRequestId.
- Bug Fixes
- Bot tags in text routed from another computer are qualified with the writer's node, so they open the right bot.
- Security
run.sent_fromwritten in the run-creating transaction and required on remote queued edits; tagged sends refuse when the writer can't be determined.
- Refactors
botTurnLimitextracted fromBridgeProfileServiceand shared with the remote bot methods.
Changes
| Cohort / File(s) | Summary |
|---|---|
src/mms/run/mcp/appTools/taggedBots.ts |
New: Markdown-aware botTagsIn, ownerTaggedBots (person-started turn only), taggedBotPlace. |
src/mms/run/mcp/appTools/thread.ts, index.ts, addressedCall.ts, host.ts |
sendTaggedBot handler, turnWriters, elsewhereRefusal; own address resolution includes tagged bots; host gains selfNode / runSentFrom. |
src/mms/bots/activation/BotEngine.ts, seams.ts |
threadMessage takes tagged / device / from; taggedFromDevice; threadMessageElsewhere. |
src/mms/bridge/remote/RemoteBots.ts, botReach.ts, BridgeProfileService.ts, MmsProfileServices.ts |
bots.threadMessage.send validation + handler; botTurnLimit; deviceLevel host hook. |
src/mms/bridge/routed/otherComputersBots.ts, protocol/otherComputersBotsPort.ts |
threadMessage port method, refusal mapping per method, agent_hops_exceeded. |
src/mms/bots/chat/BotChatService.ts, shared/bots/personal/jobs.ts, methodTable.ts |
threadMessageAccept; tagged notice wording. |
src/mms/orchestrator/OrchestratorService.ts, src/mms/run/RunEngine.ts |
run.sent_from at admission / queue drain / queued edit; runSentFromNodes. |
src/shared/bridge/routedIds.ts |
qualifyBotTags on incoming owner text. |
src/renderer/** |
Picker gets threadTaggableBots; composer / side chat / orchestrator chat wiring. |
docs/**, tests/** |
Docs for the new reach; new threadSendTaggedBot / threadBotMentions tests and extensions. |
Estimated code review effort
🎯 4 (Complex) | ⏱️ ~50 minutes
Actionable comments posted: 2
🧹 Nitpick comments (3)
src/mms/run/mcp/appTools/thread.ts:1342
sendTaggedBot is only reached from the thread_send handler behind args.bot !== undefined && !ctx.turn.bot, so this ctx.turn.bot guard can't fire. It's fine to keep as defence in depth, but a comment saying so would stop someone from "fixing" the handler condition on the strength of it.
src/mms/bots/activation/BotEngine.ts:10803
taggedFromDevice returns device!, which is undefined for an empty nodes. The only caller guards input.from?.length, but making the return type BotOwnerTurn | undefined (or throwing on empty input) would let the type system carry that guarantee.
src/mms/run/mcp/appTools/index.ts:148
botsFor('own') now runs taggedBotsOf (a remark parse of the turn's opening message) on every address resolution for a thread's agent. botTagsIn bails early when there is no mousse://bot/, so the cost only shows up on tagged turns. If addressed calls get frequent there, a small per-run cache keyed by runId would remove the repeated parse.
Reviewed at d84e3f1 by MoussePRBot.
| case 'agent_hops_exceeded': | ||
| return refused('conflict', `This thread has sent ${bot.name} several messages since the person last wrote to it. Nothing was sent: put what is left in your final answer.`, { retry: 'never', data: { ...data, conflict: code } }) | ||
| default: | ||
| return refused('uncertain', `${bot.name}'s computer did not confirm the message. It may have arrived: don't send it again; tell the person.`, { data: { ...data, reason: 'not_delivered' } }) |
There was a problem hiding this comment.
A definite refusal from the bot's computer is reported to the agent as "may have arrived".
refusalOf (otherComputersBots.ts) returns not_delivered for two different outcomes: an unconfirmed send (outcome_uncertain / deadline_exceeded, or a non-RPC error) and a definite refusal from the other side ("… did not take your message (…)"). Both, plus the unused-here bot_message_loop, land in this default, which tells the agent "It may have arrived: don't send it again". For a definite refusal, the person then hears that the message might be there when it was rejected.
Consider giving the definite-refusal fallback in refusalOf its own code (e.g. refused) and handling it here with "did not take the message", or at least passing the refusal's reason through in data:
| return refused('uncertain', `${bot.name}'s computer did not confirm the message. It may have arrived: don't send it again; tell the person.`, { data: { ...data, reason: 'not_delivered' } }) | |
| return refused('uncertain', `${bot.name}'s computer did not confirm the message. It may have arrived: don't send it again; tell the person.`, { data: { ...data, reason: 'not_delivered', ...(error instanceof Error && error.message ? { detail: error.message } : {}) } }) |
| */ | ||
| function qualifyBotTags(content: string, writer: string): string { | ||
| if (!content.includes('mousse://bot/')) return content | ||
| return content.replace(BOT_TAG, (whole, _name: string, id: string) => { |
There was a problem hiding this comment.
qualifyBotTags rewrites tags inside code spans and fences, which botTagsIn treats as plain text.
botTagsIn (taggedBots.ts) deliberately ignores tags in inline code, fenced or indented code, and escaped brackets. This regex pass rewrites every [@Name](mousse://bot/<id>) in the routed text, including ones a person pasted inside backticks as an example. Their literal code arrives changed (mousse://bot/abc becomes mousse://bot/nod_…:abc) on the thread's computer.
It's low-impact, but it's an inconsistency between "what counts as a tag" on the two sides. Either skip code regions here, as mapThreadLinks may already do for thread links, or note that the rewrite is intentionally syntax-blind.
Problem
Typing
@in an agent thread showed file and folder suggestions. The shared picker only received a bot list from bot chats, so it had no bots to show in a thread.Change
The picker in threads and side chats now includes bots on this computer and bots shared by linked computers. Remote rows name their computer and show when it is offline. File and folder suggestions stay in the picker.
Picking a bot inserts its exact bot link, including the computer ID when needed. The link also opens the right bot when the thread is viewed from another computer. A tag identifies the bot without sending a message. If the person asks the agent to contact it,
thread_sendcan use that exact ID for the current turn. Messages appear in the bot's chat as coming from the agent thread. For turns written from another computer, the send checks that computer's bot access too. Sharing and offline refusals name what happened. Linked computers need this update to receive thread messages. Mousse Remote turns without a recorded sending computer cannot contact a tagged bot.How to review
Start with the composer and
taggedBots.ts. Then followthread_sendthrough the bot engine andbots.threadMessage.send. The send path relies on the current turn's owner-authored tag and the receiving computer's device and bot sharing checks.Verification
tests/run/threadSendTaggedBot.test.ts,tests/bots/botMessagesElsewhere.test.tsandtests/net/bridge/remote/botDeviceAccess.test.tscover those checks and a retried send. Device-limit and routed tests cover a turn whose sender must be recorded at admission, blocked devices, links in remote transcripts, and a queued edit whose sender could not be saved.node scripts/verify.mjs tests/run/threadSendTaggedBot.test.ts tests/renderer/threadBotMentions.test.ts tests/bots/botMessagesElsewhere.test.ts tests/bots/botJobs.test.ts tests/run/threadAddressing.test.ts tests/run/messageParent.test.ts tests/bots/botSendThread.test.ts tests/bots/botMethodTable.test.ts tests/net/bridge/remote/bots.test.ts tests/net/bridge/remote/botDeviceAccess.test.ts tests/renderer/composerBotChips.test.ts tests/renderer/botChatView.test.ts tests/run/toolAuthorityParity.test.ts tests/composerMentionList.test.ts tests/chatModes.test.ts tests/run/toolApiContract.test.ts tests/run/botThreadParity.test.ts tests/run/botThreadsDaemon.test.ts tests/run/deviceLimitDaemon.test.ts tests/net/bridge/routed/blockTurns.test.ts tests/net/bridge/routed/threadLinks.test.ts tests/renderer/sideChatsPanel.test.ts tests/renderer/botBrowserTabs.test.ts tests/renderer/threadLinks.test.ts tests/bots/botWorkQuestions.test.ts tests/bots/botWatchers.test.ts tests/turnEditSummary.test.ts tests/renderer/turnChangedFiles.test.ts tests/renderer/turnSummaryRecordedFiles.test.ts --typecheck allpassed 979 tests and both type checks.@, picked a shared bot and checked the exact tag sent. The same check on the base showed only files and folders. An isolated dev daemon accepted an explicit send from a tagged turn and refused sends from untagged turns. Cross-computer delivery was checked with two bot engines and the routed method in the test harness.Notes
Includes the picker behavior from #2512 and works with the side panels and bot chat sender labels from #2529 and #2531. Uses the remote bot feed from #2313. The chat offers in #2496 and #2497 keep their existing behavior.
Fixed two lint errors from #2529 so Static checks can pass. The Windows watcher suite passed locally after the hosted cleanup failure.
Independent review found four issues. All four are fixed, with a regression test for each.
No issue