The backend of Comma is one Elixir/Mix umbrella with one
release, mix release comma. The release holds several subsystems. Each
subsystem is a set of OTP apps under apps/.
| Subsystem | COMMA_SUBSYSTEMS name |
What |
|---|---|---|
| Salix | salix |
The distributed, multi-tenant multi-agent runtime with optional remote VM environments |
| Comma product | comma_product |
Comma product backend and API. It drives Salix through the Comma.Salix.* boundary |
| BridgeForTeams | bridge_for_teams |
Teams backend and dashboard. It shares the Salix runtime |
| Alert Router | alert_router |
Comma notification router |
Comma's @subsystems map in apps/comma/lib/comma.ex
lists the apps of each subsystem.
A pod runs only the subsystems in COMMA_SUBSYSTEMS (comma-separated). When it
is unset, the pod runs all subsystems:
COMMA_SUBSYSTEMS=salix bin/comma start
COMMA_SUBSYSTEMS=comma_product,salix bin/comma start
COMMA_SUBSYSTEMS=bridge_for_teams,salix bin/comma startAn unknown subsystem name stops startup. The selection applies only to the
release. mix run and mix test start all umbrella apps.
Salix uses BEAM/OTP for process orchestration, object storage for aggregate
state and content, and PostgreSQL for queried control and coordination data.
See the storage boundary, the
agent runtime, and the
Salix TLA+ specs. Production deployment is in
DEPLOYMENT.md.
Production Salix requires object storage with conditional writes, PostgreSQL
through salix.database.url, and Redis through REDIS_URL or
COMMA_REDIS_URL. Production startup fails when the database or Redis
configuration is missing. PostgreSQL migrations and control-data cutover
readiness must complete before Salix serves. See DEPLOYMENT.md
for storage conditionals (including storage.atomic_operations for GCS) and
config/runtime.exs for startup requirements.
The team setup needs only Docker Desktop or OrbStack. The Dev Container image pins Elixir, OTP, Node, pnpm, native build tools, and service dependencies. From the repository root:
make dev-backendThis starts MinIO, Postgres, ClickHouse, Redis, Mailpit, and the deterministic LLM. It compiles the source-mounted backend, runs local migrations, and seeds the developer account and Group. It returns when the Salix and Comma APIs are healthy. Build output and service data stay in Docker volumes, so a restart compiles only changed source.
Lifecycle commands:
make dev-container-status
make dev-container-shell
make dev-container-restart # recompile changed backend source, then wait for health
make dev-systems-logs
make dev-systems-down # stop containers and keep every volume
make dev-container-rebuild # only when the Dev Container Dockerfile or toolchain changesRun Web and Electron from the host with host-installed client dependencies:
pnpm --dir clients install # first host setup only
make dev # container backend + host Web on :5174
make dev-electron # container backend + native ElectronWhen the backend is ready, these checks must succeed:
curl http://127.0.0.1:4000/health # Salix API
curl http://127.0.0.1:4200/health # Comma product API
nc -vz 127.0.0.1 4400 # transfer serverThe development-only bootstrap runs the Comma schema cutover on an empty local
database. It requires MIX_ENV=dev, COMMA_ENVIRONMENT=local, the local
database name, and empty product tables. It fails closed for populated or
remote data. Release containers use the one-shot comma-migrate service.
| Service | Local address |
|---|---|
| Salix API/dashboard | http://127.0.0.1:4000 |
| Comma product API | http://127.0.0.1:4200 |
| Salix transfer | 127.0.0.1:4400 |
| Mailpit inbox / SMTP | http://127.0.0.1:8025 / 127.0.0.1:1025 |
| MinIO API / console | http://127.0.0.1:19000 / http://127.0.0.1:19001 |
| Postgres | 127.0.0.1:15432 |
| ClickHouse HTTP | http://127.0.0.1:18123 |
For Salix work without the Comma product, each worktree can run its own Compose project. Only Salix HTTP and transfer are published to the host:
make salix-dev-up
make salix-dev-infoThe worktree path sets the project suffix and the two host ports. The command refuses to start if a host port belongs to another service. To override the label or ports:
SALIX_DEV_ID=router-memory \
SALIX_DEV_HTTP_PORT=25001 \
SALIX_DEV_TRANSFER_PORT=45001 \
make salix-dev-upRepeat explicit port overrides for each lifecycle command. There is no source watcher. After a Salix code change, rebuild:
make salix-dev-rebuild
make salix-dev-logs
make salix-dev-status # addresses plus container health
make salix-dev-psql # psql inside this worktree's private Postgres
make salix-dev-shell # shell inside the running Salix release container
make salix-dev-down # stop containers, keep data
make salix-dev-reset # delete only this worktree's containers and volumesGenerated configuration is in the ignored .local/salix-dev/ directory. An
optional compose.override.yml in the generated project directory applies to
all lifecycle commands. Keep private environment files there.
Dump a complete prompt through the production composer. This does not start Salix or read storage:
cd systems
mix salix.prompt.dump
mix salix.prompt.dump --role worker --runtime script --no-skill
mix salix.prompt.dump --agent-prompt "Additional diagnostic instructions"In an OTP release:
bin/comma eval 'SalixAgent.Release.dump_system_prompt()'The Dev Container seeds before it becomes healthy. make dev-systems-seed is
an idempotent rerun. It creates or reuses comma-local@example.com, its default
Workspace, the Salix Group Router and Worker, a local credit grant, and the user
Chat. It prints the Workspace ID and an API session token for local tools.
make dev-electron stores that Session in the ignored
.local/comma-dev-session.json and signs the unpackaged client in. Web, and
Electron started with pnpm --dir clients dev:electron, use the real
passwordless login. Request a code for that email and read it in Mailpit.
To issue one more credit grant, advance the generation. Repeating a generation issues nothing:
COMMA_LOCAL_CREDIT_GRANT_GENERATION=2 make dev-systems-seedThe seed command mutates users, sessions, workspaces, billing grants, and Chat
data. It rejects a non-loopback COMMA_LOCAL_API_BASE_URL. Only an intentional
remote-data operation may set
COMMA_LOCAL_DEV_SEED_ALLOW_NON_LOOPBACK=I_UNDERSTAND_THIS_MUTATES_REMOTE_DATA.
Never set it for local development.
Local builds compile the recommendation mock with
COMMA_LOCAL_RECOMMENDATION_MOCK=true. It starts disabled. Toggle it in
Settings > Debug. Production builds omit the mock. Connections created
while the mock is on must be reconnected to a real provider.
The default suite is local and deterministic. It needs no Google project or account. Start the backend and Web, then run the smoke in a third terminal:
make dev-backend
pnpm --dir clients dev:web
pnpm --dir clients smoke:auth:localWith the same backend running, the Electron smoke tests the renderer, preload, Main, and local API path. The test is opt-in:
pnpm --dir clients smoke:auth:electron:localA real Google sign-in is an optional manual canary. Use one Web OAuth Client ID per environment:
| Runtime | Google Cloud boundary | OAuth client | Authorized JavaScript origins |
|---|---|---|---|
| Local Web | Development/testing project | Web: Dev | http://127.0.0.1:5174 |
| Staging Web | Development/testing project, or dedicated staging | Web: Staging | https://app-staging.comma.surf |
| Production | Production/publishing project | Web: Prod | https://app.comma.surf |
Production must be in a separate Google project from development and testing.
Never add localhost or staging origins to the production OAuth client. Origins
are exact scheme + host + port values. The GIS callback flow needs no
redirect URI or client secret.
The local stack uses 127.0.0.1 for Web and API so the SameSite=Lax cookie
is same-site. Do not mix localhost and 127.0.0.1 in one login flow.
To run the Web canary, add the Google account as a test user while the development project is in Testing:
COMMA_GOOGLE_WEB_CLIENT_ID="YOUR_DEV_WEB_CLIENT_ID" make devElectron needs a separate Desktop app client for non-production and for production:
COMMA_GOOGLE_ELECTRON_CLIENT_ID="YOUR_DEV_DESKTOP_CLIENT_ID" \
COMMA_GOOGLE_ELECTRON_CLIENT_SECRET="YOUR_DEV_DESKTOP_CLIENT_SECRET" \
make dev-electronThe Comma backend exchanges the Desktop authorization code. The Desktop client secret stays in server configuration and is never bundled into Electron. Restart the backend after you change the client ID or secret. See Google's GIS Web client setup and production OAuth policy.
The default local LLM is deterministic. It needs no provider key:
- Send an ordinary Chat message. The reply contains
LOCAL_CHAT_OK. - Send
LOCAL_CREATE_TASK. A Task card appears, opens by its public Comma conversation ID, and reachescompletedwithLOCAL_TASK_DONE.
Keep real-provider credentials in the ignored .local/ directory. Do not put an
API key in systems/config/compose-dev.json, a tracked Compose file, or a Salix
Template record. The Template references an environment variable through
api_key_env.
Create the two private files from the repository root:
mkdir -p .local
cp systems/config/compose-dev.json .local/compose-dev-real-llm.json
chmod 600 .local/compose-dev-real-llm.jsonIn .local/compose-dev-real-llm.json, replace only llm.default_template. For
an OpenAI-compatible Responses endpoint:
{
"template_id": "comma-local-dev",
"name": "Comma Local Dev Real LLM",
"model": "YOUR_MODEL",
"provider": "openai",
"max_tokens": 2048,
"context_tokens": 200000,
"provider_config": {
"protocol": "responses",
"base_url": "YOUR_APPROVED_PROVIDER_BASE_URL",
"api_key_env": "COMMA_REAL_LLM_API_KEY"
}
}Put the credential in .local/comma-real-llm.env and restrict it:
COMMA_REAL_LLM_API_KEY=YOUR_LOCAL_PROVIDER_KEYchmod 600 .local/comma-real-llm.env
make dev-real-llm
# or: make dev-electron-real-llmsystems/docker-compose.devcontainer.real-llm.yml only mounts those ignored
files. It holds no credentials.
The local data volume keeps the journaled Template. If the checkout was seeded
with the mock, the mounted JSON does not replace the existing comma-local-dev
Template. Reset the local volumes before you switch providers:
docker compose \
-f systems/docker-compose.dev.yml \
-f systems/docker-compose.devcontainer.yml \
down -v
make dev-real-llmThis deletes only local Compose data. If replies still contain
LOCAL_CHAT_OK, the mock Template is still in the volume. If the provider
returns 401, check that api_key_env matches the variable name in
.local/comma-real-llm.env. Do not print the rendered Compose configuration,
because it expands env_file secrets.
make dev and make dev-electron run the client in the foreground. Ctrl-C
stops the client and leaves the backend running. Web uses port 5174 and
Electron Forge uses 5173. When the backend already runs, use
pnpm --dir clients dev:web and pnpm --dir clients dev:electron.
With several worktrees open, quit other Comma Dev Electron processes before an
Electron smoke. macOS can keep an older build under the same name and app-data
location.
To reset all local data and rerun every migration:
docker compose \
-f systems/docker-compose.dev.yml \
-f systems/docker-compose.devcontainer.yml \
down -v
make dev-systems-upThe default Compose scope is salix,comma_product. This stack does not fake
the BridgeForTeams dashboard or real external providers. For BFT Dashboard
work, see Bridge For Teams. For the Agent
configuration handoff after migrations, see
Local model switching.
Install the libsodium, Opus, and libsrtp2 headers, pkg-config, and a Rust
toolchain (brew install libsodium opus srtp pkg-config rustup, or
apt-get install libsodium-dev libopus-dev libsrtp2-dev pkg-config with
rustup).
# MinIO on :19000 with buckets salix-dev + salix-test
minio server /tmp/minio --address :19000 &
aws --endpoint-url http://127.0.0.1:19000 s3 mb s3://salix-dev
aws --endpoint-url http://127.0.0.1:19000 s3 mb s3://salix-test
mix deps.get
mix test # full suite (fake backend + real MinIO)
mix run --no-halt # API on :4000, transfer on :4400Salix loads runtime config from /etc/salix/config.json or
systems/config.json. Keep a local systems/config.json private (0600) and
untracked. Use config/config.example.json for
committed examples. Set SALIX_CONFIG_PATH=/absolute/path/to/config.json to
use another config file.
The platform VM configuration is ctl/vm/default_config.json, managed from
the Salix dashboard or /v1/admin/vm/default-config. When it is absent, Salix
uses the top-level vm section of the config JSON. Comma workspaces use the
platform configuration. A BridgeForTeams tenant with its own VM config keeps
it, unless an operator sets vm.config_source to "platform". A tenant with
no VM config uses the platform configuration. Sprites is retired.
Call the API:
curl -X POST localhost:4000/v1/comma/admin/users \
-H 'authorization: Bearer test-token' \
-H 'content-type: application/json' \
-d '{"email":"demo@example.com"}'This uses the deployment bearer. Human admins use Comma Admin Web. Its commands require a server-derived Admin actor, a reason, target-bound confirmation, idempotency, and durable redacted audit evidence.
New Comma Workspaces default to vm.enabled: true. Explicit
vm.enabled: false is kept. In Comma Admin, Users → Workspace & billing →
Cloud VM sets the value for a ready Workspace. A change requires an audited
reason and target-bound confirmation, and queues the Workspace convergence job.
Configuration sync is not VM readiness. Salix removes the shared VM only when
no other agent or runtime installation intent needs it.
Real rounds need provider configuration in the agent's Template
(protocol, model, base_url, and api_key or api_key_env). There is no
cluster-wide fallback key. Without a key, the round fails at the provider and
settles with an LLM-error message.
The log is disabled by default. Enable it with --log-file <path>, or with
log.file in config.json for a release:
mix run --no-halt -- --log-file salix.jsonlEach agent step becomes one JSON object per line. Credential-looking fields are
redacted. The logger is CommaLog (app comma_log), shared by all subsystems.
SalixAgent.force_recover/2 is a break-glass IEx API for an internal-runtime
agent that is stuck in a running or queued state. Run it from a trusted shell
on a prod Salix/Comma release node:
SalixAgent.force_recover("agent_...",
session_id: "...",
timeout: 5_000
)It stops the live runtime and session processes, repairs the durable internal session state, appends an operator recovery message, and wakes the session on the owning node. It does not archive, cancel, or delete the agent.
Omit session_id: to recover every internal session of the agent that has
pending work. To clear the stuck state without a wake, pass wake: false. The
session goes back to idle, and pending durable work stays for normal
activation.
The result is {:ok, %{"agent_id" => ..., "wake_requested" => ..., "sessions" => [...]}}.
Each session entry has its "status", its event count, and its wake result,
or an "error".
The API supports only Salix-managed internal runtime agents. Recover an external runtime agent through its own control plane.
Run privileged bootstrap and recovery operations from an Elixir shell on a
trusted release node, or from a trusted MIX_ENV=prod maintenance shell with
the same database configuration. The secret is returned once. Do not persist it
outside the operator handoff.
To create a one-time organization invite code:
{:ok, %{code: code}} =
BridgeForTeams.OrgCreationInvites.create_invite_code(
org_name: "Acme Co",
org_slug: "acme-co",
note: "initial owner for acme-co"
)Give the code to the owner. They redeem it in the dashboard signup flow to create the organization and their owner account. The name and slug are bound to the code. Codes are stored only as hashes and cannot be reused.
For staging smoke tests, use the manual GitHub Actions workflow
Comma Staging Bootstrap Invite from the trusted main ref. It needs no local
GKE credentials. Inputs are org_name, org_slug, note, and ttl_seconds.
Download the one-day comma-staging-bootstrap-invite-* artifact and open its
signup_url in the staging dashboard. Treat the artifact as a short-lived
secret.
To recover an account when organization SSO is misconfigured:
{:ok, %{url: url}} =
BridgeForTeams.AccountRecovery.create_recovery_link(
"owner@example.com",
base_url: "https://teams.example.com",
note: "temporary SSO recovery"
)Send the url to the account owner through a trusted channel. The link signs
that account in once at /auth/recovery. Links are stored only as hashes,
require an active user, and cannot be reused.
The product CLI is a standalone Go binary in systems/cli/bft. It needs no
Elixir or Erlang. In a source checkout:
go build -o /tmp/bft ./cli/bft/cmd/bft
/tmp/bft --help
/tmp/bft commands --json
go test -C cli/bft ./...
cli/bft/scripts/build-release.shThe BFT CLI Release workflow publishes releases to
${CLOUDFLARE_R2_PUBLIC_BASE_URL}/bft-cli. The dashboard installer reads
:bft_cli_artifact_base_url and :bft_cli_release_id.
Test exit codes with the built binary. go run turns a non-zero exit such as
64 into 1.
Output modes:
- Human mode prints guided setup steps and copyable URLs.
- Agent mode prints stable JSON. Non-TTY stdout defaults to JSON. In a TTY,
pass
--jsonor--output json. Pass--output textto force text. Use--limit,--filter, and--fieldsto bound the output. - Exit codes:
0success,2onboarding step needs manual action,64usage or context error,66not found,69runtime unavailable,70unexpected backend error.
Pass credentials by environment variable reference (for example
--app-secret-env BFT_FEISHU_APP_SECRET), not as literal arguments. The CLI
redacts secret fields and secret-bearing URL query parameters in its output.
A BotFather bot connects to one Agent Swarm. The behavior is in the moduledocs
of SalixIM.Provider.Telegram and SalixIM.ProviderRuntime.
Setup:
- Create a bot with @BotFather. Keep privacy mode on and do not make the bot a group admin: Salix has no mention filter for Telegram, so every message the bot receives starts a Router turn.
- Connect it on the Swarm Connections page, or with
bft telegram connect. Salix checks the token withgetMeand pollsgetUpdates, so there is no callback address. Salix callshttps://api.telegram.org. - Add the bot to a group. The group shows up on the page and in
bft telegram status. Allow it there, or withbft telegram chats. - Turn off
/setjoingroupsin BotFather once the bot is in its groups.
Operator notes:
- A connect made through CFT serves only its
allowed_chat_ids. Other chats never reach the Router and the agent cannot send to them. A group outside the list is noted for an admin; a stranger's private chat leaves nothing. - A private chat's id is the person's id:
bft telegram chats --chat <id>allows one. The page lists only groups and channels the bot was added to. - A connect created through the tenant API without
allowed_chat_idsserves every chat. - One bot serves one connect. Two would take each other's updates.
- OAuth links, native question buttons, the typing indicator,
/status-style commands, Task cards and topics exist only for Comma-managed Telegram chats.
A QQ open platform bot connects to one Agent Swarm. The behavior is in the
moduledocs of SalixIM.QQInbound, SalixIM.Provider.QQ,
SalixIM.Provider.QQ.Groups, SalixIM.Provider.QQ.Menu, and
SalixIM.QQMessageRecord.
Setup:
- Create a bot in the QQ open platform. Copy its AppID and AppSecret.
- Connect it on the Swarm Connections page, or with
bft qq connect. Salix checks the credentials with QQ. - In the QQ bot console, choose Webhook delivery and save the callback address
<public base URL>/v1/im/qq/events?app_id=<AppID>. Subscribe to the private chat, group, interaction, and group member events. QQ accepts only HTTPS on port 80, 443, 8080, or 8443. - If the console has an IP allowlist, add the deployment's egress addresses.
Salix calls
https://api.bot.qq.com.
Operator notes:
- Salix verifies each callback with the Ed25519 key that QQ derives from the AppSecret.
- A group takes proactive messages only after a group admin turns on "机器人主动在群聊内发言" for the bot.
- The group record has every message only when a group admin sets "机器人可获取的群聊消息范围" to "获取群内全部消息". Private chats are not recorded.
- A bare group mention uses the context QQ attached; without it, Salix reads up to 10 earlier recorded messages of that group (1.5-second budget, at most 32 concurrent reads per node). The Router asks for clarification when no clear request is found.
- A Task created from a human QQ request posts a Markdown status card to that chat, and a new one on each state change (QQ cannot edit messages). Cards use QQ's reply allowance; later group cards need proactive-message permission.
- A command panel made in the QQ bot console replaces the Swarm's menu. Delete
it in the console to show the menu. A Swarm admin edits shortcuts on the
Swarm Connections page or with
bft qq menu. qq.list_membersandqq.get_memberwork only for bots on QQ's allowlist. Other bots get error 11253. Ask the QQ open platform to add the bot.
The record uses the Postgres outbox qq_mirror_outbox and the ClickHouse table
qq_messages. It is on wherever ClickHouse is configured.
qq_mirror.enabled: false in the Salix config turns it off.
A WeCom (企业微信) AI bot in API mode connects to one Agent Swarm through its
long connection. The behavior is in the moduledocs of SalixIM.WeComSocket,
SalixIM.WeComSocketRuntime, SalixIM.WeComInbound, SalixIM.WeComFiles, and
SalixIM.Provider.WeCom.
Setup:
- In the WeCom admin console, open 工作台 → 智能机器人 and create a bot. Choose
API mode and the long connection (使用长连接). Copy the Bot ID and the Secret.
A super admin of the organization should create the bot. Then each
useridis the person's organization account. Otherwise it is an ID that WeCom makes. - Set the bot's 可见范围 to the people who will use it. The bot joins only internal groups, not groups with external contacts.
- Connect it on the Swarm Connections page, or with
bft wecom connect. Salix checks the credentials by subscribing once onwss://openws.work.weixin.qq.com.
Operator notes:
- WeCom keeps one long connection per bot. A new subscription takes the bot from the old one. Do not run the bot anywhere else, the console's 调试 too. The socket takes the bot back after 5 seconds, then waits longer each time it is taken again within 15 minutes, up to 10 minutes.
- One node in the cluster holds each socket, under the lease
ctl/im/wecom-socket/<connect_id>. A send from another node reaches it through the:pgscopeSalixIM.WeComPG. - The socket opens outbound to
openws.work.weixin.qq.com:443. Attachments download from*.myqcloud.com. No inbound address or IP allowlist is needed. - A group sends the bot only text and mixed messages that mention it. Images, voice, files, and videos come only from private chats.
- WeCom takes at most 30 messages a minute and 1000 an hour per chat. A send to a chat that never wrote to the bot fails.
Data abilities (SalixMCP.HostedServices, plugins wecom-msg, wecom-mail,
wecom-doc, wecom-todo, wecom-schedule, wecom-meeting, wecom-disk,
wecom-contact):
- In the bot's 可使用权限, grant an ability. 查看使用方式 shows its address,
https://qyapi.weixin.qq.com/mcp/v2/bot/<ability>?apikey=…. Each ability has its own key. - On the Swarm Plugins page, enable the ability's plugin and paste the key or that ability's whole address (another address is refused). Salix runs one read-only tool with it. WeCom answers a bad key with errcode 850001 inside a successful result.
Rules:
- The data is that of the bot's creator (多人使用 shares the creator's permissions). Like any connected account, it serves the whole Agent Swarm: everyone who can reach the Swarm on any channel can use it, and the Swarm's history is shared. Connect the abilities only to a Swarm whose people may read that data.
- Write tools (send mail, share documents, send messages) reach people outside the Swarm. Plugins turn whole abilities on and off: turning off mail removes reading and sending mail together; one write tool cannot be turned off alone.
- Grants expire after seven days (the console shows the date). A call with an
expired, revoked or replaced key fails as
credential_invalid(SalixMCP.Gateway), and the agent tells the person to have the ability granted again. Grant it again and paste the new key.
A custom app of the Lark open platform (open.larksuite.com) connects to one
Agent Swarm. A Lark connect holds its own credentials and does not use the
organization's Feishu app. The behavior is in the moduledocs of
SalixIM.LarkInbound, SalixIM.Provider.Lark, SalixIM.Provider.Lark.Docs,
SalixIM.Provider.Lark.Minutes, SalixIM.LarkMessageRecord, and
SalixIM.Provider.Lark.Manual.
Setup:
- Create a custom app in the Lark Developer Console and add the Bot capability. Copy the App ID, the App Secret, and the Verification Token or the Encrypt Key from Events & Callbacks.
- Connect it on the Swarm Connections page, or with
bft lark connect. - In Events & Callbacks, choose "Send events to developer's server" and save
the request URL
<public base URL>/v1/im/lark/events?app_id=<App ID>. Subscribe toim.message.receive_v1,im.message.recalled_v1andim.chat.member.bot.added_v1(the bot introduces itself in a new group). Under Callbacks, use the same URL and subscribe tocard.action.trigger. Without it, confirmation and question card buttons do nothing. - Import the scopes. Use Copy JSON in the Lark section of the Swarm
Connections page, or
bft lark scopes --output text(BridgeForTeams.LarkScopes). In Permissions & Scopes, use the batch import. Withoutim:message.group_msg, the bot gets only messages that mention it. - For a chat with members of another organization, turn on External Sharing in the app's version details and allow the bot in external groups. Lark still refuses the app history reads there with error 230027, so the bot reads what Lark delivered to it from the record.
- Create a version of the app and publish it. Scopes and events take effect with the published version.
- Run the checks: Run checks on the connect's row, or
bft lark checks --org <org> --project <project>(--connect-idfor one of several apps).mix bridge_for_teams.run_checks --surface lark_botprints the same result. The gates are inSalixIM.LarkChecks.bot.first_messageandbot.manualare alwaysneeds_manual.
Made by a scan (no Developer Console):
- On the Swarm Connections page, choose Scan to connect, or in Comma add
the Lark plugin. Salix begins Lark's one-click app creation
(
SalixIM.Provider.Lark.Registration, an OAuth device flow): the page shows a QR code of the link. - The person scans it with Lark (or opens the link in Lark) and confirms. Lark makes and publishes a custom app with the bot, its scopes and its events in that person's tenant, and returns the App ID and App Secret.
- Salix connects the app with
"events" => "socket". Such an app has no request URL: its events come through the long connection Salix opens (SalixIM.LarkSocket, one per connect in the cluster under a lease held bySalixIM.LarkSocketRuntime). The runtime finds socket connects through their own index (ctl/im_socket_connects/), not by reading every connect. A connect made from Comma has anowner_open_id: only that person's messages reach the Router. - An event the Router could not take is answered with code 500, as the Lark SDKs do, so Lark sends it again. At most 16 events are handled at a time per connect; up to 256 more wait in order, and one past that is answered with code 500.
- Lark keeps no events for a long connection that is down. Each time the
socket opens, Salix reads back the history of the connect's chats since
it was lost (the last ten minutes for a socket that just started), and
receipts keep a message from reaching the Router twice
(
SalixIM.LarkSocket.CatchUp). A message the Router could not take is tried again after 15 s, 1 min and 5 min. The chats read back are those that had a message for the bot and the groups the bot is in; a private chat whose first message comes while the socket is down is not. - An app made by a scan has nobody in the Developer Console. When Lark
refuses it for a missing scope (error 99991672, or 230027
need scope), the connect records the scope and the dashboard and Comma name it. The history backfill sets such a chat aside until the next listing. Scan to update on the connect's row (in Comma, Reconnect) begins the same scan with the app's App ID (clientID): the person confirms the scopes the app gets, and the connect keeps the same app.
The registration always begins on Feishu's accounts service and the person
confirms on open.larksuite.com/page/cli, as Lark's own CLI does: Lark's
/page/launcher makes the app but never answers the poll. The device code is
a credential; the dashboard and Comma give it to the browser only encrypted.
The Feishu plugin (飞书, listed under 中国服务 in Comma) and the Feishu section of the
dashboard's Swarm Connections page use the same scan, confirmed on
open.feishu.cn/page/cli (SalixIM.ProviderConnects.finish_feishu_registration):
- The Feishu connect owns the app's App Secret, as a Lark connect does, so a
Workspace or swarm can connect several scanned apps beside its tenant Feishu
app (
ProviderAppStore, which an app given by hand uses). The connect has"events" => "socket", and in Commaowner_only. An account whose tenant is Lark is refused. - The same long connection and catch-up run against
open.feishu.cn. Its events go toSalixIM.ProviderHTTP.handle_feishu_socket_event/2, which takes messages and card presses from the owner only. - Removing the plugin retires the connect. The app stays in the member's Feishu tenant.
Security and data notes:
- Salix accepts a callback when its signature or decryption proves the Encrypt Key, or its token equals the Verification Token. A connect made by a scan takes no callback; its long connection is opened with the App Secret.
- Documents and Minutes are read as the bot. The bot opens a document only when it is shared with a chat that includes the bot, shared with the app, or open by link inside the tenant.
- A document link must be on a
larksuite.comhost. Feishu links go to a Feishu connect. - People sign in with their Lark account on the swarm's Connections page
(Accounts), or from a chat through the link the bot posts. Each sign-in is
a Group OAuth Binding of provider
lark(SalixStore.OAuth.Adapters.Lark); the organization's OAuth app for Lark is the bot's Lark app with the redirect URL/v1/oauth/lark/callbackand the user scopes of the batch import. A person sees what they took part in or may open; the app sees what was shared with it. - The bot finds content without a link.
lark.search_docs(Lark'ssearch/v2/doc_wiki/search),lark.list_drive_filesandlark.search_meetingsrun as the app and then as every signed-in account, andlark.get_meeting/lark.get_notetry them in that order, unlessaccountnames one (appfor the app alone).lark.list_wiki_spaces,lark.list_wiki_nodesandlark.list_minutesrun as the app unlessaccountnames a person. The bot reads what it finds with the sameaccount. - Documents, spreadsheets and Base are read as the app first. When the app
is denied, the bot reads as the signed-in account of the person who asked,
asks that person to sign in when they have no account, and offers an
access request as them when their account is denied too. Content writes
(
update_doc,insert_doc_media, the comment writes) takeaccountthe same way, after that person agrees. The error of a denied call names the next step. Other operations refuseaccount. The same applies to thefeishu.*operations. A unified note has no transcript document:lark.get_notewithinclude_transcriptreads its transcript page by page from/vc/v1/notes/:id/unified_note_transcript, which Lark gives only to a person. - The bot cannot read an external chat (Lark error 230027).
lark.get_chat_history,lark.get_thread_repliesandlark.get_messagewithaccountread a group as a signed-in member (user scopeim:message.group_msg:get_as_user). The sign-in also asks forim:message.send_as_user, so a sandbox command run with it (comma exec --credential lark/<alias>=...) sends as that person. Withdocs:permission.member:applyit asks the owner of a document, spreadsheet or Base for access as that person (lark.request_doc_access,feishu.request_doc_access). The default sign-in does not ask for the scopes that read spreadsheets and Base (sheets:spreadsheet:readonly,bitable:app:readonly) or edit documents and their comments (docx:document,docx:document:write_only,docs:document.comment:create,docs:document.comment:write_only,docs:document.media:upload). The batch import offers them as user scopes, and a sign-in asks for them only when a person needs them (on_demand_scopes/0of the OAuth adapters), so an app without them still lets people sign in. Anoauth.request_authorizationthat names only these scopes asks for them on top of the default sign-in; the platform keeps what a person granted before. Any other list of scopes replaces the defaults. The sign-in does not ask for private chat scopes. - A Worker holds the document and Minutes operations of a Lark connect and every read operation (chat history, threads, search, chats, members, directory). The Router holds all of them.
- A finished Lark meeting reaches the Router as context. A turn from that
message calls no Lark operation
(
SalixIM.Provider.Lark.MeetingActivationAuthorization). - A person invites the bot from a running Lark or Feishu video meeting
(
SalixMeet.LarkBot). The app needsvc:meeting.bot.join:write,vc:meeting.message:write, the data scope "meeting owner within the app's availability", and the eventsvc.bot.meeting_invited_v1andvc.bot.meeting_ended_v1. The bot joins withbots/joinand reads transcript and chat frombots/events. A person can ask the bot something by voice or in the meeting chat. The meeting copilot writes the answer as text withbots/message. An app without the scope stays silent in the meeting. Status and the summary go to the inviter's private chat with the bot, and each invitation is its own Meeting, so the bot can be in several meetings at once. - The message record uses the outbox
lark_mirror_outbox, the ClickHouse tablelark_messages, and the switchlark_mirror.enabled. A recall removes the message from search. The record does not import history from before the connect.
Not connected for Lark: run checks for meetings and calendar, and the meeting preparation and history pages of the Dashboard.
The system plugin lark (Salix.Control.Plugins) holds the Swarm's Lark
connect (lark-im) and im_api.lark.*. It adds the Lark hosted MCP server
https://mcp.larksuite.com/mcp (target remote:lark, tools mcp.lark.*). It
is on by default in BridgeForTeams. Comma installs it by a scan (above).
- The MCP connection
lark-nativeuses native MCP OAuth (Salix.Control.RemoteMCPOAuth). A Swarm admin selects Connect on the plugin page and signs in to Lark. The token is that person's Lark user token. It is kept on the Swarm's MCP binding, and every Agent of the Swarm uses it. The bot credentials are not used. - Salix requests the same read scopes as for Feishu, plus
offline_access.
An organization can sign members in to the Dashboard with Lark
(BridgeForTeams.Auth.Lark), as SSO provider lark. It is separate from the
provider feishu and from any Swarm's Lark connect. An organization has one SSO
connection, so Lark replaces Feishu or generic OIDC.
- Create or select a custom app in the Lark Developer Console. BFT stores its credentials for sign-in only.
- Open Settings → Single sign-on, select Lark, and enter the App ID and App Secret. The secret is write-only. A blank secret keeps the stored one while the provider stays Lark.
- Copy the Redirect URI from the page (
<public base URL>/auth/callback). In Security Settings of the Lark app, add it to the redirect URLs. - Select Run checks, or run
bft sso checks --org <org>. - Sign in with a test account in a new browser session at
/login?o=<slug>.
Rules:
- Sign-in needs no scope. Lark returns the email only with
contact:user.email:readonly. Enter extra scopes on the Single sign-on page. The Lark app must have them. - The login key of a member is the Lark
union_id, or else theopen_id, in one organization. Theuser_idis never the key. - A Lark identity never matches a Feishu identity or an email. After a switch to Lark, members sign in as new members with the first-sign-in role.
- A change to or from Lark keeps no scope, tenant binding, or first-sign-in policy of the previous provider, and it needs the new secret.
- Tenant binding. Threat: a Lark app that more than one tenant can use lets a
person of another company sign in and become a member. Authority: the
tenant_keyin the Lark user info, read with the server's token. The expected value isprovider_config["tenant_key"]of the SSO connection. An operator sets it withBridgeForTeams.Orgs.upsert_sso_connection/3. The Dashboard does not write it. Owner:BridgeForTeams.Authcompares the two at each sign-in. Result: on a mismatch the person gets no session, identity, or membership, and Operations recordssso.login.failedwithlark_tenant_mismatch. A connection without the key has no tenant check. Feishu has the same check withfeishu_tenant_mismatch.
Before live Feishu acceptance, configure the Feishu app and connect. See Feishu.
For a setup-to-first-message smoke, start the local Systems app and the public callback tunnel, then run:
systems/scripts/bridge_tob_acceptance_harness.sh --print-env-template
systems/scripts/bridge_tob_acceptance_harness.shThe harness reads repo-local .env and 0600 local secret files. It checks
readiness, performs Feishu URL verification, posts a synthetic inbound event,
and reports the result.
The live smoke checks bot-visible chats and a signed callback preflight. It is
read-only by default. BRIDGE_TOB_LIVE_FEISHU_SEND=true sends one real
redacted message:
cd systems
mix run --no-start scripts/bridge_tob_feishu_live_smoke.exs
BRIDGE_TOB_LIVE_FEISHU_SEND=true mix run --no-start scripts/bridge_tob_feishu_live_smoke.exsA first-message pass requires a real Feishu user message and the assistant reply in the same group. Select the group by name or redacted ID prefix:
BRIDGE_TOB_LIVE_FEISHU_TARGET_CHAT_NAME="your smoke group name" \
BRIDGE_TOB_LIVE_FEISHU_TARGET_CHAT_ID_PREFIX=oc_redacted \
BRIDGE_TOB_LIVE_FEISHU_BASE_MESSAGE_COUNT=26 \
BRIDGE_TOB_LIVE_FEISHU_MARKER_PREFIX=bridge-tob-live-real-xxxx \
mix run --no-start scripts/bridge_tob_feishu_live_smoke.exsTo create a dedicated smoke group in Feishu (an external side effect, off by default):
BRIDGE_TOB_LIVE_FEISHU_CREATE_DEDICATED_GROUP=true \
mix run --no-start scripts/bridge_tob_feishu_live_smoke.exs| Command | What |
|---|---|
mix test |
the full suite |
mix test --include multinode |
cross-node tests on two real BEAM nodes (epmd -daemon first) |
mix test --include clickhouse |
analytics sink against a live ClickHouse at 127.0.0.1:8123 |
SALIX_E2E_LLM_API_KEY=... mix test apps/salix_agent/test/live_llm*_e2e_test.exs --include live_llm --only live_llm |
real-provider checks. SALIX_LIVE_LLM_S3_BACKEND=aws uses local MinIO |
CI is in .github/workflows/systems-ci.yml.
mix release comma builds the release. Dockerfile builds the deployable
image. Configuration comes from the environment through config/runtime.exs.
See DEPLOYMENT.md.
Follow the systems_observability guide
and Observability.