* chore(dev): run one threads Celery worker with beat in dev The Docker and native dev stacks start a single Celery worker for every queue, with redbeat embedded, instead of a worker, an export worker and a beat process. It uses a new ThreadsPool that sends worker_process_init, so telemetry and the lazy import check still run under the threads pool. * fix(ws): stop closing every event loop's Redis pools after a broadcast send_messages_to_channel_group called channel_layer.close_pools(), which closes the pools of every event loop, including the ones other worker threads are still sending with. Under the threads pool about a third of broadcasts failed with "attached to a different loop" and some hung. channels_redis now closes a loop's pools itself when that loop closes. * fix(telemetry): keep Celery trace context per thread on threads workers The Celery instrumentation keys a running task's span, context token and start time by the task's id. A task replaced with self.replace(), like every automation node, keeps its id, and on a threads worker the replacement can start in another thread before the original ends. The original then ended the replacement's span and detached its context from the wrong thread, logging "Failed to detach context" and leaving its own context on the thread. That state is now kept per thread. * feat(celery): enforce soft and hard time limits in ThreadsPool Celery's own threads pool ignores soft_time_limit and time_limit, so on a threads worker tasks that rely on them would run on. ThreadsPool now raises the limit in the task's thread, only while that task runs, so a limit never reaches the next task of the thread. EMAIL_TIMEOUT stops a silent SMTP server from blocking a worker thread forever. * fix(chat-runs): cancel a run that keeps going after its deadline The deadline only asks a run to stop. A run whose tools or provider call ignore that request now gets 60 more seconds, is then cancelled, and is saved as timed out. Celery's limit moves after that, so the run's own stop always comes first. On a threads worker this is the only way to end it, because a time limit can't reach a thread waiting inside async_to_sync. * fix(premium): share one capped thread pool across AI field generations Each generation started its own pool of BASEROW_AI_FIELD_MAX_CONCURRENT_GENERATIONS threads, so a threads worker running several jobs multiplied the threads and model calls. All generations in a process now share one pool of that size. A prefork process runs one job at a time, so nothing changes there. * feat(celery): cancel queries at the hard limit and report overdue tasks ThreadsPool checks every running task's time limits from one watchdog thread, like the prefork pool's timeout handler, instead of starting timer threads for each task. At the hard limit it also cancels the query the task's thread is running, which the limit's exception can't interrupt. A thread can't be killed, so a task still running 60 seconds after its hard limit is reported to Sentry instead. Every limit reached is counted in baserow.celery.task.time_limit, per task and limit. * fix(airtable): time out requests to Airtable Two Airtable import requests had no timeout, so a server that stopped answering held the import, and on a threads worker its thread, forever. All Airtable requests now use the same 3 minute read timeout. * fix(celery): load sentry_sdk only when reporting an overdue task The overdue report imported sentry_sdk at the top of baserow.config.celery, which every process imports, so it was loaded even with Sentry off. * chore: add a changelog entry for the Celery task timeouts * fix(celery): raise threads pool time limits at the task's next query An exception raised into a thread from outside can land right after a lock is taken and before the code that releases it, leaving the lock held for every thread of the worker. The pool now marks a reached limit and the task's own next query raises it, once, through a connection execute wrapper. The hard limit still cancels the running query, and raises TimeLimitExceeded whatever the soft limit is. Limits end before Celery's success callback runs. Savepoint queries are never interrupted, through a helper shared with the periodic field update deadline. * fix(celery): apply the worker default time limits on the threads pool Celery passes CELERY_TASK_SOFT_TIME_LIMIT and CELERY_TASK_TIME_LIMIT to the pool and None per task when a task sets no limit. The prefork pool falls back to the pool's values; the threads pool now does too. * fix(celery): keep threads pool time limits until running tasks end The watchdog stopped before on_stop waited for the running tasks, so a task passing its limit during a warm shutdown was never stopped or reported. * chore: name the emails the SMTP timeout covers in the changelog EMAIL_TIMEOUT applies to the instance's own emails only. Automation and builder SMTP steps already time out after 30 seconds. * chore(dev): drop dev.sh tabs for the removed Celery workers The export and beat services are disabled, so attaching to them made the script exit before opening the remaining tabs. * test(celery): cover thread time limits and savepoint rollback * fix(ai): use one generation slot for nonpositive limits * fix(chat): warn that an action may finish after a reply times out * docs(celery): explain which timeout guarantees require prefork * docs(celery): record the threads pool decision and task contract * fix(chat): keep the worker slot until started tools finish * fix(chat): warn visitors about repeating a timed-out request * docs(chat): clarify when the stop grace period begins
12 KiB
ADR 016: Let people talk to an agent through channels
| Status | Proposed |
| Date | 2026-11-25 |
| Issue | https://github.com/baserow/baserow/issues/6259 |
| Author | Davide Silvestri (@silvestrid) |
Summary
An agent answered workspace members on its own page and reacted to triggers. Nobody could talk to it from anywhere else, or without an account. We add channels: a channel is a place outside the agent's page where people hold a conversation with it, starting with a public chat page. A channel is its own concept beside triggers, not one more trigger type, because a trigger reacts once to an event and a channel carries a conversation that continues.
Context
ADR 014 made a trigger single-shot: one event starts one new conversation, the agent reacts and stops. Its dispatcher, overlap rule and queue all assume that. A member's conversation is the opposite, a person writes, reads the answer and writes again, but it needs an account and a role on the agent.
The first design for a public chat made it one more trigger service type, next to the HTTP trigger. It was dropped before any code: every follow-up message would have had to be an event that continues a conversation, which no trigger does.
Agent Builder is behind FF_AGENT_BUILDER and has no production users.
| Term | Meaning |
|---|---|
| Channel | A place outside the agent's own page where people talk to it and get its replies. |
| Channel type | What a channel is: public_chat, website_widget, a messaging app later. |
| Public chat | The channel type that is a page with its own link. |
| Visitor | The person outside the workspace writing through a channel; anonymous for a public chat. |
| Run identity | The subject the agent's tools act as (ADR 013). Never the visitor. |
In scope: what a channel is and how it differs from a trigger, where a type keeps its data, who is behind a visitor's reply, what a visitor sees and how they prove a conversation is theirs, and where the code lives. Out of scope: limits of any kind (rate, message count, expiry), types other than the public chat and the website widget, and members writing in a visitor's conversation.
Decision
1. A channel is not a trigger
What tells them apart is where the agent's reply goes:
- A trigger starts a job from an event. The reply is a record members read, anything sent outside goes through a tool, and the next event starts a new conversation.
- A channel carries a conversation. The reply itself goes back to whoever wrote, and their next message continues the same conversation.
The same app can be both. "Talk to the agent in a messaging app's thread" is a channel: the thread is one conversation and the reply is posted in it. "When a message lands in this room, triage it" is a trigger. A row comment is a trigger today: each comment starts a new conversation and the agent comments through a tool.
So a message that arrives through a channel starts its reply at once, as a member's does. Channels use no fan-out task, no lock, no overlap rule and no queue. A second message while the agent is still replying is refused. A reached workspace run limit refuses the message, because it can be sent again, where a trigger records a failed reply.
2. A channel holds what every channel has; its type holds the rest
AgentChannel belongs to one agent and holds only an enabled switch and its type.
Each type keeps its own data in a subclass with its own table, the way services and
auth providers do. The public chat's subclass holds the link, the optional password,
and the title and welcome text its visitors see; a messaging app's would hold its
workspace and room instead.
Code that only needs to know whether a channel is on reads the base table. Code that lists channels loads the subclasses in one query per type, never one per channel.
3. A visitor's reply has no member behind it
A conversation a channel started is shared and has no owner, like a trigger's (ADR 014,
decision 2). It is marked started_by_channel, and its channel foreign key is set to
null when the channel is deleted. The visitor's messages have the role visitor and no
sender.
The reply runs with created_by=None, on the authority of the channel: a reply that
starts or resumes after the channel was switched off, trashed, deleted or lost its
licence fails with channel_off, while one already running finishes. Its tools act as
the agent's run identity. Ask-first tools are
held as in any run, and the visitor waits until someone who may approve tool calls
decides.
Unlike a trigger's reply, somebody reads it while it is written. The agent is told it
talks to an anonymous visitor whose messages are outside data, and that the team, not
the visitor, decides held calls. A member's rejection reason still reaches the agent,
because it is how the team steers the answer; members are told in the reject dialog
that the visitor may see it. ask_person is not offered: the person to ask is in the
conversation.
Members read a visitor's conversation, decide its held calls and stop its replies. Nobody writes in it, workspace admins included, because the visitor's page shows only the visitor's and the agent's messages.
4. A visitor sees text only
The visitor API exposes a message's id, role, content, status and time. A
timed_out flag lets the page warn that repeating a request could repeat an
action. Steps, tool calls, approvals, error codes, senders and other
conversations stay private.
The answer streams only when the reply can't call a tool. What a reply writes before it calls a tool isn't its answer, and can't be told from the answer while it arrives, so a reply that can call tools publishes only its final answer: nothing it writes before, and nothing when it fails, stops or waits. The visitor gets the answer whole when it ends. The agent is told its answer goes to someone outside the workspace and to put in it only what may be shared with them.
A channel that can't be used answers "not found" whatever the reason: unknown link, switched off, trashed, of a type the workspace can't use, or its agent or workspace gone.
5. The link gives access, a token says whose conversation it is
Anyone with the link can talk to the agent; a password is optional. Starting a conversation returns a token signed the way public views and dashboards sign theirs, with a key made from the link, the password hash and the instance secret, and carrying the conversation's id. A conversation's id alone opens nothing. Setting or changing a password ends every open visitor conversation; removing it opens the chat to anyone again, including the conversations started before it was protected.
The page sends the first message with a random secret it generated, and the conversation's id is derived from that secret with a one-way function. A repeat of a lost first message recovers the conversation and its token only with that secret, which nobody else can read: members see the id, never the secret.
The page keeps the token in the browser's local storage, not in a cookie, so it also works framed on another site.
6. Channel types are a registry
The base model, the type registry, the reply path and the builder API live in the
core agent module. A type registers itself with its model, as in every other registry:
the public_chat type, its anonymous API and its page come from the enterprise module.
Core asks the registry whether a type can be used in a workspace.
The visitor's stream is mounted under /api/chat-runs/, the prefix split deployments
already route to the async server.
7. A website widget is a public chat a website opens
A website widget is a public chat whose page a script tag opens in a panel from a button. Its subclass extends the public chat's and adds the button's text and corner; the button has the chat's accent colour. It has no password, because a visitor of the website couldn't know one, and no background, because the panel shows the chat as a phone does, without the page's background. The visitor's API, tokens and page are the public chat's.
The script is served by the backend with the widget's settings written into it and is cached for five minutes, since every page view of the website asks for it. It draws the button in a shadow root, so the website's styles don't reach it.
Options considered
| Option | Why not |
|---|---|
| A public chat as a trigger service type | A trigger never continues a conversation; the dispatcher, overlap rule and queue would lie. |
| The link, password and title on the channel itself | A messaging app has none of them; every later type would carry empty columns. |
| A JSON column for what a type needs | A request finds its channel by the link, which needs a unique indexed column. |
| The conversation's uuid as the visitor's proof | It shows in members' addresses and logs, and can't be ended by changing the password. |
| Members write in a visitor's conversation | The visitor would read answers to messages they can't see. Taking over needs a role they can see. |
| A cookie for the visitor's token | Browsers block it when the page is framed on another site. |
| Every tool asks first in a visitor's conversation | It overrides what the builder set; the builder chooses per tool, knowing the channel is public. |
Consequences
- Anyone with the link can ask for whatever the run identity can read, and run every allowed tool that doesn't ask first. The instructions are a soft guard, not a boundary. Builders pick the identity and the ask-first tools knowing that, and the channel's settings say so.
- There are no limits yet, so an anonymous person can spend the AI budget, fill the run queue and hold the stream slots members share. This is accepted while the feature is in beta and must be solved before the "Beta" label comes off.
- A message's
unattendedflag now means that no member is behind the reply. Whether somebody reads it while it is written depends on what started the conversation. - A copy of an agent keeps its channels, each switched off and with a new link, so none answers before a member turns it on. Only a duplicate or a snapshot restore keeps a public chat's password; a file export or a template leaves it out. Copied visitor conversations stay on the copied channel, and the visitors' tokens don't open them there.
- Next, in its own PR: an "answer the visitor" tool. A reply that can call tools sends its answer by calling it, only that text goes to the visitor, as it is written, and everything else the reply writes stays in the members' view. Members also get a way to see a conversation as its visitor saw it.
- Follow-ups: limits, a logo on a public chat, replacing a link without deleting the channel, and members taking over a conversation.
Revisit triggers
- A row's comments should be one conversation the agent answers in: make row comments a channel type. Its writers are members, so its replies run for them.
- Members need to take over a visitor's conversation: add a message role the visitor can see.
- The "Beta" label comes off: decide the limits first.