From 34e02b5186d0c4051759974c3a76a50322869741 Mon Sep 17 00:00:00 2001 From: Danyang Chen Date: Thu, 19 Nov 2026 06:31:53 +0800 Subject: [PATCH] Give a frozen Bot one human line on share, join and invite (#3114) Written-by: Dev An emergency-stopped Bot answered with the server's own sentence on all three doors. The FRIENDLY table now carries `bot_frozen`, and the share and join-invite mappers hand that code to `mapFaceError`, so sharing, a face-to-face join or invite preview, and accepting an invite say one sentence and keep the `bot_frozen` code. A stop is a state the owner can end, so the room is not treated as ended. Fixes #3188 Part of #3114 --- changelog.d/3114-frozen-bot-one-line.fixed.md | 1 + docs/subsystems/social.md | 2 ++ plugins/social/src/face-rooms.js | 3 ++ plugins/social/src/social.js | 6 ++++ plugins/social/test/face-rooms.test.js | 12 ++++++++ plugins/social/test/social.test.js | 29 +++++++++++++++++++ 6 files changed, 53 insertions(+) create mode 100644 changelog.d/3114-frozen-bot-one-line.fixed.md diff --git a/changelog.d/3114-frozen-bot-one-line.fixed.md b/changelog.d/3114-frozen-bot-one-line.fixed.md new file mode 100644 index 000000000..93628af3a --- /dev/null +++ b/changelog.d/3114-frozen-bot-one-line.fixed.md @@ -0,0 +1 @@ +A Bot its owner has emergency-stopped on Bot Social now reads as one sentence on **Share with a friend**, a face-to-face join or invite preview, and **Add friend** — *One of these Bots is emergency-stopped on Bot Social. Its owner can resume it in My Bots on that server, then try again.* — instead of the server's own `bot is frozen (emergency stop)`, the bare `bot_frozen` code, or the MCP tool name on the invite path; the refusal keeps its code and its room, because a stop is a state the owner can end ([#3114](https://github.com/ThinkFlowLab/FlyBot/issues/3114)). diff --git a/docs/subsystems/social.md b/docs/subsystems/social.md index 9f5a8b69c..30ac01eb5 100644 --- a/docs/subsystems/social.md +++ b/docs/subsystems/social.md @@ -20,6 +20,8 @@ A second, read-only window starts the social layer from the credentials file the Face-to-face rooms (#83, #92) also live here: the primary entry is the sidebar **+** menu (slot `flybot.new-chat.action` on the core new-chat picker, after New group chat; `label` / `hint` use the same `t()` map). **Join by number or link** (zh 用号码或链接加入) and **Start a face-to-face room** (zh 面对面建群, #1021) are two rows, because one label naming a create path and a join path at once read as neither (#892 had one); **Add friend** is the third (copying an invite and your own handle live inside Add friend); the social strip has no **+ Add** button. Both face rows open the same screen with the same handlers, titled after the row that was tapped; the start path keeps the six-digit number (a room is built by typing one together) and drops the link and scan fields, which are ways into a group that already exists. The join path's copy names both ways in and its link field reads *Or paste a group invite link* (pick one or more local Bots, six-digit number, live waiting room that shows the code, **Enter chat**). The pick list and waiting roster draw each Bot with the host `BotAvatar` (team roster look for yours; a friend's Bot uses its published look or a handle-seeded look, plus any avatar face-room `members[]` carries). Waiting-room and picker Bots are a wrapping tile grid (avatar on top, name centered below; yours a tiny accent dot; waiting tiles use the server owner label, e.g. `Chief · BoxB`); **Leave** and **Enter chat** share a fixed footer while a long grid scrolls under the countdown. The plugin calls Bot Social REST (`POST /v1/face-rooms/join`, poll `GET /v1/face-rooms/{id}?after=`, start/leave/messages) with the stored connector token and hosts the result as a native room through `flybot.rooms` (`origin: 'face-to-face'`). Those face-room routes accept a connector token; owner settings do not (`GET`/`PATCH /v1/me` returns 403 `connector_token_rest_forbidden`). Peer text is fenced; `pending_approval` drafts of kind `face_room_message` use the in-chat Approve / Reject path. **Auto-send** for face rooms is one compact checkbox (tooltip) on the open room's overview, via MCP `whoami` (read) and `set_auto_approve { auto_approve_face_rooms }` (write; the owner's click requests and uses `confirm_code` in the same step); default off. A friend's Bot in the room card, waiting grid, **main sidebar row**, and core group overview uses the host `BotAvatar` (published look, optional member `avatar`, else a handle-seeded look). **Sharing → Copy invite link** creates a per-Bot grant when the friend accepts; **Share with a friend** (#500) lists current friends who do not have this Bot yet and grants it in one click (Bot Social `grant_bot_to_friend`, companion Birfy/bot-social#34) without an invite link — one row per **Bot**, not per person, labelled `Bot (Owner)` and carrying that Bot's handle and `peer_bot_id`, so a friend who runs several Bots gets a row each and the click grants to the row's own Bot while the receipt names it (#973) — from the row label the click carries, not from the home key, so a server answer without names never prints `selftestb2` (#994), and a caller that sends no label gets `with your friend` instead; the filter asks per **Bot** too, so a friend whose Bot already has it still gets a row for the others and only a grant that names no Bot falls back to hiding that whole friend (#981); the friend is named by `friend_bot_id`, the peer id `list_friends` returns — the platform never lists a friend's owner id — and `friend_owner_id` still works for a server that only knows it (#592); a server without that tool tries the REST route `POST /v1/bots/:id/grants` and, when it 404s too, says *Bot Social needs an update to share with a friend. Invite links still work.* instead of the raw MCP error (the production `MCP error -32602: Tool … not found` wording counts as an unknown tool, #563); a server that has the tool but refuses the arguments says *Bot Social did not accept that share request. Its server may need an update; invite links still work.*, never the raw `-32602` text (#592); A failed **Share** and a failed friend-list read keep separate notes (#987) — two slots, not one (#992): the share outcome (`share-note`) and the list error (`share-list-error`) are drawn side by side, so a share click cannot erase the list error and its **Try again**, and the 5 s poll cannot erase the share's message; a successful read settles the list error only, a successful share settles the share line only, and "No friends left to share with" is suppressed by a list error only — a share error never speaks for the list. **People with access** lists one row per **Bot** that has this Bot — named `Bot (Owner)` like the share list, carrying that Bot's handle, the groups it is used in, and its own **Revoke** (#995). **Revoke** asks once before it runs (#1073): the button opens `Revoke ? They lose this Bot.` (and `in N rooms` when that row already names rooms) with **Revoke** and **Keep**, and never the browser confirm box. The handle, or the home when the row names no Bot, and the usage hint share one line with a middle dot between them (`@handle · In use in N rooms`), so the two never run together (#1073). One **Auto-send** switch per person. The hint stays one readable row however long the share lives (#955): it names at most three rooms and then `+N more`, keeps every room one per line in its tooltip, and a room a grant row already named is not printed again under **This room only**. There is no published toggle. A line that Bot sends 1:1 to a seat in that room is judged under the room (#948): the plugin resolves it before the member check (`roomFor` → `roomContextFor`), the seat itself is the target when the roster does not list it (`pairFor`), and the send names that room (`room_id`) so Bot Social checks the same consent the host already did; the `roomOnly` identity is neither dropped nor widened — with no such room the refusal is the same sentence as before, and `send_as_member` is never reached. Bringing my own Bot by number is an implicit room-scoped grant: if it has no identity yet, join registers it room-only (`add_home_member`) and revokes that identity (`remove_home_member`) when it leaves its last face room. Friends' Bots lists only Bots granted to me. Held replies show in the chat (owner Approve / Reject). **Remove this Bot** declines that grant on Bot Social (`decline_bot_grant`) so it leaves the owner's Manage access; an older server falls back to a local hide. The row drops immediately; room leave and a roster refresh continue in the background. A local hide is forgotten only after two consecutive successful `list_remote_bots` results without that handle, or an explicit re-share / `regranted` join. Hidden, gone, and home-level remotes stay out of `flybot.remote.publish` and the new-chat picker. Friends' Bots paints a cached roster immediately and refreshes in the background (keep-alive HTTP, parallel mount calls). +A Bot its owner has emergency-stopped on Bot Social reads as one sentence on all three doors — **Share with a friend**, a face-to-face join or invite preview, and **Add friend** (accepting an invite): *One of these Bots is emergency-stopped on Bot Social. Its owner can resume it in My Bots on that server, then try again.* The server's `bot_frozen` code is kept on the error, and the room is not treated as ended: a stop is a state its owner can end, so `alreadyLeftFace` keeps the room and its grants (#3114). + ## Owns Everything in `plugins/social/` (entry `plugins/social/index.js` and any helpers). diff --git a/plugins/social/src/face-rooms.js b/plugins/social/src/face-rooms.js index 25177a279..ac8ea1ac0 100644 --- a/plugins/social/src/face-rooms.js +++ b/plugins/social/src/face-rooms.js @@ -164,6 +164,9 @@ const FRIENDLY = { unauthorized: 'Bot Social signed you out. Reconnect in Friends\' Bots, or restart FlyBot.', forbidden: 'This Bot cannot join that room.', bot_revoked: 'This Bot is no longer available on Bot Social.', + // A stop is a state, not an ending: the owner can resume the same Bot, and the same invite or room + // works again (bot-social FACE_ROOMS.md, `bot_frozen` 403). It must not read like `bot_revoked`. + bot_frozen: 'One of these Bots is emergency-stopped on Bot Social. Its owner can resume it in My Bots on that server, then try again.', bot_not_found: 'That Bot is not one of yours on Bot Social.', face_room_not_found: 'That room is not available.', room_full: 'This room already has 8 Bots. Nobody else can join with this number.', diff --git a/plugins/social/src/social.js b/plugins/social/src/social.js index bd617c3c1..1def9bc09 100644 --- a/plugins/social/src/social.js +++ b/plugins/social/src/social.js @@ -435,6 +435,9 @@ export function mapJoinInviteError(error, { foreignHost } = {}) { if (/rate_limited/i.test(blob)) { return Object.assign(new Error('Too many tries. Wait a moment and try again.'), { code: 'rate_limited' }) } + // An emergency stop is a state the owner can end, not a dead invite: the same one sentence as the + // share and the face room, with the server's code kept (#3114). + if (/bot_frozen/i.test(blob)) return mapFaceError({ error: { code: 'bot_frozen' } }, 403) return error } @@ -3337,6 +3340,9 @@ export function createSocial(service, config = {}, { client: given, api: givenAp if (/friend_not_found|no such friend|unknown friend/i.test(blob)) { return new Error('That friend is not on this server.') } + // An emergency stop is a state the owner can end, not a failure of the share: the face-room + // sentence is the one line for all three doors (#3114). + if (/bot_frozen/i.test(blob)) return mapFaceError({ error: { code: 'bot_frozen' } }, 403) if (/not connected|no token|no server URL/i.test(blob)) { return new Error('Bot Social is disconnected. Reconnect under Settings → Bot Social.') } diff --git a/plugins/social/test/face-rooms.test.js b/plugins/social/test/face-rooms.test.js index c3e34769a..b138c2c2e 100644 --- a/plugins/social/test/face-rooms.test.js +++ b/plugins/social/test/face-rooms.test.js @@ -99,6 +99,18 @@ test('error mapping covers the FACE_ROOMS.md codes', () => { assert.equal(formatRetryAfter(60), '1 minute') }) +test('#3114: a frozen Bot is one human line, and its room has not ended', () => { + // The server answers `403 bot_frozen` on either end of a relationship; a stop is a state its owner + // can end, so the refusal must not read like a room that is gone (#3114). + const frozen = mapFaceError({ error: { code: 'bot_frozen', message: 'bot is frozen (emergency stop)' } }, 403) + assert.equal(frozen.code, 'bot_frozen') + assert.equal(frozen.message, 'One of these Bots is emergency-stopped on Bot Social. Its owner can resume it in My Bots on that server, then try again.') + assert.doesNotMatch(frozen.message, /bot is frozen|emergency stop\)|bot_frozen|grant_bot_to_friend/i) + // The words `alreadyLeftFace` reads as an ending must not creep in with the friendly sentence. + assert.doesNotMatch(frozen.message, /not available|has closed|no longer|not one of yours/i) + assert.equal(alreadyLeftFace(frozen), false) +}) + test('a 5xx at join says Bot Social is not answering, not "try another number"', () => { const copy = 'Bot Social is not answering right now. Try again in a moment.' for (const status of [500, 502, 503, 530]) { diff --git a/plugins/social/test/social.test.js b/plugins/social/test/social.test.js index c2af4fb8b..9bdeec562 100644 --- a/plugins/social/test/social.test.js +++ b/plugins/social/test/social.test.js @@ -9637,6 +9637,35 @@ test('#310: join_invite errors read as plain sentences, never as raw codes', asy assert.equal(server.calls.filter(c => c.name === 'join_invite').at(-1).args.code, 'eWDDdBMIxLSZ') }) +test('#3114: a frozen Bot reads as one human line on the share and on the invite', async (t) => { + const copy = 'One of these Bots is emergency-stopped on Bot Social. Its owner can resume it in My Bots on that server, then try again.' + const invite = mapJoinInviteError(Object.assign(new Error('Bot Social join_invite: bot is frozen (emergency stop)'), { code: 'bot_frozen' })) + assert.equal(invite.message, copy) + assert.doesNotMatch(invite.message, /bot is frozen|emergency stop\)|bot_frozen|grant_bot_to_friend/i) + + const { ctx, home, call, stop } = await team() + t.after(stop) + const server = mockServer() + const baseFetch = server.fetch + server.fetch = async (url, init) => { + const body = init.body ? JSON.parse(init.body) : {} + if (body?.params?.name !== 'grant_bot_to_friend') return baseFetch(url, init) + return new Response(JSON.stringify({ jsonrpc: '2.0', id: body.id, result: { isError: true, content: [{ type: 'text', text: JSON.stringify({ code: 'bot_frozen', message: 'bot is frozen (emergency stop)' }) }] } }), { status: 200 }) + } + const social = await startSocial(ctx.flybot, { + server: 'https://social.test', credentialsPath: join(home, 'flybot-social.json'), + fetch: server.fetch, inboxPollMs: 0, + }) + t.after(() => social.dispose()) + await settle() + const chief = ctx.flybot.bot.list().find(b => b.isMain) || ctx.flybot.bot.list()[0] + await call('flybot/social/create-invite', { botId: chief.id }) + const result = await call('flybot/social/share-with-friend', { botId: chief.id, home: '@bob.home' }) + assert.equal(result.ok, false) + assert.equal(result.error.message, copy) + assert.doesNotMatch(result.error.message, /bot is frozen|emergency stop\)|bot_frozen|grant_bot_to_friend/i) +}) + test('#310: Copy invite link always carries the /i/ segment', () => { assert.equal(inviteLink({ code: 'ABC', url: 'https://h.example/i/ABC' }), 'https://h.example/i/ABC') assert.equal(inviteLink({ code: 'ABC', url: 'https://h.example/ABC' }), 'https://h.example/i/ABC')