# Factory rooms

> How factory rooms, turns, asking, reading along and teams work in the code.

Source: https://werker.cloud/docs/engineering/factory-rooms (updated 2026-12-01)

Using one is in [factories](../factories.md#rooms). A factory thread
is a room: several members take part, a message can address several of
them, and members can ask each other.

## How a room works

- **Participants.** A member joins a room when a message addresses it
  (`factory_thread_participants`).
- **Addressing.** Every message lists the members it addresses
  (`factory_messages.recipients`). Each addressed member is given a
  turn and replies.
- **Reading along.** The other members already in the room are given
  the message too, as a listening turn (`factory_turns.listening`).
  They are told to stay quiet unless it is squarely theirs and nobody
  addressed covers it. A quiet member reports `(quiet)`, which is
  never posted; a short report that names it, such as "Exactly
  (quiet)", counts too (`is_quiet` in
  `packages/db/src/rooms/quiet.ts`). Each read is a model call; a
  factory can switch reading along off (`factories.listen`). It
  applies to the user's messages and to what members ask, not to
  replies.
- **Read-along check.** When the workspace has `classify@1` bound, a
  listening turn first asks it whether the message is about the
  member's responsibilities, given the message, its author, who it
  addresses and the member (`listen_gate` in
  `packages/runtime/src/run/decisions/listen-gate.ts`, the question
  and rule in `packages/rules/src/decisions/listen-gate.ts`). Below
  0.3 the turn ends `(quiet)` at once, with no sandbox and no model
  turn, and its activity says "skipped reading along"; otherwise, and
  whenever no classifier is bound or the call fails or takes over 10
  seconds, the turn runs. The call's cost is on the listening run.
- **Turns.** A turn is one run answering one message
  (`factory_turns`). Its final report is posted to the room as the
  member's message. The private transcript is not.
- **Asking.** During a turn a member can call `ask_members` with other
  members' IDs and one message. The message is posted when the turn
  finishes, and each member asked takes a turn. When all of them have
  finished, the asker gets a follow-up turn with their replies. A
  member asked this way can ask others in turn. Members already
  waiting for its reply in that chain are not asked again or queued to
  listen, including when the question crosses rooms.
- **New rooms.** `open_room` does the same in a new room with only the
  members named, and the follow-up comes back to the room it was
  called from.
- **The user.** The room page's composer addresses one member,
  several, or everyone, from the recipient control or by typing
  `@name` (the member's name with hyphens for spaces), `@lead` or
  `@all` (`apps/app/src/lib/mentions/mentions.ts`). Typing `@` opens a
  menu of the members, `@lead` and `@all`; a picked one is typed in
  and addresses the member, and recognised mentions show as badges in
  the text ([menu and badges](ui.md#mentions-and-commands-on-new)).
  `/status` sends the lead a fixed request for a report
  (`apps/app/src/lib/mentions/room-menu.ts`). Starting a conversation
  from a factory page works the same way; the lead is the default.
- **Room links.** A message links to the room its turn opened, and
  that room links back. A factory's list of rooms updates live.

The tools are in `packages/runtime/src/workflow/step/tools.ts`;
dispatch, the join and the follow-up are in
`packages/db/src/rooms/factory-rooms.ts`.

## What the room shows

- **The person's messages, in full:** a message is the person's when
  they wrote it, or when a member wrote it to them. A member's message
  is to the person when it addresses nobody (a reply to a member who
  asked addresses that member, `settle_factory_turn` in
  `packages/db/src/rooms/factory-rooms.ts`) and the first turn of its
  member's chain answered the person's message. A follow-up turn
  continues an earlier turn of the same member
  (`factory_turns.continues_run_id`), so a member's final report back
  to the person after asking others is shown in full too.
- **Between members, folded:** everything else (asks, replies to an
  ask, and a member reading along who speaks up about an ask). Runs of
  such messages that come one after another fold into one line, "Team
  worked for X · N messages between members", where X runs from the
  message shown before the fold to the last folded one. A final report
  between two folds splits them.
- **Where:** `room_feed` and `is_for_person` in
  `apps/app/src/lib/factory/fold.ts` (unit tests in `fold.test.ts`).
  The factory page's conversation list picks each room's latest
  message to or from the person with the same rule in SQL
  (`room_states` in `packages/db/src/factories/status.ts`).
- **Work in progress:** turns queued or running are live rows at the
  end of the feed; a turn waiting for the person's answer is a card
  with the answer form there. A turn that ended with nothing posted
  (failed, stopped, finished without replying) still shows under the
  message it answers.
- **Live:** the room's stream re-reads on a message in the room and on
  any run of the workspace changing status (`follow_factory_thread` in
  `packages/core/src/factories/threads.ts`), and also sends the
  factory's status for the side panel (`follow_factory_status` in
  `packages/core/src/factories/status.ts`).

## Teams

A factory has one factory lead (`factory_members.role = 'lead'`, in no
team) and 1 to 4 teams (`factory_teams`: name, one line of purpose,
position).

- **One team:** the factory lead leads it and it has no lead of its
  own. It has one strip, every member is in every room, and `@lead`
  and `@all` reach the lead and everyone.
- **Two or more:** each team has exactly one team lead
  (`role = 'team_lead'`) and at most 4 members besides it.
- **Limits** are rules in `packages/rules/src/teams/limits.ts`
  (`team_plan_problems`, constants `factory_max_teams`,
  `factory_max_team_members` in `packages/domain/src/factories.ts`):
  at most 4 teams, one lead each, at most 4 members, names of at most
  40 characters that differ from each other, from members' names and
  from `lead`, `all`, `everyone` and `factory`. The board, the server,
  starter and factory proposals all check them and show the sentence
  where it bites.

Who may ask whom is `ask_refusal` in
`packages/rules/src/teams/shape.ts`, enforced in `ask_targets`
(`packages/runtime/src/run/factory/room.ts`); a refused `ask_members`
or `open_room` fails with its sentence. The rule is in
[factories](../factories.md#with-more-than-one-team). With one team
anyone may ask anyone.

Rooms:

- Each room belongs to a team (`factory_threads.team_id`) or, with
  null, is the leads' room, shown as "Whole factory (leads)". A room
  `open_room` opens belongs to the team of everyone in it, else it is
  a leads' room (`room_team`; `factory_asks.room_team_id`).
- **Reading along** applies only to the room's readers who are in it:
  its team's members in a team room, the leads in the leads' room
  (`room_readers`). A lead of another team asked into a room answers
  but does not read along, so a message in a team room never wakes
  another team (`send_factory_message` in
  `packages/core/src/factories/threads.ts`, `listener_ids` in the
  runtime).
- **Mentions** (`room_mentions`, `mentioned_ids`; the web app's
  `mentioned_members` with a scope). The server resolves mentions in
  the text too.
- **Turns per message** are counted across teams.
- **Fold:** a message between leads of different teams folds like one
  between members; only messages to or from the person stay unfolded
  (`apps/app/src/lib/factory/fold.ts`).

The Team page (`/factories/<id>/team`) is the shared team page
(`apps/app/src/lib/components/team-page/team-page.svelte`). Its board
is saved with `edit_factory_teams` (`packages/db/src/teams/edit.ts`)
in one transaction and one factory version; a removed team's rooms
become leads' rooms. Changes apply to new turns.

## Changing the team by asking

See
[a factory's team changed by asking](agents-workflows-factories.md#a-factorys-team-changed-by-asking).

## Settings

Each factory sets these under Room settings on its Team page
(`apps/app/src/lib/components/starter/room.svelte`, the same form a
saved team uses). What each does is in
[room settings](../factories.md#room-settings). The built-in prompt is
`factory_conversation_prompt` and the built-in turn limit
`factory_default_turn_limit`, in `packages/domain/src/factories.ts`.
An ask that would pass the limit is refused and the member is told to
reply with what it has.

A [starter](agents-workflows-factories.md#starters) saves these three
settings with the team, and a factory created from it starts with
them.

## Fixed rules

- **One ask per turn.** A turn can call `ask_members` or `open_room`
  once, naming as many members as it needs.
- **No change to a member while its team is working.** Editing a
  member, its agent or its equipment is refused while any turn in its
  factory is queued, running or waiting for an answer.
- **No turn while a new team is being fitted.** While the change that
  fits a new factory's team to its brief works, a message to the
  factory is refused and no member can be edited. A change by asking
  that a person asked for does not hold messages back; applying it
  waits until no turn is queued, running or waiting.

## Failure and stopping

- A turn that fails, is stopped or reports nothing counts as finished;
  the asker's follow-up is told which.
- An ask recorded by an attempt that lost its lease is not sent by the
  attempt that replaces it.
- **Stopping a room.** `/stop` in a room's composer (shown to a member
  who may stop runs) stops every turn of the room that is queued,
  running or waiting, and every such turn those set off in rooms they
  opened, with no follow-up turn: the exchange ends there. Asks they
  were waiting on are marked `factory_asks.stopped_at`. A member of
  another room who asked for a stopped turn still gets its follow-up.
  The composer says how many turns it stopped, here and elsewhere
  (`stop_room` in `packages/db/src/rooms/stop.ts`). The room panel has
  a `/stop` button for a role that may stop runs.
