Files
Davide Silvestri f5bc919473 feat(celery): make every task work on a threads worker, and use one in dev (#6926)
* 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
2026-12-03 09:39:52 +01:00
..

Architecture decision records

This directory holds architecture decision records (ADRs): one file per significant technical decision, written so that someone joining later can see what was decided, why, and what was ruled out.

Write an ADR when a change affects more than one module or team, is hard to reverse, or picks between several reasonable designs. Small, local choices belong in the PR description instead.

Files and numbering

  • Name the file NNN-short-kebab-title.md, taking the next free number (numbers are never reused, even when a record is dropped).
  • Open a PR with the ADR in Proposed status so the discussion happens in review.
  • Once accepted, edit the record only to update its status or to link the record that supersedes it. A changed decision gets a new ADR.

Template

Copy the block below into a new file. Keep sections short; drop any optional section that has nothing to say.

# ADR NNN: Title stating the decision area

|              |                                            |
| ------------ | ------------------------------------------ |
| Status       | Proposed                                   |
| Date         | YYYY-MM-DD                                 |
| Issue        | https://github.com/baserow/baserow/issues/ |
| Author       | Name (@github-handle)                      |
| Contributors | Name (@github-handle)                      |

## Summary

Two or three sentences: the problem and the decision taken.

## Context

What exists today, the constraints, and what is in and out of scope. Define any terms
the rest of the record relies on, in a table if there are several.

## Decision

What we will do. Split into numbered subsections when the decision has several parts.

## Options considered (optional)

| Option | Why not |
| ------ | ------- |
|        |         |

Use a subsection per option with pros and cons instead when the trade-off needs more
than a line.

## Consequences

What becomes easier or harder, new costs and risks, and follow-up work.

## Revisit triggers (optional)

Conditions under which this decision should be reopened.

Status values

Status Meaning
Proposed Under discussion in a PR.
Accepted Agreed and being or already implemented.
Rejected Discussed and not adopted; kept for the record.
Superseded Replaced by a later ADR; link it, e.g. Superseded by ADR 012.