Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/3114-frozen-bot-one-line.fixed.md
Original file line number Diff line number Diff line change
@@ -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)).
2 changes: 2 additions & 0 deletions docs/subsystems/social.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <name>? 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).
Expand Down
3 changes: 3 additions & 0 deletions plugins/social/src/face-rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
// system copy that embeds those names.
export function cleanFaceName(value, fallback = 'a remote Bot') {
const text = cutCodePoints(stripFaceMarkers(String(value ?? ''))
.replace(/[\u0000-\u001f\u007f-\u009f\u2028\u2029]/g, ' ')

Check warning on line 88 in plugins/social/src/face-rooms.js

View workflow job for this annotation

GitHub Actions / plugins (social)

eslint(no-control-regex)

Unexpected control characters
.replace(/[[\]"<>`@]/g, '')
.replace(/\s+/g, ' ')
.trim(), NAME_MAX)
Expand Down Expand Up @@ -164,6 +164,9 @@
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.',
Expand Down Expand Up @@ -489,7 +492,7 @@
|| (typeof member.color === 'string' && !HEX_ONLY.test(member.color) ? member.color.trim().slice(0, 32) : '')
if (color && !/[\n<>]/.test(color)) out.color = color
const src = member.avatar && typeof member.avatar === 'object' ? member.avatar : {}
const avatar = { ...(fromServer.avatar ?? {}) }

Check warning on line 495 in plugins/social/src/face-rooms.js

View workflow job for this annotation

GitHub Actions / plugins (social)

unicorn(no-useless-fallback-in-spread)

Empty fallbacks in spreads are unnecessary
if (typeof src.shape === 'string' && /^[a-z][\w-]{0,31}$/.test(src.shape)) avatar.shape = src.shape
const image = typeof src.image === 'string' ? src.image.trim() : (typeof member.image === 'string' ? member.image.trim() : '')
if (image && image.length <= 65536 && /^(https?:\/\/|data:image\/)/i.test(image) && !/[\s<>]/.test(image)) avatar.image = image
Expand Down Expand Up @@ -519,7 +522,7 @@
export function cleanFaceRole(value) {
if (typeof value !== 'string') return ''
return cutCodePoints(stripFaceMarkers(value)
.replace(/[\u0000-\u001f\u007f-\u009f\u2028\u2029]/g, ' ')

Check warning on line 525 in plugins/social/src/face-rooms.js

View workflow job for this annotation

GitHub Actions / plugins (social)

eslint(no-control-regex)

Unexpected control characters
.replace(/[[\]"<>`@]/g, '')
.replace(/\s+/g, ' ')
.trim(), FACE_ROLE_MAX)
Expand Down Expand Up @@ -628,7 +631,7 @@
if (type === 'room.started') return platformStartedText(reason, language)
if (type === 'room.lead_changed') return platformLeadText(member, reason, language)
const cleaned = cutCodePoints(String(text ?? '')
.replace(/[\u0000-\u001f\u007f-\u009f\u2028\u2029]/g, ' ')

Check warning on line 634 in plugins/social/src/face-rooms.js

View workflow job for this annotation

GitHub Actions / plugins (social)

eslint(no-control-regex)

Unexpected control characters
.replace(/[[\]"<>`@]/g, '')
.replace(/\s+/g, ' ')
.trim(), 200)
Expand Down
6 changes: 6 additions & 0 deletions plugins/social/src/social.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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.')
}
Expand Down
12 changes: 12 additions & 0 deletions plugins/social/test/face-rooms.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down
29 changes: 29 additions & 0 deletions plugins/social/test/social.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
Loading